Disassociate metadata's SAV reference from clone

Necessary for gen3 manual overrides; the fetched properties for Metadata should refer to the cloned data that it is using, not the original reference.

Closes #3582
This commit is contained in:
Kurt 2022-09-11 09:59:00 -07:00
parent 2bbd767066
commit c5908b2b97
3 changed files with 5 additions and 7 deletions

View file

@ -32,7 +32,7 @@ public abstract class SaveFile : ITrainerInfo, IGameValueLimit, IBoxDetailWallpa
public SaveFile Clone()
{
var sav = CloneInternal();
sav.Metadata = Metadata;
sav.Metadata = Metadata with {SAV = sav};
return sav;
}

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
namespace PKHeX.Core;
@ -6,10 +6,9 @@ namespace PKHeX.Core;
/// <summary>
/// Tracks information about where the <see cref="SAV"/> originated from, and provides logic for saving to a file.
/// </summary>
public sealed class SaveFileMetadata
public sealed record SaveFileMetadata(SaveFile SAV)
{
private readonly SaveFile SAV;
public SaveFileMetadata(SaveFile sav) => SAV = sav;
public SaveFile SAV { private get; init; } = SAV;
/// <summary>
/// Full path where the <see cref="SAV"/> originated from.

View file

@ -738,6 +738,7 @@ public partial class Main : Form
PKME_Tabs.Focus(); // flush any pending changes
StoreLegalSaveGameData(sav);
ParseSettings.InitFromSaveFileData(sav); // physical GB, no longer used in logic
RecentTrainerCache.SetRecentTrainer(sav);
SpriteUtil.Initialize(sav); // refresh sprite generator
dragout.Size = new Size(SpriteUtil.Spriter.Width, SpriteUtil.Spriter.Height);
@ -877,8 +878,6 @@ public partial class Main : Form
private static bool SanityCheckSAV(ref SaveFile sav)
{
ParseSettings.InitFromSaveFileData(sav); // physical GB, no longer used in logic
if (sav.State.Exportable && sav is SAV3 s3)
{
if (ModifierKeys == Keys.Control || s3.IsCorruptPokedexFF())