Implemented BlockGroups and related translation
This commit is contained in:
@@ -142,6 +142,7 @@
|
||||
<Compile Include="Services\FileSystemService.cs" />
|
||||
<Compile Include="Services\ItemFilterPersistenceService.cs" />
|
||||
<Compile Include="Services\StaticDataService.cs" />
|
||||
<Compile Include="Translators\BlockGroupHierarchyBuilder.cs" />
|
||||
<Compile Include="Translators\ItemFilterBlockTranslator.cs" />
|
||||
<Compile Include="Translators\ItemFilterScriptTranslator.cs" />
|
||||
<Compile Include="UserControls\AutoScrollingListBox.cs" />
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Filtration.Models
|
||||
}
|
||||
|
||||
public string Description { get; set; }
|
||||
public ItemFilterBlockGroup BlockGroup { get; set; }
|
||||
|
||||
public BlockAction Action
|
||||
{
|
||||
|
||||
@@ -1,12 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Filtration.Models
|
||||
{
|
||||
class ItemFilterBlockGroup
|
||||
internal class ItemFilterBlockGroup
|
||||
{
|
||||
public ItemFilterBlockGroup(string groupName, ItemFilterBlockGroup parent)
|
||||
{
|
||||
GroupName = groupName;
|
||||
ParentGroup = parent;
|
||||
ChildGroups = new List<ItemFilterBlockGroup>();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var currentBlockGroup = this;
|
||||
|
||||
var outputString = GroupName;
|
||||
while (currentBlockGroup.ParentGroup.ParentGroup != null)
|
||||
{
|
||||
outputString = currentBlockGroup.ParentGroup.GroupName + " - " + outputString;
|
||||
currentBlockGroup = currentBlockGroup.ParentGroup;
|
||||
}
|
||||
|
||||
return outputString;
|
||||
}
|
||||
|
||||
public string GroupName { get; private set; }
|
||||
public ItemFilterBlockGroup ParentGroup { get; private set; }
|
||||
public List<ItemFilterBlockGroup> ChildGroups { get; private set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,15 @@ namespace Filtration.Models
|
||||
public ItemFilterScript()
|
||||
{
|
||||
ItemFilterBlocks = new ObservableCollection<ItemFilterBlock>();
|
||||
ItemFilterBlockGroups = new ObservableCollection<ItemFilterBlockGroup>
|
||||
{
|
||||
new ItemFilterBlockGroup("Root", null)
|
||||
};
|
||||
}
|
||||
|
||||
public ObservableCollection<ItemFilterBlock> ItemFilterBlocks { get; set; }
|
||||
public ObservableCollection<ItemFilterBlock> ItemFilterBlocks { get; private set; }
|
||||
public ObservableCollection<ItemFilterBlockGroup> ItemFilterBlockGroups { get; private set; }
|
||||
|
||||
public string FilePath { get; set; }
|
||||
public string Description { get; set; }
|
||||
public DateTime DateModified { get; set; }
|
||||
|
||||
54
Filtration/Translators/BlockGroupHierarchyBuilder.cs
Normal file
54
Filtration/Translators/BlockGroupHierarchyBuilder.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Filtration.Models;
|
||||
|
||||
namespace Filtration.Translators
|
||||
{
|
||||
internal interface IBlockGroupHierarchyBuilder
|
||||
{
|
||||
void Initialise(ItemFilterBlockGroup rootBlockGroup);
|
||||
ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings);
|
||||
}
|
||||
|
||||
internal class BlockGroupHierarchyBuilder : IBlockGroupHierarchyBuilder
|
||||
{
|
||||
private ItemFilterBlockGroup _rootBlockGroup;
|
||||
|
||||
public void Initialise(ItemFilterBlockGroup rootBlockGroup)
|
||||
{
|
||||
_rootBlockGroup = rootBlockGroup;
|
||||
}
|
||||
|
||||
public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings)
|
||||
{
|
||||
if (_rootBlockGroup == null)
|
||||
{
|
||||
throw new Exception("BlockGroupHierarchyBuilder must be initialised with root BlockGroup before use");
|
||||
}
|
||||
return IntegrateStringListIntoBlockGroupHierarchy(groupStrings, _rootBlockGroup);
|
||||
}
|
||||
|
||||
public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings, ItemFilterBlockGroup startItemGroup)
|
||||
{
|
||||
var inputGroups = groupStrings.ToList();
|
||||
var firstGroup = inputGroups.First().Trim();
|
||||
|
||||
ItemFilterBlockGroup matchingChildItemGroup = null;
|
||||
if (startItemGroup.ChildGroups.Count(g => g.GroupName == firstGroup) > 0)
|
||||
{
|
||||
matchingChildItemGroup = startItemGroup.ChildGroups.First(c => c.GroupName == firstGroup);
|
||||
}
|
||||
|
||||
if (matchingChildItemGroup == null)
|
||||
{
|
||||
var newItemGroup = new ItemFilterBlockGroup(inputGroups.First().Trim(), startItemGroup);
|
||||
startItemGroup.ChildGroups.Add(newItemGroup);
|
||||
inputGroups = inputGroups.Skip(1).ToList();
|
||||
return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, newItemGroup) : newItemGroup;
|
||||
}
|
||||
inputGroups = inputGroups.Skip(1).ToList();
|
||||
return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, matchingChildItemGroup) : matchingChildItemGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,15 @@ namespace Filtration.Translators
|
||||
|
||||
internal class ItemFilterBlockTranslator : IItemFilterBlockTranslator
|
||||
{
|
||||
private readonly IBlockGroupHierarchyBuilder _blockGroupHierarchyBuilder;
|
||||
private const string Indent = " ";
|
||||
private readonly string _newLine = Environment.NewLine + Indent;
|
||||
|
||||
public ItemFilterBlockTranslator(IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder)
|
||||
{
|
||||
_blockGroupHierarchyBuilder = blockGroupHierarchyBuilder;
|
||||
}
|
||||
|
||||
// This method converts a string into a ItemFilterBlock. This is used for pasting ItemFilterBlocks
|
||||
// and reading ItemFilterScripts from a file.
|
||||
public ItemFilterBlock TranslateStringToItemFilterBlock(string inputString)
|
||||
@@ -32,6 +38,7 @@ namespace Filtration.Translators
|
||||
var showHideFound = false;
|
||||
foreach (var line in new LineReader(() => new StringReader(inputString)))
|
||||
{
|
||||
|
||||
if (line.StartsWith(@"# Section:"))
|
||||
{
|
||||
var section = new ItemFilterSection
|
||||
@@ -47,7 +54,8 @@ namespace Filtration.Translators
|
||||
continue;
|
||||
}
|
||||
|
||||
var trimmedLine = line.TrimStart(' ');
|
||||
var adjustedLine = line.Replace("#", " # ");
|
||||
var trimmedLine = adjustedLine.TrimStart(' ');
|
||||
var spaceOrEndOfLinePos = trimmedLine.IndexOf(" ", StringComparison.Ordinal) > 0 ? trimmedLine.IndexOf(" ", StringComparison.Ordinal) : trimmedLine.Length;
|
||||
|
||||
var lineOption = trimmedLine.Substring(0, spaceOrEndOfLinePos);
|
||||
@@ -56,10 +64,12 @@ namespace Filtration.Translators
|
||||
case "Show":
|
||||
showHideFound = true;
|
||||
block.Action = BlockAction.Show;
|
||||
AddBlockGroupToBlock(block, trimmedLine);
|
||||
break;
|
||||
case "Hide":
|
||||
showHideFound = true;
|
||||
block.Action = BlockAction.Hide;
|
||||
AddBlockGroupToBlock(block, trimmedLine);
|
||||
break;
|
||||
case "ItemLevel":
|
||||
{
|
||||
@@ -122,20 +132,6 @@ namespace Filtration.Translators
|
||||
}
|
||||
case "SocketGroup":
|
||||
{
|
||||
//var blockItem = new SocketGroupBlockItem();
|
||||
|
||||
//var socketGroups = Regex.Matches(trimmedLine, @"\s+([RGBW]{1,6})");
|
||||
|
||||
//foreach (Match socketGroupMatch in socketGroups)
|
||||
//{
|
||||
|
||||
// var socketGroupCharArray = socketGroupMatch.Groups[1].Value.Trim(' ').ToCharArray();
|
||||
// var socketColorList = socketGroupCharArray.Select(c => (EnumHelper.GetEnumValueFromDescription<SocketColor>(c.ToString()))).ToList();
|
||||
|
||||
// blockItem.SocketColorGroups.Add(socketColorList);
|
||||
//}
|
||||
|
||||
//block.FilterBlockItems.Add(blockItem);
|
||||
AddStringListItemToBlockItems<SocketGroupBlockItem>(block, trimmedLine);
|
||||
break;
|
||||
}
|
||||
@@ -268,6 +264,19 @@ namespace Filtration.Translators
|
||||
block.BlockItems.Add(blockItem);
|
||||
}
|
||||
|
||||
private void AddBlockGroupToBlock(ItemFilterBlock block, string inputString)
|
||||
{
|
||||
var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal);
|
||||
if (blockGroupStart <= 0) return;
|
||||
|
||||
var blockGroupText = inputString.Substring(blockGroupStart + 1);
|
||||
var blockGroups = blockGroupText.Split('-').ToList();
|
||||
if (blockGroups.Count(b => !string.IsNullOrEmpty(b.Trim())) > 0)
|
||||
{
|
||||
block.BlockGroup = _blockGroupHierarchyBuilder.IntegrateStringListIntoBlockGroupHierarchy(blockGroups);
|
||||
}
|
||||
}
|
||||
|
||||
private static Color GetColorFromString(string inputString)
|
||||
{
|
||||
var argbValues = Regex.Matches(inputString, @"\s+(\d+)");
|
||||
@@ -294,7 +303,7 @@ namespace Filtration.Translators
|
||||
return new Color();
|
||||
}
|
||||
|
||||
// This method converts a ItemFilterBlock object into a string. This is used for copying a ItemFilterBlock
|
||||
// This method converts an ItemFilterBlock object into a string. This is used for copying a ItemFilterBlock
|
||||
// to the clipboard, and when saving a ItemFilterScript.
|
||||
public string TranslateItemFilterBlockToString(ItemFilterBlock block)
|
||||
{
|
||||
@@ -312,6 +321,11 @@ namespace Filtration.Translators
|
||||
|
||||
outputString += block.Action.GetAttributeDescription();
|
||||
|
||||
if (block.BlockGroup != null)
|
||||
{
|
||||
outputString += " # " + block.BlockGroup;
|
||||
}
|
||||
|
||||
// This could be refactored to use the upcasted NumericFilterPredicateBlockItem (or even IItemFilterBlockItem) instead
|
||||
// of the specific downcasts. Leaving it like this currently to preserve sorting since the different
|
||||
// downcasts have no defined sort order (yet).
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Filtration.Models;
|
||||
using Filtration.Utilities;
|
||||
@@ -16,15 +17,19 @@ namespace Filtration.Translators
|
||||
internal class ItemFilterScriptTranslator : IItemFilterScriptTranslator
|
||||
{
|
||||
private readonly IItemFilterBlockTranslator _blockTranslator;
|
||||
private readonly IBlockGroupHierarchyBuilder _blockGroupHierarchyBuilder;
|
||||
|
||||
public ItemFilterScriptTranslator(IItemFilterBlockTranslator blockTranslator)
|
||||
public ItemFilterScriptTranslator(IItemFilterBlockTranslator blockTranslator, IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder)
|
||||
{
|
||||
_blockTranslator = blockTranslator;
|
||||
_blockGroupHierarchyBuilder = blockGroupHierarchyBuilder;
|
||||
}
|
||||
|
||||
public ItemFilterScript TranslateStringToItemFilterScript(string inputString)
|
||||
{
|
||||
var script = new ItemFilterScript();
|
||||
_blockGroupHierarchyBuilder.Initialise(script.ItemFilterBlockGroups.First());
|
||||
|
||||
inputString = inputString.Replace("\t", "");
|
||||
var conditionBoundaries = IdentifyBlockBoundaries(inputString);
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ namespace Filtration.WindsorInstallers
|
||||
Component.For<IItemFilterBlockTranslator>()
|
||||
.ImplementedBy<ItemFilterBlockTranslator>()
|
||||
.LifeStyle.Singleton);
|
||||
|
||||
container.Register(
|
||||
Component.For<IBlockGroupHierarchyBuilder>()
|
||||
.ImplementedBy<BlockGroupHierarchyBuilder>()
|
||||
.LifeStyle.Singleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user