2018-05-18 05:43:07 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
2018-05-22 00:04:02 +00:00
|
|
|
|
using System.Linq;
|
2018-05-18 05:43:07 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Carries out a batch edit and contains information summarizing the results.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class BatchEditor
|
2018-05-18 05:43:07 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private int Modified { get; set; }
|
|
|
|
|
private int Iterated { get; set; }
|
|
|
|
|
private int Failed { get; set; }
|
|
|
|
|
|
2019-07-14 22:06:45 +00:00
|
|
|
|
/// <summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
|
/// Tries to modify the <see cref="PKM"/>.
|
2019-07-14 22:06:45 +00:00
|
|
|
|
/// </summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
|
/// <param name="pk">Object to modify.</param>
|
|
|
|
|
/// <param name="filters">Filters which must be satisfied prior to any modifications being made.</param>
|
|
|
|
|
/// <param name="modifications">Modifications to perform on the <see cref="pk"/>.</param>
|
|
|
|
|
/// <returns>Result of the attempted modification.</returns>
|
|
|
|
|
public bool Process(PKM pk, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications)
|
2018-05-18 05:43:07 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (pk.Species <= 0)
|
|
|
|
|
return false;
|
|
|
|
|
if (!pk.Valid)
|
2018-05-18 05:43:07 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
Iterated++;
|
|
|
|
|
const string reason = "Not Valid.";
|
|
|
|
|
Debug.WriteLine($"{MsgBEModifyFailBlocked} {reason}");
|
|
|
|
|
return false;
|
2018-05-18 05:43:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
var result = BatchEditing.TryModifyPKM(pk, filters, modifications);
|
|
|
|
|
if (result != ModifyResult.Invalid)
|
|
|
|
|
Iterated++;
|
|
|
|
|
if (result == ModifyResult.Error)
|
|
|
|
|
Failed++;
|
|
|
|
|
if (result != ModifyResult.Modified)
|
|
|
|
|
return false;
|
2018-05-22 00:04:02 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
pk.RefreshChecksum();
|
|
|
|
|
Modified++;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a message indicating the overall result of all modifications performed across multiple Batch Edit jobs.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sets">Collection of modifications.</param>
|
|
|
|
|
/// <returns>Friendly (multi-line) string indicating the result of the batch edits.</returns>
|
|
|
|
|
public string GetEditorResults(ICollection<StringInstructionSet> sets)
|
|
|
|
|
{
|
|
|
|
|
if (sets.Count == 0)
|
|
|
|
|
return MsgBEInstructionNone;
|
|
|
|
|
int ctr = Modified / sets.Count;
|
|
|
|
|
int len = Iterated / sets.Count;
|
|
|
|
|
string maybe = sets.Count == 1 ? string.Empty : "~";
|
|
|
|
|
string result = string.Format(MsgBEModifySuccess, maybe, ctr, len);
|
|
|
|
|
if (Failed > 0)
|
|
|
|
|
result += Environment.NewLine + maybe + string.Format(MsgBEModifyFailError, Failed);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public static BatchEditor Execute(IList<string> lines, IEnumerable<PKM> data)
|
|
|
|
|
{
|
|
|
|
|
var editor = new BatchEditor();
|
|
|
|
|
var sets = StringInstructionSet.GetBatchSets(lines).ToArray();
|
|
|
|
|
foreach (var pk in data)
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
foreach (var set in sets)
|
|
|
|
|
editor.Process(pk, set.Filters, set.Instructions);
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
|
|
return editor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddSkipped()
|
|
|
|
|
{
|
|
|
|
|
++Iterated;
|
2018-05-18 05:43:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|