From 3c7d083c1e0cfd442daff5e102349dcf9873dbf8 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 21 May 2018 17:04:02 -0700 Subject: [PATCH] Add more utility to batcheditor method ( string[] , pkm[] ) carry out batch edit, all within core (no gui needed) --- PKHeX.Core/Editing/Bulk/BatchEditor.cs | 12 +++++++++++- PKHeX.Core/Editing/Bulk/StringInstructionSet.cs | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/PKHeX.Core/Editing/Bulk/BatchEditor.cs b/PKHeX.Core/Editing/Bulk/BatchEditor.cs index e9df71ee4..7e8775ef1 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditor.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditor.cs @@ -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 sets) result += Environment.NewLine + maybe + string.Format(MsgBEModifyFailError, Errored); return result; } + + public static BatchEditor Execute(IList lines, IEnumerable 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; + } } } diff --git a/PKHeX.Core/Editing/Bulk/StringInstructionSet.cs b/PKHeX.Core/Editing/Bulk/StringInstructionSet.cs index ea6790167..84aaf4357 100644 --- a/PKHeX.Core/Editing/Bulk/StringInstructionSet.cs +++ b/PKHeX.Core/Editing/Bulk/StringInstructionSet.cs @@ -12,17 +12,17 @@ public class StringInstructionSet public IList Instructions { get; private set; } private const string SetSeparator = ";"; - public static IEnumerable GetBatchSets(string[] lines) + public static IEnumerable GetBatchSets(IList 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 set) + private static StringInstructionSet GetBatchSet(ICollection set) { return new StringInstructionSet {