diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index cee2650..370d27d 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -94,7 +94,7 @@ namespace Filtration.Parser.Tests.Services // Arrange var inputString = "HideDisabled" + Environment.NewLine + " ItemLevel >= 55"; - + // Act var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); @@ -374,37 +374,37 @@ namespace Filtration.Parser.Tests.Services } [Test] - public void TranslateStringToItemFilterBlock_ElderItem_ReturnsCorrectObject() - { - // Arrange - var inputString = "Show" + Environment.NewLine + - " ElderItem False"; - - // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); - - // Assert - - Assert.AreEqual(1, result.BlockItems.Count(b => b is ElderItemBlockItem)); - var blockItem = result.BlockItems.OfType().First(); - Assert.IsFalse(blockItem.BooleanValue); + public void TranslateStringToItemFilterBlock_ElderItem_ReturnsCorrectObject() + { + // Arrange + var inputString = "Show" + Environment.NewLine + + " ElderItem False"; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + + Assert.AreEqual(1, result.BlockItems.Count(b => b is ElderItemBlockItem)); + var blockItem = result.BlockItems.OfType().First(); + Assert.IsFalse(blockItem.BooleanValue); } [Test] - public void TranslateStringToItemFilterBlock_ShaperItem_ReturnsCorrectObject() - { - // Arrange - var inputString = "Show" + Environment.NewLine + - " ShaperItem True"; - - // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); - - // Assert - - Assert.AreEqual(1, result.BlockItems.Count(b => b is ShaperItemBlockItem)); - var blockItem = result.BlockItems.OfType().First(); - Assert.IsTrue(blockItem.BooleanValue); + public void TranslateStringToItemFilterBlock_ShaperItem_ReturnsCorrectObject() + { + // Arrange + var inputString = "Show" + Environment.NewLine + + " ShaperItem True"; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + + Assert.AreEqual(1, result.BlockItems.Count(b => b is ShaperItemBlockItem)); + var blockItem = result.BlockItems.OfType().First(); + Assert.IsTrue(blockItem.BooleanValue); } [Test] @@ -426,37 +426,37 @@ namespace Filtration.Parser.Tests.Services } [Test] - public void TranslateStringToItemFilterBlock_ShapedMap_ReturnsCorrectObject() - { - // Arrange - var inputString = "Show" + Environment.NewLine + - " ShapedMap false"; - - // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); - - // Assert - - Assert.AreEqual(1, result.BlockItems.Count(b => b is ShapedMapBlockItem)); - var blockItem = result.BlockItems.OfType().First(); - Assert.IsFalse(blockItem.BooleanValue); + public void TranslateStringToItemFilterBlock_ShapedMap_ReturnsCorrectObject() + { + // Arrange + var inputString = "Show" + Environment.NewLine + + " ShapedMap false"; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + + Assert.AreEqual(1, result.BlockItems.Count(b => b is ShapedMapBlockItem)); + var blockItem = result.BlockItems.OfType().First(); + Assert.IsFalse(blockItem.BooleanValue); } [Test] - public void TranslateStringToItemFilterBlock_ElderMap_ReturnsCorrectObject() - { - // Arrange - var inputString = "Show" + Environment.NewLine + - " ElderMap false"; - - // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); - - // Assert - - Assert.AreEqual(1, result.BlockItems.Count(b => b is ElderMapBlockItem)); - var blockItem = result.BlockItems.OfType().First(); - Assert.IsFalse(blockItem.BooleanValue); + public void TranslateStringToItemFilterBlock_ElderMap_ReturnsCorrectObject() + { + // Arrange + var inputString = "Show" + Environment.NewLine + + " ElderMap false"; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + + Assert.AreEqual(1, result.BlockItems.Count(b => b is ElderMapBlockItem)); + var blockItem = result.BlockItems.OfType().First(); + Assert.IsFalse(blockItem.BooleanValue); } [Test] @@ -795,7 +795,7 @@ namespace Filtration.Parser.Tests.Services " SetTextColor 255 20 100 # Rare Item Text"; var testComponent = new ColorThemeComponent(ThemeComponentType.TextColor, "Rare Item Text", new Color { A = 240, R = 255, G = 20, B = 100}); var testInputThemeComponentCollection = new ThemeComponentCollection { testComponent }; - + // Act var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.ThemeComponentCollection == testInputThemeComponentCollection)); @@ -896,22 +896,22 @@ namespace Filtration.Parser.Tests.Services } [Test] - public void TranslateStringToItemFilterBlock_DisableDropSound_ReturnsCorrectObject() - { - // Arrange - var inputString = "Show" + Environment.NewLine + - " DisableDropSound True"; - - // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); - - // Assert - - Assert.AreEqual(1, result.BlockItems.Count(b => b is DisableDropSoundBlockItem)); - var blockItem = result.BlockItems.OfType().First(); - Assert.IsTrue(blockItem.BooleanValue); - } - + public void TranslateStringToItemFilterBlock_DisableDropSound_ReturnsCorrectObject() + { + // Arrange + var inputString = "Show" + Environment.NewLine + + " DisableDropSound True"; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + + Assert.AreEqual(1, result.BlockItems.Count(b => b is DisableDropSoundBlockItem)); + var blockItem = result.BlockItems.OfType().First(); + Assert.IsTrue(blockItem.BooleanValue); + } + [Test] public void TranslateStringToItemFilterBlock_Everything_ReturnsCorrectObject() { @@ -1046,7 +1046,7 @@ namespace Filtration.Parser.Tests.Services var fontSizeblockItem = result.BlockItems.OfType().First(); Assert.AreEqual(50, fontSizeblockItem.Value); - + Assert.AreEqual(0, result.BlockItems.OfType().Count()); var disableDropSoundBlockItem = result.BlockItems.OfType().First(); @@ -1089,9 +1089,9 @@ namespace Filtration.Parser.Tests.Services // Arrange var inputString = "Show" + Environment.NewLine + - " ItemLevel >= 70" + Environment.NewLine + - " ItemLevel <= 80" + Environment.NewLine + - " Quality = 15" + Environment.NewLine + + " ItemLevel >= 70" + Environment.NewLine + + " ItemLevel <= 80" + Environment.NewLine + + " Quality = 15" + Environment.NewLine + " Quality < 17"; // Act @@ -1152,7 +1152,7 @@ namespace Filtration.Parser.Tests.Services var blockItem = result.BlockItems.OfType().First(); Assert.AreEqual(27, blockItem.Value); } - + [Test] public void TranslateStringToItemFilterBlock_MultipleSoundItems_OnlyLastOneUsed() { @@ -1308,6 +1308,86 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual(ItemRarity.Magic, (ItemRarity)rarityBlockItem.FilterPredicate.PredicateOperand); } + [Test] + public void TranslateStringToItemFilterBlock_CustomSoundDocumentsFile() + { + // Arrange + var inputString = @"Show" + Environment.NewLine + + "CustomAlertSound \"test.mp3\""; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + Assert.AreEqual(1, result.BlockItems.Count(b => b is CustomSoundBlockItem)); + var customSoundBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual("test.mp3", customSoundBlockItem.Value); + } + + [Test] + public void TranslateStringToItemFilterBlock_CustomSoundDocumentsRelativeFile() + { + // Arrange + var inputString = @"Show" + Environment.NewLine + + "CustomAlertSound \"Sounds\test.mp3\""; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + Assert.AreEqual(1, result.BlockItems.Count(b => b is CustomSoundBlockItem)); + var customSoundBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual("Sounds\test.mp3", customSoundBlockItem.Value); + } + + [Test] + public void TranslateStringToItemFilterBlock_CustomSoundFullBackSlashPath() + { + // Arrange + var inputString = @"Show" + Environment.NewLine + + "CustomAlertSound \"C:\\Sounds\\test.mp3\""; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + Assert.AreEqual(1, result.BlockItems.Count(b => b is CustomSoundBlockItem)); + var customSoundBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual("C:\\Sounds\\test.mp3", customSoundBlockItem.Value); + } + + [Test] + public void TranslateStringToItemFilterBlock_CustomSoundFullForwardSlashPath() + { + // Arrange + var inputString = @"Show" + Environment.NewLine + + "CustomAlertSound \"C:/Sounds/test.mp3\""; + + //Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + Assert.AreEqual(1, result.BlockItems.Count(b => b is CustomSoundBlockItem)); + var customSoundBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual("C:/Sounds/test.mp3", customSoundBlockItem.Value); + } + + [Test] + public void TranslateStringToItemFilterBlock_CustomSoundFullMixedPath() + { + // Arrange + var inputString = @"Show" + Environment.NewLine + + "CustomAlertSound \"C:\\Sounds/test.mp3\""; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + Assert.AreEqual(1, result.BlockItems.Count(b => b is CustomSoundBlockItem)); + var customSoundBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual("C:\\Sounds/test.mp3", customSoundBlockItem.Value); + } + [Test] public void TranslateItemFilterBlockToString_NothingPopulated_ReturnsCorrectString() { @@ -1328,13 +1408,13 @@ namespace Filtration.Parser.Tests.Services { // Arrange var expectedResult = "Show # Child 1 Block Group - Child 2 Block Group"; - + var rootBlockGroup = new ItemFilterBlockGroup("Root Block Group", null); var child1BlockGroup = new ItemFilterBlockGroup("Child 1 Block Group", rootBlockGroup); var child2BlockGroup = new ItemFilterBlockGroup("Child 2 Block Group", child1BlockGroup); - _testUtility.TestBlock.BlockGroup = child2BlockGroup; - - // TODO: Shouldn't be set to edited this way + _testUtility.TestBlock.BlockGroup = child2BlockGroup; + + // TODO: Shouldn't be set to edited this way _testUtility.TestBlock.IsEdited = true; // Act var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock); @@ -1853,7 +1933,7 @@ namespace Filtration.Parser.Tests.Services { // Arrange var expectedResult = "Show" + Environment.NewLine + - " ItemLevel > 56" + Environment.NewLine + + " ItemLevel > 56" + Environment.NewLine + " ItemLevel >= 45" + Environment.NewLine + " ItemLevel < 100"; @@ -1895,7 +1975,7 @@ namespace Filtration.Parser.Tests.Services // Arrange var expectedResult = "#Show" + Environment.NewLine + "# Width = 4"; - + _testUtility.TestBlock.Enabled = false; _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); @@ -1942,7 +2022,7 @@ namespace Filtration.Parser.Tests.Services " DisableDropSound True" + Environment.NewLine + " MinimapIcon 1 Blue Circle" + Environment.NewLine + " PlayEffect Red Temp" + Environment.NewLine + - " CustomAlertSound \"test.mp3\""; + " CustomAlertSound \"test.mp3\""; _testUtility.TestBlock.BlockItems.Add(new ActionBlockItem(BlockAction.Show)); _testUtility.TestBlock.BlockItems.Add(new IdentifiedBlockItem(true)); @@ -2010,7 +2090,7 @@ namespace Filtration.Parser.Tests.Services // Act _testUtility.Translator.ReplaceAudioVisualBlockItemsFromString(testInputBlockItems, testInputString); - + // Assert var textColorBlockItem = testInputBlockItems.First(b => b is TextColorBlockItem) as TextColorBlockItem; Assert.IsNotNull(textColorBlockItem); @@ -2085,7 +2165,7 @@ namespace Filtration.Parser.Tests.Services // Arrange var testInputString = "SetTextColor 240 200 150 # Rarest Currency" + Environment.NewLine + "SetBackgroundColor 0 0 0 # Rarest Currency Background" + Environment.NewLine + - "SetBorderColor 255 255 255 # Rarest Currency Border" + Environment.NewLine + + "SetBorderColor 255 255 255 # Rarest Currency Border" + Environment.NewLine + "PlayAlertSound 7 280"; var testInputBlockItems = new ObservableCollection(); @@ -2131,9 +2211,9 @@ namespace Filtration.Parser.Tests.Services // Arrange var testInputString = "SetTextColor 240 200 150 # Rarest Currency" + Environment.NewLine + "SetBackgroundColor 0 0 0 # Rarest Currency Background" + Environment.NewLine + - "SetBorderColor 255 255 255 # Rarest Currency Border" + Environment.NewLine + + "SetBorderColor 255 255 255 # Rarest Currency Border" + Environment.NewLine + "PlayAlertSound 7 280"; - + var testInputBlockItems = new ObservableCollection(); // Act @@ -2203,9 +2283,9 @@ namespace Filtration.Parser.Tests.Services _testUtility.Translator.ReplaceAudioVisualBlockItemsFromString(testInputBlockItems, testInputString); // Assert - + } - + private class ItemFilterBlockTranslatorTestUtility { public ItemFilterBlockTranslatorTestUtility() diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index 32818df..d7970d9 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -1,73 +1,73 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; -using System.Windows.Media; -using Filtration.Common.Utilities; -using Filtration.ObjectModel; -using Filtration.ObjectModel.BlockItemBaseTypes; -using Filtration.ObjectModel.BlockItemTypes; -using Filtration.ObjectModel.Enums; -using Filtration.ObjectModel.Extensions; -using Filtration.ObjectModel.ThemeEditor; -using Filtration.Parser.Interface.Services; - -namespace Filtration.Parser.Services -{ - internal class ItemFilterBlockTranslator : IItemFilterBlockTranslator - { - private readonly IBlockGroupHierarchyBuilder _blockGroupHierarchyBuilder; - private const string _indent = " "; - private readonly string _newLine = Environment.NewLine + _indent; - private readonly string _disabledNewLine = Environment.NewLine + "#" + _indent; - private ThemeComponentCollection _masterComponentCollection; - - public ItemFilterBlockTranslator(IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder) - { - _blockGroupHierarchyBuilder = blockGroupHierarchyBuilder; - } - - // Converts a string into an ItemFilterCommentBlock maintaining newlines and spaces but removing # characters - public IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString, IItemFilterScript parentItemFilterScript, string originalString = "") - { - var itemFilterCommentBlock = new ItemFilterCommentBlock(parentItemFilterScript) {OriginalText = originalString}; - - foreach (var line in new LineReader(() => new StringReader(inputString))) - { - var trimmedLine = line.TrimStart(' ').TrimStart('#'); - itemFilterCommentBlock.Comment += trimmedLine + Environment.NewLine; - } - +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using System.Windows.Media; +using Filtration.Common.Utilities; +using Filtration.ObjectModel; +using Filtration.ObjectModel.BlockItemBaseTypes; +using Filtration.ObjectModel.BlockItemTypes; +using Filtration.ObjectModel.Enums; +using Filtration.ObjectModel.Extensions; +using Filtration.ObjectModel.ThemeEditor; +using Filtration.Parser.Interface.Services; + +namespace Filtration.Parser.Services +{ + internal class ItemFilterBlockTranslator : IItemFilterBlockTranslator + { + private readonly IBlockGroupHierarchyBuilder _blockGroupHierarchyBuilder; + private const string _indent = " "; + private readonly string _newLine = Environment.NewLine + _indent; + private readonly string _disabledNewLine = Environment.NewLine + "#" + _indent; + private ThemeComponentCollection _masterComponentCollection; + + public ItemFilterBlockTranslator(IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder) + { + _blockGroupHierarchyBuilder = blockGroupHierarchyBuilder; + } + + // Converts a string into an ItemFilterCommentBlock maintaining newlines and spaces but removing # characters + public IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString, IItemFilterScript parentItemFilterScript, string originalString = "") + { + var itemFilterCommentBlock = new ItemFilterCommentBlock(parentItemFilterScript) {OriginalText = originalString}; + + foreach (var line in new LineReader(() => new StringReader(inputString))) + { + var trimmedLine = line.TrimStart(' ').TrimStart('#'); + itemFilterCommentBlock.Comment += trimmedLine + Environment.NewLine; + } + itemFilterCommentBlock.Comment = itemFilterCommentBlock.Comment.TrimEnd('\r', '\n'); - itemFilterCommentBlock.IsEdited = false; - return itemFilterCommentBlock; - } - - // This method converts a string into a ItemFilterBlock. This is used for pasting ItemFilterBlocks - // and reading ItemFilterScripts from a file. - public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScript parentItemFilterScript, string originalString = "", bool initialiseBlockGroupHierarchyBuilder = false) - { - if (initialiseBlockGroupHierarchyBuilder) - { - _blockGroupHierarchyBuilder.Initialise(parentItemFilterScript.ItemFilterBlockGroups.First()); - } - - _masterComponentCollection = parentItemFilterScript.ItemFilterScriptSettings.ThemeComponentCollection; - var block = new ItemFilterBlock(parentItemFilterScript); - var showHideFound = false; - block.OriginalText = originalString; - - foreach (var line in new LineReader(() => new StringReader(inputString))) - { - if (line.StartsWith(@"#")) - { + itemFilterCommentBlock.IsEdited = false; + return itemFilterCommentBlock; + } + + // This method converts a string into a ItemFilterBlock. This is used for pasting ItemFilterBlocks + // and reading ItemFilterScripts from a file. + public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScript parentItemFilterScript, string originalString = "", bool initialiseBlockGroupHierarchyBuilder = false) + { + if (initialiseBlockGroupHierarchyBuilder) + { + _blockGroupHierarchyBuilder.Initialise(parentItemFilterScript.ItemFilterBlockGroups.First()); + } + + _masterComponentCollection = parentItemFilterScript.ItemFilterScriptSettings.ThemeComponentCollection; + var block = new ItemFilterBlock(parentItemFilterScript); + var showHideFound = false; + block.OriginalText = originalString; + + foreach (var line in new LineReader(() => new StringReader(inputString))) + { + if (line.StartsWith(@"#")) + { if(!showHideFound) { block.Description = line.TrimStart('#').TrimStart(' '); - } + } else { if(block.BlockItems.Count > 1) @@ -78,201 +78,201 @@ namespace Filtration.Parser.Services { block.ActionBlockItem.Comment += Environment.NewLine + line.TrimStart('#'); } - } - continue; - } - - var fullLine = line.Trim(); - var trimmedLine = fullLine; - var blockComment = ""; - var themeComponentType = -1; + } + continue; + } + + var fullLine = line.Trim(); + var trimmedLine = fullLine; + var blockComment = ""; + var themeComponentType = -1; if(trimmedLine.IndexOf('#') > 0) { blockComment = trimmedLine.Substring(trimmedLine.IndexOf('#') + 1); trimmedLine = trimmedLine.Substring(0, trimmedLine.IndexOf('#')).Trim(); - } - var spaceOrEndOfLinePos = trimmedLine.IndexOf(" ", StringComparison.Ordinal) > 0 ? trimmedLine.IndexOf(" ", StringComparison.Ordinal) : trimmedLine.Length; - - var lineOption = trimmedLine.Substring(0, spaceOrEndOfLinePos); - switch (lineOption) - { - case "Show": - case "Hide": - case "ShowDisabled": - case "HideDisabled": - { - showHideFound = true; - block.Action = lineOption.StartsWith("Show") ? BlockAction.Show : BlockAction.Hide; - block.Enabled = !lineOption.EndsWith("Disabled"); - - // If block groups are enabled for this script, the comment after Show/Hide is parsed as a block - // group hierarchy, if block groups are disabled it is preserved as a simple text comment. - if (parentItemFilterScript.ItemFilterScriptSettings.BlockGroupsEnabled) - { - AddBlockGroupToBlock(block, fullLine); - } - else - { - block.ActionBlockItem.Comment = GetTextAfterFirstComment(fullLine); - } - break; - } - case "ItemLevel": - { - AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); - break; - } - case "DropLevel": - { - AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); - break; - } - case "Quality": - { - AddNumericFilterPredicateItemToBlockItems(block,trimmedLine); - break; - } - case "Rarity": - { - RemoveExistingBlockItemsOfType(block); - - var blockItemValue = new RarityBlockItem(); - var result = Regex.Match(trimmedLine, @"^\w+\s+([>(string.IsNullOrEmpty(result.Groups[1].Value) ? "=" : result.Groups[1].Value); - blockItemValue.FilterPredicate.PredicateOperand = - (int)EnumHelper.GetEnumValueFromDescription(result.Groups[2].Value); - } - - block.BlockItems.Add(blockItemValue); - break; - } - case "Class": - { - AddStringListItemToBlockItems(block, trimmedLine); - break; - } - case "BaseType": - { - AddStringListItemToBlockItems(block, trimmedLine); - break; - } - case "Corrupted": - { - AddBooleanItemToBlockItems(block, trimmedLine); - break; - } - case "Identified": - { - AddBooleanItemToBlockItems(block, trimmedLine); - break; - } - case "ElderItem": - { - AddBooleanItemToBlockItems(block, trimmedLine); - break; - } - case "ShaperItem": - { - AddBooleanItemToBlockItems(block, trimmedLine); - break; - } - case "ShapedMap": - { - AddBooleanItemToBlockItems(block, trimmedLine); - break; - } - case "Sockets": - { - AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); - break; - } - case "LinkedSockets": - { - AddNumericFilterPredicateItemToBlockItems(block,trimmedLine); - break; - } - case "Width": - { - AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); - break; - } - case "Height": - { - AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); - break; - } - case "SocketGroup": - { - AddStringListItemToBlockItems(block, trimmedLine); - break; - } - case "SetTextColor": - { - // Only ever use the last SetTextColor item encountered as multiples aren't valid. - RemoveExistingBlockItemsOfType(block); - - var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); - - var blockItem = new TextColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; - block.BlockItems.Add(blockItem); - themeComponentType = (int)ThemeComponentType.TextColor; - break; - } - case "SetBackgroundColor": - { - // Only ever use the last SetBackgroundColor item encountered as multiples aren't valid. - RemoveExistingBlockItemsOfType(block); - - var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); - - var blockItem = new BackgroundColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; - block.BlockItems.Add(blockItem); - themeComponentType = (int)ThemeComponentType.BackgroundColor; - break; - } - case "SetBorderColor": - { - // Only ever use the last SetBorderColor item encountered as multiples aren't valid. - RemoveExistingBlockItemsOfType(block); - - var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); - - var blockItem = new BorderColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; - block.BlockItems.Add(blockItem); - themeComponentType = (int)ThemeComponentType.BorderColor; - break; - } - case "SetFontSize": - { - // Only ever use the last SetFontSize item encountered as multiples aren't valid. - RemoveExistingBlockItemsOfType(block); - - var match = Regex.Matches(trimmedLine, @"(\s+(\d+)\s*)"); - if (match.Count > 0) - { - var blockItem = new FontSizeBlockItem(Convert.ToInt16(match[0].Groups[2].Value)); - block.BlockItems.Add(blockItem); - themeComponentType = (int)ThemeComponentType.FontSize; - } - break; - } - case "PlayAlertSound": - case "PlayAlertSoundPositional": - { - // Only ever use the last PlayAlertSound item encountered as multiples aren't valid. - RemoveExistingBlockItemsOfType(block); - RemoveExistingBlockItemsOfType(block); - RemoveExistingBlockItemsOfType(block); - - var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?"); - + } + var spaceOrEndOfLinePos = trimmedLine.IndexOf(" ", StringComparison.Ordinal) > 0 ? trimmedLine.IndexOf(" ", StringComparison.Ordinal) : trimmedLine.Length; + + var lineOption = trimmedLine.Substring(0, spaceOrEndOfLinePos); + switch (lineOption) + { + case "Show": + case "Hide": + case "ShowDisabled": + case "HideDisabled": + { + showHideFound = true; + block.Action = lineOption.StartsWith("Show") ? BlockAction.Show : BlockAction.Hide; + block.Enabled = !lineOption.EndsWith("Disabled"); + + // If block groups are enabled for this script, the comment after Show/Hide is parsed as a block + // group hierarchy, if block groups are disabled it is preserved as a simple text comment. + if (parentItemFilterScript.ItemFilterScriptSettings.BlockGroupsEnabled) + { + AddBlockGroupToBlock(block, fullLine); + } + else + { + block.ActionBlockItem.Comment = GetTextAfterFirstComment(fullLine); + } + break; + } + case "ItemLevel": + { + AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); + break; + } + case "DropLevel": + { + AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); + break; + } + case "Quality": + { + AddNumericFilterPredicateItemToBlockItems(block,trimmedLine); + break; + } + case "Rarity": + { + RemoveExistingBlockItemsOfType(block); + + var blockItemValue = new RarityBlockItem(); + var result = Regex.Match(trimmedLine, @"^\w+\s+([>(string.IsNullOrEmpty(result.Groups[1].Value) ? "=" : result.Groups[1].Value); + blockItemValue.FilterPredicate.PredicateOperand = + (int)EnumHelper.GetEnumValueFromDescription(result.Groups[2].Value); + } + + block.BlockItems.Add(blockItemValue); + break; + } + case "Class": + { + AddStringListItemToBlockItems(block, trimmedLine); + break; + } + case "BaseType": + { + AddStringListItemToBlockItems(block, trimmedLine); + break; + } + case "Corrupted": + { + AddBooleanItemToBlockItems(block, trimmedLine); + break; + } + case "Identified": + { + AddBooleanItemToBlockItems(block, trimmedLine); + break; + } + case "ElderItem": + { + AddBooleanItemToBlockItems(block, trimmedLine); + break; + } + case "ShaperItem": + { + AddBooleanItemToBlockItems(block, trimmedLine); + break; + } + case "ShapedMap": + { + AddBooleanItemToBlockItems(block, trimmedLine); + break; + } + case "Sockets": + { + AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); + break; + } + case "LinkedSockets": + { + AddNumericFilterPredicateItemToBlockItems(block,trimmedLine); + break; + } + case "Width": + { + AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); + break; + } + case "Height": + { + AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); + break; + } + case "SocketGroup": + { + AddStringListItemToBlockItems(block, trimmedLine); + break; + } + case "SetTextColor": + { + // Only ever use the last SetTextColor item encountered as multiples aren't valid. + RemoveExistingBlockItemsOfType(block); + + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new TextColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; + block.BlockItems.Add(blockItem); + themeComponentType = (int)ThemeComponentType.TextColor; + break; + } + case "SetBackgroundColor": + { + // Only ever use the last SetBackgroundColor item encountered as multiples aren't valid. + RemoveExistingBlockItemsOfType(block); + + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new BackgroundColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; + block.BlockItems.Add(blockItem); + themeComponentType = (int)ThemeComponentType.BackgroundColor; + break; + } + case "SetBorderColor": + { + // Only ever use the last SetBorderColor item encountered as multiples aren't valid. + RemoveExistingBlockItemsOfType(block); + + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new BorderColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; + block.BlockItems.Add(blockItem); + themeComponentType = (int)ThemeComponentType.BorderColor; + break; + } + case "SetFontSize": + { + // Only ever use the last SetFontSize item encountered as multiples aren't valid. + RemoveExistingBlockItemsOfType(block); + + var match = Regex.Matches(trimmedLine, @"(\s+(\d+)\s*)"); + if (match.Count > 0) + { + var blockItem = new FontSizeBlockItem(Convert.ToInt16(match[0].Groups[2].Value)); + block.BlockItems.Add(blockItem); + themeComponentType = (int)ThemeComponentType.FontSize; + } + break; + } + case "PlayAlertSound": + case "PlayAlertSoundPositional": + { + // Only ever use the last PlayAlertSound item encountered as multiples aren't valid. + RemoveExistingBlockItemsOfType(block); + RemoveExistingBlockItemsOfType(block); + RemoveExistingBlockItemsOfType(block); + + var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?"); + if (match.Success) { - string firstValue = match.Groups[1].Value; - + string firstValue = match.Groups[1].Value; + var secondValue = match.Groups[2].Success ? Convert.ToInt16(match.Groups[2].Value) : 79; if (lineOption == "PlayAlertSound") @@ -292,77 +292,77 @@ namespace Filtration.Parser.Services SecondValue = secondValue }; block.BlockItems.Add(blockItemValue); - } + } themeComponentType = (int)ThemeComponentType.AlertSound; } - break; - } - case "GemLevel": - { - AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); - break; - } - case "StackSize": - { - AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); - break; - } - case "HasExplicitMod": - { - AddStringListItemToBlockItems(block, trimmedLine); - break; - } - case "ElderMap": - { - AddBooleanItemToBlockItems(block, trimmedLine); - break; - } - case "DisableDropSound": - { - // Only ever use the last DisableDropSound item encountered as multiples aren't valid. - RemoveExistingBlockItemsOfType(block); - - AddBooleanItemToBlockItems(block, trimmedLine); - break; - } - case "MinimapIcon": - { - // Only ever use the last Icon item encountered as multiples aren't valid. - RemoveExistingBlockItemsOfType(block); - - // TODO: Get size, color, shape values programmatically - var match = Regex.Match(trimmedLine, - @"\S+\s+(0|1|2)\s+(Red|Green|Blue|Brown|White|Yellow)\s+(Circle|Diamond|Hexagon|Square|Star|Triangle)\s*([#]?)(.*)", - RegexOptions.IgnoreCase); - + break; + } + case "GemLevel": + { + AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); + break; + } + case "StackSize": + { + AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); + break; + } + case "HasExplicitMod": + { + AddStringListItemToBlockItems(block, trimmedLine); + break; + } + case "ElderMap": + { + AddBooleanItemToBlockItems(block, trimmedLine); + break; + } + case "DisableDropSound": + { + // Only ever use the last DisableDropSound item encountered as multiples aren't valid. + RemoveExistingBlockItemsOfType(block); + + AddBooleanItemToBlockItems(block, trimmedLine); + break; + } + case "MinimapIcon": + { + // Only ever use the last Icon item encountered as multiples aren't valid. + RemoveExistingBlockItemsOfType(block); + + // TODO: Get size, color, shape values programmatically + var match = Regex.Match(trimmedLine, + @"\S+\s+(0|1|2)\s+(Red|Green|Blue|Brown|White|Yellow)\s+(Circle|Diamond|Hexagon|Square|Star|Triangle)\s*([#]?)(.*)", + RegexOptions.IgnoreCase); + if (match.Success) { - var blockItemValue = new MapIconBlockItem - { - Size = (IconSize)short.Parse(match.Groups[1].Value), - Color = EnumHelper.GetEnumValueFromDescription(match.Groups[2].Value), - Shape = EnumHelper.GetEnumValueFromDescription(match.Groups[3].Value) - }; - - var themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.Icon, match.Groups[5].Value.Trim(), - blockItemValue.Size, blockItemValue.Color, blockItemValue.Shape); + var blockItemValue = new MapIconBlockItem + { + Size = (IconSize)short.Parse(match.Groups[1].Value), + Color = EnumHelper.GetEnumValueFromDescription(match.Groups[2].Value), + Shape = EnumHelper.GetEnumValueFromDescription(match.Groups[3].Value) + }; + + var themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.Icon, match.Groups[5].Value.Trim(), + blockItemValue.Size, blockItemValue.Color, blockItemValue.Shape); if(match.Groups[4].Value == "#" && !string.IsNullOrWhiteSpace(match.Groups[5].Value)) - { + { blockItemValue.ThemeComponent = themeComponent; } block.BlockItems.Add(blockItemValue); themeComponentType = (int)ThemeComponentType.Icon; } - break; - } - case "PlayEffect": - { - // Only ever use the last BeamColor item encountered as multiples aren't valid. - RemoveExistingBlockItemsOfType(block); - - // TODO: Get colors programmatically - var match = Regex.Match(trimmedLine, @"\S+\s+(Red|Green|Blue|Brown|White|Yellow)\s*(Temp)?", RegexOptions.IgnoreCase); - + break; + } + case "PlayEffect": + { + // Only ever use the last BeamColor item encountered as multiples aren't valid. + RemoveExistingBlockItemsOfType(block); + + // TODO: Get colors programmatically + var match = Regex.Match(trimmedLine, @"\S+\s+(Red|Green|Blue|Brown|White|Yellow)\s*(Temp)?", RegexOptions.IgnoreCase); + if (match.Success) { var blockItemValue = new PlayEffectBlockItem @@ -370,40 +370,40 @@ namespace Filtration.Parser.Services Color = EnumHelper.GetEnumValueFromDescription(match.Groups[1].Value), Temporary = match.Groups[2].Value.Trim().ToLower() == "temp" }; - block.BlockItems.Add(blockItemValue); + block.BlockItems.Add(blockItemValue); themeComponentType = (int)ThemeComponentType.Effect; - } - break; - } - case "CustomAlertSound": - { - // Only ever use the last CustomSoundBlockItem item encountered as multiples aren't valid. - RemoveExistingBlockItemsOfType(block); - RemoveExistingBlockItemsOfType(block); - RemoveExistingBlockItemsOfType(block); - - var match = Regex.Match(trimmedLine, @"\S+\s+""(\S+)"""); - + } + break; + } + case "CustomAlertSound": + { + // Only ever use the last CustomSoundBlockItem item encountered as multiples aren't valid. + RemoveExistingBlockItemsOfType(block); + RemoveExistingBlockItemsOfType(block); + RemoveExistingBlockItemsOfType(block); + + var match = Regex.Match(trimmedLine, @"\S+\s+""([^\*\<\>\?|]+)"""); + if (match.Success) { var blockItemValue = new CustomSoundBlockItem { Value = match.Groups[1].Value }; - block.BlockItems.Add(blockItemValue); + block.BlockItems.Add(blockItemValue); themeComponentType = (int)ThemeComponentType.CustomSound; } - break; - } - case "MapTier": - { - AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); - break; - } + break; + } + case "MapTier": + { + AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); + break; + } } if (!string.IsNullOrWhiteSpace(blockComment) && block.BlockItems.Count > 1) - { + { if(!(block.BlockItems.Last() is IBlockItemWithTheme blockItemWithTheme)) { block.BlockItems.Last().Comment = blockComment; @@ -479,288 +479,288 @@ namespace Filtration.Parser.Services } } } - } + } } - block.IsEdited = false; - return block; - } - - private static void RemoveExistingBlockItemsOfType(IItemFilterBlock block) - { - var existingBlockItemCount = block.BlockItems.Count(b => b.GetType() == typeof(T)); - if (existingBlockItemCount > 0) - { - var existingBlockItem = block.BlockItems.First(b => b.GetType() == typeof(T)); - block.BlockItems.Remove(existingBlockItem); - } - } - - private static void AddBooleanItemToBlockItems(IItemFilterBlock block, string inputString) where T : BooleanBlockItem - { - inputString = Regex.Replace(inputString, @"\s+", " "); - var blockItem = Activator.CreateInstance(); - var splitString = inputString.Split(' '); - if (splitString.Length == 2) - { - blockItem.BooleanValue = splitString[1].Trim().ToLowerInvariant() == "true"; - block.BlockItems.Add(blockItem); - } - } - - private static void AddNumericFilterPredicateItemToBlockItems(IItemFilterBlock block, string inputString) where T : NumericFilterPredicateBlockItem - { - var blockItem = Activator.CreateInstance(); - - SetNumericFilterPredicateFromString(blockItem.FilterPredicate, inputString); - block.BlockItems.Add(blockItem); - } - - private static void SetNumericFilterPredicateFromString(NumericFilterPredicate predicate, string inputString) - { - var result = Regex.Match(inputString, @"^\w+\s+([><=]{0,2})\s*(\d{0,3})$"); - if (result.Groups.Count != 3) return; - - predicate.PredicateOperator = - EnumHelper.GetEnumValueFromDescription(string.IsNullOrEmpty(result.Groups[1].Value) ? "=" : result.Groups[1].Value); - predicate.PredicateOperand = Convert.ToInt16(result.Groups[2].Value); - } - - private static void AddStringListItemToBlockItems(IItemFilterBlock block, string inputString) where T : StringListBlockItem - { - var blockItem = Activator.CreateInstance(); - PopulateListFromString(blockItem.Items, inputString.Substring(inputString.IndexOf(" ", StringComparison.Ordinal) + 1).Trim()); - block.BlockItems.Add(blockItem); - } - - private static void PopulateListFromString(ICollection list, string inputString) - { - var result = Regex.Matches(inputString, @"[^\s""]+|""([^""]*)"""); - foreach (Match match in result) - { - list.Add(match.Groups[1].Success - ? match.Groups[1].Value - : match.Groups[0].Value); - } - } - - public void ReplaceAudioVisualBlockItemsFromString(ObservableCollection blockItems, string inputString) - { - // Reverse iterate to remove existing IAudioVisualBlockItems - for (var idx = blockItems.Count - 1; idx >= 0; idx--) - { - if (blockItems[idx] is IAudioVisualBlockItem) - { - blockItems.RemoveAt(idx); - } - } - - foreach (var line in new LineReader(() => new StringReader(inputString))) - { - var matches = Regex.Match(line, @"(\w+)"); - var blockComment = ""; - var trimmedLine = line.Trim(); + block.IsEdited = false; + return block; + } + + private static void RemoveExistingBlockItemsOfType(IItemFilterBlock block) + { + var existingBlockItemCount = block.BlockItems.Count(b => b.GetType() == typeof(T)); + if (existingBlockItemCount > 0) + { + var existingBlockItem = block.BlockItems.First(b => b.GetType() == typeof(T)); + block.BlockItems.Remove(existingBlockItem); + } + } + + private static void AddBooleanItemToBlockItems(IItemFilterBlock block, string inputString) where T : BooleanBlockItem + { + inputString = Regex.Replace(inputString, @"\s+", " "); + var blockItem = Activator.CreateInstance(); + var splitString = inputString.Split(' '); + if (splitString.Length == 2) + { + blockItem.BooleanValue = splitString[1].Trim().ToLowerInvariant() == "true"; + block.BlockItems.Add(blockItem); + } + } + + private static void AddNumericFilterPredicateItemToBlockItems(IItemFilterBlock block, string inputString) where T : NumericFilterPredicateBlockItem + { + var blockItem = Activator.CreateInstance(); + + SetNumericFilterPredicateFromString(blockItem.FilterPredicate, inputString); + block.BlockItems.Add(blockItem); + } + + private static void SetNumericFilterPredicateFromString(NumericFilterPredicate predicate, string inputString) + { + var result = Regex.Match(inputString, @"^\w+\s+([><=]{0,2})\s*(\d{0,3})$"); + if (result.Groups.Count != 3) return; + + predicate.PredicateOperator = + EnumHelper.GetEnumValueFromDescription(string.IsNullOrEmpty(result.Groups[1].Value) ? "=" : result.Groups[1].Value); + predicate.PredicateOperand = Convert.ToInt16(result.Groups[2].Value); + } + + private static void AddStringListItemToBlockItems(IItemFilterBlock block, string inputString) where T : StringListBlockItem + { + var blockItem = Activator.CreateInstance(); + PopulateListFromString(blockItem.Items, inputString.Substring(inputString.IndexOf(" ", StringComparison.Ordinal) + 1).Trim()); + block.BlockItems.Add(blockItem); + } + + private static void PopulateListFromString(ICollection list, string inputString) + { + var result = Regex.Matches(inputString, @"[^\s""]+|""([^""]*)"""); + foreach (Match match in result) + { + list.Add(match.Groups[1].Success + ? match.Groups[1].Value + : match.Groups[0].Value); + } + } + + public void ReplaceAudioVisualBlockItemsFromString(ObservableCollection blockItems, string inputString) + { + // Reverse iterate to remove existing IAudioVisualBlockItems + for (var idx = blockItems.Count - 1; idx >= 0; idx--) + { + if (blockItems[idx] is IAudioVisualBlockItem) + { + blockItems.RemoveAt(idx); + } + } + + foreach (var line in new LineReader(() => new StringReader(inputString))) + { + var matches = Regex.Match(line, @"(\w+)"); + var blockComment = ""; + var trimmedLine = line.Trim(); if (trimmedLine.IndexOf('#') > 0) { blockComment = trimmedLine.Substring(trimmedLine.IndexOf('#') + 1); trimmedLine = trimmedLine.Substring(0, trimmedLine.IndexOf('#')).Trim(); } - switch (matches.Value) - { - case "PlayAlertSound": - { - var match = Regex.Match(trimmedLine, @"\s+(\S+) (\d+)"); - if (!match.Success) break; - var blockItem = new SoundBlockItem(match.Groups[1].Value, Convert.ToInt16(match.Groups[2].Value)); + switch (matches.Value) + { + case "PlayAlertSound": + { + var match = Regex.Match(trimmedLine, @"\s+(\S+) (\d+)"); + if (!match.Success) break; + var blockItem = new SoundBlockItem(match.Groups[1].Value, Convert.ToInt16(match.Groups[2].Value)); if(_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.AlertSound, blockComment, blockItem.Value, blockItem.SecondValue); blockItem.ThemeComponent = themeComponent; - } - blockItems.Add(blockItem); - break; - } - case "SetTextColor": - { - var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); - - var blockItem = new TextColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; + } + blockItems.Add(blockItem); + break; + } + case "SetTextColor": + { + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new TextColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; if(_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.TextColor, blockComment, blockItem.Color); blockItem.ThemeComponent = themeComponent; - } - blockItems.Add(blockItem); - break; - } - case "SetBackgroundColor": - { - var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); - - var blockItem = new BackgroundColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; + } + blockItems.Add(blockItem); + break; + } + case "SetBackgroundColor": + { + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new BackgroundColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; if(_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BackgroundColor, blockComment, blockItem.Color); blockItem.ThemeComponent = themeComponent; - } - blockItems.Add(blockItem); - break; - } - case "SetBorderColor": - { - var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); - - var blockItem = new BorderColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; + } + blockItems.Add(blockItem); + break; + } + case "SetBorderColor": + { + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new BorderColorBlockItem {Color = GetColorFromString(result[0].Groups[1].Value)}; if(_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BorderColor, blockComment, blockItem.Color); blockItem.ThemeComponent = themeComponent; - } - blockItems.Add(blockItem); - break; - } - case "SetFontSize": - { - var match = Regex.Match(trimmedLine, @"\s+(\d+)"); - if (!match.Success) break; - var blockItem = new FontSizeBlockItem(Convert.ToInt16(match.Value)); + } + blockItems.Add(blockItem); + break; + } + case "SetFontSize": + { + var match = Regex.Match(trimmedLine, @"\s+(\d+)"); + if (!match.Success) break; + var blockItem = new FontSizeBlockItem(Convert.ToInt16(match.Value)); if (_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.FontSize, blockComment, blockItem.Value); blockItem.ThemeComponent = themeComponent; - } - blockItems.Add(blockItem); - break; - } - } - } - } - - private void AddBlockGroupToBlock(IItemFilterBlock block, string inputString) - { - var blockGroupText = GetTextAfterFirstComment(inputString); - var blockGroups = blockGroupText.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries) - .Select(s => s.Trim()) - .ToList(); - - if (blockGroups.Count(b => !string.IsNullOrEmpty(b.Trim())) > 0) - { - block.BlockGroup = _blockGroupHierarchyBuilder.IntegrateStringListIntoBlockGroupHierarchy(blockGroups, - block.Action == BlockAction.Show, block.Enabled); - } - } - - private static string GetTextAfterFirstComment(string inputString) - { - var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal); - if (blockGroupStart <= 0) return string.Empty; - - return inputString.Substring(blockGroupStart + 1); - } - - private static Color GetColorFromString(string inputString) - { - var argbValues = Regex.Matches(inputString, @"\s+(\d+)"); - - switch (argbValues.Count) - { - case 3: - return new Color - { - A = 240, - R = Convert.ToByte(argbValues[0].Value), - G = Convert.ToByte(argbValues[1].Value), - B = Convert.ToByte(argbValues[2].Value) - }; - case 4: - return new Color - { - R = Convert.ToByte(argbValues[0].Value), - G = Convert.ToByte(argbValues[1].Value), - B = Convert.ToByte(argbValues[2].Value), - A = Convert.ToByte(argbValues[3].Value) - }; - } - return new Color(); - } - - public string TranslateItemFilterBlockBaseToString(IItemFilterBlockBase itemFilterBlockBase) - { - if (itemFilterBlockBase is IItemFilterBlock itemFilterBlock) - { - return TranslateItemFilterBlockToString(itemFilterBlock); - } - - if (itemFilterBlockBase is IItemFilterCommentBlock itemFilterCommentBlock) - { - return TranslateItemFilterCommentBlockToString(itemFilterCommentBlock); - } - - throw new InvalidOperationException("Unable to translate unknown ItemFilterBlock type"); - } - - // TODO: Private - public string TranslateItemFilterCommentBlockToString(IItemFilterCommentBlock itemFilterCommentBlock) - { + } + blockItems.Add(blockItem); + break; + } + } + } + } + + private void AddBlockGroupToBlock(IItemFilterBlock block, string inputString) + { + var blockGroupText = GetTextAfterFirstComment(inputString); + var blockGroups = blockGroupText.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries) + .Select(s => s.Trim()) + .ToList(); + + if (blockGroups.Count(b => !string.IsNullOrEmpty(b.Trim())) > 0) + { + block.BlockGroup = _blockGroupHierarchyBuilder.IntegrateStringListIntoBlockGroupHierarchy(blockGroups, + block.Action == BlockAction.Show, block.Enabled); + } + } + + private static string GetTextAfterFirstComment(string inputString) + { + var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal); + if (blockGroupStart <= 0) return string.Empty; + + return inputString.Substring(blockGroupStart + 1); + } + + private static Color GetColorFromString(string inputString) + { + var argbValues = Regex.Matches(inputString, @"\s+(\d+)"); + + switch (argbValues.Count) + { + case 3: + return new Color + { + A = 240, + R = Convert.ToByte(argbValues[0].Value), + G = Convert.ToByte(argbValues[1].Value), + B = Convert.ToByte(argbValues[2].Value) + }; + case 4: + return new Color + { + R = Convert.ToByte(argbValues[0].Value), + G = Convert.ToByte(argbValues[1].Value), + B = Convert.ToByte(argbValues[2].Value), + A = Convert.ToByte(argbValues[3].Value) + }; + } + return new Color(); + } + + public string TranslateItemFilterBlockBaseToString(IItemFilterBlockBase itemFilterBlockBase) + { + if (itemFilterBlockBase is IItemFilterBlock itemFilterBlock) + { + return TranslateItemFilterBlockToString(itemFilterBlock); + } + + if (itemFilterBlockBase is IItemFilterCommentBlock itemFilterCommentBlock) + { + return TranslateItemFilterCommentBlockToString(itemFilterCommentBlock); + } + + throw new InvalidOperationException("Unable to translate unknown ItemFilterBlock type"); + } + + // TODO: Private + public string TranslateItemFilterCommentBlockToString(IItemFilterCommentBlock itemFilterCommentBlock) + { if (!itemFilterCommentBlock.IsEdited) { return itemFilterCommentBlock.OriginalText; - } - - // TODO: Tests - // TODO: # Section: text? + } + + // TODO: Tests + // TODO: # Section: text? var commentWithHashes = string.Empty; - // Add "# " to the beginning of each line of the comment before saving it - foreach (var line in new LineReader(() => new StringReader(itemFilterCommentBlock.Comment))) - { - commentWithHashes += $"# {line.TrimStart(' ')}{Environment.NewLine}"; - } - - // Remove trailing newline - return commentWithHashes.TrimEnd('\r', '\n'); - } - - // This method converts an ItemFilterBlock object into a string. This is used for copying a ItemFilterBlock - // to the clipboard, and when saving a ItemFilterScript. - // TODO: Private - public string TranslateItemFilterBlockToString(IItemFilterBlock block) - { + // Add "# " to the beginning of each line of the comment before saving it + foreach (var line in new LineReader(() => new StringReader(itemFilterCommentBlock.Comment))) + { + commentWithHashes += $"# {line.TrimStart(' ')}{Environment.NewLine}"; + } + + // Remove trailing newline + return commentWithHashes.TrimEnd('\r', '\n'); + } + + // This method converts an ItemFilterBlock object into a string. This is used for copying a ItemFilterBlock + // to the clipboard, and when saving a ItemFilterScript. + // TODO: Private + public string TranslateItemFilterBlockToString(IItemFilterBlock block) + { if(!block.IsEdited) { return block.OriginalText; - } - - var outputString = string.Empty; - - if (!string.IsNullOrEmpty(block.Description)) - { - outputString += "# " + block.Description + Environment.NewLine; - } - - outputString += (!block.Enabled ? "#" : string.Empty) + block.Action.GetAttributeDescription(); - - if (block.BlockGroup != null) - { - outputString += " # " + block.BlockGroup; - } - else if (!string.IsNullOrEmpty(block.ActionBlockItem?.Comment)) - { - outputString += " #" + block.ActionBlockItem.Comment; - } - - // ReSharper disable once LoopCanBeConvertedToQuery - foreach (var blockItem in block.BlockItems.Where(b => b.GetType() != typeof(ActionBlockItem)).OrderBy(b => b.SortOrder)) - { - if (blockItem.OutputText != string.Empty) - { - outputString += (!block.Enabled ? _disabledNewLine : _newLine) + blockItem.OutputText; - } + } + + var outputString = string.Empty; + + if (!string.IsNullOrEmpty(block.Description)) + { + outputString += "# " + block.Description + Environment.NewLine; + } + + outputString += (!block.Enabled ? "#" : string.Empty) + block.Action.GetAttributeDescription(); + + if (block.BlockGroup != null) + { + outputString += " # " + block.BlockGroup; + } + else if (!string.IsNullOrEmpty(block.ActionBlockItem?.Comment)) + { + outputString += " #" + block.ActionBlockItem.Comment; + } + + // ReSharper disable once LoopCanBeConvertedToQuery + foreach (var blockItem in block.BlockItems.Where(b => b.GetType() != typeof(ActionBlockItem)).OrderBy(b => b.SortOrder)) + { + if (blockItem.OutputText != string.Empty) + { + outputString += (!block.Enabled ? _disabledNewLine : _newLine) + blockItem.OutputText; + } } //TODO: Disabled for the time being. A better solution is needed. @@ -769,7 +769,7 @@ namespace Filtration.Parser.Services //outputString.Replace("Maelström of Chaos", "Maelstr"); //outputString.Replace("Maelström", "Maelstr"); - return outputString; - } - } -} + return outputString; + } + } +} diff --git a/README.md b/README.md index 6b93dfc..95fc213 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ Filtration is an editor for Path of Exile item filter scripts. -## Current Release (Released 2018-08-30) -Installer filtration_0.19_setup.exe +## Current Release (Released 2018-09-01) +Installer filtration_0.20_setup.exe -Zip File filtration_0.19.zip +Zip File filtration_0.20.zip ## System Requirements Filtration requires .NET Framework 4.6.1 installed.