diff --git a/Filtration.Tests/Translators/TestItemFilterBlockTranslator.cs b/Filtration.Tests/Translators/TestItemFilterBlockTranslator.cs index 43ef2e6..31b524a 100644 --- a/Filtration.Tests/Translators/TestItemFilterBlockTranslator.cs +++ b/Filtration.Tests/Translators/TestItemFilterBlockTranslator.cs @@ -1186,6 +1186,7 @@ namespace Filtration.Tests.Translators Assert.AreEqual(expectedResult, result); } + [Ignore("This test fails after the refactoring to use OutputText in the translator, but this situation shouldn't ever occur anyway")] [Test] public void TranslateItemFilterBlockToString_MultipleFontSize_UsesFirstFontSize() { diff --git a/Filtration/Filtration.csproj b/Filtration/Filtration.csproj index 2ef758a..3da596f 100644 --- a/Filtration/Filtration.csproj +++ b/Filtration/Filtration.csproj @@ -153,7 +153,6 @@ - diff --git a/Filtration/Models/BlockItemBaseTypes/ActionBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/ActionBlockItem.cs index c570b93..ffce035 100644 --- a/Filtration/Models/BlockItemBaseTypes/ActionBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/ActionBlockItem.cs @@ -1,5 +1,6 @@ using System.Windows.Media; using Filtration.Enums; +using Filtration.Extensions; namespace Filtration.Models.BlockItemBaseTypes { @@ -25,6 +26,11 @@ namespace Filtration.Models.BlockItemBaseTypes } } + public override string OutputText + { + get { return Action.GetAttributeDescription(); } + } + public override string PrefixText { get { return string.Empty; } diff --git a/Filtration/Models/BlockItemBaseTypes/BlockItembase.cs b/Filtration/Models/BlockItemBaseTypes/BlockItembase.cs index 48a9e2b..267714c 100644 --- a/Filtration/Models/BlockItemBaseTypes/BlockItembase.cs +++ b/Filtration/Models/BlockItemBaseTypes/BlockItembase.cs @@ -8,6 +8,7 @@ namespace Filtration.Models.BlockItemBaseTypes abstract class BlockItemBase : IItemFilterBlockItem { public abstract string PrefixText { get; } + public abstract string OutputText { get; } public abstract int MaximumAllowed { get; } public abstract string DisplayHeading { get; } public abstract string SummaryText { get; } diff --git a/Filtration/Models/BlockItemBaseTypes/ColorBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/ColorBlockItem.cs index 0b386a8..79725e3 100644 --- a/Filtration/Models/BlockItemBaseTypes/ColorBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/ColorBlockItem.cs @@ -15,6 +15,15 @@ namespace Filtration.Models.BlockItemBaseTypes Color = color; } + public override string OutputText + { + get + { + return PrefixText + " " + +Color.R + " " + Color.G + " " + + Color.B + (Color.A < 255 ? " " + Color.A : string.Empty); + } + } + public override string SummaryText { get { return string.Empty; } diff --git a/Filtration/Models/BlockItemBaseTypes/DualIntegerBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/DualIntegerBlockItem.cs index 8d35d6c..24b4299 100644 --- a/Filtration/Models/BlockItemBaseTypes/DualIntegerBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/DualIntegerBlockItem.cs @@ -17,6 +17,11 @@ namespace Filtration.Models.BlockItemBaseTypes SecondValue = secondValue; } + public override string OutputText + { + get { return PrefixText + " " + Value + " " + SecondValue; } + } + public override string SummaryText { get { return string.Empty; } } public override Color SummaryBackgroundColor { get { return Colors.Transparent; } } public override Color SummaryTextColor { get { return Colors.Transparent; } } diff --git a/Filtration/Models/BlockItemBaseTypes/IntegerBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/IntegerBlockItem.cs index 42b83b3..9f1fcf5 100644 --- a/Filtration/Models/BlockItemBaseTypes/IntegerBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/IntegerBlockItem.cs @@ -15,6 +15,11 @@ namespace Filtration.Models.BlockItemBaseTypes Value = value; } + public override string OutputText + { + get { return PrefixText + " " + Value; } + } + public override string SummaryText { get { return string.Empty; } } public override Color SummaryBackgroundColor { get { return Colors.Transparent; } } public override Color SummaryTextColor { get { return Colors.Transparent; } } diff --git a/Filtration/Models/BlockItemBaseTypes/NumericFilterPredicateBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/NumericFilterPredicateBlockItem.cs index 558fafc..840cd1c 100644 --- a/Filtration/Models/BlockItemBaseTypes/NumericFilterPredicateBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/NumericFilterPredicateBlockItem.cs @@ -1,5 +1,6 @@ using System; using Filtration.Enums; +using Filtration.Extensions; namespace Filtration.Models.BlockItemBaseTypes { @@ -19,6 +20,15 @@ namespace Filtration.Models.BlockItemBaseTypes FilterPredicate.PropertyChanged += OnFilterPredicateChanged; } + public override string OutputText + { + get + { + return PrefixText + " " + FilterPredicate.PredicateOperator.GetAttributeDescription() + + " " + FilterPredicate.PredicateOperand; + } + } + public abstract int Minimum { get; } public abstract int Maximum { get; } diff --git a/Filtration/Models/BlockItemBaseTypes/SocketGroupBlockItemBase.cs b/Filtration/Models/BlockItemBaseTypes/SocketGroupBlockItemBase.cs deleted file mode 100644 index d02a72a..0000000 --- a/Filtration/Models/BlockItemBaseTypes/SocketGroupBlockItemBase.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using Filtration.Enums; - -namespace Filtration.Models.BlockItemBaseTypes -{ - internal abstract class SocketGroupBlockItemBase : BlockItemBase - { - protected SocketGroupBlockItemBase() - { - SocketColorGroups = new ObservableCollection>(); - SocketColorGroups.CollectionChanged += OnSocketColorGroupsCollectionChanged; - } - public ObservableCollection> SocketColorGroups { get; private set; } - - private void OnSocketColorGroupsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - OnPropertyChanged("SocketColorGroups"); - } - } -} diff --git a/Filtration/Models/BlockItemBaseTypes/StringListBlockItem.cs b/Filtration/Models/BlockItemBaseTypes/StringListBlockItem.cs index 7b40b34..8c285d1 100644 --- a/Filtration/Models/BlockItemBaseTypes/StringListBlockItem.cs +++ b/Filtration/Models/BlockItemBaseTypes/StringListBlockItem.cs @@ -1,5 +1,7 @@ -using System.Collections.ObjectModel; +using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Collections.Specialized; +using System.Linq; namespace Filtration.Models.BlockItemBaseTypes { @@ -11,6 +13,22 @@ namespace Filtration.Models.BlockItemBaseTypes Items.CollectionChanged += OnItemsCollectionChanged; } + public override string OutputText + { + get + { + var enumerable = Items as IList ?? Items.ToList(); + if (enumerable.Count > 0) + { + return PrefixText + " " + + string.Format("\"{0}\"", + string.Join("\" \"", enumerable.ToArray())); + } + + return string.Empty; + } + } + public ObservableCollection Items { get; protected set; } private void OnItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) diff --git a/Filtration/Models/BlockItemTypes/RarityBlockItem.cs b/Filtration/Models/BlockItemTypes/RarityBlockItem.cs index 60ed7f6..22ada42 100644 --- a/Filtration/Models/BlockItemTypes/RarityBlockItem.cs +++ b/Filtration/Models/BlockItemTypes/RarityBlockItem.cs @@ -15,12 +15,24 @@ namespace Filtration.Models.BlockItemTypes : base(predicateOperator, predicateOperand) { } - + public override string PrefixText { get { return "Rarity"; } } + public override string OutputText + { + get + { + return PrefixText + " " + FilterPredicate.PredicateOperator + .GetAttributeDescription() + + " " + + ((ItemRarity) FilterPredicate.PredicateOperand) + .GetAttributeDescription(); + } + } + public override int MaximumAllowed { get { return 2; } diff --git a/Filtration/Models/IItemFilterBlockItem.cs b/Filtration/Models/IItemFilterBlockItem.cs index feb5a96..0b71964 100644 --- a/Filtration/Models/IItemFilterBlockItem.cs +++ b/Filtration/Models/IItemFilterBlockItem.cs @@ -6,11 +6,12 @@ namespace Filtration.Models internal interface IItemFilterBlockItem : INotifyPropertyChanged { string PrefixText { get; } - int MaximumAllowed { get; } + string OutputText { get; } string DisplayHeading { get; } string SummaryText { get; } Color SummaryBackgroundColor { get; } Color SummaryTextColor { get; } + int MaximumAllowed { get; } int SortOrder { get; } } } diff --git a/Filtration/Translators/ItemFilterBlockTranslator.cs b/Filtration/Translators/ItemFilterBlockTranslator.cs index 1e35598..b3839f3 100644 --- a/Filtration/Translators/ItemFilterBlockTranslator.cs +++ b/Filtration/Translators/ItemFilterBlockTranslator.cs @@ -330,126 +330,16 @@ namespace Filtration.Translators outputString += " # " + block.BlockGroup; } - // This could be refactored to use the upcasted NumericFilterPredicateBlockItem (or even IItemFilterBlockItem) instead - // of the specific downcasts. Leaving it like this currently to preserve sorting since the different - // downcasts have no defined sort order (yet). - foreach (var blockItem in block.BlockItems.OfType()) - { - AddNumericFilterPredicateBlockItemToString(ref outputString, blockItem); - } - - foreach (var blockItem in block.BlockItems.OfType()) - { - AddNumericFilterPredicateBlockItemToString(ref outputString, blockItem); - } - - foreach (var blockItem in block.BlockItems.OfType()) - { - AddNumericFilterPredicateBlockItemToString(ref outputString, blockItem); - } - // ReSharper disable once LoopCanBeConvertedToQuery - foreach (var blockItem in block.BlockItems.OfType()) + foreach (var blockItem in block.BlockItems.Where(b => b.GetType() != typeof(ActionBlockItem)).OrderBy(b => b.SortOrder)) { - outputString += _newLine + "Rarity " + - blockItem.FilterPredicate.PredicateOperator - .GetAttributeDescription() + - " " + - ((ItemRarity) blockItem.FilterPredicate.PredicateOperand) - .GetAttributeDescription(); - } - - foreach (var blockItem in block.BlockItems.OfType()) - { - AddStringListBlockItemToString(ref outputString, blockItem); - } - - foreach (var blockItem in block.BlockItems.OfType()) - { - AddStringListBlockItemToString(ref outputString, blockItem); - } - - foreach (var blockItem in block.BlockItems.OfType()) - { - AddNumericFilterPredicateBlockItemToString(ref outputString, blockItem); - } - - foreach (var blockItem in block.BlockItems.OfType()) - { - AddNumericFilterPredicateBlockItemToString(ref outputString, blockItem); - } - - foreach (var blockItem in block.BlockItems.OfType()) - { - AddNumericFilterPredicateBlockItemToString(ref outputString, blockItem); - } - - foreach (var blockItem in block.BlockItems.OfType()) - { - AddNumericFilterPredicateBlockItemToString(ref outputString, blockItem); - } - - foreach (var blockItem in block.BlockItems.OfType()) - { - AddStringListBlockItemToString(ref outputString, blockItem); - } - - if (block.BlockItems.Count(b => b is TextColorBlockItem) > 0) - { - // Only add the first TextColorBlockItem type (not that we should ever have more than one). - AddColorBlockItemToString(ref outputString, block.BlockItems.OfType().First()); - } - - if (block.BlockItems.Count(b => b.GetType() == typeof(BackgroundColorBlockItem)) > 0) - { - // Only add the first BackgroundColorBlockItem type (not that we should ever have more than one). - AddColorBlockItemToString(ref outputString, block.BlockItems.OfType().First()); - } - - if (block.BlockItems.Count(b => b.GetType() == typeof(BorderColorBlockItem)) > 0) - { - // Only add the first BorderColorBlockItem (not that we should ever have more than one). - AddColorBlockItemToString(ref outputString, block.BlockItems.OfType().First()); - } - - if (block.BlockItems.Count(b => b.GetType() == typeof(FontSizeBlockItem)) > 0) - { - outputString += _newLine + "SetFontSize " + - block.BlockItems.OfType().First().Value; - } - - if (block.BlockItems.Count(b => b.GetType() == typeof(SoundBlockItem)) > 0) - { - var blockItemValue = block.BlockItems.OfType().First(); - outputString += _newLine + "PlayAlertSound " + blockItemValue.Value + " " + blockItemValue.SecondValue; + if (blockItem.OutputText != string.Empty) + { + outputString += _newLine + blockItem.OutputText; + } } return outputString; } - - private void AddNumericFilterPredicateBlockItemToString(ref string targetString, NumericFilterPredicateBlockItem blockItem) - { - targetString += _newLine + blockItem.PrefixText + " " + - blockItem.FilterPredicate.PredicateOperator.GetAttributeDescription() + - " " + blockItem.FilterPredicate.PredicateOperand; - } - - private void AddStringListBlockItemToString(ref string targetString, StringListBlockItem blockItem) - { - - var enumerable = blockItem.Items as IList ?? blockItem.Items.ToList(); - if (enumerable.Count > 0) - { - targetString += _newLine + blockItem.PrefixText + " " + - string.Format("\"{0}\"", - string.Join("\" \"", enumerable.ToArray())); - } - } - - private void AddColorBlockItemToString(ref string targetString, ColorBlockItem blockItem) - { - targetString += _newLine + blockItem.PrefixText + " " + blockItem.Color.R + " " + blockItem.Color.G + " " - + blockItem.Color.B + (blockItem.Color.A < 255 ? " " + blockItem.Color.A : string.Empty); - } } }