Improve test block for beam feature

This commit is contained in:
azakhi 2018-08-22 20:20:12 +03:00
parent 2a7df9a1ca
commit 4c76dc9bab
6 changed files with 85 additions and 11 deletions

View File

@ -0,0 +1,53 @@
using System;
using System.Windows.Media;
using Filtration.ObjectModel.ThemeEditor;
namespace Filtration.ObjectModel.BlockItemBaseTypes
{
public abstract class ColorBooleanBlockItem : BlockItemBase, IAudioVisualBlockItem
{
private Color _color;
private bool _booleanValue;
protected ColorBooleanBlockItem()
{
}
protected ColorBooleanBlockItem(Color color, bool booleanValue)
{
Color = color;
BooleanValue = booleanValue;
}
public override string OutputText => PrefixText + " " + +Color.R + " " + Color.G + " "
+ Color.B + (Color.A < 255 ? " " + Color.A : string.Empty) +
(BooleanValue ? " True" : " False");
public override string SummaryText => string.Empty;
public override Color SummaryBackgroundColor => Colors.Transparent;
public override Color SummaryTextColor => Colors.Transparent;
public Color Color
{
get { return _color; }
set
{
_color = value;
IsDirty = true;
OnPropertyChanged();
}
}
public bool BooleanValue
{
get { return _booleanValue; }
set
{
_booleanValue = value;
IsDirty = true;
OnPropertyChanged();
}
}
}
}

View File

@ -3,13 +3,13 @@ using Filtration.ObjectModel.BlockItemBaseTypes;
namespace Filtration.ObjectModel.BlockItemTypes
{
public class BeamBlockItem : ColorBlockItem
public class BeamBlockItem : ColorBooleanBlockItem
{
public BeamBlockItem()
{
}
public BeamBlockItem(Color color) : base(color)
public BeamBlockItem(Color color, bool booleanValue) : base(color, booleanValue)
{
}

View File

@ -52,6 +52,7 @@
<Compile Include="BlockItemBaseTypes\BlockItemBase.cs" />
<Compile Include="BlockItemBaseTypes\BooleanBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\ColorBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\ColorBooleanBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\DualIntegerBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StringBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StringIntBlockItem.cs" />

View File

@ -914,7 +914,7 @@ namespace Filtration.Parser.Tests.Services
{
// Arrange
var inputString = "Show" + Environment.NewLine +
" BeamColor 255 20 100";
" BeamColor 255 20 100 True";
// Act
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript);
@ -924,7 +924,8 @@ namespace Filtration.Parser.Tests.Services
var blockItem = result.BlockItems.OfType<BeamBlockItem>().First();
Assert.AreEqual(255, blockItem.Color.R);
Assert.AreEqual(20, blockItem.Color.G);
Assert.AreEqual(100, blockItem.Color.B);
Assert.AreEqual(100, blockItem.Color.B);
Assert.IsTrue(blockItem.BooleanValue);
}
[Test]
@ -962,7 +963,7 @@ namespace Filtration.Parser.Tests.Services
" PlayAlertSound 3" + Environment.NewLine +
" DisableDropSound False" + Environment.NewLine +
" Icon Icon2" + Environment.NewLine +
" BeamColor 255 100 5" + Environment.NewLine;
" BeamColor 255 100 5 false" + Environment.NewLine;
// Act
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript);
@ -1075,6 +1076,7 @@ namespace Filtration.Parser.Tests.Services
Assert.AreEqual(255, beamBlockItem.Color.R);
Assert.AreEqual(100, beamBlockItem.Color.G);
Assert.AreEqual(5, beamBlockItem.Color.B);
Assert.IsFalse(beamBlockItem.BooleanValue);
}
[Test]
@ -1951,7 +1953,7 @@ namespace Filtration.Parser.Tests.Services
" PlayAlertSound 6 90" + Environment.NewLine +
" DisableDropSound True";/* + Environment.NewLine +
" Icon Icon4";
" BeamColor 120 130 140";*/
" BeamColor 120 130 140 False";*/
_testUtility.TestBlock.BlockItems.Add(new ActionBlockItem(BlockAction.Show));
_testUtility.TestBlock.BlockItems.Add(new IdentifiedBlockItem(true));
@ -1996,7 +1998,7 @@ namespace Filtration.Parser.Tests.Services
_testUtility.TestBlock.BlockItems.Add(new ElderMapBlockItem(true));
_testUtility.TestBlock.BlockItems.Add(new DisableDropSoundBlockItem(true));
_testUtility.TestBlock.BlockItems.Add(new IconBlockItem("Icon4"));
_testUtility.TestBlock.BlockItems.Add(new BeamBlockItem(new Color { A = 255, R = 120, G = 130, B = 140 }));
_testUtility.TestBlock.BlockItems.Add(new BeamBlockItem(new Color { A = 255, R = 120, G = 130, B = 140 }, false));
// Act
var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock);

View File

@ -308,7 +308,7 @@ namespace Filtration.Parser.Services
{
var blockItemValue = new IconBlockItem
{
Value = match.Groups[1].Value,
Value = match.Groups[1].Value
};
block.BlockItems.Add(blockItemValue);
}
@ -318,8 +318,15 @@ namespace Filtration.Parser.Services
{
// Only ever use the last BeamColor item encountered as multiples aren't valid.
RemoveExistingBlockItemsOfType<BeamBlockItem>(block);
AddColorItemToBlockItems<BeamBlockItem>(block, trimmedLine);
var result = Regex.Matches(trimmedLine, @"([\w\s]*)(True|False)[#]?(.*)", RegexOptions.IgnoreCase);
var color = GetColorFromString(result[0].Groups[1].Value);
var beamBlockItem = new BeamBlockItem
{
Color = GetColorFromString(result[0].Groups[1].Value),
BooleanValue = result[0].Groups[2].Value.Trim().ToLowerInvariant() == "true"
};
block.BlockItems.Add(beamBlockItem);
break;
}
}

View File

@ -85,7 +85,18 @@
<DataTemplate DataType="{x:Type blockItemTypes:SocketGroupBlockItem}">
<userControls:EditableListBoxControl Margin="5,5,5,5" ItemsSource="{Binding Items}" />
</DataTemplate>
<!-- Beam Block Template -->
<DataTemplate DataType="{x:Type blockItemTypes:BeamBlockItem}">
<StackPanel>
<WrapPanel VerticalAlignment="Center" Margin="5,5,5,5">
<RadioButton IsChecked="{Binding BooleanValue}" Margin="0,0,10,0">Permanent</RadioButton>
<RadioButton IsChecked="{Binding BooleanValue, Converter={StaticResource BoolInverterConverter}}" >Temporary</RadioButton>
</WrapPanel>
<xctk:ColorPicker SelectedColor="{Binding Color}" AvailableColors="{Binding ElementName=BlockItemContentControl, Path=DataContext.AvailableColors }" ShowAvailableColors="True" AvailableColorsHeader="Path of Exile Colors"/>
</StackPanel>
</DataTemplate>
<!-- Color Template -->
<DataTemplate DataType="{x:Type blockItemBaseTypes:ColorBlockItem}">
<StackPanel>