FIL-4 Refactored script parsing to retain isolated comments as a new ItemFilterBlockComment type - UI still needs reworking with new templates and such.
This commit is contained in:
parent
797c911bb5
commit
4def27c49d
|
@ -2,6 +2,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ namespace Filtration.Common.Utilities
|
||||||
/// the stream into text.
|
/// the stream into text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="streamSource">Data source</param>
|
/// <param name="streamSource">Data source</param>
|
||||||
|
[DebuggerStepThrough]
|
||||||
public LineReader(Func<Stream> streamSource)
|
public LineReader(Func<Stream> streamSource)
|
||||||
: this(streamSource, Encoding.UTF8)
|
: this(streamSource, Encoding.UTF8)
|
||||||
{
|
{
|
||||||
|
@ -33,6 +35,7 @@ namespace Filtration.Common.Utilities
|
||||||
/// <param name="streamSource">Data source</param>
|
/// <param name="streamSource">Data source</param>
|
||||||
/// <param name="encoding">Encoding to use to decode the stream
|
/// <param name="encoding">Encoding to use to decode the stream
|
||||||
/// into text</param>
|
/// into text</param>
|
||||||
|
[DebuggerStepThrough]
|
||||||
public LineReader(Func<Stream> streamSource, Encoding encoding)
|
public LineReader(Func<Stream> streamSource, Encoding encoding)
|
||||||
: this(() => new StreamReader(streamSource(), encoding))
|
: this(() => new StreamReader(streamSource(), encoding))
|
||||||
{
|
{
|
||||||
|
@ -44,6 +47,7 @@ namespace Filtration.Common.Utilities
|
||||||
/// UTF8 is used to decode the file into text.
|
/// UTF8 is used to decode the file into text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">File to read from</param>
|
/// <param name="filename">File to read from</param>
|
||||||
|
[DebuggerStepThrough]
|
||||||
public LineReader(string filename)
|
public LineReader(string filename)
|
||||||
: this(filename, Encoding.UTF8)
|
: this(filename, Encoding.UTF8)
|
||||||
{
|
{
|
||||||
|
@ -56,6 +60,7 @@ namespace Filtration.Common.Utilities
|
||||||
/// <param name="filename">File to read from</param>
|
/// <param name="filename">File to read from</param>
|
||||||
/// <param name="encoding">Encoding to use to decode the file
|
/// <param name="encoding">Encoding to use to decode the file
|
||||||
/// into text</param>
|
/// into text</param>
|
||||||
|
[DebuggerStepThrough]
|
||||||
public LineReader(string filename, Encoding encoding)
|
public LineReader(string filename, Encoding encoding)
|
||||||
: this(() => new StreamReader(filename, encoding))
|
: this(() => new StreamReader(filename, encoding))
|
||||||
{
|
{
|
||||||
|
@ -66,6 +71,7 @@ namespace Filtration.Common.Utilities
|
||||||
/// is only called when the enumerator is fetched
|
/// is only called when the enumerator is fetched
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dataSource">Data source</param>
|
/// <param name="dataSource">Data source</param>
|
||||||
|
[DebuggerStepThrough]
|
||||||
public LineReader(Func<TextReader> dataSource)
|
public LineReader(Func<TextReader> dataSource)
|
||||||
{
|
{
|
||||||
_dataSource = dataSource;
|
_dataSource = dataSource;
|
||||||
|
@ -74,6 +80,7 @@ namespace Filtration.Common.Utilities
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enumerates the data source line by line.
|
/// Enumerates the data source line by line.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DebuggerStepThrough]
|
||||||
public IEnumerator<string> GetEnumerator()
|
public IEnumerator<string> GetEnumerator()
|
||||||
{
|
{
|
||||||
using (TextReader reader = _dataSource())
|
using (TextReader reader = _dataSource())
|
||||||
|
@ -89,6 +96,7 @@ namespace Filtration.Common.Utilities
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enumerates the data source line by line.
|
/// Enumerates the data source line by line.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DebuggerStepThrough]
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
{
|
{
|
||||||
return GetEnumerator();
|
return GetEnumerator();
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace Filtration.ItemFilterPreview.Tests.Services
|
||||||
//Arrange
|
//Arrange
|
||||||
var testInputItem = Mock.Of<IItem>();
|
var testInputItem = Mock.Of<IItem>();
|
||||||
var testInputBlock = Mock.Of<IItemFilterBlock>();
|
var testInputBlock = Mock.Of<IItemFilterBlock>();
|
||||||
var testInputScript = Mock.Of<IItemFilterScript>(s => s.ItemFilterBlocks == new ObservableCollection<IItemFilterBlock> {testInputBlock});
|
var testInputScript = Mock.Of<IItemFilterScript>(s => s.ItemFilterBlocks == new ObservableCollection<IItemFilterBlockBase> {testInputBlock});
|
||||||
|
|
||||||
_testUtility.MockBlockItemMatcher
|
_testUtility.MockBlockItemMatcher
|
||||||
.Setup(b => b.ItemBlockMatch(testInputBlock, testInputItem))
|
.Setup(b => b.ItemBlockMatch(testInputBlock, testInputItem))
|
||||||
|
@ -50,7 +50,7 @@ namespace Filtration.ItemFilterPreview.Tests.Services
|
||||||
//Arrange
|
//Arrange
|
||||||
var testInputItem = Mock.Of<IItem>();
|
var testInputItem = Mock.Of<IItem>();
|
||||||
var testInputBlock = Mock.Of<IItemFilterBlock>();
|
var testInputBlock = Mock.Of<IItemFilterBlock>();
|
||||||
var testInputScript = Mock.Of<IItemFilterScript>(s => s.ItemFilterBlocks == new ObservableCollection<IItemFilterBlock> { testInputBlock });
|
var testInputScript = Mock.Of<IItemFilterScript>(s => s.ItemFilterBlocks == new ObservableCollection<IItemFilterBlockBase> { testInputBlock });
|
||||||
|
|
||||||
_testUtility.MockBlockItemMatcher
|
_testUtility.MockBlockItemMatcher
|
||||||
.Setup(b => b.ItemBlockMatch(testInputBlock, testInputItem))
|
.Setup(b => b.ItemBlockMatch(testInputBlock, testInputItem))
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace Filtration.ItemFilterPreview.Services
|
||||||
sw.Restart();
|
sw.Restart();
|
||||||
|
|
||||||
var matchedBlock = itemFilterScript.ItemFilterBlocks
|
var matchedBlock = itemFilterScript.ItemFilterBlocks
|
||||||
|
.OfType<IItemFilterBlock>()
|
||||||
.Where(b => !(b is ItemFilterSection))
|
.Where(b => !(b is ItemFilterSection))
|
||||||
.FirstOrDefault(block => _blockItemMatcher.ItemBlockMatch(block, item));
|
.FirstOrDefault(block => _blockItemMatcher.ItemBlockMatch(block, item));
|
||||||
|
|
||||||
|
|
|
@ -6,23 +6,6 @@ namespace Filtration.ObjectModel.Tests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestItemFilterBlock
|
public class TestItemFilterBlock
|
||||||
{
|
{
|
||||||
[Test]
|
|
||||||
public void ItemFilterBlock_BlockCount_ReturnsCorrectNumber()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var block = new ItemFilterBlock();
|
|
||||||
block.BlockItems.Add(new ItemLevelBlockItem());
|
|
||||||
block.BlockItems.Add(new ItemLevelBlockItem());
|
|
||||||
block.BlockItems.Add(new ItemLevelBlockItem());
|
|
||||||
block.BlockItems.Add(new ItemLevelBlockItem());
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var count = block.BlockCount(typeof (ItemLevelBlockItem));
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(4, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ItemFilterBlock_AddBlockItemAllowed_LessThanMaximum_ReturnsTrue()
|
public void ItemFilterBlock_AddBlockItemAllowed_LessThanMaximum_ReturnsTrue()
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,7 +9,7 @@ using Filtration.ObjectModel.Extensions;
|
||||||
|
|
||||||
namespace Filtration.ObjectModel
|
namespace Filtration.ObjectModel
|
||||||
{
|
{
|
||||||
public interface IItemFilterBlock
|
public interface IItemFilterBlock : IItemFilterBlockBase
|
||||||
{
|
{
|
||||||
bool Enabled { get; set; }
|
bool Enabled { get; set; }
|
||||||
string Description { get; set; }
|
string Description { get; set; }
|
||||||
|
@ -21,13 +21,32 @@ namespace Filtration.ObjectModel
|
||||||
Color DisplayTextColor { get; }
|
Color DisplayTextColor { get; }
|
||||||
Color DisplayBorderColor { get; }
|
Color DisplayBorderColor { get; }
|
||||||
double DisplayFontSize { get; }
|
double DisplayFontSize { get; }
|
||||||
int BlockCount(Type type);
|
|
||||||
bool AddBlockItemAllowed(Type type);
|
|
||||||
bool HasBlockItemOfType<T>();
|
bool HasBlockItemOfType<T>();
|
||||||
bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup);
|
bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ItemFilterBlock : IItemFilterBlock
|
public interface IItemFilterBlockBase
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ItemFilterBlockBase : IItemFilterBlockBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IItemFilterCommentBlock : IItemFilterBlockBase
|
||||||
|
{
|
||||||
|
string Comment { get; set; }
|
||||||
|
bool IsSection { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ItemFilterCommentBlock : ItemFilterBlockBase, IItemFilterCommentBlock
|
||||||
|
{
|
||||||
|
public string Comment { get; set; }
|
||||||
|
public bool IsSection { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ItemFilterBlock : ItemFilterBlockBase, IItemFilterBlock
|
||||||
{
|
{
|
||||||
private ItemFilterBlockGroup _blockGroup;
|
private ItemFilterBlockGroup _blockGroup;
|
||||||
|
|
||||||
|
@ -43,7 +62,7 @@ namespace Filtration.ObjectModel
|
||||||
|
|
||||||
public ItemFilterBlockGroup BlockGroup
|
public ItemFilterBlockGroup BlockGroup
|
||||||
{
|
{
|
||||||
get { return _blockGroup; }
|
get => _blockGroup;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
var oldBlockGroup = _blockGroup;
|
var oldBlockGroup = _blockGroup;
|
||||||
|
@ -85,15 +104,15 @@ namespace Filtration.ObjectModel
|
||||||
|
|
||||||
public ObservableCollection<IItemFilterBlockItem> BlockItems { get; }
|
public ObservableCollection<IItemFilterBlockItem> BlockItems { get; }
|
||||||
|
|
||||||
public int BlockCount(Type type)
|
public bool AddBlockItemAllowed(Type type)
|
||||||
|
{
|
||||||
|
int BlockCount()
|
||||||
{
|
{
|
||||||
return BlockItems?.Count(b => b.GetType() == type) ?? 0;
|
return BlockItems?.Count(b => b.GetType() == type) ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddBlockItemAllowed(Type type)
|
|
||||||
{
|
|
||||||
var blockItem = (IItemFilterBlockItem)Activator.CreateInstance(type);
|
var blockItem = (IItemFilterBlockItem)Activator.CreateInstance(type);
|
||||||
return BlockCount(type) < blockItem.MaximumAllowed;
|
return BlockCount() < blockItem.MaximumAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasBlockItemOfType<T>()
|
public bool HasBlockItemOfType<T>()
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace Filtration.ObjectModel
|
||||||
{
|
{
|
||||||
public interface IItemFilterScript
|
public interface IItemFilterScript
|
||||||
{
|
{
|
||||||
ObservableCollection<IItemFilterBlock> ItemFilterBlocks { get; }
|
ObservableCollection<IItemFilterBlockBase> ItemFilterBlocks { get; }
|
||||||
ObservableCollection<ItemFilterBlockGroup> ItemFilterBlockGroups { get; }
|
ObservableCollection<ItemFilterBlockGroup> ItemFilterBlockGroups { get; }
|
||||||
ThemeComponentCollection ThemeComponents { get; set; }
|
ThemeComponentCollection ThemeComponents { get; set; }
|
||||||
string FilePath { get; set; }
|
string FilePath { get; set; }
|
||||||
|
@ -25,7 +25,7 @@ namespace Filtration.ObjectModel
|
||||||
{
|
{
|
||||||
public ItemFilterScript()
|
public ItemFilterScript()
|
||||||
{
|
{
|
||||||
ItemFilterBlocks = new ObservableCollection<IItemFilterBlock>();
|
ItemFilterBlocks = new ObservableCollection<IItemFilterBlockBase>();
|
||||||
ItemFilterBlockGroups = new ObservableCollection<ItemFilterBlockGroup>
|
ItemFilterBlockGroups = new ObservableCollection<ItemFilterBlockGroup>
|
||||||
{
|
{
|
||||||
new ItemFilterBlockGroup("Root", null)
|
new ItemFilterBlockGroup("Root", null)
|
||||||
|
@ -34,7 +34,7 @@ namespace Filtration.ObjectModel
|
||||||
ItemFilterScriptSettings = new ItemFilterScriptSettings(ThemeComponents);
|
ItemFilterScriptSettings = new ItemFilterScriptSettings(ThemeComponents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableCollection<IItemFilterBlock> ItemFilterBlocks { get; }
|
public ObservableCollection<IItemFilterBlockBase> ItemFilterBlocks { get; }
|
||||||
public ObservableCollection<ItemFilterBlockGroup> ItemFilterBlockGroups { get; }
|
public ObservableCollection<ItemFilterBlockGroup> ItemFilterBlockGroups { get; }
|
||||||
|
|
||||||
public ThemeComponentCollection ThemeComponents { get; set; }
|
public ThemeComponentCollection ThemeComponents { get; set; }
|
||||||
|
@ -59,9 +59,7 @@ namespace Filtration.ObjectModel
|
||||||
|
|
||||||
public void ReplaceColors(ReplaceColorsParameterSet replaceColorsParameterSet)
|
public void ReplaceColors(ReplaceColorsParameterSet replaceColorsParameterSet)
|
||||||
{
|
{
|
||||||
foreach (
|
foreach (var block in ItemFilterBlocks.OfType<ItemFilterBlock>().Where(b => BlockIsColorReplacementCandidate(replaceColorsParameterSet, b)))
|
||||||
var block in
|
|
||||||
ItemFilterBlocks.Where(b => BlockIsColorReplacementCandidate(replaceColorsParameterSet, b)))
|
|
||||||
{
|
{
|
||||||
if (replaceColorsParameterSet.ReplaceTextColor)
|
if (replaceColorsParameterSet.ReplaceTextColor)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,5 +8,6 @@ namespace Filtration.Parser.Interface.Services
|
||||||
IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings);
|
IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings);
|
||||||
string TranslateItemFilterBlockToString(IItemFilterBlock block);
|
string TranslateItemFilterBlockToString(IItemFilterBlock block);
|
||||||
void ReplaceAudioVisualBlockItemsFromString(ObservableCollection<IItemFilterBlockItem> blockItems, string inputString);
|
void ReplaceAudioVisualBlockItemsFromString(ObservableCollection<IItemFilterBlockItem> blockItems, string inputString);
|
||||||
|
IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -109,6 +109,9 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Resources\testscript2.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<Choose>
|
<Choose>
|
||||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -91,6 +91,37 @@ namespace Filtration.Parser.Tests.Properties {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to #Script description
|
||||||
|
///#Script description
|
||||||
|
///#Script description
|
||||||
|
///#Script description
|
||||||
|
///
|
||||||
|
///#Comment
|
||||||
|
///#SomeComment
|
||||||
|
///
|
||||||
|
///#Blockdescription
|
||||||
|
///Show #Flasks - Endgame - Life/Mana - Divine/Eternal - Q10+ - Normal
|
||||||
|
/// Class "Life Flasks" "Mana Flasks"
|
||||||
|
/// Rarity Normal
|
||||||
|
/// DropLevel >= 60
|
||||||
|
/// Quality >= 10
|
||||||
|
/// SetFontSize 28
|
||||||
|
/// SetTextColor 240 240 240 #Normal Item Highlight
|
||||||
|
///
|
||||||
|
///#commentymccommentface
|
||||||
|
///
|
||||||
|
///Show #Flasks - Endgame - Life/Mana - Divine/Eternal - Q10+ - Normal
|
||||||
|
/// Class "Life Flasks" "Mana Flasks"
|
||||||
|
/// Rarity Normal
|
||||||
|
/// DropL [rest of string was truncated]";.
|
||||||
|
/// </summary>
|
||||||
|
public static string testscript2 {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("testscript2", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to ###BETA VERSION 1.0.0.1-8
|
/// Looks up a localized string similar to ###BETA VERSION 1.0.0.1-8
|
||||||
///#Please test and let me know via pm on reddit /u/brute_force or @Thiole in game if i am online
|
///#Please test and let me know via pm on reddit /u/brute_force or @Thiole in game if i am online
|
||||||
|
|
|
@ -118,10 +118,13 @@
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
<data name="ThioleItemFilter" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
|
||||||
<value>..\Resources\ThioleItemFilter.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
|
||||||
</data>
|
|
||||||
<data name="testscript" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="testscript" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>..\Resources\testscript.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
<value>..\Resources\testscript.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="testscript2" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\testscript2.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||||
|
</data>
|
||||||
|
<data name="ThioleItemFilter" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\ThioleItemFilter.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -0,0 +1,31 @@
|
||||||
|
#Script description
|
||||||
|
#Script description
|
||||||
|
#Script description
|
||||||
|
#Script description
|
||||||
|
|
||||||
|
#Blockdescription
|
||||||
|
Show #Flasks - Endgame - Life/Mana - Divine/Eternal - Q10+ - Normal
|
||||||
|
Class "Life Flasks" "Mana Flasks"
|
||||||
|
Rarity Normal
|
||||||
|
SetFontSize 28
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# commentymccommentface
|
||||||
|
|
||||||
|
Show
|
||||||
|
Class "Life Flasks" "Mana Flasks"
|
||||||
|
Rarity Normal
|
||||||
|
DropLevel >= 60
|
||||||
|
|
||||||
|
#commment
|
||||||
|
#morecomment
|
||||||
|
#blah
|
||||||
|
|
||||||
|
#anothercomment
|
||||||
|
|
||||||
|
#notpartofblockdescription
|
||||||
|
#blockdescription2
|
||||||
|
Show #TestBlock
|
||||||
|
Class "Life Flasks" "Mana Flasks"
|
||||||
|
Rarity Normal
|
|
@ -26,6 +26,19 @@ namespace Filtration.Parser.Tests.Services
|
||||||
_testUtility = new ItemFilterBlockTranslatorTestUtility();
|
_testUtility = new ItemFilterBlockTranslatorTestUtility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TranslateStringToItemFilterBlockComment_ReturnsItemFilterBlockCommentWithSpacesNotRemoved()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var testInputString = "# This is a comment\r\n# Line 2 \r\n # Test";
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = _testUtility.Translator.TranslateStringToItemFilterCommentBlock(testInputString);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.AreEqual(" This is a comment\r\n Line 2 \r\n Test", result.Comment);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_ActionBlockItemCommentIsNull()
|
public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_ActionBlockItemCommentIsNull()
|
||||||
{
|
{
|
||||||
|
@ -704,21 +717,6 @@ namespace Filtration.Parser.Tests.Services
|
||||||
Assert.AreEqual(95, blockItem.SecondValue);
|
Assert.AreEqual(95, blockItem.SecondValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TranslateStringToItemFilterBlock_SectionComment_ReturnsItemFilterSectionObjectWithCorrectDescription()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
const string testInputSectionDescription = "Wonderful items that you definitely won't want to miss!";
|
|
||||||
var inputString = "# Section: " + testInputSectionDescription;
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScriptSettings>());
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.IsInstanceOf<ItemFilterSection>(result);
|
|
||||||
Assert.AreEqual(testInputSectionDescription, result.Description);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TranslateStringToItemFilterBlock_Everything_ReturnsCorrectObject()
|
public void TranslateStringToItemFilterBlock_Everything_ReturnsCorrectObject()
|
||||||
{
|
{
|
||||||
|
@ -1571,22 +1569,6 @@ namespace Filtration.Parser.Tests.Services
|
||||||
Assert.AreEqual(expectedResult, result);
|
Assert.AreEqual(expectedResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TranslateItemFilterBlockToString_Section_ReturnsCorrectString()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
const string testInputSectionText = "Ermagerd it's a section!";
|
|
||||||
var expectedResult = "# Section: " + testInputSectionText;
|
|
||||||
|
|
||||||
_testUtility.TestBlock = new ItemFilterSection { Description = testInputSectionText };
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(expectedResult, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TranslateItemFilterBlockToString_DisabledBlock_ReturnsCorrectString()
|
public void TranslateItemFilterBlockToString_DisabledBlock_ReturnsCorrectString()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Filtration.ObjectModel;
|
using Filtration.ObjectModel;
|
||||||
using Filtration.ObjectModel.BlockItemTypes;
|
using Filtration.ObjectModel.BlockItemTypes;
|
||||||
|
@ -9,6 +10,7 @@ using Filtration.Parser.Interface.Services;
|
||||||
using Filtration.Parser.Services;
|
using Filtration.Parser.Services;
|
||||||
using Filtration.Parser.Tests.Properties;
|
using Filtration.Parser.Tests.Properties;
|
||||||
using Filtration.Properties;
|
using Filtration.Properties;
|
||||||
|
using FluentAssertions;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
@ -75,6 +77,36 @@ namespace Filtration.Parser.Tests.Services
|
||||||
// Not crashing out when loading a huge script means this integration test has passed!
|
// Not crashing out when loading a huge script means this integration test has passed!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TranslateStringToItemFilterScript_Blah()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var testInput = Resources.testscript2;
|
||||||
|
|
||||||
|
var blockTranslator = new ItemFilterBlockTranslator(_testUtility.MockBlockGroupHierarchyBuilder.Object);
|
||||||
|
var translator = new ItemFilterScriptTranslator(blockTranslator, _testUtility.MockBlockGroupHierarchyBuilder.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = translator.TranslateStringToItemFilterScript(testInput);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var expectedResult = Mock.Of<IItemFilterScript>(s => s.ItemFilterBlocks == new ObservableCollection<IItemFilterBlockBase>
|
||||||
|
{
|
||||||
|
Mock.Of<IItemFilterBlock>(c => c.Description == "Blockdescription"),
|
||||||
|
Mock.Of<IItemFilterCommentBlock>(c => c.Comment == " commentymccommentface"),
|
||||||
|
Mock.Of<IItemFilterBlock>(),
|
||||||
|
Mock.Of<IItemFilterCommentBlock>(c => c.Comment == "commment\r\nmorecomment\r\nblah"),
|
||||||
|
Mock.Of<IItemFilterCommentBlock>(c => c.Comment == "anothercomment"),
|
||||||
|
Mock.Of<IItemFilterCommentBlock>(c => c.Comment == "notpartofblockdescription "),
|
||||||
|
Mock.Of<IItemFilterBlock>(c => c.Description == "blockdescription2")
|
||||||
|
} && s.ItemFilterBlockGroups == new ObservableCollection<ItemFilterBlockGroup> { new ItemFilterBlockGroup("Root", null, false) }
|
||||||
|
&& s.ThemeComponents == new ThemeComponentCollection()
|
||||||
|
&& s.ItemFilterScriptSettings == new ItemFilterScriptSettings(new ThemeComponentCollection())
|
||||||
|
&& s.Description == "Script description\r\nScript description\r\nScript description\r\nScript description");
|
||||||
|
|
||||||
|
result.ShouldBeEquivalentTo(expectedResult);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TranslateItemFilterScriptToString_OneBlock_CallsTranslator()
|
public void TranslateItemFilterScriptToString_OneBlock_CallsTranslator()
|
||||||
{
|
{
|
||||||
|
@ -221,7 +253,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(2, result.ItemFilterBlocks.Count);
|
Assert.AreEqual(2, result.ItemFilterBlocks.Count);
|
||||||
var block = result.ItemFilterBlocks.First(l => l.GetType() != typeof(ItemFilterSection));
|
var block = result.ItemFilterBlocks.OfType<ItemFilterBlock>().First(l => l.GetType() != typeof(ItemFilterSection));
|
||||||
Assert.AreEqual(4, block.BlockItems.Count);
|
Assert.AreEqual(4, block.BlockItems.Count);
|
||||||
var baseTypeItem = block.BlockItems.OfType<BaseTypeBlockItem>().First();
|
var baseTypeItem = block.BlockItems.OfType<BaseTypeBlockItem>().First();
|
||||||
Assert.AreEqual(2, baseTypeItem.Items.Count);
|
Assert.AreEqual(2, baseTypeItem.Items.Count);
|
||||||
|
@ -244,7 +276,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual("Script edited with Filtration - https://github.com/ben-wallis/Filtration", result.Description);
|
Assert.AreEqual("Script edited with Filtration - https://github.com/ben-wallis/Filtration", result.Description);
|
||||||
var firstBlock = result.ItemFilterBlocks.First();
|
var firstBlock = result.ItemFilterBlocks.OfType<ItemFilterBlock>().First();
|
||||||
Assert.IsNull(firstBlock.Description);
|
Assert.IsNull(firstBlock.Description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,9 +343,9 @@ namespace Filtration.Parser.Tests.Services
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(3, result.ItemFilterBlocks.Count);
|
Assert.AreEqual(3, result.ItemFilterBlocks.Count);
|
||||||
|
|
||||||
var firstBlock = result.ItemFilterBlocks.First();
|
var firstBlock = result.ItemFilterBlocks.OfType<ItemFilterBlock>().First();
|
||||||
var secondBlock = result.ItemFilterBlocks.Skip(1).First();
|
var secondBlock = result.ItemFilterBlocks.OfType<ItemFilterBlock>().Skip(1).First();
|
||||||
var thirdBlock = result.ItemFilterBlocks.Skip(2).First();
|
var thirdBlock = result.ItemFilterBlocks.OfType<ItemFilterBlock>().Skip(2).First();
|
||||||
|
|
||||||
Assert.AreEqual(3, firstBlock.BlockItems.Count);
|
Assert.AreEqual(3, firstBlock.BlockItems.Count);
|
||||||
Assert.AreEqual(5, secondBlock.BlockItems.Count);
|
Assert.AreEqual(5, secondBlock.BlockItems.Count);
|
||||||
|
@ -344,7 +376,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(2, result.ItemFilterBlocks.Count);
|
Assert.AreEqual(2, result.ItemFilterBlocks.Count);
|
||||||
var secondBlock = result.ItemFilterBlocks.Skip(1).First();
|
var secondBlock = result.ItemFilterBlocks.OfType<ItemFilterBlock>().Skip(1).First();
|
||||||
Assert.AreEqual("This is a disabled block", secondBlock.Description);
|
Assert.AreEqual("This is a disabled block", secondBlock.Description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +411,7 @@ namespace Filtration.Parser.Tests.Services
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.AreEqual(2, result.ItemFilterBlocks.Count);
|
Assert.AreEqual(2, result.ItemFilterBlocks.Count);
|
||||||
var secondBlock = result.ItemFilterBlocks.Skip(1).First();
|
var secondBlock = result.ItemFilterBlocks.OfType<ItemFilterBlock>().Skip(1).First();
|
||||||
Assert.AreEqual("This is a disabled block", secondBlock.Description);
|
Assert.AreEqual("This is a disabled block", secondBlock.Description);
|
||||||
Assert.AreEqual("My Block Group", secondBlock.BlockGroup.GroupName);
|
Assert.AreEqual("My Block Group", secondBlock.BlockGroup.GroupName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,22 @@ namespace Filtration.Parser.Services
|
||||||
_blockGroupHierarchyBuilder = blockGroupHierarchyBuilder;
|
_blockGroupHierarchyBuilder = blockGroupHierarchyBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Converts a string into an ItemFilterCommentBlock maintaining newlines and spaces but removing # characters
|
||||||
|
public IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString)
|
||||||
|
{
|
||||||
|
var itemFilterCommentBlock = new ItemFilterCommentBlock();
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
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.
|
// and reading ItemFilterScripts from a file.
|
||||||
public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings)
|
public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings)
|
||||||
|
@ -39,16 +55,6 @@ namespace Filtration.Parser.Services
|
||||||
|
|
||||||
foreach (var line in new LineReader(() => new StringReader(inputString)))
|
foreach (var line in new LineReader(() => new StringReader(inputString)))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (line.StartsWith(@"# Section:"))
|
|
||||||
{
|
|
||||||
var section = new ItemFilterSection
|
|
||||||
{
|
|
||||||
Description = line.Substring(line.IndexOf(":", StringComparison.Ordinal) + 1).Trim()
|
|
||||||
};
|
|
||||||
return section;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.StartsWith(@"#") && !showHideFound)
|
if (line.StartsWith(@"#") && !showHideFound)
|
||||||
{
|
{
|
||||||
block.Description = line.TrimStart('#').TrimStart(' ');
|
block.Description = line.TrimStart('#').TrimStart(' ');
|
||||||
|
@ -205,6 +211,7 @@ namespace Filtration.Parser.Services
|
||||||
switch (matches.Count)
|
switch (matches.Count)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
{
|
||||||
if (matches[0].Success)
|
if (matches[0].Success)
|
||||||
{
|
{
|
||||||
var blockItemValue = new SoundBlockItem
|
var blockItemValue = new SoundBlockItem
|
||||||
|
@ -215,7 +222,9 @@ namespace Filtration.Parser.Services
|
||||||
block.BlockItems.Add(blockItemValue);
|
block.BlockItems.Add(blockItemValue);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 2:
|
case 2:
|
||||||
|
{
|
||||||
if (matches[0].Success && matches[1].Success)
|
if (matches[0].Success && matches[1].Success)
|
||||||
{
|
{
|
||||||
var blockItemValue = new SoundBlockItem
|
var blockItemValue = new SoundBlockItem
|
||||||
|
@ -227,6 +236,7 @@ namespace Filtration.Parser.Services
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,7 +446,8 @@ namespace Filtration.Parser.Services
|
||||||
// to the clipboard, and when saving a ItemFilterScript.
|
// to the clipboard, and when saving a ItemFilterScript.
|
||||||
public string TranslateItemFilterBlockToString(IItemFilterBlock block)
|
public string TranslateItemFilterBlockToString(IItemFilterBlock block)
|
||||||
{
|
{
|
||||||
if (block.GetType() == typeof (ItemFilterSection))
|
// TODO: fix
|
||||||
|
if (block.GetType() == typeof (ItemFilterCommentBlock))
|
||||||
{
|
{
|
||||||
return "# Section: " + block.Description;
|
return "# Section: " + block.Description;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Filtration.Common.Utilities;
|
using Filtration.Common.Utilities;
|
||||||
using Filtration.ObjectModel;
|
using Filtration.ObjectModel;
|
||||||
|
@ -10,6 +11,26 @@ using Filtration.Properties;
|
||||||
|
|
||||||
namespace Filtration.Parser.Services
|
namespace Filtration.Parser.Services
|
||||||
{
|
{
|
||||||
|
|
||||||
|
internal class ItemFilterBlockBoundary
|
||||||
|
{
|
||||||
|
public ItemFilterBlockBoundary(int startLine, ItemFilterBlockBoundaryType itemFilterBlockBoundaryType)
|
||||||
|
{
|
||||||
|
StartLine = startLine;
|
||||||
|
BoundaryType = itemFilterBlockBoundaryType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int StartLine { get; set; }
|
||||||
|
public ItemFilterBlockBoundaryType BoundaryType { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal enum ItemFilterBlockBoundaryType
|
||||||
|
{
|
||||||
|
ItemFilterBlock,
|
||||||
|
CommentBlock
|
||||||
|
}
|
||||||
|
|
||||||
internal class ItemFilterScriptTranslator : IItemFilterScriptTranslator
|
internal class ItemFilterScriptTranslator : IItemFilterScriptTranslator
|
||||||
{
|
{
|
||||||
private readonly IItemFilterBlockTranslator _blockTranslator;
|
private readonly IItemFilterBlockTranslator _blockTranslator;
|
||||||
|
@ -98,7 +119,7 @@ namespace Filtration.Parser.Services
|
||||||
var lines = Regex.Split(inputString, "\r\n|\r|\n");
|
var lines = Regex.Split(inputString, "\r\n|\r|\n");
|
||||||
|
|
||||||
// Process the script header
|
// Process the script header
|
||||||
for (var i = 0; i < conditionBoundaries.First.Value; i++)
|
for (var i = 0; i < conditionBoundaries.First.Value.StartLine; i++)
|
||||||
{
|
{
|
||||||
if (lines[i].StartsWith("#"))
|
if (lines[i].StartsWith("#"))
|
||||||
{
|
{
|
||||||
|
@ -115,43 +136,85 @@ namespace Filtration.Parser.Services
|
||||||
// and add that object to the ItemFilterBlocks list
|
// and add that object to the ItemFilterBlocks list
|
||||||
for (var boundary = conditionBoundaries.First; boundary != null; boundary = boundary.Next)
|
for (var boundary = conditionBoundaries.First; boundary != null; boundary = boundary.Next)
|
||||||
{
|
{
|
||||||
var begin = boundary.Value;
|
var begin = boundary.Value.StartLine;
|
||||||
var end = boundary.Next?.Value ?? lines.Length;
|
var end = boundary.Next?.Value.StartLine ?? lines.Length;
|
||||||
var block = new string[end - begin];
|
var block = new string[end - begin];
|
||||||
Array.Copy(lines, begin, block, 0, end - begin);
|
Array.Copy(lines, begin, block, 0, end - begin);
|
||||||
var blockString = string.Join("\r\n", block);
|
var blockString = string.Join("\r\n", block);
|
||||||
|
|
||||||
|
if (boundary.Value.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock)
|
||||||
|
{
|
||||||
script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script.ItemFilterScriptSettings));
|
script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script.ItemFilterScriptSettings));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterCommentBlock(blockString));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_blockGroupHierarchyBuilder.Cleanup();
|
_blockGroupHierarchyBuilder.Cleanup();
|
||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LinkedList<int> IdentifyBlockBoundaries(string inputString)
|
private static LinkedList<ItemFilterBlockBoundary> IdentifyBlockBoundaries(string inputString)
|
||||||
{
|
{
|
||||||
var blockBoundaries = new LinkedList<int>();
|
var blockBoundaries = new LinkedList<ItemFilterBlockBoundary>();
|
||||||
var previousLine = string.Empty;
|
var previousLine = string.Empty;
|
||||||
var currentLine = 0;
|
var currentLine = -1;
|
||||||
|
|
||||||
|
var currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(1, ItemFilterBlockBoundaryType.CommentBlock);
|
||||||
|
|
||||||
foreach (var line in new LineReader(() => new StringReader(inputString)))
|
foreach (var line in new LineReader(() => new StringReader(inputString)))
|
||||||
{
|
{
|
||||||
currentLine++;
|
currentLine++;
|
||||||
var trimmedLine = line.Trim(' ');
|
var trimmedLine = line.Trim(' ');
|
||||||
if (trimmedLine.StartsWith("Show") || trimmedLine.StartsWith("Hide") ||
|
|
||||||
trimmedLine.StartsWith("# Section:"))
|
if (string.IsNullOrWhiteSpace(trimmedLine))
|
||||||
|
{
|
||||||
|
previousLine = line;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
blockBoundaries.AddLast(currentItemFilterBlockBoundary);
|
||||||
|
currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(currentLine, ItemFilterBlockBoundaryType.CommentBlock);
|
||||||
|
}
|
||||||
|
// A line starting with a comment where the previous line was null represents the start of a new comment (unless we're on the first
|
||||||
|
// line in which case it's not a new comment).
|
||||||
|
else if (trimmedLine.StartsWith("#") && string.IsNullOrWhiteSpace(previousLine) && currentLine > 0)
|
||||||
|
{
|
||||||
|
if (blockBoundaries.Count > 0)
|
||||||
|
{
|
||||||
|
blockBoundaries.AddLast(currentItemFilterBlockBoundary);
|
||||||
|
}
|
||||||
|
currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(currentLine, ItemFilterBlockBoundaryType.CommentBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (trimmedLine.StartsWith("Show") || trimmedLine.StartsWith("Hide"))
|
||||||
{
|
{
|
||||||
// If the line previous to the Show or Hide line is a comment then we should include that in the block
|
// If the line previous to the Show or Hide line is a comment then we should include that in the block
|
||||||
// as it represents the block description.
|
// as it represents the block description.
|
||||||
// currentLine > 2 caters for an edge case where the script description is a single line and the first
|
// currentLine > 2 caters for an edge case where the script description is a single line and the first
|
||||||
// block has no description. This prevents the script description from being assigned to the first block's description.
|
// block has no description. This prevents the script description from being assigned to the first block's description.
|
||||||
blockBoundaries.AddLast(previousLine.StartsWith("#") && !previousLine.StartsWith("# Section:") &&
|
if (!(currentItemFilterBlockBoundary.StartLine == currentLine - 1 && currentItemFilterBlockBoundary.BoundaryType == ItemFilterBlockBoundaryType.CommentBlock))
|
||||||
currentLine > 2
|
{
|
||||||
? currentLine - 2
|
blockBoundaries.AddLast(currentItemFilterBlockBoundary);
|
||||||
: currentLine - 1);
|
|
||||||
}
|
}
|
||||||
|
currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(previousLine.StartsWith("#") && currentLine > 2 ? currentLine - 1 : currentLine,
|
||||||
|
ItemFilterBlockBoundaryType.ItemFilterBlock);
|
||||||
|
}
|
||||||
|
|
||||||
previousLine = line;
|
previousLine = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (blockBoundaries.Last.Value != currentItemFilterBlockBoundary)
|
||||||
|
{
|
||||||
|
blockBoundaries.AddLast(currentItemFilterBlockBoundary);
|
||||||
|
}
|
||||||
|
|
||||||
return blockBoundaries;
|
return blockBoundaries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +241,7 @@ namespace Filtration.Parser.Services
|
||||||
// ReSharper disable once LoopCanBeConvertedToQuery
|
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||||
foreach (var block in script.ItemFilterBlocks)
|
foreach (var block in script.ItemFilterBlocks)
|
||||||
{
|
{
|
||||||
outputString += _blockTranslator.TranslateItemFilterBlockToString(block) + Environment.NewLine;
|
outputString += _blockTranslator.TranslateItemFilterBlockToString(block as ItemFilterBlock) + Environment.NewLine;
|
||||||
|
|
||||||
if (Settings.Default.ExtraLineBetweenBlocks)
|
if (Settings.Default.ExtraLineBetweenBlocks)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace Filtration.ThemeEditor.Services
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var block in script.ItemFilterBlocks)
|
foreach (var block in script.ItemFilterBlocks.OfType<ItemFilterBlock>())
|
||||||
{
|
{
|
||||||
foreach (var blockItem in block.BlockItems.Where(i => i.GetType() == targetType))
|
foreach (var blockItem in block.BlockItems.Where(i => i.GetType() == targetType))
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,6 @@ using System.Collections.ObjectModel;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Filtration.Common.ViewModels;
|
|
||||||
using Filtration.ObjectModel;
|
using Filtration.ObjectModel;
|
||||||
using Filtration.ObjectModel.BlockItemBaseTypes;
|
using Filtration.ObjectModel.BlockItemBaseTypes;
|
||||||
using Filtration.ObjectModel.BlockItemTypes;
|
using Filtration.ObjectModel.BlockItemTypes;
|
||||||
|
|
|
@ -320,7 +320,7 @@ namespace Filtration.ViewModels
|
||||||
ItemFilterBlockViewModels.Clear();
|
ItemFilterBlockViewModels.Clear();
|
||||||
|
|
||||||
Script = itemFilterScript;
|
Script = itemFilterScript;
|
||||||
foreach (var block in Script.ItemFilterBlocks)
|
foreach (var block in Script.ItemFilterBlocks.OfType<ItemFilterBlock>())
|
||||||
{
|
{
|
||||||
var vm = _itemFilterBlockViewModelFactory.Create();
|
var vm = _itemFilterBlockViewModelFactory.Create();
|
||||||
vm.Initialise(block, this);
|
vm.Initialise(block, this);
|
||||||
|
@ -426,7 +426,7 @@ namespace Filtration.ViewModels
|
||||||
var unusedThemeComponents =
|
var unusedThemeComponents =
|
||||||
Script.ThemeComponents.Where(
|
Script.ThemeComponents.Where(
|
||||||
t =>
|
t =>
|
||||||
Script.ItemFilterBlocks.Count(
|
Script.ItemFilterBlocks.OfType<ItemFilterBlock>().Count(
|
||||||
b => b.BlockItems.OfType<ColorBlockItem>().Count(i => i.ThemeComponent == t) > 0) == 0).ToList();
|
b => b.BlockItems.OfType<ColorBlockItem>().Count(i => i.ThemeComponent == t) > 0) == 0).ToList();
|
||||||
|
|
||||||
if (unusedThemeComponents.Count <= 0) return true;
|
if (unusedThemeComponents.Count <= 0) return true;
|
||||||
|
|
Loading…
Reference in New Issue