mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-07 05:55:18 -05:00
Add more utility to batcheditor
method ( string[] , pkm[] ) carry out batch edit, all within core (no gui needed)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user