diff --git a/PKHeX.Core/Editing/Bulk/BatchEditing.cs b/PKHeX.Core/Editing/Bulk/BatchEditing.cs
index 345c8787f..7258cee85 100644
--- a/PKHeX.Core/Editing/Bulk/BatchEditing.cs
+++ b/PKHeX.Core/Editing/Bulk/BatchEditing.cs
@@ -17,6 +17,7 @@ public static class BatchEditing
typeof (PK3), typeof (XK3), typeof (CK3),
typeof (PK2), typeof (PK1),
};
+
public static readonly string[] CustomProperties = { PROP_LEGAL };
public static readonly string[][] Properties = GetPropArray();
@@ -30,6 +31,7 @@ public static class BatchEditing
private const string CONST_BYTES = "$[]";
private const string PROP_LEGAL = "Legal";
+ private const string IdentifierContains = nameof(PKM.Identifier) + "Contains";
private static string[][] GetPropArray()
{
@@ -53,22 +55,25 @@ private static string[][] GetPropArray()
return p1;
}
- public static bool TryGetHasProperty(PKM pk, string name, out PropertyInfo pi)
+ ///
+ /// Tries to fetch the property from the cache of available properties.
+ ///
+ /// Pokémon to check
+ /// Property Name to check
+ /// Property Info retrieved (if any).
+ /// True if has property, false if does not.
+ public static bool TryGetHasProperty(PKM pkm, string name, out PropertyInfo pi)
{
- var props = Props[Array.IndexOf(Types, pk.GetType())];
+ var props = Props[Array.IndexOf(Types, pkm.GetType())];
return props.TryGetValue(name, out pi);
}
- public static bool TryGetPropertyValue(PKM pk, string name, out object value)
- {
- if (TryGetHasProperty(pk, name, out var pi))
- {
- value = pi.GetValue(pk);
- return true;
- }
- value = null;
- return false;
- }
+ ///
+ /// Gets the type of the property using the saved cache of properties.
+ ///
+ /// Property Name to fetch the type for
+ /// Type index (within . Leave empty (0) for a nonspecific format.
+ /// Short name of the property's type.
public static string GetPropertyType(string propertyName, int typeIndex = 0)
{
if (CustomProperties.Contains(propertyName))
@@ -83,12 +88,16 @@ public static string GetPropertyType(string propertyName, int typeIndex = 0)
}
int index = typeIndex == Props.Length - 1 ? 0 : typeIndex - 1; // All vs Specific
- var pr = Props[typeIndex - 1];
+ var pr = Props[index];
if (!pr.TryGetValue(propertyName, out var info))
return null;
return info.PropertyType.Name;
}
+ ///
+ /// Initializes the list with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index.
+ ///
+ /// Instructions to initialize.
public static void ScreenStrings(IEnumerable il)
{
foreach (var i in il.Where(i => !i.PropertyValue.All(char.IsDigit)))
@@ -101,6 +110,10 @@ public static void ScreenStrings(IEnumerable il)
}
}
+ ///
+ /// Initializes the with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index.
+ ///
+ /// Instruction to initialize.
private static void SetInstructionScreenedValue(StringInstruction i)
{
switch (i.PropertyName)
@@ -122,30 +135,80 @@ private static void SetInstructionScreenedValue(StringInstruction i)
}
}
- internal static ModifyResult TryModifyPKM(PKM PKM, IEnumerable Filters, IEnumerable Instructions)
+ ///
+ /// Checks if the object is filtered by the provided .
+ ///
+ /// Filters which must be satisfied.
+ /// Object to check.
+ /// True if matches all filters.
+ public static bool IsFiltered(IEnumerable filters, PKM pkm) => filters.All(z => IsPKMFiltered(z, pkm));
+
+ ///
+ /// Checks if the object is filtered by the provided .
+ ///
+ /// Filters which must be satisfied.
+ /// Object to check.
+ /// True if matches all filters.
+ public static bool IsFiltered(IEnumerable filters, object obj)
{
- if (!PKM.ChecksumValid || PKM.Species == 0)
+ foreach (var cmd in filters)
+ {
+ if (!ReflectUtil.HasProperty(obj, cmd.PropertyName, out var pi))
+ return false;
+ try { if (pi.IsValueEqual(obj, cmd.PropertyValue) == cmd.Evaluator) continue; }
+ catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Tries to modify the .
+ ///
+ /// Object to modify.
+ /// Filters which must be satisfied prior to any modifications being made.
+ /// Modifications to perform on the .
+ /// Result of the attempted modification.
+ public static bool TryModify(PKM pkm, IEnumerable filters, IEnumerable modifications)
+ {
+ var result = TryModifyPKM(pkm, filters, modifications);
+ return result == ModifyResult.Modified;
+ }
+
+ ///
+ /// Tries to modify the .
+ ///
+ /// Command Filter
+ /// Filters which must be satisfied prior to any modifications being made.
+ /// Modifications to perform on the .
+ /// Result of the attempted modification.
+ internal static ModifyResult TryModifyPKM(PKM pkm, IEnumerable filters, IEnumerable modifications)
+ {
+ if (!pkm.ChecksumValid || pkm.Species == 0)
return ModifyResult.Invalid;
- PKMInfo info = new PKMInfo(PKM);
- var pi = Props[Array.IndexOf(Types, PKM.GetType())];
- foreach (var cmd in Filters)
+ PKMInfo info = new PKMInfo(pkm);
+ var pi = Props[Array.IndexOf(Types, pkm.GetType())];
+ foreach (var cmd in filters)
{
try
{
- var filter = IsPKMFiltered(cmd, info, pi);
- if (filter != ModifyResult.None)
- return filter; // why it was filtered out
+ if (IsPKMFiltered(cmd, info, pi))
+ return ModifyResult.Filtered;
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(MsgBEModifyFailCompare + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue);
+ return ModifyResult.Error;
}
- catch (Exception ex) { Debug.WriteLine(MsgBEModifyFailCompare + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue); }
}
ModifyResult result = ModifyResult.Modified;
- foreach (var cmd in Instructions)
+ foreach (var cmd in modifications)
{
try
{
- var tmp = SetPKMProperty(PKM, info, cmd, pi);
+ var tmp = SetPKMProperty(cmd, info, pi);
if (result != ModifyResult.Modified)
result = tmp;
}
@@ -153,61 +216,127 @@ internal static ModifyResult TryModifyPKM(PKM PKM, IEnumerable props)
+
+ ///
+ /// Sets the if the should be filtered due to the provided.
+ ///
+ /// Command Filter
+ /// Pokémon to check.
+ /// PropertyInfo cache (optional)
+ /// True if filtered, else false.
+ private static ModifyResult SetPKMProperty(StringInstruction cmd, PKMInfo info, IReadOnlyDictionary props)
{
+ var pkm = info.pkm;
if (cmd.PropertyValue.StartsWith(CONST_BYTES))
- return SetByteArrayProperty(PKM, cmd)
- ? ModifyResult.Modified
- : ModifyResult.Error;
+ return SetByteArrayProperty(pkm, cmd);
if (cmd.PropertyValue == CONST_SUGGEST)
- return SetSuggestedPKMProperty(cmd, info)
- ? ModifyResult.Modified
- : ModifyResult.Error;
+ return SetSuggestedPKMProperty(cmd.PropertyName, info);
- if (SetComplexProperty(PKM, cmd))
+ if (SetComplexProperty(pkm, cmd))
return ModifyResult.Modified;
- object val = cmd.Random ? (object)cmd.RandomValue : cmd.PropertyValue;
- if (TryGetHasProperty(PKM, cmd.PropertyName, out var pi))
- {
- ReflectUtil.SetValue(pi, PKM, val);
- return ModifyResult.Modified;
- }
- return ModifyResult.Error;
- }
- private static ModifyResult IsPKMFiltered(StringInstruction cmd, PKMInfo info, Dictionary props)
- {
- if (cmd.PropertyName == PROP_LEGAL)
- {
- if (!bool.TryParse(cmd.PropertyValue, out bool legal))
- return ModifyResult.Error;
- if (legal == info.Legal == cmd.Evaluator)
- return ModifyResult.None;
- return ModifyResult.Filtered;
- }
-
if (!props.TryGetValue(cmd.PropertyName, out var pi))
- return ModifyResult.Filtered;
- if (pi.IsValueEqual(info.pkm, cmd.PropertyValue) != cmd.Evaluator)
- return ModifyResult.Filtered;
- return ModifyResult.None;
+ return ModifyResult.Error;
+
+ object val = cmd.Random ? (object)cmd.RandomValue : cmd.PropertyValue;
+ ReflectUtil.SetValue(pi, pkm, val);
+ return ModifyResult.Modified;
}
- private static bool SetSuggestedPKMProperty(StringInstruction cmd, PKMInfo info)
+
+ ///
+ /// Checks if the should be filtered due to the provided.
+ ///
+ /// Command Filter
+ /// Pokémon to check.
+ /// PropertyInfo cache (optional)
+ /// True if filtered, else false.
+ private static bool IsPKMFiltered(StringInstruction cmd, PKMInfo info, IReadOnlyDictionary props = null)
+ {
+ if (IsLegalFiltered(cmd, () => info.Legal))
+ return true;
+ return IsPropertyFiltered(cmd, info.pkm, props);
+ }
+
+ ///
+ /// Checks if the should be filtered due to the provided.
+ ///
+ /// Command Filter
+ /// Pokémon to check.
+ /// PropertyInfo cache (optional)
+ /// True if filtered, else false.
+ private static bool IsPKMFiltered(StringInstruction cmd, PKM pkm, IReadOnlyDictionary props = null)
+ {
+ if (IsLegalFiltered(cmd, () => new LegalityAnalysis(pkm).Valid))
+ return true;
+ return IsPropertyFiltered(cmd, pkm, props);
+ }
+
+ ///
+ /// Checks if the should be filtered due to the provided.
+ ///
+ /// Command Filter
+ /// Pokémon to check.
+ /// PropertyInfo cache (optional)
+ /// True if filtered, else false.
+ private static bool IsPropertyFiltered(StringInstruction cmd, PKM pkm, IReadOnlyDictionary props = null)
+ {
+ if (IsIdentifierFiltered(cmd, pkm))
+ return true;
+ return !props?.TryGetValue(cmd.PropertyName, out _) ?? !ReflectUtil.HasProperty(pkm, cmd.PropertyName, out _);
+ }
+
+ ///
+ /// Checks if the should be filtered due to its containing a value.
+ ///
+ /// Command Filter
+ /// Pokémon to check.
+ /// True if filtered, else false.
+ private static bool IsIdentifierFiltered(StringInstruction cmd, PKM pkm)
+ {
+ if (cmd.PropertyName != IdentifierContains)
+ return false;
+
+ bool result = pkm.Identifier.Contains(cmd.PropertyValue);
+ return result != cmd.Evaluator;
+ }
+
+ ///
+ /// Checks if the should be filtered due to its legality.
+ ///
+ /// Command Filter
+ /// Function to check if the is legal.
+ /// True if filtered, else false.
+ private static bool IsLegalFiltered(StringInstruction cmd, Func isLegal)
+ {
+ if (cmd.PropertyName != PROP_LEGAL)
+ return false;
+
+ if (!bool.TryParse(cmd.PropertyValue, out bool legal))
+ return true;
+ return legal == isLegal() != cmd.Evaluator;
+ }
+
+ ///
+ /// Sets the data with a suggested value based on its .
+ ///
+ /// Property to modify.
+ /// Cached info storing Legal data.
+ private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info)
{
var PKM = info.pkm;
- switch (cmd.PropertyName)
+ switch (name)
{
case nameof(PKM.HyperTrainFlags):
- PKM.HyperTrainFlags = GetSuggestedHyperTrainingStatus(PKM);
- return true;
+ PKM.SetSuggestedHyperTrainingData();
+ return ModifyResult.Modified;
case nameof(PKM.RelearnMoves):
PKM.RelearnMoves = info.SuggestedRelearn;
- return true;
+ return ModifyResult.Modified;
case nameof(PKM.Met_Location):
var encounter = info.SuggestedEncounter;
if (encounter == null)
- return false;
+ return ModifyResult.Error;
int level = encounter.Level;
int location = encounter.Location;
@@ -217,92 +346,88 @@ private static bool SetSuggestedPKMProperty(StringInstruction cmd, PKMInfo info)
PKM.Met_Location = location;
PKM.CurrentLevel = Math.Max(minlvl, level);
- return true;
+ return ModifyResult.Modified;
case nameof(PKM.Moves):
var moves = info.SuggestedMoves;
Util.Shuffle(moves);
PKM.SetMoves(moves);
- return true;
+ return ModifyResult.Modified;
default:
- return false;
+ return ModifyResult.Error;
}
}
- private static int GetSuggestedHyperTrainingStatus(PKM pkm)
- {
- if (pkm.Format < 7 || pkm.CurrentLevel != 100)
- return 0;
-
- int val = 0;
- if (pkm.IV_HP != 31)
- val |= 1 << 0;
- if (pkm.IV_ATK < 31 && pkm.IV_ATK > 1)
- val |= 1 << 1;
- if (pkm.IV_DEF != 31)
- val |= 1 << 2;
- if (pkm.IV_SPE < 31 && pkm.IV_SPE > 1)
- val |= 1 << 3;
- if (pkm.IV_SPA != 31)
- val |= 1 << 4;
- if (pkm.IV_SPD != 31)
- val |= 1 << 5;
- return val;
- }
-
- private static bool SetByteArrayProperty(PKM PKM, StringInstruction cmd)
+ ///
+ /// Sets the byte array propery to a specified value.
+ ///
+ /// Pokémon to modify.
+ /// Modification
+ private static ModifyResult SetByteArrayProperty(PKM pkm, StringInstruction cmd)
{
switch (cmd.PropertyName)
{
- case nameof(PKM.Nickname_Trash):
- PKM.Nickname_Trash = string2arr(cmd.PropertyValue);
- return true;
- case nameof(PKM.OT_Trash):
- PKM.OT_Trash = string2arr(cmd.PropertyValue);
- return true;
+ case nameof(pkm.Nickname_Trash):
+ pkm.Nickname_Trash = string2arr(cmd.PropertyValue);
+ return ModifyResult.Modified;
+ case nameof(pkm.OT_Trash):
+ pkm.OT_Trash = string2arr(cmd.PropertyValue);
+ return ModifyResult.Modified;
default:
- return false;
+ return ModifyResult.Error;
}
byte[] string2arr(string str) => str.Substring(CONST_BYTES.Length).Split(',').Select(z => Convert.ToByte(z.Trim(), 16)).ToArray();
}
- private static bool SetComplexProperty(PKM PKM, StringInstruction cmd)
+
+ ///
+ /// Sets the property to a non-specific smart value.
+ ///
+ /// Pokémon to modify.
+ /// Modification
+ private static bool SetComplexProperty(PKM pkm, StringInstruction cmd)
{
- if (cmd.PropertyName == nameof(PKM.MetDate))
- PKM.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
- else if (cmd.PropertyName == nameof(PKM.EggMetDate))
- PKM.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
- else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == CONST_RAND)
- PKM.EncryptionConstant = Util.Rand32();
- else if ((cmd.PropertyName == nameof(PKM.Ability) || cmd.PropertyName == nameof(PKM.AbilityNumber)) && cmd.PropertyValue.StartsWith("$"))
- PKM.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30);
- else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_RAND)
- PKM.SetPIDGender(PKM.Gender);
- else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == nameof(PKM.PID))
- PKM.EncryptionConstant = PKM.PID;
- else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_SHINY)
- PKM.SetShinyPID();
- else if (cmd.PropertyName == nameof(PKM.Species) && cmd.PropertyValue == "0")
- PKM.Data = new byte[PKM.Data.Length];
+ if (cmd.PropertyName == nameof(pkm.MetDate))
+ pkm.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
+ else if (cmd.PropertyName == nameof(pkm.EggMetDate))
+ pkm.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
+ else if (cmd.PropertyName == nameof(pkm.EncryptionConstant) && cmd.PropertyValue == CONST_RAND)
+ pkm.EncryptionConstant = Util.Rand32();
+ else if ((cmd.PropertyName == nameof(pkm.Ability) || cmd.PropertyName == nameof(pkm.AbilityNumber)) && cmd.PropertyValue.StartsWith("$"))
+ pkm.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30);
+ else if (cmd.PropertyName == nameof(pkm.PID) && cmd.PropertyValue == CONST_RAND)
+ pkm.SetPIDGender(pkm.Gender);
+ else if (cmd.PropertyName == nameof(pkm.EncryptionConstant) && cmd.PropertyValue == nameof(pkm.PID))
+ pkm.EncryptionConstant = pkm.PID;
+ else if (cmd.PropertyName == nameof(pkm.PID) && cmd.PropertyValue == CONST_SHINY)
+ pkm.SetShinyPID();
+ else if (cmd.PropertyName == nameof(pkm.Species) && cmd.PropertyValue == "0")
+ pkm.Data = new byte[pkm.Data.Length];
else if (cmd.PropertyName.StartsWith("IV") && cmd.PropertyValue == CONST_RAND)
- SetRandomIVs(PKM, cmd);
- else if (cmd.PropertyName == nameof(PKM.IsNicknamed) && string.Equals(cmd.PropertyValue, "false", StringComparison.OrdinalIgnoreCase))
- { PKM.IsNicknamed = false; PKM.Nickname = PKX.GetSpeciesNameGeneration(PKM.Species, PKM.Language, PKM.Format); }
+ SetRandomIVs(pkm, cmd);
+ else if (cmd.PropertyName == nameof(pkm.IsNicknamed) && string.Equals(cmd.PropertyValue, "false", StringComparison.OrdinalIgnoreCase))
+ { pkm.IsNicknamed = false; pkm.Nickname = PKX.GetSpeciesNameGeneration(pkm.Species, pkm.Language, pkm.Format); }
else
return false;
return true;
}
- private static void SetRandomIVs(PKM PKM, StringInstruction cmd)
+
+ ///
+ /// Sets the IV(s) to a random value.
+ ///
+ /// Pokémon to modify.
+ /// Modification
+ private static void SetRandomIVs(PKM pkm, StringInstruction cmd)
{
- if (cmd.PropertyName == nameof(PKM.IVs))
+ if (cmd.PropertyName == nameof(pkm.IVs))
{
- PKM.SetRandomIVs();
+ pkm.SetRandomIVs();
return;
}
- if (TryGetHasProperty(PKM, cmd.PropertyName, out var pi))
- ReflectUtil.SetValue(pi, PKM, Util.Rand32() & PKM.MaxIV);
+ if (TryGetHasProperty(pkm, cmd.PropertyName, out var pi))
+ ReflectUtil.SetValue(pi, pkm, Util.Rand32() & pkm.MaxIV);
}
}
}
diff --git a/PKHeX.Core/Editing/Bulk/BatchEditor.cs b/PKHeX.Core/Editing/Bulk/BatchEditor.cs
index 49a579892..0270596ab 100644
--- a/PKHeX.Core/Editing/Bulk/BatchEditor.cs
+++ b/PKHeX.Core/Editing/Bulk/BatchEditor.cs
@@ -12,7 +12,14 @@ public class BatchEditor
private int Iterated { get; set; }
private int Errored { get; set; }
- public bool ProcessPKM(PKM pkm, IEnumerable Filters, IEnumerable Instructions)
+ ///
+ /// Tries to modify the .
+ ///
+ /// Object to modify.
+ /// Filters which must be satisfied prior to any modifications being made.
+ /// Modifications to perform on the .
+ /// Result of the attempted modification.
+ public bool ProcessPKM(PKM pkm, IEnumerable filters, IEnumerable modifications)
{
if (pkm.Species <= 0)
return false;
@@ -24,7 +31,7 @@ public bool ProcessPKM(PKM pkm, IEnumerable Filters, IEnumera
return false;
}
- var r = BatchEditing.TryModifyPKM(pkm, Filters, Instructions);
+ var r = BatchEditing.TryModifyPKM(pkm, filters, modifications);
if (r != ModifyResult.Invalid)
Iterated++;
if (r == ModifyResult.Error)
@@ -37,6 +44,11 @@ public bool ProcessPKM(PKM pkm, IEnumerable Filters, IEnumera
return true;
}
+ ///
+ /// Gets a message indicating the overall result of all modifications performed across multiple Batch Edit jobs.
+ ///
+ /// Collection of modifications.
+ /// Friendly (multi-line) string indicating the result of the batch edits.
public string GetEditorResults(ICollection sets)
{
int ctr = Modified / sets.Count;
@@ -44,7 +56,7 @@ public string GetEditorResults(ICollection sets)
string maybe = sets.Count == 1 ? string.Empty : "~";
string result = string.Format(MsgBEModifySuccess, maybe, ctr, len);
if (Errored > 0)
- result += $"{Environment.NewLine}{maybe}" + string.Format(MsgBEModifyFailError, Errored);
+ result += Environment.NewLine + maybe + string.Format(MsgBEModifyFailError, Errored);
return result;
}
}
diff --git a/PKHeX.Core/Editing/Bulk/StringInstruction.cs b/PKHeX.Core/Editing/Bulk/StringInstruction.cs
index b7b19fee9..9e4c967cf 100644
--- a/PKHeX.Core/Editing/Bulk/StringInstruction.cs
+++ b/PKHeX.Core/Editing/Bulk/StringInstruction.cs
@@ -7,23 +7,31 @@ namespace PKHeX.Core
{
public class StringInstruction
{
- public string PropertyName { get; set; }
- public string PropertyValue { get; set; }
- public bool Evaluator { get; set; }
+ public string PropertyName { get; private set; }
+ public string PropertyValue { get; private set; }
+ public bool Evaluator { get; private set; }
public void SetScreenedValue(string[] arr)
{
int index = Array.IndexOf(arr, PropertyValue);
PropertyValue = index > -1 ? index.ToString() : PropertyValue;
}
+ public static readonly char[] Prefixes = { Apply, Require, Exclude };
+ private const char Exclude = '!';
+ private const char Require = '=';
+ private const char Apply = '.';
+ private const char SplitRange = ',';
+ private const char SplitInstruction = '=';
+
// Extra Functionality
private int Min, Max;
public bool Random { get; private set; }
public int RandomValue => Util.Rand.Next(Min, Max + 1);
+
public void SetRandRange(string pv)
{
string str = pv.Substring(1);
- var split = str.Split(',');
+ var split = str.Split(SplitRange);
int.TryParse(split[0], out Min);
int.TryParse(split[1], out Max);
@@ -38,18 +46,18 @@ public void SetRandRange(string pv)
public static IEnumerable GetFilters(IEnumerable lines)
{
- var raw = GetRelevantStrings(lines, '!', '=');
+ var raw = GetRelevantStrings(lines, Exclude, Require);
return from line in raw
- let eval = line[0] == '='
- let split = line.Substring(1).Split('=')
+ let eval = line[0] == Require
+ let split = line.Substring(1).Split(SplitInstruction)
where split.Length == 2 && !string.IsNullOrWhiteSpace(split[0])
select new StringInstruction { PropertyName = split[0], PropertyValue = split[1], Evaluator = eval };
}
public static IEnumerable GetInstructions(IEnumerable lines)
{
- var raw = GetRelevantStrings(lines, '.').Select(line => line.Substring(1));
+ var raw = GetRelevantStrings(lines, Apply).Select(line => line.Substring(1));
return from line in raw
- select line.Split('=') into split
+ select line.Split(SplitInstruction) into split
where split.Length == 2
select new StringInstruction { PropertyName = split[0], PropertyValue = split[1] };
}
diff --git a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs
index 09d5186be..6d07460f5 100644
--- a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs
+++ b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs
@@ -63,7 +63,7 @@ private void B_Add_Click(object sender, EventArgs e)
if (CB_Property.SelectedIndex < 0)
{ WinFormsUtil.Alert(MsgBEPropertyInvalid); return; }
- char[] prefix = { '.', '=', '!' };
+ char[] prefix = StringInstruction.Prefixes;
string s = prefix[CB_Require.SelectedIndex] + CB_Property.Items[CB_Property.SelectedIndex].ToString() + "=";
if (RTB_Instructions.Lines.Length != 0 && RTB_Instructions.Lines.Last().Length > 0)
s = Environment.NewLine + s;
diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs
index b265d087d..db2c838ae 100644
--- a/PKHeX.WinForms/Subforms/SAV_Database.cs
+++ b/PKHeX.WinForms/Subforms/SAV_Database.cs
@@ -511,7 +511,7 @@ private IEnumerable SearchDatabase()
{
var filters = StringInstruction.GetFilters(RTB_Instructions.Lines).ToArray();
BatchEditing.ScreenStrings(filters);
- res = res.Where(pkm => IsPKMFiltered(pkm, filters)); // Compare across all filters
+ res = res.Where(pkm => BatchEditing.IsFiltered(filters, pkm)); // Compare across all filters
}
if (Menu_SearchClones.Checked)
@@ -520,27 +520,6 @@ private IEnumerable SearchDatabase()
return res;
}
- private static bool IsPKMFiltered(PKM pkm, IEnumerable filters)
- {
- foreach (var cmd in filters)
- {
- if (cmd.PropertyName == nameof(PKM.Identifier) + "Contains")
- {
- bool result = pkm.Identifier.Contains(cmd.PropertyValue);
- if (result != cmd.Evaluator)
- return false;
- continue;
- }
-
- if (!ReflectUtil.HasProperty(pkm, cmd.PropertyName, out var pi))
- return false;
- try { if (pi.IsValueEqual(pkm, cmd.PropertyValue) == cmd.Evaluator) continue; }
- catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
- return false;
- }
- return true;
- }
-
private static IEnumerable FilterByLVL(IEnumerable res, int option, string lvl)
{
if (string.IsNullOrWhiteSpace(lvl))
diff --git a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs
index d5c9748ab..cd21d2802 100644
--- a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs
+++ b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs
@@ -283,7 +283,7 @@ private void B_Search_Click(object sender, EventArgs e)
{
var filters = StringInstruction.GetFilters(RTB_Instructions.Lines).ToArray();
BatchEditing.ScreenStrings(filters);
- res = res.Where(pkm => IsPKMFiltered(pkm, filters)); // Compare across all filters
+ res = res.Where(pkm => BatchEditing.IsFiltered(filters, pkm)); // Compare across all filters
}
var results = res.ToArray();
@@ -294,19 +294,6 @@ private void B_Search_Click(object sender, EventArgs e)
System.Media.SystemSounds.Asterisk.Play();
}
- private static bool IsPKMFiltered(MysteryGift gift, StringInstruction[] filters)
- {
- foreach (var cmd in filters)
- {
- if (!ReflectUtil.HasProperty(gift, cmd.PropertyName, out var pi))
- return false;
- try { if (pi.IsValueEqual(gift, cmd.PropertyValue) == cmd.Evaluator) continue; }
- catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
- return false;
- }
- return true;
- }
-
private void UpdateScroll(object sender, ScrollEventArgs e)
{
if (e.OldValue != e.NewValue)