fix changes to save handling
The postfix for an enumerable method is raised when the enumerable is returned, not when it finishes enumerating.
This commit is contained in:
parent
90ca3d6ba1
commit
e16584527c
|
@ -282,7 +282,7 @@ namespace StardewModdingAPI.Framework
|
|||
// apply game patches
|
||||
new GamePatcher(this.Monitor).Apply(
|
||||
new DialogueErrorPatch(this.MonitorForGame, this.Reflection),
|
||||
new SaveGamePatch(onSaving: this.GameInstance.OnSaving, onSaved: this.GameInstance.OnSaved)
|
||||
new SaveGamePatch(onSaving: this.GameInstance.OnSaving)
|
||||
);
|
||||
|
||||
// start game
|
||||
|
|
|
@ -199,7 +199,7 @@ namespace StardewModdingAPI.Framework
|
|||
}
|
||||
|
||||
/// <summary>A callback invoked before <see cref="Game1.newDayAfterFade"/> runs.</summary>
|
||||
protected void OnNewDayAfterFade()
|
||||
private void OnNewDayAfterFade()
|
||||
{
|
||||
this.Events.DayEnding.RaiseEmpty();
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ namespace StardewModdingAPI.Framework
|
|||
}
|
||||
|
||||
/// <summary>A callback invoked after <see cref="SaveGame.Save"/> runs.</summary>
|
||||
internal void OnSaved()
|
||||
private void OnSaved()
|
||||
{
|
||||
// reset flags
|
||||
this.IsBetweenCreateEvents = false;
|
||||
|
@ -419,6 +419,10 @@ namespace StardewModdingAPI.Framework
|
|||
// during enumeration errors). To avoid problems, events are not invoked while a save
|
||||
// is in progress.
|
||||
if (this.IsBetweenCreateEvents || this.IsBetweenSaveEvents)
|
||||
{
|
||||
if (!Context.IsSaving)
|
||||
this.OnSaved();
|
||||
else
|
||||
{
|
||||
this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
|
||||
base.Update(gameTime);
|
||||
|
@ -428,6 +432,7 @@ namespace StardewModdingAPI.Framework
|
|||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*********
|
||||
** Update context
|
||||
|
|
|
@ -16,9 +16,6 @@ namespace StardewModdingAPI.Patches
|
|||
/// <summary>A callback to invoke before <see cref="SaveGame.Save"/> runs.</summary>
|
||||
private static Action OnSaving;
|
||||
|
||||
/// <summary>A callback to invoke before <see cref="SaveGame.Save"/> runs.</summary>
|
||||
private static Action OnSaved;
|
||||
|
||||
|
||||
/*********
|
||||
** Accessors
|
||||
|
@ -32,11 +29,9 @@ namespace StardewModdingAPI.Patches
|
|||
*********/
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="onSaving">A callback to invoke before <see cref="SaveGame.Save"/> runs.</param>
|
||||
/// <param name="onSaved">A callback to invoke after <see cref="SaveGame.Save"/> runs.</param>
|
||||
public SaveGamePatch(Action onSaving, Action onSaved)
|
||||
public SaveGamePatch(Action onSaving)
|
||||
{
|
||||
SaveGamePatch.OnSaving = onSaving;
|
||||
SaveGamePatch.OnSaved = onSaved;
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,10 +41,8 @@ namespace StardewModdingAPI.Patches
|
|||
{
|
||||
MethodInfo method = AccessTools.Method(typeof(SaveGame), nameof(SaveGame.Save));
|
||||
MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(SaveGamePatch.Prefix));
|
||||
MethodInfo postfix = AccessTools.Method(this.GetType(), nameof(SaveGamePatch.Postfix));
|
||||
|
||||
harmony.Patch(method, prefix: new HarmonyMethod(prefix));
|
||||
harmony.Patch(method, postfix: new HarmonyMethod(postfix));
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,13 +58,5 @@ namespace StardewModdingAPI.Patches
|
|||
SaveGamePatch.OnSaving();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The method to call after <see cref="SaveGame.Save"/>.</summary>
|
||||
/// <remarks>This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments.</remarks>
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony.")]
|
||||
private static void Postfix()
|
||||
{
|
||||
SaveGamePatch.OnSaved();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue