diff --git a/Filtration.ObjectModel/BlockItemBaseTypes/ActionBlockItem.cs b/Filtration.ObjectModel/BlockItemBaseTypes/ActionBlockItem.cs index 8660377..5dd20c2 100644 --- a/Filtration.ObjectModel/BlockItemBaseTypes/ActionBlockItem.cs +++ b/Filtration.ObjectModel/BlockItemBaseTypes/ActionBlockItem.cs @@ -27,8 +27,6 @@ namespace Filtration.ObjectModel.BlockItemBaseTypes } } - public string Comment { get; set; } - public override string OutputText => Action.GetAttributeDescription(); public override string PrefixText => string.Empty; diff --git a/Filtration.ObjectModel/BlockItemBaseTypes/BlockItembase.cs b/Filtration.ObjectModel/BlockItemBaseTypes/BlockItembase.cs index b6ce2d9..d7c76f2 100644 --- a/Filtration.ObjectModel/BlockItemBaseTypes/BlockItembase.cs +++ b/Filtration.ObjectModel/BlockItemBaseTypes/BlockItembase.cs @@ -17,6 +17,7 @@ namespace Filtration.ObjectModel.BlockItemBaseTypes public abstract Color SummaryBackgroundColor { get; } public abstract Color SummaryTextColor { get; } public abstract int SortOrder { get; } + public string Comment { get; set; } public bool IsDirty { diff --git a/Filtration.ObjectModel/IBlockItemWithTheme.cs b/Filtration.ObjectModel/IBlockItemWithTheme.cs index 5971eb0..8d8dd81 100644 --- a/Filtration.ObjectModel/IBlockItemWithTheme.cs +++ b/Filtration.ObjectModel/IBlockItemWithTheme.cs @@ -4,6 +4,6 @@ namespace Filtration.ObjectModel { public interface IBlockItemWithTheme : IItemFilterBlockItem { - ThemeComponent ThemeComponent { get; } + ThemeComponent ThemeComponent { get; set; } } } diff --git a/Filtration.ObjectModel/IItemFilterBlockItem.cs b/Filtration.ObjectModel/IItemFilterBlockItem.cs index ec693d0..ce9f880 100644 --- a/Filtration.ObjectModel/IItemFilterBlockItem.cs +++ b/Filtration.ObjectModel/IItemFilterBlockItem.cs @@ -14,5 +14,6 @@ namespace Filtration.ObjectModel int MaximumAllowed { get; } int SortOrder { get; } bool IsDirty { get; } + string Comment { get; set; } } } diff --git a/Filtration.ObjectModel/ThemeEditor/StringThemeComponent.cs b/Filtration.ObjectModel/ThemeEditor/StringThemeComponent.cs index 98b98e4..1975dc5 100644 --- a/Filtration.ObjectModel/ThemeEditor/StringThemeComponent.cs +++ b/Filtration.ObjectModel/ThemeEditor/StringThemeComponent.cs @@ -1,5 +1,6 @@ using System; using System.Collections.ObjectModel; +using System.Linq; using Filtration.ObjectModel.Enums; using GalaSoft.MvvmLight.Command; using Microsoft.Win32; @@ -25,13 +26,34 @@ namespace Filtration.ObjectModel.ThemeEditor if (_customSoundsAvailable == null || _customSoundsAvailable.Count < 1) { - _customSoundsAvailable = new ObservableCollection { - "1maybevaluable.mp3", "2currency.mp3", "3uniques.mp3", "4maps.mp3", "5highmaps.mp3", - "6veryvaluable.mp3", "7chancing.mp3", "12leveling.mp3", "placeholder.mp3" - }; + + _customSoundsAvailable = new ObservableCollection(); + + var poeFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString() + @"\My Games\Path of Exile\"; + if(System.IO.Directory.Exists(poeFolderPath)) + { + var poeFolderFiles = System.IO.Directory.GetFiles(poeFolderPath).Where( + s => s.EndsWith(".mp3") + || s.EndsWith(".wav") + || s.EndsWith(".wma") + || s.EndsWith(".3gp") + || s.EndsWith(".aag") + || s.EndsWith(".m4a") + || s.EndsWith(".ogg") + ).OrderBy(f => f); + + foreach (var file in poeFolderFiles) + { + _customSoundsAvailable.Add(file.Replace(poeFolderPath, "")); + } + } } - if (_customSoundsAvailable.IndexOf(Value) < 0) + if(string.IsNullOrWhiteSpace(Value)) + { + Value = _customSoundsAvailable.Count > 0 ? _customSoundsAvailable[0] : ""; + } + else if (_customSoundsAvailable.IndexOf(Value) < 0) { _customSoundsAvailable.Add(Value); } diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index 8da9022..d21aef7 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -405,6 +405,24 @@ namespace Filtration.Parser.Tests.Services Assert.IsTrue(blockItem.BooleanValue); } + [Test] + public void TranslateStringToItemFilterBlock_MapTier_ReturnsCorrectObject() + { + // Arrange + var inputString = "Show" + Environment.NewLine + + " MapTier >= 15"; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); + + // Assert + + Assert.AreEqual(1, result.BlockItems.Count(b => b is MapTierBlockItem)); + var blockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(15, blockItem.FilterPredicate.PredicateOperand); + Assert.AreEqual(FilterPredicateOperator.GreaterThanOrEqual, blockItem.FilterPredicate.PredicateOperator); + } + [Test] public void TranslateStringToItemFilterBlock_ShapedMap_ReturnsCorrectObject() { @@ -925,7 +943,10 @@ namespace Filtration.Parser.Tests.Services " SetBorderColor 0 0 0" + Environment.NewLine + " SetFontSize 50" + Environment.NewLine + " PlayAlertSound 3" + Environment.NewLine + - " DisableDropSound False" + Environment.NewLine; + " DisableDropSound False" + Environment.NewLine + + " CustomAlertSound \"test.mp3\" # customSoundTheme" + Environment.NewLine + + " MinimapIcon 2 Green Triangle # iconTheme" + Environment.NewLine + + " PlayEffect Green Temp # effectTheme" + Environment.NewLine; // Act var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); @@ -1023,13 +1044,41 @@ namespace Filtration.Parser.Tests.Services var fontSizeblockItem = result.BlockItems.OfType().First(); Assert.AreEqual(50, fontSizeblockItem.Value); - - var soundblockItem = result.BlockItems.OfType().First(); - Assert.AreEqual("3", soundblockItem.Value); - Assert.AreEqual(79, soundblockItem.SecondValue); + + Assert.AreEqual(0, result.BlockItems.OfType().Count()); var disableDropSoundBlockItem = result.BlockItems.OfType().First(); Assert.IsFalse(disableDropSoundBlockItem.BooleanValue); + + var customSoundBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual("test.mp3", customSoundBlockItem.Value); + Assert.AreNotEqual(null, customSoundBlockItem.ThemeComponent); + Assert.AreEqual(ThemeComponentType.CustomSound, customSoundBlockItem.ThemeComponent.ComponentType); + Assert.AreEqual("customSoundTheme", customSoundBlockItem.ThemeComponent.ComponentName); + Assert.AreEqual(typeof(StringThemeComponent), customSoundBlockItem.ThemeComponent.GetType()); + Assert.AreEqual("test.mp3", ((StringThemeComponent)customSoundBlockItem.ThemeComponent).Value); + + var mapIconBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(IconSize.Small, mapIconBlockItem.Size); + Assert.AreEqual(IconColor.Green, mapIconBlockItem.Color); + Assert.AreEqual(IconShape.Triangle, mapIconBlockItem.Shape); + Assert.AreNotEqual(null, mapIconBlockItem.ThemeComponent); + Assert.AreEqual(ThemeComponentType.Icon, mapIconBlockItem.ThemeComponent.ComponentType); + Assert.AreEqual("iconTheme", mapIconBlockItem.ThemeComponent.ComponentName); + Assert.AreEqual(typeof(IconThemeComponent), mapIconBlockItem.ThemeComponent.GetType()); + Assert.AreEqual(IconSize.Small, ((IconThemeComponent)mapIconBlockItem.ThemeComponent).IconSize); + Assert.AreEqual(IconColor.Green, ((IconThemeComponent)mapIconBlockItem.ThemeComponent).IconColor); + Assert.AreEqual(IconShape.Triangle, ((IconThemeComponent)mapIconBlockItem.ThemeComponent).IconShape); + + var effectColorBlockItem = result.BlockItems.OfType().First(); + Assert.AreEqual(EffectColor.Green, effectColorBlockItem.Color); + Assert.IsTrue(effectColorBlockItem.Temporary); + Assert.AreNotEqual(null, effectColorBlockItem.ThemeComponent); + Assert.AreEqual(ThemeComponentType.Effect, effectColorBlockItem.ThemeComponent.ComponentType); + Assert.AreEqual("effectTheme", effectColorBlockItem.ThemeComponent.ComponentName); + Assert.AreEqual(typeof(EffectColorThemeComponent), effectColorBlockItem.ThemeComponent.GetType()); + Assert.AreEqual(EffectColor.Green, ((EffectColorThemeComponent)effectColorBlockItem.ThemeComponent).EffectColor); + Assert.IsTrue(((EffectColorThemeComponent)effectColorBlockItem.ThemeComponent).Temporary); } [Test] diff --git a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs index 31290a8..a859cc2 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs @@ -285,13 +285,11 @@ namespace Filtration.Parser.Tests.Services " ItemLevel > 2" + Environment.NewLine + " SetTextColor 255 40 0" + Environment.NewLine + Environment.NewLine + - "#Disabled Block Start" + Environment.NewLine + "#Show" + Environment.NewLine + "# ItemLevel > 2" + Environment.NewLine + "# SetTextColor 255 215 0" + Environment.NewLine + "# SetBorderColor 255 105 180" + Environment.NewLine + "# SetFontSize 32" + Environment.NewLine + - "#Disabled Block End" + Environment.NewLine + Environment.NewLine + "Show" + Environment.NewLine + " ItemLevel > 20" + Environment.NewLine + @@ -316,13 +314,11 @@ namespace Filtration.Parser.Tests.Services " ItemLevel > 2" + Environment.NewLine + " SetTextColor 255 40 0" + Environment.NewLine + Environment.NewLine + - "#Disabled Block Start" + Environment.NewLine + "#Show" + Environment.NewLine + "# ItemLevel > 2" + Environment.NewLine + "# SetTextColor 255 215 0" + Environment.NewLine + "# SetBorderColor 255 105 180" + Environment.NewLine + "# SetFontSize 32" + Environment.NewLine + - "#Disabled Block End" + Environment.NewLine + Environment.NewLine + "Show" + Environment.NewLine + " ItemLevel > 20" + Environment.NewLine + @@ -355,11 +351,9 @@ namespace Filtration.Parser.Tests.Services " ItemLevel > 2" + Environment.NewLine + " SetTextColor 255 40 0" + Environment.NewLine + Environment.NewLine + - "#Disabled Block Start" + Environment.NewLine + "# This is a disabled block" + Environment.NewLine + "#Show" + Environment.NewLine + - "# ItemLevel > 2" + Environment.NewLine + - "#Disabled Block End"; + "# ItemLevel > 2"; var blockTranslator = new ItemFilterBlockTranslator(Mock.Of()); @@ -384,11 +378,9 @@ namespace Filtration.Parser.Tests.Services " ItemLevel > 2" + Environment.NewLine + " SetTextColor 255 40 0" + Environment.NewLine + Environment.NewLine + - "#Disabled Block Start" + Environment.NewLine + "# This is a disabled block" + Environment.NewLine + "#Show#My Block Group" + Environment.NewLine + - "# ItemLevel > 2" + Environment.NewLine + - "#Disabled Block End"; + "# ItemLevel > 2"; var mockBlockGroupHierarchyBuilder = new Mock(); diff --git a/Filtration.Parser/Filtration.Parser.csproj b/Filtration.Parser/Filtration.Parser.csproj index 2a8d160..31c62ba 100644 --- a/Filtration.Parser/Filtration.Parser.csproj +++ b/Filtration.Parser/Filtration.Parser.csproj @@ -39,6 +39,7 @@ ..\packages\Castle.Windsor.3.4.0\lib\net45\Castle.Windsor.dll + diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index a48148e..9d27596 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -63,13 +63,35 @@ namespace Filtration.Parser.Services foreach (var line in new LineReader(() => new StringReader(inputString))) { - if (line.StartsWith(@"#") && !showHideFound) + if (line.StartsWith(@"#")) { - block.Description = line.TrimStart('#').TrimStart(' '); + if(!showHideFound) + { + block.Description = line.TrimStart('#').TrimStart(' '); + } + else + { + if(block.BlockItems.Count > 1) + { + block.BlockItems.Last().Comment += Environment.NewLine + line.TrimStart('#'); + } + else + { + block.ActionBlockItem.Comment += Environment.NewLine + line.TrimStart('#'); + } + } continue; } - var trimmedLine = line.Trim(); + 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); @@ -88,11 +110,11 @@ namespace Filtration.Parser.Services // group hierarchy, if block groups are disabled it is preserved as a simple text comment. if (parentItemFilterScript.ItemFilterScriptSettings.BlockGroupsEnabled) { - AddBlockGroupToBlock(block, trimmedLine); + AddBlockGroupToBlock(block, fullLine); } else { - block.ActionBlockItem.Comment = GetTextAfterFirstComment(trimmedLine); + block.ActionBlockItem.Comment = GetTextAfterFirstComment(fullLine); } break; } @@ -193,7 +215,12 @@ namespace Filtration.Parser.Services // Only ever use the last SetTextColor item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType(block); - AddColorItemToBlockItems(block, trimmedLine); + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new TextColorBlockItem(); + blockItem.Color = GetColorFromString(result[0].Groups[1].Value); + block.BlockItems.Add(blockItem); + themeComponentType = (int)ThemeComponentType.TextColor; break; } case "SetBackgroundColor": @@ -201,7 +228,12 @@ namespace Filtration.Parser.Services // Only ever use the last SetBackgroundColor item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType(block); - AddColorItemToBlockItems(block, trimmedLine); + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new BackgroundColorBlockItem(); + blockItem.Color = GetColorFromString(result[0].Groups[1].Value); + block.BlockItems.Add(blockItem); + themeComponentType = (int)ThemeComponentType.BackgroundColor; break; } case "SetBorderColor": @@ -209,7 +241,12 @@ namespace Filtration.Parser.Services // Only ever use the last SetBorderColor item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType(block); - AddColorItemToBlockItems(block, trimmedLine); + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new BorderColorBlockItem(); + blockItem.Color = GetColorFromString(result[0].Groups[1].Value); + block.BlockItems.Add(blockItem); + themeComponentType = (int)ThemeComponentType.BorderColor; break; } case "SetFontSize": @@ -217,15 +254,12 @@ namespace Filtration.Parser.Services // Only ever use the last SetFontSize item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType(block); - var match = Regex.Matches(trimmedLine, @"(\s+(\d+)\s*)([#]?)(.*)"); + var match = Regex.Matches(trimmedLine, @"(\s+(\d+)\s*)"); if (match.Count > 0) { var blockItem = new FontSizeBlockItem(Convert.ToInt16(match[0].Groups[2].Value)); - if(match[0].Groups[3].Value == "#" && !string.IsNullOrWhiteSpace(match[0].Groups[4].Value)) - { - blockItem.ThemeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.FontSize, match[0].Groups[4].Value.Trim(), blockItem.Value); - } block.BlockItems.Add(blockItem); + themeComponentType = (int)ThemeComponentType.FontSize; } break; } @@ -237,7 +271,7 @@ namespace Filtration.Parser.Services RemoveExistingBlockItemsOfType(block); RemoveExistingBlockItemsOfType(block); - var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?\s*([#]?)(.*)"); + var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?"); if (match.Success) { @@ -251,12 +285,6 @@ namespace Filtration.Parser.Services else { secondValue = 79; - } - - ThemeComponent themeComponent = null; - if(match.Groups[3].Value == "#" && !string.IsNullOrWhiteSpace(match.Groups[4].Value)) - { - themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.AlertSound, match.Groups[4].Value.Trim(), firstValue, secondValue); } if (lineOption == "PlayAlertSound") @@ -266,7 +294,6 @@ namespace Filtration.Parser.Services Value = firstValue, SecondValue = secondValue }; - blockItemValue.ThemeComponent = themeComponent; block.BlockItems.Add(blockItemValue); } else @@ -276,9 +303,9 @@ namespace Filtration.Parser.Services Value = firstValue, SecondValue = secondValue }; - blockItemValue.ThemeComponent = themeComponent; block.BlockItems.Add(blockItemValue); - } + } + themeComponentType = (int)ThemeComponentType.AlertSound; } break; } @@ -336,6 +363,7 @@ namespace Filtration.Parser.Services blockItemValue.ThemeComponent = themeComponent; } block.BlockItems.Add(blockItemValue); + themeComponentType = (int)ThemeComponentType.Icon; } break; } @@ -345,7 +373,7 @@ namespace Filtration.Parser.Services RemoveExistingBlockItemsOfType(block); // TODO: Get colors programmatically - var match = Regex.Match(trimmedLine, @"\S+\s+(Red|Green|Blue|Brown|White|Yellow)\s*(Temp)?\s*([#]?)(.*)", RegexOptions.IgnoreCase); + var match = Regex.Match(trimmedLine, @"\S+\s+(Red|Green|Blue|Brown|White|Yellow)\s*(Temp)?", RegexOptions.IgnoreCase); if (match.Success) { @@ -353,15 +381,9 @@ namespace Filtration.Parser.Services { Color = EnumHelper.GetEnumValueFromDescription(match.Groups[1].Value), Temporary = match.Groups[2].Value.Trim().ToLower() == "temp" - }; - - if(match.Groups[3].Value == "#" && !string.IsNullOrWhiteSpace(match.Groups[4].Value)) - { - ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.Effect, match.Groups[4].Value.Trim(), - blockItemValue.Color, blockItemValue.Temporary); - blockItemValue.ThemeComponent = themeComponent; - } - block.BlockItems.Add(blockItemValue); + }; + block.BlockItems.Add(blockItemValue); + themeComponentType = (int)ThemeComponentType.Effect; } break; } @@ -372,21 +394,16 @@ namespace Filtration.Parser.Services RemoveExistingBlockItemsOfType(block); RemoveExistingBlockItemsOfType(block); - var match = Regex.Match(trimmedLine, @"\S+\s+""(\S+)""\s*([#]?)(.*)"); + var match = Regex.Match(trimmedLine, @"\S+\s+""(\S+)"""); if (match.Success) { var blockItemValue = new CustomSoundBlockItem { Value = match.Groups[1].Value - }; - - if(match.Groups[2].Value == "#" && !string.IsNullOrWhiteSpace(match.Groups[3].Value)) - { - ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.CustomSound, match.Groups[3].Value.Trim(), blockItemValue.Value); - blockItemValue.ThemeComponent = themeComponent; - } - block.BlockItems.Add(blockItemValue); + }; + block.BlockItems.Add(blockItemValue); + themeComponentType = (int)ThemeComponentType.CustomSound; } break; } @@ -395,9 +412,88 @@ namespace Filtration.Parser.Services AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); break; } + } + + if (!string.IsNullOrWhiteSpace(blockComment) && block.BlockItems.Count > 1) + { + var blockItemWithTheme = block.BlockItems.Last() as IBlockItemWithTheme; + if(blockItemWithTheme == null) + { + block.BlockItems.Last().Comment = blockComment; + } + else + { + switch((ThemeComponentType)themeComponentType) + { + case ThemeComponentType.AlertSound: + { + ThemeComponent themeComponent = null; + if(blockItemWithTheme is SoundBlockItem) + { + themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.AlertSound, blockComment.Trim(), + ((SoundBlockItem)blockItemWithTheme).Value, ((SoundBlockItem)blockItemWithTheme).SecondValue); + } + else + { + themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.AlertSound, blockComment.Trim(), + ((PositionalSoundBlockItem)blockItemWithTheme).Value, ((PositionalSoundBlockItem)blockItemWithTheme).SecondValue); + } + blockItemWithTheme.ThemeComponent = themeComponent; + break; + } + case ThemeComponentType.BackgroundColor: + { + ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BackgroundColor, + blockComment.Trim(), ((BackgroundColorBlockItem)blockItemWithTheme).Color); + blockItemWithTheme.ThemeComponent = themeComponent; + break; + } + case ThemeComponentType.BorderColor: + { + ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BorderColor, + blockComment.Trim(), ((BorderColorBlockItem)blockItemWithTheme).Color); + blockItemWithTheme.ThemeComponent = themeComponent; + break; + } + case ThemeComponentType.CustomSound: + { + ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.CustomSound, + blockComment.Trim(), ((CustomSoundBlockItem)blockItemWithTheme).Value); + blockItemWithTheme.ThemeComponent = themeComponent; + break; + } + case ThemeComponentType.Effect: + { + ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.Effect, + blockComment.Trim(), ((EffectColorBlockItem)blockItemWithTheme).Color, ((EffectColorBlockItem)blockItemWithTheme).Temporary); + blockItemWithTheme.ThemeComponent = themeComponent; + break; + } + case ThemeComponentType.FontSize: + { + ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.FontSize, + blockComment.Trim(), ((FontSizeBlockItem)blockItemWithTheme).Value); + blockItemWithTheme.ThemeComponent = themeComponent; + break; + } + case ThemeComponentType.Icon: + { + ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.Icon, blockComment.Trim(), + ((IconBlockItem)blockItemWithTheme).Size, ((IconBlockItem)blockItemWithTheme).Color, ((IconBlockItem)blockItemWithTheme).Shape); + blockItemWithTheme.ThemeComponent = themeComponent; + break; + } + case ThemeComponentType.TextColor: + { + ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.TextColor, + blockComment.Trim(), ((TextColorBlockItem)blockItemWithTheme).Color); + blockItemWithTheme.ThemeComponent = themeComponent; + break; + } + } + } } } - block.IsEdited = false; return block; } @@ -460,48 +556,6 @@ namespace Filtration.Parser.Services } } - private void AddColorItemToBlockItems(IItemFilterBlock block, string inputString) where T : ColorBlockItem - { - block.BlockItems.Add(GetColorBlockItemFromString(inputString)); - } - - private T GetColorBlockItemFromString(string inputString) where T: ColorBlockItem - { - var blockItem = Activator.CreateInstance(); - var result = Regex.Matches(inputString, @"([\w\s]*)[#]?(.*)"); - - blockItem.Color = GetColorFromString(result[0].Groups[1].Value); - - var componentName = result[0].Groups[2].Value.Trim(); - if (!string.IsNullOrEmpty(componentName)) - { - ThemeComponentType componentType; - if (typeof(T) == typeof(TextColorBlockItem)) - { - componentType = ThemeComponentType.TextColor; - } - else if (typeof(T) == typeof(BackgroundColorBlockItem)) - { - componentType = ThemeComponentType.BackgroundColor; - } - else if (typeof(T) == typeof(BorderColorBlockItem)) - { - componentType = ThemeComponentType.BorderColor; - } - else - { - throw new Exception("Parsing error - unknown theme component type"); - } - if (_masterComponentCollection != null) - { - blockItem.ThemeComponent = _masterComponentCollection.AddComponent(componentType, componentName, - blockItem.Color); - } - } - - return blockItem; - } - public void ReplaceAudioVisualBlockItemsFromString(ObservableCollection blockItems, string inputString) { // Reverse iterate to remove existing IAudioVisualBlockItems @@ -516,36 +570,87 @@ namespace Filtration.Parser.Services 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(line, @"\s+(\S+) (\d+)"); + var match = Regex.Match(trimmedLine, @"\s+(\S+) (\d+)"); if (!match.Success) break; - blockItems.Add(new SoundBlockItem(match.Groups[1].Value, Convert.ToInt16(match.Groups[2].Value))); + 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": { - blockItems.Add(GetColorBlockItemFromString(line)); + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new TextColorBlockItem(); + blockItem.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": { - blockItems.Add(GetColorBlockItemFromString(line)); + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new BackgroundColorBlockItem(); + blockItem.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": { - blockItems.Add(GetColorBlockItemFromString(line)); + var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); + + var blockItem = new BorderColorBlockItem(); + blockItem.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(line, @"\s+(\d+)"); + var match = Regex.Match(trimmedLine, @"\s+(\d+)"); if (!match.Success) break; - blockItems.Add(new FontSizeBlockItem(Convert.ToInt16(match.Value))); + 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; } } diff --git a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs index 6407226..e386963 100644 --- a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; +using System.Windows; using Filtration.Common.Utilities; using Filtration.ObjectModel; using Filtration.ObjectModel.Factories; @@ -48,18 +48,58 @@ namespace Filtration.Parser.Services _itemFilterScriptFactory = itemFilterScriptFactory; } - public static string PreprocessDisabledBlocks(string inputString) + public static string PreprocessDisabledBlocks(string inputString, out List inBlock) { bool inDisabledBlock = false; + inBlock = new List(); var lines = Regex.Split(inputString, "\r\n|\r|\n").ToList(); + // find first show/hide and check script + for (var i = 0; i < lines.Count; i++) + { + inBlock.Add(false); + lines[i] = lines[i].Trim(); + if(!lines[i].StartsWith("#")) + { + string curLine = Regex.Replace(lines[i], @"\s+", ""); + if ((curLine.StartsWith("Show") || curLine.StartsWith("Hide")) && (curLine.Length == 4 || curLine[4] == '#')) // found + { + inBlock[i] = true; + break; + } + else // This means script has wrong syntax, just replace those lines with empty string + { + lines[i] = ""; + } + } + } + + // find remaining boundaries + var lastInBlock = inBlock.Count - 1; + for (var i = inBlock.Count; i < lines.Count; i++) + { + inBlock.Add(false); + lines[i] = lines[i].Trim(); + if (!lines[i].StartsWith("#") && lines[i].Length > 0) + { + if (!lines[i].StartsWith("Show") && !lines[i].StartsWith("Hide")) // Continuing inline + { + for(int j = lastInBlock + 1; j < i; j++) + { + inBlock[j] = true; + } + } + lastInBlock = i; + inBlock[i] = true; + } + } for (var i = 0; i < lines.Count; i++) { if (!inDisabledBlock && lines[i].StartsWith("#")) { string curLine = Regex.Replace(lines[i].Substring(1), @"\s+", ""); - if ((curLine.StartsWith("Show") || curLine.StartsWith("Hide")) && (curLine.Length == 4 || curLine[4] == '#')) + if ((curLine.StartsWith("Show") || curLine.StartsWith("Hide")) && (curLine.Length == 4 || curLine[4] == '#') && !inBlock[i]) { inDisabledBlock = true; lines[i] = lines[i].Substring(1).TrimStart(' '); @@ -88,16 +128,29 @@ namespace Filtration.Parser.Services var script = _itemFilterScriptFactory.Create(); _blockGroupHierarchyBuilder.Initialise(script.ItemFilterBlockGroups.First()); - //Remove old disabled tags - inputString = Regex.Replace(inputString, @"#Disabled\sBlock\s(Start|End).*?\n", ""); - inputString = (inputString.EndsWith("\n#Disabled Block End")) ? inputString.Substring(0, inputString.Length - 19) : inputString; + if(Regex.Matches(inputString, @"#Disabled\sBlock\s(Start|End).*?\n").Count > 0) + { + if (MessageBox.Show( + "Loaded script contains special '#Disabled Block Start' lines." + + " These may be coming from old versions of Filtration or Greengroove's filter." + + "It is suggested to remove them however this may cause problems with original source" + + Environment.NewLine + "(There is no in game effect of those lines)" + + Environment.NewLine + Environment.NewLine + "Would you like to remove them?", "Special Comment Lines Found", + MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) + { + //Remove old disabled tags + inputString = Regex.Replace(inputString, @"#Disabled\sBlock\s(Start|End).*?\n", ""); + inputString = (inputString.EndsWith("\n#Disabled Block End")) ? inputString.Substring(0, inputString.Length - 19) : inputString; + } + } var originalLines = Regex.Split(inputString, "\r\n|\r|\n"); inputString = inputString.Replace("\t", ""); - inputString = PreprocessDisabledBlocks(inputString); + List inBlock; + inputString = PreprocessDisabledBlocks(inputString, out inBlock); - var conditionBoundaries = IdentifyBlockBoundaries(inputString); + var conditionBoundaries = IdentifyBlockBoundaries(inputString, inBlock); var lines = Regex.Split(inputString, "\r\n|\r|\n"); @@ -158,7 +211,7 @@ namespace Filtration.Parser.Services return script; } - private static LinkedList IdentifyBlockBoundaries(string inputString) + private static LinkedList IdentifyBlockBoundaries(string inputString, List inBlock) { var blockBoundaries = new LinkedList(); var previousLine = string.Empty; @@ -177,9 +230,10 @@ namespace Filtration.Parser.Services continue; } - // A line starting with a comment when we're inside a ItemFilterBlock boundary represents the end of that block - // as ItemFilterBlocks cannot have comment lines after the block description - if (trimmedLine.StartsWith("#") && currentItemFilterBlockBoundary.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock) + // A line starting with a comment when we're inside a ItemFilterBlock boundary may represent the end of that block + // or a block item comment + if (trimmedLine.StartsWith("#") && !inBlock[currentLine] && + currentItemFilterBlockBoundary.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock) { blockBoundaries.AddLast(currentItemFilterBlockBoundary); currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(currentLine, ItemFilterBlockBoundaryType.CommentBlock); diff --git a/Filtration.ThemeEditor/ViewModels/ThemeEditorViewModel.cs b/Filtration.ThemeEditor/ViewModels/ThemeEditorViewModel.cs index c18a8c9..14f0442 100644 --- a/Filtration.ThemeEditor/ViewModels/ThemeEditorViewModel.cs +++ b/Filtration.ThemeEditor/ViewModels/ThemeEditorViewModel.cs @@ -209,7 +209,7 @@ namespace Filtration.ThemeEditor.ViewModels Components.Add(new StrIntThemeComponent(themeComponentType, "Untitled Component", "1", 100)); break; case ThemeComponentType.CustomSound: - Components.Add(new StringThemeComponent(themeComponentType, "Untitled Component", "placeholder.mp3")); + Components.Add(new StringThemeComponent(themeComponentType, "Untitled Component", "")); break; case ThemeComponentType.Icon: Components.Add(new IconThemeComponent(themeComponentType, "Untitled Component", IconSize.Largest, IconColor.Red, IconShape.Circle)); diff --git a/Filtration/Converters/SizeColorToRectConverter.cs b/Filtration/Converters/SizeColorToRectConverter.cs index 216c0da..5facce6 100644 --- a/Filtration/Converters/SizeColorToRectConverter.cs +++ b/Filtration/Converters/SizeColorToRectConverter.cs @@ -11,7 +11,7 @@ namespace Filtration.Converters { if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue) - return null; + return new Rect(0, 0, 0, 0); var size = (int)(values[0]); var color = (int)(values[1]); diff --git a/Filtration/Resources/DropIcons/Circle.png b/Filtration/Resources/DropIcons/Circle.png index 7b59891..296d755 100644 Binary files a/Filtration/Resources/DropIcons/Circle.png and b/Filtration/Resources/DropIcons/Circle.png differ diff --git a/Filtration/Resources/DropIcons/Diamond.png b/Filtration/Resources/DropIcons/Diamond.png index ab917dd..3c6041d 100644 Binary files a/Filtration/Resources/DropIcons/Diamond.png and b/Filtration/Resources/DropIcons/Diamond.png differ diff --git a/Filtration/Resources/DropIcons/Hexagon.png b/Filtration/Resources/DropIcons/Hexagon.png index 549fa94..1694503 100644 Binary files a/Filtration/Resources/DropIcons/Hexagon.png and b/Filtration/Resources/DropIcons/Hexagon.png differ diff --git a/Filtration/Resources/DropIcons/Square.png b/Filtration/Resources/DropIcons/Square.png index 9e143cf..3b8e6e4 100644 Binary files a/Filtration/Resources/DropIcons/Square.png and b/Filtration/Resources/DropIcons/Square.png differ diff --git a/Filtration/Resources/DropIcons/Star.png b/Filtration/Resources/DropIcons/Star.png index 9158e90..2695433 100644 Binary files a/Filtration/Resources/DropIcons/Star.png and b/Filtration/Resources/DropIcons/Star.png differ diff --git a/Filtration/Resources/DropIcons/Triangle.png b/Filtration/Resources/DropIcons/Triangle.png index 3d8d6d9..88f8ca1 100644 Binary files a/Filtration/Resources/DropIcons/Triangle.png and b/Filtration/Resources/DropIcons/Triangle.png differ diff --git a/Filtration/ViewModels/ItemFilterBlockViewModel.cs b/Filtration/ViewModels/ItemFilterBlockViewModel.cs index edcf88d..4fa9893 100644 --- a/Filtration/ViewModels/ItemFilterBlockViewModel.cs +++ b/Filtration/ViewModels/ItemFilterBlockViewModel.cs @@ -251,6 +251,13 @@ namespace Filtration.ViewModels var newBlockItem = (IItemFilterBlockItem) Activator.CreateInstance(blockItemType); newBlockItem.PropertyChanged += OnBlockItemChanged; + + var customSoundBlockItem = newBlockItem as CustomSoundBlockItem; + if(customSoundBlockItem != null && _parentScriptViewModel.CustomSoundsAvailable.Count > 0) + { + customSoundBlockItem.Value = _parentScriptViewModel.CustomSoundsAvailable[0]; + } + BlockItems.Add(newBlockItem); OnBlockItemChanged(this, EventArgs.Empty); IsDirty = true; diff --git a/Filtration/ViewModels/ItemFilterCommentBlockViewModel.cs b/Filtration/ViewModels/ItemFilterCommentBlockViewModel.cs index 618065a..90bb853 100644 --- a/Filtration/ViewModels/ItemFilterCommentBlockViewModel.cs +++ b/Filtration/ViewModels/ItemFilterCommentBlockViewModel.cs @@ -1,6 +1,7 @@ using Filtration.ObjectModel; using GalaSoft.MvvmLight.CommandWpf; using System; +using System.Text.RegularExpressions; namespace Filtration.ViewModels { @@ -61,7 +62,7 @@ namespace Filtration.ViewModels { string[] commentLines = ItemFilterCommentBlock.Comment.Split(new[] { Environment.NewLine }, StringSplitOptions.None); var titleOffset = 1; - if (commentLines.Length > 1 && (commentLines[0].TrimStart(' ').StartsWith(@"============") || commentLines[0].TrimStart(' ').StartsWith(@"------------"))) + if (commentLines.Length > 1 && !Regex.Match(commentLines[0], "[a-zA-Z]+").Success) { titleOffset = 3; commentLines[0] = commentLines[1]; diff --git a/Filtration/ViewModels/ItemFilterScriptViewModel.cs b/Filtration/ViewModels/ItemFilterScriptViewModel.cs index e915c76..a5b3c15 100644 --- a/Filtration/ViewModels/ItemFilterScriptViewModel.cs +++ b/Filtration/ViewModels/ItemFilterScriptViewModel.cs @@ -166,10 +166,22 @@ namespace Filtration.ViewModels _viewItemFilterBlockViewModels = new ObservableCollection(); - _customSoundsAvailable = new ObservableCollection { - "1maybevaluable.mp3", "2currency.mp3", "3uniques.mp3", "4maps.mp3", "5highmaps.mp3", - "6veryvaluable.mp3", "7chancing.mp3", "12leveling.mp3", "placeholder.mp3" - }; + _customSoundsAvailable = new ObservableCollection(); + + var poeFolderFiles = Directory.GetFiles(persistenceService.DefaultPathOfExileDirectory() + "\\").Where( + s => s.EndsWith(".mp3") + || s.EndsWith(".wav") + || s.EndsWith(".wma") + || s.EndsWith(".3gp") + || s.EndsWith(".aag") + || s.EndsWith(".m4a") + || s.EndsWith(".ogg") + ).OrderBy(f => f); + + foreach(var file in poeFolderFiles) + { + _customSoundsAvailable.Add(file.Replace(persistenceService.DefaultPathOfExileDirectory() + "\\", "")); + } } public void Initialise(IItemFilterScript itemFilterScript, bool newScript)