Rework entity import settings param passing

Closes #4418

Introduce a readonly record struct to contain all the settings selected. Add simple static get for none/all to disable/force the updates.

Split the UpdateRecord behavior out of UpdatePKM (adapt to save file) so that it behaves similarly to UpdateDex.
Only AdaptToSaveFile when opening a file in the PKM Editor.
This commit is contained in:
Kurt 2025-02-23 15:50:17 -06:00
parent 8f86e3fec0
commit c8ec63992b
23 changed files with 152 additions and 129 deletions

View File

@ -35,9 +35,9 @@ public interface ISlotInfo
/// </summary>
/// <param name="sav">Save file to try writing to.</param>
/// <param name="pk">Entity data to try writing.</param>
/// <param name="setting">Setting to use when importing the <see cref="pk"/> data</param>
/// <param name="settings">Setting to use when importing the <see cref="pk"/> data</param>
/// <returns>Returns false if it did not succeed.</returns>
bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault);
bool WriteTo(SaveFile sav, PKM pk, EntityImportSettings settings = default);
/// <summary>
/// Reads a <see cref="PKM"/> from the <see cref="sav"/>.

View File

@ -9,9 +9,9 @@ public sealed record SlotInfoBox(int Box, int Slot) : ISlotInfo
public bool CanWriteTo(SaveFile sav) => sav.HasBox && !sav.IsBoxSlotLocked(Box, Slot);
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => WriteBlockedMessage.None;
public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault)
public bool WriteTo(SaveFile sav, PKM pk, EntityImportSettings settings = default)
{
sav.SetBoxSlotAtIndex(pk, Box, Slot, setting, setting);
sav.SetBoxSlotAtIndex(pk, Box, Slot, settings);
return true;
}

View File

@ -11,6 +11,6 @@ public sealed record SlotInfoFile(string Path) : ISlotInfo
public bool CanWriteTo(SaveFile sav) => false;
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => WriteBlockedMessage.InvalidDestination;
public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault) => false;
public bool WriteTo(SaveFile sav, PKM pk, EntityImportSettings settings = default) => false;
public PKM Read(SaveFile sav) => sav.BlankPKM;
}

View File

@ -11,13 +11,13 @@ public sealed record SlotInfoMisc(Memory<byte> Data, int Slot, bool PartyFormat
public bool CanWriteTo(SaveFile sav) => Mutable;
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => Mutable ? WriteBlockedMessage.None : WriteBlockedMessage.InvalidDestination;
public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault)
public bool WriteTo(SaveFile sav, PKM pk, EntityImportSettings settings = default)
{
var span = Data.Span;
if (PartyFormat)
sav.SetSlotFormatParty(pk, span, setting, setting);
sav.SetSlotFormatParty(pk, span, settings);
else
sav.SetSlotFormatStored(pk, span, setting, setting);
sav.SetSlotFormatStored(pk, span, settings);
return true;
}

View File

@ -15,7 +15,7 @@ public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => pk.IsEgg && sav.I
? WriteBlockedMessage.InvalidPartyConfiguration
: WriteBlockedMessage.None;
public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault)
public bool WriteTo(SaveFile sav, PKM pk, EntityImportSettings settings = default)
{
if (pk.Species == 0)
{
@ -24,7 +24,7 @@ public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSe
return true;
}
Slot = Math.Min(Slot, sav.PartyCount); // realign if necessary
sav.SetPartySlotAtIndex(pk, Slot, setting, setting);
sav.SetPartySlotAtIndex(pk, Slot, settings);
return true;
}

View File

@ -71,6 +71,6 @@ private sealed class SingleSlotReversion(ISlotInfo info, PKM Entity) : SlotRever
{
public SingleSlotReversion(ISlotInfo info, SaveFile sav) : this(info, info.Read(sav)) { }
public override void Revert(SaveFile sav) => Info.WriteTo(sav, Entity, PKMImportSetting.Skip);
public override void Revert(SaveFile sav) => Info.WriteTo(sav, Entity, EntityImportSettings.None);
}
}

View File

@ -68,16 +68,16 @@ public SlotTouchResult Swap(ISlotInfo source, ISlotInfo dest)
if (!dest.CanWriteTo(SAV))
return SlotTouchResult.FailDestination;
const PKMImportSetting skip = PKMImportSetting.Skip;
var settings = EntityImportSettings.None;
var s = source.Read(SAV);
var d = dest.Read(SAV);
WriteSlot(source, s, SlotTouchType.None, skip);
WriteSlot(dest, d, SlotTouchType.Swap, skip);
WriteSlot(source, s, SlotTouchType.None, settings);
WriteSlot(dest, d, SlotTouchType.Swap, settings);
return SlotTouchResult.Success;
}
private bool WriteSlot(ISlotInfo slot, PKM pk, SlotTouchType type = SlotTouchType.Set, PKMImportSetting setDetail = PKMImportSetting.UseDefault)
private bool WriteSlot(ISlotInfo slot, PKM pk, SlotTouchType type = SlotTouchType.Set, EntityImportSettings setDetail = default)
{
Changelog.AddNewChange(slot);
var result = slot.WriteTo(SAV, pk, setDetail);
@ -89,7 +89,8 @@ private bool WriteSlot(ISlotInfo slot, PKM pk, SlotTouchType type = SlotTouchTyp
private bool DeleteSlot(ISlotInfo slot)
{
var pk = SAV.BlankPKM;
return WriteSlot(slot, pk, SlotTouchType.Delete, PKMImportSetting.Skip);
var settings = EntityImportSettings.None;
return WriteSlot(slot, pk, SlotTouchType.Delete, settings);
}
public void Undo()

View File

@ -130,7 +130,7 @@ public static class PersonalTable
private static void PopulateGen3Tutors()
{
// Update Gen3 data with Emerald's data, FR/LG is a subset of Emerald's compatibility.
// Enable Gen3 data with Emerald's data, FR/LG is a subset of Emerald's compatibility.
var machine = BinLinkerAccessor.Get(Util.GetBinaryResource("hmtm_g3.pkl"), "g3"u8);
var tutors = BinLinkerAccessor.Get(Util.GetBinaryResource("tutors_g3.pkl"), "g3"u8);
E.LoadTables(machine, tutors);

View File

@ -104,10 +104,10 @@ protected override void SetPKM(PKM pk, bool isParty = false)
}
pk.RefreshChecksum();
if (SetUpdateRecords != PKMImportSetting.Skip)
AddCountAcquired(pk);
}
protected override void SetRecord(PKM pk) => AddCountAcquired(pk);
private void AddCountAcquired(PKM pk)
{
Records.AddRecord(pk.WasEgg ? 009 : 007); // egg, capture

View File

@ -165,10 +165,10 @@ protected override void SetPKM(PKM pk, bool isParty = false)
pk7.FormArgumentRemain = (byte)GetFormArgument(pk);
pk.RefreshChecksum();
if (SetUpdateRecords != PKMImportSetting.Skip)
AddCountAcquired(pk);
}
protected override void SetRecord(PKM pk) => AddCountAcquired(pk);
private void AddCountAcquired(PKM pk)
{
Records.AddRecord(pk.WasEgg ? 008 : 006); // egg, capture

View File

@ -312,10 +312,10 @@ protected override void SetPKM(PKM pk, bool isParty = false)
pb8.UpdateHandler(this);
pb8.RefreshChecksum();
if (SetUpdateRecords != PKMImportSetting.Skip)
AddCountAcquired(pk);
}
protected override void SetRecord(PKM pk) => AddCountAcquired(pk);
private void AddCountAcquired(PKM pk)
{
// There aren't many records, and they only track Capture/Fish/Hatch/Defeat.

View File

@ -198,10 +198,10 @@ protected override void SetPKM(PKM pk, bool isParty = false)
}
pk8.RefreshChecksum();
if (SetUpdateRecords != PKMImportSetting.Skip)
AddCountAcquired(pk8);
}
protected override void SetRecord(PKM pk) => AddCountAcquired(pk);
private static uint GetFormArgument(PKM pk)
{
if (pk.Form == 0)

View File

@ -205,10 +205,10 @@ protected override void SetPKM(PKM pk, bool isParty = false)
}
pk9.RefreshChecksum();
if (SetUpdateRecords != PKMImportSetting.Skip)
AddCountAcquired(pk9);
}
protected override void SetRecord(PKM pk) => AddCountAcquired(pk);
private static uint GetFormArgument(PKM pk)
{
if (pk.Form == 0)

View File

@ -1,6 +1,8 @@
using Microsoft.VisualBasic.FileIO;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
namespace PKHeX.Core;
@ -212,7 +214,7 @@ public IList<PKM> PartyData
private Span<byte> GetPartySpan(int index) => PartyBuffer[GetPartyOffset(index)..];
public PKM GetPartySlotAtIndex(int index) => GetPartySlot(GetPartySpan(index));
public void SetPartySlotAtIndex(PKM pk, int index, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
public void SetPartySlotAtIndex(PKM pk, int index, EntityImportSettings settings = default)
{
// update party count
if ((uint)index > 5)
@ -229,37 +231,38 @@ public void SetPartySlotAtIndex(PKM pk, int index, PKMImportSetting trade = PKMI
PartyCount = index;
}
SetPartySlot(pk, GetPartySpan(index), trade, dex);
SetPartySlot(pk, GetPartySpan(index), settings);
}
public void SetSlotFormatParty(PKM pk, Span<byte> data, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
public void SetSlotFormatParty(PKM pk, Span<byte> data, EntityImportSettings settings = default)
{
if (pk.GetType() != PKMType)
throw new ArgumentException($"PKM Format needs to be {PKMType} when setting to this Save File.");
UpdatePKM(pk, isParty: true, trade, dex);
UpdatePKM(pk, isParty: true, settings);
SetPartyValues(pk, isParty: true);
WritePartySlot(pk, data);
}
public void SetSlotFormatStored(PKM pk, Span<byte> data, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
public void SetSlotFormatStored(PKM pk, Span<byte> data, EntityImportSettings settings = default)
{
if (pk.GetType() != PKMType)
throw new ArgumentException($"PKM Format needs to be {PKMType} when setting to this Save File.");
UpdatePKM(pk, isParty: false, trade, dex);
UpdatePKM(pk, isParty: false, settings);
SetPartyValues(pk, isParty: false);
WriteSlotFormatStored(pk, data);
}
public void SetPartySlot(PKM pk, Span<byte> data, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault) => SetSlotFormatParty(pk, data, trade, dex);
public void SetPartySlot(PKM pk, Span<byte> data, EntityImportSettings settings = default)
=> SetSlotFormatParty(pk, data, settings);
public void SetBoxSlot(PKM pk, Span<byte> data, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
public void SetBoxSlot(PKM pk, Span<byte> data, EntityImportSettings settings = default)
{
if (pk.GetType() != PKMType)
throw new ArgumentException($"PKM Format needs to be {PKMType} when setting to this Save File.");
UpdatePKM(pk, isParty: false, trade, dex);
UpdatePKM(pk, isParty: false, settings);
SetPartyValues(pk, isParty: false);
WriteBoxSlot(pk, data);
}
@ -273,16 +276,17 @@ public void DeletePartySlot(int slot)
for (int i = slot + 1; i <= newEmpty; i++) // Slide slots down
{
var current = GetPartySlotAtIndex(i);
SetPartySlotAtIndex(current, i - 1, PKMImportSetting.Skip, PKMImportSetting.Skip);
SetPartySlotAtIndex(current, i - 1, EntityImportSettings.None);
}
SetPartySlotAtIndex(BlankPKM, newEmpty, PKMImportSetting.Skip, PKMImportSetting.Skip);
SetPartySlotAtIndex(BlankPKM, newEmpty, EntityImportSettings.None);
// PartyCount will automatically update via above call. Do not adjust.
}
#region Slot Storing
public static PKMImportSetting SetUpdateDex { protected get; set; } = PKMImportSetting.Update;
public static PKMImportSetting SetUpdatePKM { protected get; set; } = PKMImportSetting.Update;
public static PKMImportSetting SetUpdateRecords { protected get; set; } = PKMImportSetting.Update;
public static EntityImportOption SetUpdateDex { protected get; set; } = EntityImportOption.Enable;
public static EntityImportOption SetUpdatePKM { protected get; set; } = EntityImportOption.Enable;
public static EntityImportOption SetUpdateRecords { protected get; set; } = EntityImportOption.Enable;
public static EntityImportSettings SetUpdateSettings => new(SetUpdatePKM, SetUpdateDex, SetUpdateRecords);
public abstract Type PKMType { get; }
protected abstract PKM GetPKM(byte[] data);
@ -321,41 +325,52 @@ protected virtual void SetPartyValues(PKM pk, bool isParty)
pk.ResetPartyStats();
}
protected void UpdatePKM(PKM pk, bool isParty, EntityImportSettings settings = default)
{
if (IsUpdateAdapt(settings.UpdateToSaveFile))
SetPKM(pk, isParty);
if (IsUpdateDex(settings.UpdatePokeDex))
SetDex(pk);
if (IsUpdateRecord(settings.UpdateRecord))
SetRecord(pk);
}
/// <summary>
/// Conditions a <see cref="pk"/> for this save file as if it was traded to it.
/// </summary>
/// <param name="pk">Entity to adapt</param>
/// <param name="party">Entity exists in party format</param>
/// <param name="trade">Setting on whether to adapt</param>
public void AdaptPKM(PKM pk, bool party = true, PKMImportSetting trade = PKMImportSetting.UseDefault)
/// <param name="isParty">Entity exists in party format</param>
/// <param name="option">Setting on whether to adapt</param>
public void AdaptToSaveFile(PKM pk, bool isParty = true, EntityImportOption option = EntityImportOption.UseDefault)
{
if (GetTradeUpdateSetting(trade))
SetPKM(pk, party);
if (IsUpdateAdapt(option))
SetPKM(pk, isParty);
}
protected void UpdatePKM(PKM pk, bool isParty, PKMImportSetting trade, PKMImportSetting dex)
private static bool IsUpdateAdapt(EntityImportOption option = EntityImportOption.UseDefault)
{
AdaptPKM(pk, isParty, trade);
if (GetDexUpdateSetting(dex))
SetDex(pk);
if (option == EntityImportOption.UseDefault)
option = SetUpdatePKM;
return option == EntityImportOption.Enable;
}
private static bool GetTradeUpdateSetting(PKMImportSetting trade = PKMImportSetting.UseDefault)
private static bool IsUpdateDex(EntityImportOption option = EntityImportOption.UseDefault)
{
if (trade == PKMImportSetting.UseDefault)
trade = SetUpdatePKM;
return trade == PKMImportSetting.Update;
if (option == EntityImportOption.UseDefault)
option = SetUpdateDex;
return option == EntityImportOption.Enable;
}
private static bool GetDexUpdateSetting(PKMImportSetting trade = PKMImportSetting.UseDefault)
private static bool IsUpdateRecord(EntityImportOption option = EntityImportOption.UseDefault)
{
if (trade == PKMImportSetting.UseDefault)
trade = SetUpdateDex;
return trade == PKMImportSetting.Update;
if (option == EntityImportOption.UseDefault)
option = SetUpdateDex;
return option == EntityImportOption.Enable;
}
protected virtual void SetPKM(PKM pk, bool isParty = false) { }
protected virtual void SetDex(PKM pk) { }
protected virtual void SetRecord(PKM pk) { }
#endregion
#region Pokédex
@ -557,11 +572,11 @@ public int GetBoxSlotOffset(int index)
return GetBoxSlotOffset(box, slot);
}
public void SetBoxSlotAtIndex(PKM pk, int box, int slot, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
=> SetBoxSlot(pk, BoxBuffer[GetBoxSlotOffset(box, slot)..], trade, dex);
public void SetBoxSlotAtIndex(PKM pk, int box, int slot, EntityImportSettings settings = default)
=> SetBoxSlot(pk, BoxBuffer[GetBoxSlotOffset(box, slot)..], settings);
public void SetBoxSlotAtIndex(PKM pk, int index, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
=> SetBoxSlot(pk, BoxBuffer[GetBoxSlotOffset(index)..], trade, dex);
public void SetBoxSlotAtIndex(PKM pk, int index, EntityImportSettings settings = default)
=> SetBoxSlot(pk, BoxBuffer[GetBoxSlotOffset(index)..], settings);
#endregion
#region Storage Manipulations
@ -685,10 +700,11 @@ public int SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>, i
SlotPointerUtil.UpdateRepointFrom(boxclone, BD, 0, SlotPointers);
var settings = EntityImportSettings.None;
for (int i = 0; i < boxclone.Length; i++)
{
var pk = boxclone[i];
SetBoxSlotAtIndex(pk, i, PKMImportSetting.Skip, PKMImportSetting.Skip);
SetBoxSlotAtIndex(pk, i, settings);
}
return count;
}
@ -754,6 +770,7 @@ public int ModifyBoxes(Action<PKM> action, int BoxStart = 0, int BoxEnd = -1)
var storage = BoxBuffer;
int modified = 0;
var settings = EntityImportSettings.None;
for (int b = BoxStart; b <= BoxEnd; b++)
{
for (int s = 0; s < BoxSlotCount; s++)
@ -767,7 +784,7 @@ public int ModifyBoxes(Action<PKM> action, int BoxStart = 0, int BoxEnd = -1)
var pk = GetBoxSlotAtIndex(b, s);
action(pk);
++modified;
SetBoxSlot(pk, dest, PKMImportSetting.Skip, PKMImportSetting.Skip);
SetBoxSlot(pk, dest, settings);
}
}
return modified;

View File

@ -0,0 +1,28 @@
using static PKHeX.Core.EntityImportOption;
namespace PKHeX.Core;
/// <summary>
/// Settings to conditionally update entity and save file properties when adapting or importing to a save file.
/// </summary>
public readonly record struct EntityImportSettings(
EntityImportOption UpdateToSaveFile,
EntityImportOption UpdatePokeDex,
EntityImportOption UpdateRecord)
{
public static EntityImportSettings None => new(Disable, Disable, Disable);
public static EntityImportSettings All => new(Enable, Enable, Enable);
}
/// <summary>
/// Option to enable/disable conditional updates when adapting or importing to a save file.
/// </summary>
public enum EntityImportOption : byte
{
/// <summary>
/// Use whatever the global setting is.
/// </summary>
UseDefault,
Enable,
Disable,
}

View File

@ -1,22 +0,0 @@
namespace PKHeX.Core;
/// <summary>
/// Setting to conditionally update PKM properties when importing to a save file.
/// </summary>
public enum PKMImportSetting
{
/// <summary>
/// Use whatever the global setting is.
/// </summary>
UseDefault,
/// <summary>
/// Always update the PKM properties to match the save file.
/// </summary>
Update,
/// <summary>
/// Never update the PKM properties to match the save file.
/// </summary>
Skip,
}

View File

@ -95,17 +95,17 @@ public static int DumpBox(this SaveFile sav, string path, int currentBox)
/// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param>
/// <param name="boxClear">Instruction to clear boxes after the starting box.</param>
/// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param>
/// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <param name="settings">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <param name="all">Enumerate all files even in sub-folders.</param>
/// <returns>Count of files imported.</returns>
public static int LoadBoxes(this SaveFile sav, string path, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault, bool all = false)
public static int LoadBoxes(this SaveFile sav, string path, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, EntityImportSettings settings = default, bool all = false)
{
if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path))
{ result = MsgSaveBoxExportPathInvalid; return -1; }
var option = all ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
var files = Directory.EnumerateFiles(path, "*.*", option);
return sav.LoadBoxes(files, out result, boxStart, boxClear, overwrite, noSetb);
return sav.LoadBoxes(files, out result, boxStart, boxClear, overwrite, settings);
}
/// <summary>
@ -117,12 +117,12 @@ public static int LoadBoxes(this SaveFile sav, string path, out string result, i
/// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param>
/// <param name="boxClear">Instruction to clear boxes after the starting box.</param>
/// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param>
/// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <param name="settings">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <returns>Count of files imported.</returns>
public static int LoadBoxes(this SaveFile sav, IEnumerable<string> files, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
public static int LoadBoxes(this SaveFile sav, IEnumerable<string> files, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, EntityImportSettings settings = default)
{
var pks = GetPossiblePKMsFromPaths(sav, files);
return sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb);
return sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, settings);
}
/// <summary>
@ -134,12 +134,12 @@ public static int LoadBoxes(this SaveFile sav, IEnumerable<string> files, out st
/// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param>
/// <param name="boxClear">Instruction to clear boxes after the starting box.</param>
/// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param>
/// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <param name="settings">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <returns>Count of files imported.</returns>
public static int LoadBoxes(this SaveFile sav, IEnumerable<IEncounterConvertible> encounters, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
public static int LoadBoxes(this SaveFile sav, IEnumerable<IEncounterConvertible> encounters, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, EntityImportSettings settings = default)
{
var pks = encounters.Select(z => z.ConvertToPKM(sav));
return sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb);
return sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, settings);
}
/// <summary>
@ -151,9 +151,9 @@ public static int LoadBoxes(this SaveFile sav, IEnumerable<IEncounterConvertible
/// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param>
/// <param name="boxClear">Instruction to clear boxes after the starting box.</param>
/// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param>
/// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <param name="settings">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <returns>True if any files are imported.</returns>
public static int LoadBoxes(this SaveFile sav, IEnumerable<PKM> pks, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
public static int LoadBoxes(this SaveFile sav, IEnumerable<PKM> pks, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, EntityImportSettings settings = default)
{
if (!sav.HasBox)
{ result = MsgSaveBoxFailNone; return -1; }
@ -162,7 +162,7 @@ public static int LoadBoxes(this SaveFile sav, IEnumerable<PKM> pks, out string
if (boxClear)
sav.ClearBoxes(boxStart);
int ctr = sav.ImportPKMs(compat, overwrite, boxStart, noSetb);
int ctr = sav.ImportPKMs(compat, overwrite, boxStart, settings);
if (ctr <= 0)
{
result = MsgSaveBoxImportNoFiles;

View File

@ -89,9 +89,9 @@ private static List<string> GetSaveFileErrata(this SaveFile sav, PKM pk, IBasicS
/// <param name="compat">Compatible <see cref="PKM"/> data that can be set to the <see cref="sav"/> without conversion.</param>
/// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param>
/// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param>
/// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <param name="settings">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
/// <returns>Count of injected <see cref="PKM"/>.</returns>
public static int ImportPKMs(this SaveFile sav, IEnumerable<PKM> compat, bool overwrite = false, int boxStart = 0, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
public static int ImportPKMs(this SaveFile sav, IEnumerable<PKM> compat, bool overwrite = false, int boxStart = 0, EntityImportSettings settings = default)
{
int startCount = boxStart * sav.BoxSlotCount;
int maxCount = sav.SlotCount;
@ -109,7 +109,7 @@ public static int ImportPKMs(this SaveFile sav, IEnumerable<PKM> compat, bool ov
if (index >= maxCount) // Boxes full!
break;
sav.SetBoxSlotAtIndex(pk, index, noSetb);
sav.SetBoxSlotAtIndex(pk, index, settings);
}
else
{
@ -117,7 +117,7 @@ public static int ImportPKMs(this SaveFile sav, IEnumerable<PKM> compat, bool ov
if (index < 0) // Boxes full!
break;
sav.SetBoxSlotAtIndex(pk, index, noSetb);
sav.SetBoxSlotAtIndex(pk, index, settings);
nonOverwriteImport++;
}

View File

@ -907,15 +907,15 @@ private void ClickVerifyStoredEntities(object sender, EventArgs e)
}
// File I/O
public bool GetBulkImportSettings(out bool clearAll, out bool overwrite, out PKMImportSetting noSetb)
public bool GetBulkImportSettings(out bool clearAll, out bool overwrite, out EntityImportSettings settings)
{
clearAll = false; noSetb = PKMImportSetting.UseDefault; overwrite = false;
clearAll = false; settings = default; overwrite = false;
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, MsgSaveBoxImportClear, MsgSaveBoxImportClearNo);
if (dr == DialogResult.Cancel)
return false;
clearAll = dr == DialogResult.Yes;
noSetb = GetPKMSetOverride(ModifyPKM);
settings = GetImportSettingsOverride();
return true;
}
@ -1016,8 +1016,8 @@ public bool OpenGroup(IPokeGroup b, out string c)
return false;
}
var noSetb = GetPKMSetOverride(ModifyPKM);
var slotSkipped = ImportGroup(b.Contents, SAV, Box.CurrentBox, noSetb);
var settings = GetImportSettingsOverride();
var slotSkipped = ImportGroup(b.Contents, SAV, Box.CurrentBox, settings);
SetPKMBoxes();
UpdateBoxViewers();
@ -1027,7 +1027,7 @@ public bool OpenGroup(IPokeGroup b, out string c)
return true;
}
private static int ImportGroup(IEnumerable<PKM> data, SaveFile sav, int box, PKMImportSetting noSetb)
private static int ImportGroup(IEnumerable<PKM> data, SaveFile sav, int box, EntityImportSettings settings)
{
var type = sav.PKMType;
int slotSkipped = 0;
@ -1047,7 +1047,7 @@ private static int ImportGroup(IEnumerable<PKM> data, SaveFile sav, int box, PKM
slotSkipped++;
continue;
}
sav.SetBoxSlotAtIndex(x, box, i, noSetb);
sav.SetBoxSlotAtIndex(x, box, i, settings);
}
return slotSkipped;
@ -1068,10 +1068,10 @@ public bool LoadBoxes(out string result, string? path = null)
if (!Directory.Exists(path))
return false;
if (!GetBulkImportSettings(out bool clearAll, out var overwrite, out var noSetb))
if (!GetBulkImportSettings(out bool clearAll, out var overwrite, out var settings))
return false;
SAV.LoadBoxes(path, out result, Box.CurrentBox, clearAll, overwrite, noSetb);
SAV.LoadBoxes(path, out result, Box.CurrentBox, clearAll, overwrite, settings);
SetPKMBoxes();
UpdateBoxViewers();
return true;
@ -1382,19 +1382,18 @@ private void B_MailBox_Click(object sender, EventArgs e)
ResetParty();
}
private static PKMImportSetting GetPKMSetOverride(bool currentSetting)
private static EntityImportSettings GetImportSettingsOverride()
{
var yn = currentSetting ? MsgYes : MsgNo;
var choice = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel,
MsgSaveBoxImportModifyIntro,
MsgSaveBoxImportModifyYes + Environment.NewLine +
MsgSaveBoxImportModifyNo + Environment.NewLine +
string.Format(MsgSaveBoxImportModifyCurrent, yn));
string.Format(MsgSaveBoxImportModifyCurrent, SaveFile.SetUpdateSettings));
return choice switch
{
DialogResult.Yes => PKMImportSetting.Update,
DialogResult.No => PKMImportSetting.Skip,
_ => PKMImportSetting.UseDefault,
DialogResult.Yes => EntityImportSettings.All,
DialogResult.No => EntityImportSettings.None,
_ => default,
};
}

View File

@ -436,9 +436,9 @@ private void ReloadProgramSettings(PKHeXSettings settings)
SpriteBuilderUtil.SpriterPreference = settings.Sprite.SpritePreference;
var write = settings.SlotWrite;
SaveFile.SetUpdateDex = write.SetUpdateDex ? PKMImportSetting.Update : PKMImportSetting.Skip;
SaveFile.SetUpdatePKM = write.SetUpdatePKM ? PKMImportSetting.Update : PKMImportSetting.Skip;
SaveFile.SetUpdateRecords = write.SetUpdateRecords ? PKMImportSetting.Update : PKMImportSetting.Skip;
SaveFile.SetUpdateDex = write.SetUpdateDex ? EntityImportOption.Enable : EntityImportOption.Disable;
SaveFile.SetUpdatePKM = write.SetUpdatePKM ? EntityImportOption.Enable : EntityImportOption.Disable;
SaveFile.SetUpdateRecords = write.SetUpdateRecords ? EntityImportOption.Enable : EntityImportOption.Disable;
C_SAV.ModifyPKM = PKME_Tabs.ModifyPKM = settings.SlotWrite.SetUpdatePKM;
CommonEdits.ShowdownSetIVMarkings = settings.Import.ApplyMarkings;
@ -666,7 +666,7 @@ private bool OpenPKM(PKM pk)
Debug.WriteLine(c.GetDisplayString(pk, destType));
if (tmp is null)
return false;
C_SAV.SAV.AdaptPKM(tmp);
C_SAV.SAV.AdaptToSaveFile(tmp);
PKME_Tabs.PopulateFields(tmp);
return true;
}
@ -698,7 +698,7 @@ private bool OpenMysteryGift(MysteryGift tg, string path)
return true;
}
C_SAV.SAV.AdaptPKM(pk);
C_SAV.SAV.AdaptToSaveFile(pk);
PKME_Tabs.PopulateFields(pk);
Debug.WriteLine(c);
return true;

View File

@ -185,7 +185,7 @@ private void RunBatchEditSaveFile(IReadOnlyCollection<StringInstructionSet> sets
SlotInfoLoader.AddPartyData(SAV, data);
process(data);
foreach (var slot in data)
slot.Source.WriteTo(SAV, slot.Entity, PKMImportSetting.Skip);
slot.Source.WriteTo(SAV, slot.Entity, EntityImportSettings.None);
}
if (boxes)
{
@ -193,7 +193,7 @@ private void RunBatchEditSaveFile(IReadOnlyCollection<StringInstructionSet> sets
SlotInfoLoader.AddBoxData(SAV, data);
process(data);
foreach (var slot in data)
slot.Source.WriteTo(SAV, slot.Entity, PKMImportSetting.Skip);
slot.Source.WriteTo(SAV, slot.Entity, EntityImportSettings.None);
}
void process(IList<SlotCache> d)
{

View File

@ -491,11 +491,11 @@ private void Menu_Export_Click(object sender, EventArgs e)
private void Menu_Import_Click(object sender, EventArgs e)
{
if (!BoxView.GetBulkImportSettings(out var clearAll, out var overwrite, out var noSetb))
if (!BoxView.GetBulkImportSettings(out var clearAll, out var overwrite, out var settings))
return;
int box = BoxView.Box.CurrentBox;
int ctr = SAV.LoadBoxes(Results.Select(z => z.Entity), out var result, box, clearAll, overwrite, noSetb);
int ctr = SAV.LoadBoxes(Results.Select(z => z.Entity), out var result, box, clearAll, overwrite, settings);
if (ctr <= 0)
return;

View File

@ -140,7 +140,7 @@ private void ClickView(object sender, EventArgs e)
WinFormsUtil.Error(c.GetDisplayString(temp, SAV.PKMType));
return;
}
SAV.AdaptPKM(pk);
SAV.AdaptToSaveFile(pk);
PKME_Tabs.PopulateFields(pk, false);
slotSelected = index;
slotColor = SpriteUtil.Spriter.View;
@ -407,11 +407,11 @@ private void UpdateSlotColor(int start)
private void Menu_Import_Click(object sender, EventArgs e)
{
if (!BoxView.GetBulkImportSettings(out var clearAll, out var overwrite, out var noSetb))
if (!BoxView.GetBulkImportSettings(out var clearAll, out var overwrite, out var settings))
return;
int box = BoxView.Box.CurrentBox;
int ctr = SAV.LoadBoxes(Results, out var result, box, clearAll, overwrite, noSetb);
int ctr = SAV.LoadBoxes(Results, out var result, box, clearAll, overwrite, settings);
if (ctr <= 0)
return;