Fix the reading of CustomAlertSounds containing path separators.

This commit is contained in:
GlenCFL 2018-08-31 19:57:14 -04:00
parent 7162e16b49
commit 24df1d7687
2 changed files with 403 additions and 323 deletions

View File

@ -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);
@ -372,37 +372,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<ElderItemBlockItem>().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<ElderItemBlockItem>().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<ShaperItemBlockItem>().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<ShaperItemBlockItem>().First();
Assert.IsTrue(blockItem.BooleanValue);
}
[Test]
@ -424,37 +424,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<ShapedMapBlockItem>().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<ShapedMapBlockItem>().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<ElderMapBlockItem>().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<ElderMapBlockItem>().First();
Assert.IsFalse(blockItem.BooleanValue);
}
[Test]
@ -793,7 +793,7 @@ namespace Filtration.Parser.Tests.Services
" SetTextColor 255 20 100 # Rare Item Text";
var testComponent = new ColorThemeComponent(ThemeComponentType.TextColor, "Rare Item Text", new Color { R = 255, G = 20, B = 100});
var testInputThemeComponentCollection = new ThemeComponentCollection { testComponent };
// Act
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScript>(i => i.ItemFilterScriptSettings.ThemeComponentCollection == testInputThemeComponentCollection));
@ -894,22 +894,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<DisableDropSoundBlockItem>().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<DisableDropSoundBlockItem>().First();
Assert.IsTrue(blockItem.BooleanValue);
}
[Test]
public void TranslateStringToItemFilterBlock_Everything_ReturnsCorrectObject()
{
@ -1044,7 +1044,7 @@ namespace Filtration.Parser.Tests.Services
var fontSizeblockItem = result.BlockItems.OfType<FontSizeBlockItem>().First();
Assert.AreEqual(50, fontSizeblockItem.Value);
Assert.AreEqual(0, result.BlockItems.OfType<SoundBlockItem>().Count());
var disableDropSoundBlockItem = result.BlockItems.OfType<DisableDropSoundBlockItem>().First();
@ -1087,9 +1087,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
@ -1150,7 +1150,7 @@ namespace Filtration.Parser.Tests.Services
var blockItem = result.BlockItems.OfType<FontSizeBlockItem>().First();
Assert.AreEqual(27, blockItem.Value);
}
[Test]
public void TranslateStringToItemFilterBlock_MultipleSoundItems_OnlyLastOneUsed()
{
@ -1271,6 +1271,86 @@ namespace Filtration.Parser.Tests.Services
Assert.AreEqual(ItemRarity.Rare, (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<CustomSoundBlockItem>().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<CustomSoundBlockItem>().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<CustomSoundBlockItem>().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<CustomSoundBlockItem>().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<CustomSoundBlockItem>().First();
Assert.AreEqual("C:\\Sounds/test.mp3", customSoundBlockItem.Value);
}
[Test]
public void TranslateStringToItemFilterBlock_SpecificTest_2()
{
@ -1326,13 +1406,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);
@ -1851,7 +1931,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";
@ -1893,7 +1973,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));
@ -1940,7 +2020,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));
@ -2008,7 +2088,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);
@ -2083,7 +2163,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<IItemFilterBlockItem>();
@ -2129,9 +2209,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<IItemFilterBlockItem>();
// Act
@ -2201,9 +2281,9 @@ namespace Filtration.Parser.Tests.Services
_testUtility.Translator.ReplaceAudioVisualBlockItemsFromString(testInputBlockItems, testInputString);
// Assert
}
private class ItemFilterBlockTranslatorTestUtility
{
public ItemFilterBlockTranslatorTestUtility()

View File

@ -41,13 +41,13 @@ namespace Filtration.Parser.Services
itemFilterCommentBlock.Comment += trimmedLine + Environment.NewLine;
}
itemFilterCommentBlock.Comment = itemFilterCommentBlock.Comment.TrimEnd('\r', '\n');
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
// 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)
{
@ -65,20 +65,20 @@ namespace Filtration.Parser.Services
{
if (line.StartsWith(@"#"))
{
if(!showHideFound)
{
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('#');
}
else
{
if(block.BlockItems.Count > 1)
{
block.BlockItems.Last().Comment += Environment.NewLine + line.TrimStart('#');
}
else
{
block.ActionBlockItem.Comment += Environment.NewLine + line.TrimStart('#');
}
}
continue;
}
@ -87,10 +87,10 @@ namespace Filtration.Parser.Services
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();
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;
@ -216,7 +216,7 @@ namespace Filtration.Parser.Services
RemoveExistingBlockItemsOfType<TextColorBlockItem>(block);
var result = Regex.Matches(trimmedLine, @"([\w\s]*)");
var blockItem = new TextColorBlockItem();
blockItem.Color = GetColorFromString(result[0].Groups[1].Value);
block.BlockItems.Add(blockItem);
@ -229,7 +229,7 @@ namespace Filtration.Parser.Services
RemoveExistingBlockItemsOfType<BackgroundColorBlockItem>(block);
var result = Regex.Matches(trimmedLine, @"([\w\s]*)");
var blockItem = new BackgroundColorBlockItem();
blockItem.Color = GetColorFromString(result[0].Groups[1].Value);
block.BlockItems.Add(blockItem);
@ -242,7 +242,7 @@ namespace Filtration.Parser.Services
RemoveExistingBlockItemsOfType<BorderColorBlockItem>(block);
var result = Regex.Matches(trimmedLine, @"([\w\s]*)");
var blockItem = new BorderColorBlockItem();
blockItem.Color = GetColorFromString(result[0].Groups[1].Value);
block.BlockItems.Add(blockItem);
@ -272,41 +272,41 @@ namespace Filtration.Parser.Services
RemoveExistingBlockItemsOfType<CustomSoundBlockItem>(block);
var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?");
if (match.Success)
{
string firstValue = match.Groups[1].Value;
int secondValue;
if (match.Groups[2].Success)
{
secondValue = Convert.ToInt16(match.Groups[2].Value);
}
else
{
secondValue = 79;
}
if (lineOption == "PlayAlertSound")
{
var blockItemValue = new SoundBlockItem
{
Value = firstValue,
SecondValue = secondValue
};
block.BlockItems.Add(blockItemValue);
}
else
{
var blockItemValue = new PositionalSoundBlockItem
{
Value = firstValue,
SecondValue = secondValue
};
block.BlockItems.Add(blockItemValue);
if (match.Success)
{
string firstValue = match.Groups[1].Value;
int secondValue;
if (match.Groups[2].Success)
{
secondValue = Convert.ToInt16(match.Groups[2].Value);
}
themeComponentType = (int)ThemeComponentType.AlertSound;
}
else
{
secondValue = 79;
}
if (lineOption == "PlayAlertSound")
{
var blockItemValue = new SoundBlockItem
{
Value = firstValue,
SecondValue = secondValue
};
block.BlockItems.Add(blockItemValue);
}
else
{
var blockItemValue = new PositionalSoundBlockItem
{
Value = firstValue,
SecondValue = secondValue
};
block.BlockItems.Add(blockItemValue);
}
themeComponentType = (int)ThemeComponentType.AlertSound;
}
break;
}
case "GemLevel":
@ -341,49 +341,49 @@ namespace Filtration.Parser.Services
{
// Only ever use the last Icon item encountered as multiples aren't valid.
RemoveExistingBlockItemsOfType<MapIconBlockItem>(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)Int16.Parse(match.Groups[1].Value),
Color = EnumHelper.GetEnumValueFromDescription<IconColor>(match.Groups[2].Value),
Shape = EnumHelper.GetEnumValueFromDescription<IconShape>(match.Groups[3].Value)
if (match.Success)
{
var blockItemValue = new MapIconBlockItem
{
Size = (IconSize)Int16.Parse(match.Groups[1].Value),
Color = EnumHelper.GetEnumValueFromDescription<IconColor>(match.Groups[2].Value),
Shape = EnumHelper.GetEnumValueFromDescription<IconShape>(match.Groups[3].Value)
};
if(match.Groups[4].Value == "#" && !string.IsNullOrWhiteSpace(match.Groups[5].Value))
{
ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.Icon, match.Groups[5].Value.Trim(),
blockItemValue.Size, blockItemValue.Color, blockItemValue.Shape);
blockItemValue.ThemeComponent = themeComponent;
}
block.BlockItems.Add(blockItemValue);
themeComponentType = (int)ThemeComponentType.Icon;
}
if(match.Groups[4].Value == "#" && !string.IsNullOrWhiteSpace(match.Groups[5].Value))
{
ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.Icon, match.Groups[5].Value.Trim(),
blockItemValue.Size, blockItemValue.Color, blockItemValue.Shape);
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<PlayEffectBlockItem>(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
{
Color = EnumHelper.GetEnumValueFromDescription<EffectColor>(match.Groups[1].Value),
Temporary = match.Groups[2].Value.Trim().ToLower() == "temp"
};
if (match.Success)
{
var blockItemValue = new PlayEffectBlockItem
{
Color = EnumHelper.GetEnumValueFromDescription<EffectColor>(match.Groups[1].Value),
Temporary = match.Groups[2].Value.Trim().ToLower() == "temp"
};
block.BlockItems.Add(blockItemValue);
themeComponentType = (int)ThemeComponentType.Effect;
themeComponentType = (int)ThemeComponentType.Effect;
}
break;
}
@ -394,17 +394,17 @@ namespace Filtration.Parser.Services
RemoveExistingBlockItemsOfType<SoundBlockItem>(block);
RemoveExistingBlockItemsOfType<PositionalSoundBlockItem>(block);
var match = Regex.Match(trimmedLine, @"\S+\s+""(\S+)""");
if (match.Success)
{
var blockItemValue = new CustomSoundBlockItem
{
Value = match.Groups[1].Value
};
var match = Regex.Match(trimmedLine, @"\S+\s+""([^\*\<\>\?|]+)""");
if (match.Success)
{
var blockItemValue = new CustomSoundBlockItem
{
Value = match.Groups[1].Value
};
block.BlockItems.Add(blockItemValue);
themeComponentType = (int)ThemeComponentType.CustomSound;
}
themeComponentType = (int)ThemeComponentType.CustomSound;
}
break;
}
case "MapTier":
@ -412,88 +412,88 @@ namespace Filtration.Parser.Services
AddNumericFilterPredicateItemToBlockItems<MapTierBlockItem>(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;
}
}
}
}
}
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;
}
@ -523,7 +523,7 @@ namespace Filtration.Parser.Services
private static void AddNumericFilterPredicateItemToBlockItems<T>(IItemFilterBlock block, string inputString) where T : NumericFilterPredicateBlockItem
{
var blockItem = Activator.CreateInstance<T>();
SetNumericFilterPredicateFromString(blockItem.FilterPredicate, inputString);
block.BlockItems.Add(blockItem);
}
@ -572,12 +572,12 @@ namespace Filtration.Parser.Services
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();
}
if (trimmedLine.IndexOf('#') > 0)
{
blockComment = trimmedLine.Substring(trimmedLine.IndexOf('#') + 1);
trimmedLine = trimmedLine.Substring(0, trimmedLine.IndexOf('#')).Trim();
}
switch (matches.Value)
{
case "PlayAlertSound":
@ -585,11 +585,11 @@ namespace Filtration.Parser.Services
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;
if(_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment))
{
ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.AlertSound,
blockComment, blockItem.Value, blockItem.SecondValue);
blockItem.ThemeComponent = themeComponent;
}
blockItems.Add(blockItem);
break;
@ -597,14 +597,14 @@ namespace Filtration.Parser.Services
case "SetTextColor":
{
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;
if(_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment))
{
ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.TextColor,
blockComment, blockItem.Color);
blockItem.ThemeComponent = themeComponent;
}
blockItems.Add(blockItem);
break;
@ -612,14 +612,14 @@ namespace Filtration.Parser.Services
case "SetBackgroundColor":
{
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;
if(_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment))
{
ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BackgroundColor,
blockComment, blockItem.Color);
blockItem.ThemeComponent = themeComponent;
}
blockItems.Add(blockItem);
break;
@ -627,14 +627,14 @@ namespace Filtration.Parser.Services
case "SetBorderColor":
{
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;
if(_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment))
{
ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BorderColor,
blockComment, blockItem.Color);
blockItem.ThemeComponent = themeComponent;
}
blockItems.Add(blockItem);
break;
@ -644,19 +644,19 @@ namespace Filtration.Parser.Services
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;
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);
@ -723,15 +723,15 @@ namespace Filtration.Parser.Services
// TODO: Private
public string TranslateItemFilterCommentBlockToString(IItemFilterCommentBlock itemFilterCommentBlock)
{
if (!itemFilterCommentBlock.IsEdited)
{
return itemFilterCommentBlock.OriginalText;
if (!itemFilterCommentBlock.IsEdited)
{
return itemFilterCommentBlock.OriginalText;
}
// TODO: Tests
// TODO: # Section: text?
var commentWithHashes = string.Empty;
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)))
{
@ -741,15 +741,15 @@ namespace Filtration.Parser.Services
// 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;
if(!block.IsEdited)
{
return block.OriginalText;
}
var outputString = string.Empty;
@ -777,14 +777,14 @@ namespace Filtration.Parser.Services
{
outputString += (!block.Enabled ? _disabledNewLine : _newLine) + blockItem.OutputText;
}
}
//TODO: Disabled for the time being. A better solution is needed.
// Replace 'Maelström' to prevent encoding problems in other editors
//outputString.Replace("Maelström Staff", "Maelstr");
//outputString.Replace("Maelström of Chaos", "Maelstr");
//outputString.Replace("Maelström", "Maelstr");
}
//TODO: Disabled for the time being. A better solution is needed.
// Replace 'Maelström' to prevent encoding problems in other editors
//outputString.Replace("Maelström Staff", "Maelstr");
//outputString.Replace("Maelström of Chaos", "Maelstr");
//outputString.Replace("Maelström", "Maelstr");
return outputString;
}
}