mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
Use enum instead of nullable bool tristate
This commit is contained in:
parent
4f2b9baede
commit
5dcf2f4dc8
8 changed files with 68 additions and 47 deletions
|
@ -515,7 +515,7 @@ namespace PKHeX.Core
|
|||
return GetFlag(Offsets.DexCaught + ofs, bit & 7);
|
||||
}
|
||||
|
||||
public override void SetStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
|
||||
public override void SetStoredSlot(PKM pkm, int offset, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
|
||||
{
|
||||
// pkm that have never been boxed have yet to save the 'current level' for box indication
|
||||
// set this value at this time
|
||||
|
|
|
@ -181,21 +181,11 @@ namespace PKHeX.Core
|
|||
|
||||
protected override void SetDex(PKM pkm) { /* No Pokedex for this game, do nothing */ }
|
||||
|
||||
public override void SetStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
|
||||
public override void SetStoredSlot(PKM pkm, int offset, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
|
||||
{
|
||||
if (pkm == null) return;
|
||||
if (pkm.GetType() != PKMType)
|
||||
throw new InvalidCastException($"PKM Format needs to be {PKMType} when setting to a Gen{Generation} Save File.");
|
||||
if (trade ?? SetUpdatePKM)
|
||||
SetPKM(pkm);
|
||||
if (dex ?? SetUpdateDex)
|
||||
SetDex(pkm);
|
||||
byte[] data = pkm.EncryptedBoxData;
|
||||
SetData(data, offset);
|
||||
|
||||
BitConverter.GetBytes((ushort)pkm.TID).CopyTo(Data, offset + data.Length + 0);
|
||||
BitConverter.GetBytes((ushort)pkm.SID).CopyTo(Data, offset + data.Length + 2);
|
||||
Edited = true;
|
||||
base.SetStoredSlot(pkm, offset, trade, dex);
|
||||
BitConverter.GetBytes((ushort)pkm.TID).CopyTo(Data, offset + PKX.SIZE_3STORED + 0);
|
||||
BitConverter.GetBytes((ushort)pkm.SID).CopyTo(Data, offset + PKX.SIZE_3STORED + 2);
|
||||
}
|
||||
|
||||
public override string GetString(byte[] data, int offset, int length) => StringConverter3.GetString3(data, offset, length, Japanese);
|
||||
|
|
|
@ -10,8 +10,8 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
public abstract class SaveFile : ITrainerInfo, IGameValueLimit
|
||||
{
|
||||
public static bool SetUpdateDex { protected get; set; } = true;
|
||||
public static bool SetUpdatePKM { protected get; set; } = true;
|
||||
public static PKMImportSetting SetUpdateDex { protected get; set; } = PKMImportSetting.Update;
|
||||
public static PKMImportSetting SetUpdatePKM { protected get; set; } = PKMImportSetting.Update;
|
||||
|
||||
// General Object Properties
|
||||
public byte[] Data;
|
||||
|
@ -586,9 +586,14 @@ namespace PKHeX.Core
|
|||
return GetBoxSlotOffset(box, slot);
|
||||
}
|
||||
|
||||
public void SetBoxSlotAtIndex(PKM pkm, int box, int slot, bool? trade, bool? dex = null) => SetStoredSlot(pkm, GetBoxSlotOffset(box, slot), trade, dex);
|
||||
public void SetBoxSlotAtIndex(PKM pkm, int index, bool? trade, bool? dex = null) => SetStoredSlot(pkm, GetBoxSlotOffset(index), trade, dex);
|
||||
public void SetPartySlotAtIndex(PKM pkm, int index, bool? trade = null, bool? dex = null) => SetPartySlot(pkm, GetPartyOffset(index), trade, dex);
|
||||
public void SetBoxSlotAtIndex(PKM pkm, int box, int slot, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
|
||||
=> SetStoredSlot(pkm, GetBoxSlotOffset(box, slot), trade, dex);
|
||||
|
||||
public void SetBoxSlotAtIndex(PKM pkm, int index, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
|
||||
=> SetStoredSlot(pkm, GetBoxSlotOffset(index), trade, dex);
|
||||
|
||||
public void SetPartySlotAtIndex(PKM pkm, int index, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
|
||||
=> SetPartySlot(pkm, GetPartyOffset(index), trade, dex);
|
||||
|
||||
public virtual PKM GetPartySlot(int offset) => GetPKM(DecryptPKM(GetData(offset, SIZE_PARTY)));
|
||||
|
||||
|
@ -597,15 +602,12 @@ namespace PKHeX.Core
|
|||
return GetPKM(DecryptPKM(GetData(offset, SIZE_STORED)));
|
||||
}
|
||||
|
||||
public void SetPartySlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
|
||||
public void SetPartySlot(PKM pkm, int offset, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
|
||||
{
|
||||
if (pkm == null) return;
|
||||
if (pkm.GetType() != PKMType)
|
||||
throw new ArgumentException($"PKM Format needs to be {PKMType} when setting to this Save File.");
|
||||
if (trade ?? SetUpdatePKM)
|
||||
SetPKM(pkm);
|
||||
if (dex ?? SetUpdateDex)
|
||||
SetDex(pkm);
|
||||
UpdatePKM(pkm, trade, dex);
|
||||
SetPartyValues(pkm, isParty: true);
|
||||
|
||||
int i = GetPartyIndex(offset);
|
||||
|
@ -627,6 +629,28 @@ namespace PKHeX.Core
|
|||
Edited = true;
|
||||
}
|
||||
|
||||
protected void UpdatePKM(PKM pkm, PKMImportSetting trade, PKMImportSetting dex)
|
||||
{
|
||||
if (GetTradeUpdateSetting(trade))
|
||||
SetPKM(pkm);
|
||||
if (GetDexUpdateSetting(dex))
|
||||
SetDex(pkm);
|
||||
}
|
||||
|
||||
private static bool GetTradeUpdateSetting(PKMImportSetting trade = PKMImportSetting.UseDefault)
|
||||
{
|
||||
if (trade == PKMImportSetting.UseDefault)
|
||||
trade = SetUpdatePKM;
|
||||
return trade == PKMImportSetting.Update;
|
||||
}
|
||||
|
||||
private static bool GetDexUpdateSetting(PKMImportSetting trade = PKMImportSetting.UseDefault)
|
||||
{
|
||||
if (trade == PKMImportSetting.UseDefault)
|
||||
trade = SetUpdateDex;
|
||||
return trade == PKMImportSetting.Update;
|
||||
}
|
||||
|
||||
private int GetPartyIndex(int offset)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
|
@ -637,15 +661,12 @@ namespace PKHeX.Core
|
|||
return -1;
|
||||
}
|
||||
|
||||
public virtual void SetStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
|
||||
public virtual void SetStoredSlot(PKM pkm, int offset, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
|
||||
{
|
||||
if (pkm == null) return;
|
||||
if (pkm.GetType() != PKMType)
|
||||
throw new ArgumentException($"PKM Format needs to be {PKMType} when setting to this Save File.");
|
||||
if (trade ?? SetUpdatePKM)
|
||||
SetPKM(pkm);
|
||||
if (dex ?? SetUpdateDex)
|
||||
SetDex(pkm);
|
||||
UpdatePKM(pkm, trade, dex);
|
||||
SetPartyValues(pkm, isParty: false);
|
||||
SetData(pkm.EncryptedBoxData, offset);
|
||||
Edited = true;
|
||||
|
@ -662,7 +683,7 @@ namespace PKHeX.Core
|
|||
int slotFrom = GetPartyOffset(i);
|
||||
SetData(GetData(slotFrom, SIZE_PARTY), slotTo);
|
||||
}
|
||||
SetStoredSlot(BlankPKM, GetPartyOffset(5), false, false);
|
||||
SetStoredSlot(BlankPKM, GetPartyOffset(5), PKMImportSetting.Skip, PKMImportSetting.Skip);
|
||||
PartyCount--;
|
||||
}
|
||||
|
||||
|
@ -784,7 +805,7 @@ namespace PKHeX.Core
|
|||
var pk = GetStoredSlot(ofs);
|
||||
action(pk);
|
||||
++modified;
|
||||
SetStoredSlot(pk, ofs, false, false);
|
||||
SetStoredSlot(pk, ofs, PKMImportSetting.Skip, PKMImportSetting.Skip);
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
|
|
9
PKHeX.Core/Saves/Storage/PKMImportSetting.cs
Normal file
9
PKHeX.Core/Saves/Storage/PKMImportSetting.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
public enum PKMImportSetting
|
||||
{
|
||||
UseDefault,
|
||||
Update,
|
||||
Skip,
|
||||
}
|
||||
}
|
|
@ -90,7 +90,7 @@ namespace PKHeX.Core
|
|||
/// <param name="noSetb">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, bool? noSetb = null, bool all = false)
|
||||
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)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path))
|
||||
{ result = MsgSaveBoxExportPathInvalid; return -1; }
|
||||
|
@ -111,7 +111,7 @@ namespace PKHeX.Core
|
|||
/// <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>
|
||||
/// <returns>Count of files imported.</returns>
|
||||
public static int LoadBoxes(this SaveFile SAV, IEnumerable<string> filepaths, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, bool? noSetb = null)
|
||||
public static int LoadBoxes(this SaveFile SAV, IEnumerable<string> filepaths, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
|
||||
{
|
||||
var pks = GetPossiblePKMsFromPaths(SAV, filepaths);
|
||||
return SAV.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb);
|
||||
|
@ -128,7 +128,7 @@ namespace PKHeX.Core
|
|||
/// <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>
|
||||
/// <returns>Count of files imported.</returns>
|
||||
public static int LoadBoxes(this SaveFile SAV, IEnumerable<IEncounterable> encounters, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, bool? noSetb = null)
|
||||
public static int LoadBoxes(this SaveFile SAV, IEnumerable<IEncounterable> encounters, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
|
||||
{
|
||||
var pks = encounters.Select(z => z.ConvertToPKM(SAV));
|
||||
return SAV.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb);
|
||||
|
@ -145,7 +145,7 @@ namespace PKHeX.Core
|
|||
/// <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>
|
||||
/// <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, bool? noSetb = null)
|
||||
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)
|
||||
{
|
||||
if (!SAV.HasBox)
|
||||
{ result = MsgSaveBoxFailNone; return -1; }
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace PKHeX.Core
|
|||
/// <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>
|
||||
/// <returns>Count of injected <see cref="PKM"/>.</returns>
|
||||
public static int ImportPKMs(this SaveFile SAV, IEnumerable<PKM> compat, bool overwrite = false, int boxStart = 0, bool? noSetb = null)
|
||||
public static int ImportPKMs(this SaveFile SAV, IEnumerable<PKM> compat, bool overwrite = false, int boxStart = 0, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
|
||||
{
|
||||
int startCount = boxStart * SAV.BoxSlotCount;
|
||||
int maxCount = SAV.SlotCount;
|
||||
|
|
|
@ -695,9 +695,9 @@ namespace PKHeX.WinForms.Controls
|
|||
}
|
||||
|
||||
// File I/O
|
||||
public bool GetBulkImportSettings(out bool clearAll, out bool overwrite, out bool? noSetb)
|
||||
public bool GetBulkImportSettings(out bool clearAll, out bool overwrite, out PKMImportSetting noSetb)
|
||||
{
|
||||
clearAll = false; noSetb = false; overwrite = false;
|
||||
clearAll = false; noSetb = PKMImportSetting.UseDefault; overwrite = false;
|
||||
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, MsgSaveBoxImportClear, MsgSaveBoxImportClearNo);
|
||||
if (dr == DialogResult.Cancel)
|
||||
return false;
|
||||
|
@ -709,7 +709,7 @@ namespace PKHeX.WinForms.Controls
|
|||
|
||||
private static bool IsFolderPath(out string path)
|
||||
{
|
||||
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
||||
var fbd = new FolderBrowserDialog();
|
||||
var result = fbd.ShowDialog() == DialogResult.OK;
|
||||
path = fbd.SelectedPath;
|
||||
return result;
|
||||
|
@ -785,7 +785,7 @@ namespace PKHeX.WinForms.Controls
|
|||
return false;
|
||||
}
|
||||
|
||||
bool? noSetb = GetPKMSetOverride(ModifyPKM);
|
||||
var noSetb = GetPKMSetOverride(ModifyPKM);
|
||||
PKM[] data = b.BattlePKMs;
|
||||
int offset = SAV.GetBoxOffset(Box.CurrentBox);
|
||||
int slotSkipped = 0;
|
||||
|
@ -1121,7 +1121,7 @@ namespace PKHeX.WinForms.Controls
|
|||
ReloadSlots();
|
||||
}
|
||||
|
||||
private static bool? GetPKMSetOverride(bool currentSetting)
|
||||
private static PKMImportSetting GetPKMSetOverride(bool currentSetting)
|
||||
{
|
||||
var yn = currentSetting ? MsgYes : MsgNo;
|
||||
DialogResult noSet = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel,
|
||||
|
@ -1131,9 +1131,9 @@ namespace PKHeX.WinForms.Controls
|
|||
string.Format(MsgSaveBoxImportModifyCurrent, yn));
|
||||
switch (noSet)
|
||||
{
|
||||
case DialogResult.Yes: return true;
|
||||
case DialogResult.No: return false;
|
||||
default: return null;
|
||||
case DialogResult.Yes: return PKMImportSetting.Update;
|
||||
case DialogResult.No: return PKMImportSetting.Skip;
|
||||
default: return PKMImportSetting.UseDefault;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -428,8 +428,9 @@ namespace PKHeX.WinForms
|
|||
PKME_Tabs.Unicode = Unicode = settings.Unicode;
|
||||
PKME_Tabs.UpdateUnicode(GenderSymbols);
|
||||
PKX.AllowShinySprite = settings.ShinySprites;
|
||||
SaveFile.SetUpdateDex = settings.SetUpdateDex;
|
||||
SaveFile.SetUpdatePKM = C_SAV.ModifyPKM = PKME_Tabs.ModifyPKM = settings.SetUpdatePKM;
|
||||
SaveFile.SetUpdateDex = settings.SetUpdateDex ? PKMImportSetting.Update : PKMImportSetting.Skip;
|
||||
SaveFile.SetUpdatePKM = settings.SetUpdatePKM ? PKMImportSetting.Update : PKMImportSetting.Skip;
|
||||
C_SAV.ModifyPKM = PKME_Tabs.ModifyPKM = settings.SetUpdatePKM;
|
||||
CommonEdits.ShowdownSetIVMarkings = settings.ApplyMarkings;
|
||||
C_SAV.FlagIllegal = settings.FlagIllegal;
|
||||
C_SAV.M.GlowHover = settings.HoverSlotGlowEdges;
|
||||
|
|
Loading…
Reference in a new issue