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 namespace Filtration.ObjectModel.BlockItemTypes
{ {
public class BeamBlockItem : ColorBlockItem public class BeamBlockItem : ColorBooleanBlockItem
{ {
public BeamBlockItem() 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\BlockItemBase.cs" />
<Compile Include="BlockItemBaseTypes\BooleanBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\BooleanBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\ColorBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\ColorBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\ColorBooleanBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\DualIntegerBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\DualIntegerBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StringBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\StringBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StringIntBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\StringIntBlockItem.cs" />

View File

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

View File

@ -308,7 +308,7 @@ namespace Filtration.Parser.Services
{ {
var blockItemValue = new IconBlockItem var blockItemValue = new IconBlockItem
{ {
Value = match.Groups[1].Value, Value = match.Groups[1].Value
}; };
block.BlockItems.Add(blockItemValue); block.BlockItems.Add(blockItemValue);
} }
@ -319,7 +319,14 @@ namespace Filtration.Parser.Services
// Only ever use the last BeamColor item encountered as multiples aren't valid. // Only ever use the last BeamColor item encountered as multiples aren't valid.
RemoveExistingBlockItemsOfType<BeamBlockItem>(block); 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; break;
} }
} }

View File

@ -86,6 +86,17 @@
<userControls:EditableListBoxControl Margin="5,5,5,5" ItemsSource="{Binding Items}" /> <userControls:EditableListBoxControl Margin="5,5,5,5" ItemsSource="{Binding Items}" />
</DataTemplate> </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 --> <!-- Color Template -->
<DataTemplate DataType="{x:Type blockItemBaseTypes:ColorBlockItem}"> <DataTemplate DataType="{x:Type blockItemBaseTypes:ColorBlockItem}">
<StackPanel> <StackPanel>