Add tests and fix theme bug

This commit is contained in:
azakhi
2018-08-31 16:02:17 +03:00
parent 3851ad51e1
commit 6be29dbd28
2 changed files with 71 additions and 23 deletions

View File

@@ -86,8 +86,7 @@ namespace Filtration.Parser.Services
var fullLine = line.Trim();
var trimmedLine = fullLine;
var blockComment = "";
var nextBlockIndex = block.BlockItems.Count;
ThemeComponentType themeComponentType = ThemeComponentType.AlertSound;
var themeComponentType = -1;
if(trimmedLine.IndexOf('#') > 0)
{
blockComment = trimmedLine.Substring(trimmedLine.IndexOf('#') + 1);
@@ -221,7 +220,7 @@ namespace Filtration.Parser.Services
var blockItem = new TextColorBlockItem();
blockItem.Color = GetColorFromString(result[0].Groups[1].Value);
block.BlockItems.Add(blockItem);
themeComponentType = ThemeComponentType.TextColor;
themeComponentType = (int)ThemeComponentType.TextColor;
break;
}
case "SetBackgroundColor":
@@ -234,7 +233,7 @@ namespace Filtration.Parser.Services
var blockItem = new BackgroundColorBlockItem();
blockItem.Color = GetColorFromString(result[0].Groups[1].Value);
block.BlockItems.Add(blockItem);
themeComponentType = ThemeComponentType.BackgroundColor;
themeComponentType = (int)ThemeComponentType.BackgroundColor;
break;
}
case "SetBorderColor":
@@ -247,7 +246,7 @@ namespace Filtration.Parser.Services
var blockItem = new BorderColorBlockItem();
blockItem.Color = GetColorFromString(result[0].Groups[1].Value);
block.BlockItems.Add(blockItem);
themeComponentType = ThemeComponentType.BorderColor;
themeComponentType = (int)ThemeComponentType.BorderColor;
break;
}
case "SetFontSize":
@@ -260,8 +259,8 @@ namespace Filtration.Parser.Services
{
var blockItem = new FontSizeBlockItem(Convert.ToInt16(match[0].Groups[2].Value));
block.BlockItems.Add(blockItem);
themeComponentType = (int)ThemeComponentType.FontSize;
}
themeComponentType = ThemeComponentType.FontSize;
break;
}
case "PlayAlertSound":
@@ -305,9 +304,9 @@ namespace Filtration.Parser.Services
SecondValue = secondValue
};
block.BlockItems.Add(blockItemValue);
}
}
themeComponentType = ThemeComponentType.AlertSound;
}
themeComponentType = (int)ThemeComponentType.AlertSound;
}
break;
}
case "GemLevel":
@@ -364,8 +363,8 @@ namespace Filtration.Parser.Services
blockItemValue.ThemeComponent = themeComponent;
}
block.BlockItems.Add(blockItemValue);
themeComponentType = (int)ThemeComponentType.Icon;
}
themeComponentType = ThemeComponentType.Icon;
break;
}
case "PlayEffect":
@@ -383,9 +382,9 @@ namespace Filtration.Parser.Services
Color = EnumHelper.GetEnumValueFromDescription<EffectColor>(match.Groups[1].Value),
Temporary = match.Groups[2].Value.Trim().ToLower() == "temp"
};
block.BlockItems.Add(blockItemValue);
block.BlockItems.Add(blockItemValue);
themeComponentType = (int)ThemeComponentType.Effect;
}
themeComponentType = ThemeComponentType.Effect;
break;
}
case "CustomAlertSound":
@@ -403,9 +402,9 @@ namespace Filtration.Parser.Services
{
Value = match.Groups[1].Value
};
block.BlockItems.Add(blockItemValue);
}
themeComponentType = ThemeComponentType.CustomSound;
block.BlockItems.Add(blockItemValue);
themeComponentType = (int)ThemeComponentType.CustomSound;
}
break;
}
case "MapTier":
@@ -422,9 +421,9 @@ namespace Filtration.Parser.Services
{
block.BlockItems.Last().Comment = blockComment;
}
else if(nextBlockIndex == block.BlockItems.Count - 1) // If these 2 are not equal, this theme doesn't belong to last block
else
{
switch(themeComponentType)
switch((ThemeComponentType)themeComponentType)
{
case ThemeComponentType.AlertSound:
{
@@ -461,7 +460,7 @@ namespace Filtration.Parser.Services
ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.CustomSound,
blockComment.Trim(), ((CustomSoundBlockItem)blockItemWithTheme).Value);
blockItemWithTheme.ThemeComponent = themeComponent;
break;
break;
}
case ThemeComponentType.Effect:
{