Create a nil value type for DisableDropSound. (#114)

This commit is contained in:
Glen M 2018-12-05 11:42:59 -05:00 committed by Ben Wallis
parent 892b2f15f2
commit 2415be089b
7 changed files with 49 additions and 21 deletions

View File

@ -0,0 +1,16 @@
namespace Filtration.ObjectModel.BlockItemBaseTypes
{
public abstract class NilBlockItem : BlockItemBase
{
protected NilBlockItem()
{
}
public override string OutputText => PrefixText;
public override string SummaryText => DisplayHeading;
public override int MaximumAllowed => 1;
public abstract string Description { get; }
}
}

View File

@ -4,18 +4,15 @@ using Filtration.ObjectModel.Enums;
namespace Filtration.ObjectModel.BlockItemTypes namespace Filtration.ObjectModel.BlockItemTypes
{ {
public sealed class DisableDropSoundBlockItem : BooleanBlockItem, IAudioVisualBlockItem public sealed class DisableDropSoundBlockItem : NilBlockItem, IAudioVisualBlockItem
{ {
public DisableDropSoundBlockItem() public DisableDropSoundBlockItem() : base()
{
}
public DisableDropSoundBlockItem(bool booleanValue) : base(booleanValue)
{ {
} }
public override string PrefixText => "DisableDropSound"; public override string PrefixText => "DisableDropSound";
public override string DisplayHeading => "Disable Drop Sound"; public override string DisplayHeading => "Disable Drop Sound";
public override string Description => "Default drop sound disabled.";
public override Color SummaryBackgroundColor => Colors.Transparent; public override Color SummaryBackgroundColor => Colors.Transparent;
public override Color SummaryTextColor => Colors.Transparent; public override Color SummaryTextColor => Colors.Transparent;
public override BlockItemOrdering SortOrder => BlockItemOrdering.DisableDropSound; public override BlockItemOrdering SortOrder => BlockItemOrdering.DisableDropSound;

View File

@ -75,6 +75,7 @@
<Compile Include="BlockItemBaseTypes\DualIntegerBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\DualIntegerBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\EffectColorBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\EffectColorBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\IconBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\IconBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\NilBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StringBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\StringBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\StrIntBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\StrIntBlockItem.cs" />
<Compile Include="BlockItemBaseTypes\IntegerBlockItem.cs" /> <Compile Include="BlockItemBaseTypes\IntegerBlockItem.cs" />

View File

@ -919,7 +919,7 @@ namespace Filtration.Parser.Tests.Services
{ {
// Arrange // Arrange
var inputString = "Show" + Environment.NewLine + var inputString = "Show" + Environment.NewLine +
" DisableDropSound True"; " DisableDropSound # Test";
// Act // Act
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript);
@ -928,7 +928,7 @@ namespace Filtration.Parser.Tests.Services
Assert.AreEqual(1, result.BlockItems.Count(b => b is DisableDropSoundBlockItem)); Assert.AreEqual(1, result.BlockItems.Count(b => b is DisableDropSoundBlockItem));
var blockItem = result.BlockItems.OfType<DisableDropSoundBlockItem>().First(); var blockItem = result.BlockItems.OfType<DisableDropSoundBlockItem>().First();
Assert.IsTrue(blockItem.BooleanValue); Assert.AreEqual(blockItem.Comment, " Test");
} }
[Test] [Test]
@ -965,7 +965,7 @@ namespace Filtration.Parser.Tests.Services
" SetBorderColor 0 0 0" + Environment.NewLine + " SetBorderColor 0 0 0" + Environment.NewLine +
" SetFontSize 50" + Environment.NewLine + " SetFontSize 50" + Environment.NewLine +
" PlayAlertSound 3" + Environment.NewLine + " PlayAlertSound 3" + Environment.NewLine +
" DisableDropSound False" + Environment.NewLine + " DisableDropSound # False" + Environment.NewLine +
" CustomAlertSound \"test.mp3\" # customSoundTheme" + Environment.NewLine + " CustomAlertSound \"test.mp3\" # customSoundTheme" + Environment.NewLine +
" MinimapIcon 2 Green Triangle # iconTheme" + Environment.NewLine + " MinimapIcon 2 Green Triangle # iconTheme" + Environment.NewLine +
" PlayEffect Green Temp # effectTheme" + Environment.NewLine; " PlayEffect Green Temp # effectTheme" + Environment.NewLine;
@ -1075,7 +1075,7 @@ namespace Filtration.Parser.Tests.Services
Assert.AreEqual(0, result.BlockItems.OfType<SoundBlockItem>().Count()); Assert.AreEqual(0, result.BlockItems.OfType<SoundBlockItem>().Count());
var disableDropSoundBlockItem = result.BlockItems.OfType<DisableDropSoundBlockItem>().First(); var disableDropSoundBlockItem = result.BlockItems.OfType<DisableDropSoundBlockItem>().First();
Assert.IsFalse(disableDropSoundBlockItem.BooleanValue); Assert.AreEqual(disableDropSoundBlockItem.Comment, " False");
var customSoundBlockItem = result.BlockItems.OfType<CustomSoundBlockItem>().First(); var customSoundBlockItem = result.BlockItems.OfType<CustomSoundBlockItem>().First();
Assert.AreEqual("test.mp3", customSoundBlockItem.Value); Assert.AreEqual("test.mp3", customSoundBlockItem.Value);
@ -2065,7 +2065,7 @@ namespace Filtration.Parser.Tests.Services
" SetBorderColor 255 1 254" + Environment.NewLine + " SetBorderColor 255 1 254" + Environment.NewLine +
" SetFontSize 50" + Environment.NewLine + " SetFontSize 50" + Environment.NewLine +
" PlayAlertSound 6 90" + Environment.NewLine + " PlayAlertSound 6 90" + Environment.NewLine +
" DisableDropSound True" + Environment.NewLine + " DisableDropSound" + Environment.NewLine +
" MinimapIcon 1 Blue Circle" + Environment.NewLine + " MinimapIcon 1 Blue Circle" + Environment.NewLine +
" PlayEffect Red Temp" + Environment.NewLine + " PlayEffect Red Temp" + Environment.NewLine +
" CustomAlertSound \"test.mp3\""; " CustomAlertSound \"test.mp3\"";
@ -2120,7 +2120,7 @@ namespace Filtration.Parser.Tests.Services
_testUtility.TestBlock.BlockItems.Add(new MapTierBlockItem(FilterPredicateOperator.LessThan, 10)); _testUtility.TestBlock.BlockItems.Add(new MapTierBlockItem(FilterPredicateOperator.LessThan, 10));
_testUtility.TestBlock.BlockItems.Add(new MapIconBlockItem(IconSize.Medium, IconColor.Blue, IconShape.Circle)); _testUtility.TestBlock.BlockItems.Add(new MapIconBlockItem(IconSize.Medium, IconColor.Blue, IconShape.Circle));
_testUtility.TestBlock.BlockItems.Add(new PlayEffectBlockItem(EffectColor.Red, true)); _testUtility.TestBlock.BlockItems.Add(new PlayEffectBlockItem(EffectColor.Red, true));
_testUtility.TestBlock.BlockItems.Add(new DisableDropSoundBlockItem(true)); _testUtility.TestBlock.BlockItems.Add(new DisableDropSoundBlockItem());
// Act // Act
var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock); var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock);

View File

@ -327,7 +327,7 @@ namespace Filtration.Parser.Services
// Only ever use the last DisableDropSound item encountered as multiples aren't valid. // Only ever use the last DisableDropSound item encountered as multiples aren't valid.
RemoveExistingBlockItemsOfType<DisableDropSoundBlockItem>(block); RemoveExistingBlockItemsOfType<DisableDropSoundBlockItem>(block);
AddBooleanItemToBlockItems<DisableDropSoundBlockItem>(block, trimmedLine); AddNilItemToBlockItems<DisableDropSoundBlockItem>(block, trimmedLine);
break; break;
} }
case "MinimapIcon": case "MinimapIcon":
@ -512,6 +512,13 @@ namespace Filtration.Parser.Services
} }
} }
private static void AddNilItemToBlockItems<T>(IItemFilterBlock block, string inputString) where T : NilBlockItem
{
var blockItem = Activator.CreateInstance<T>();
blockItem.Comment = GetTextAfterFirstComment(inputString);
block.BlockItems.Add(blockItem);
}
private static void AddNumericFilterPredicateItemToBlockItems<T>(IItemFilterBlock block, string inputString) where T : NumericFilterPredicateBlockItem private static void AddNumericFilterPredicateItemToBlockItems<T>(IItemFilterBlock block, string inputString) where T : NumericFilterPredicateBlockItem
{ {
var blockItem = Activator.CreateInstance<T>(); var blockItem = Activator.CreateInstance<T>();

View File

@ -246,6 +246,13 @@
</userControls:ThemeComponentSelectionControl> </userControls:ThemeComponentSelectionControl>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
<!-- Disable Drop Sound Template -->
<DataTemplate DataType="{x:Type blockItemBaseTypes:NilBlockItem}">
<Grid>
<TextBlock Text="{Binding Description}" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ContentControl.Resources> </ContentControl.Resources>
</ContentControl> </ContentControl>
</Grid> </Grid>

View File

@ -1309,10 +1309,10 @@ namespace Filtration.ViewModels
} }
} }
if (input.Count > 0) if (input.Count > 0)
{ {
_scriptCommandManager.ExecuteCommand(new RemoveBlockItemFromBlocksCommand(input)); _scriptCommandManager.ExecuteCommand(new RemoveBlockItemFromBlocksCommand(input));
SetDirtyFlag(); SetDirtyFlag();
} }
} }
@ -1335,15 +1335,15 @@ namespace Filtration.ViewModels
} }
if (!found) { if (!found) {
var item = new DisableDropSoundBlockItem(true); var item = new DisableDropSoundBlockItem();
input.Add(new Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>(blockItems, item)); input.Add(new Tuple<ObservableCollection<IItemFilterBlockItem>, IItemFilterBlockItem>(blockItems, item));
} }
} }
if (input.Count > 0) if (input.Count > 0)
{ {
_scriptCommandManager.ExecuteCommand(new AddBlockItemToBlocksCommand(input)); _scriptCommandManager.ExecuteCommand(new AddBlockItemToBlocksCommand(input));
SetDirtyFlag(); SetDirtyFlag();
} }
} }