Add more utility to batcheditor

method ( string[] , pkm[] )
carry out batch edit, all within core (no gui needed)
This commit is contained in:
Kurt
2018-05-21 17:04:02 -07:00
parent 620d822fef
commit 3c7d083c1e
2 changed files with 14 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using static PKHeX.Core.MessageStrings;
namespace PKHeX.Core
@@ -61,5 +61,15 @@ public string GetEditorResults(ICollection<StringInstructionSet> sets)
result += Environment.NewLine + maybe + string.Format(MsgBEModifyFailError, Errored);
return result;
}
public static BatchEditor Execute(IList<string> lines, IEnumerable<PKM> data)
{
var editor = new BatchEditor();
var sets = StringInstructionSet.GetBatchSets(lines).ToList();
foreach (var pk in data)
foreach (var set in sets)
editor.ProcessPKM(pk, set.Filters, set.Instructions);
return editor;
}
}
}

View File

@@ -12,17 +12,17 @@ public class StringInstructionSet
public IList<StringInstruction> Instructions { get; private set; }
private const string SetSeparator = ";";
public static IEnumerable<StringInstructionSet> GetBatchSets(string[] lines)
public static IEnumerable<StringInstructionSet> GetBatchSets(IList<string> lines)
{
int start = 0;
while (start < lines.Length)
while (start < lines.Count)
{
var list = lines.Skip(start).TakeWhile(_ => !lines[start++].StartsWith(SetSeparator)).ToList();
yield return GetBatchSet(list);
}
}
private static StringInstructionSet GetBatchSet(IList<string> set)
private static StringInstructionSet GetBatchSet(ICollection<string> set)
{
return new StringInstructionSet
{