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
|
// apply game patches
|
||||||
new GamePatcher(this.Monitor).Apply(
|
new GamePatcher(this.Monitor).Apply(
|
||||||
new DialogueErrorPatch(this.MonitorForGame, this.Reflection),
|
new DialogueErrorPatch(this.MonitorForGame, this.Reflection),
|
||||||
new SaveGamePatch(onSaving: this.GameInstance.OnSaving, onSaved: this.GameInstance.OnSaved)
|
new SaveGamePatch(onSaving: this.GameInstance.OnSaving)
|
||||||
);
|
);
|
||||||
|
|
||||||
// start game
|
// start game
|
||||||
|
|
|
@ -199,7 +199,7 @@ namespace StardewModdingAPI.Framework
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>A callback invoked before <see cref="Game1.newDayAfterFade"/> runs.</summary>
|
/// <summary>A callback invoked before <see cref="Game1.newDayAfterFade"/> runs.</summary>
|
||||||
protected void OnNewDayAfterFade()
|
private void OnNewDayAfterFade()
|
||||||
{
|
{
|
||||||
this.Events.DayEnding.RaiseEmpty();
|
this.Events.DayEnding.RaiseEmpty();
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ namespace StardewModdingAPI.Framework
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>A callback invoked after <see cref="SaveGame.Save"/> runs.</summary>
|
/// <summary>A callback invoked after <see cref="SaveGame.Save"/> runs.</summary>
|
||||||
internal void OnSaved()
|
private void OnSaved()
|
||||||
{
|
{
|
||||||
// reset flags
|
// reset flags
|
||||||
this.IsBetweenCreateEvents = false;
|
this.IsBetweenCreateEvents = false;
|
||||||
|
@ -419,6 +419,10 @@ namespace StardewModdingAPI.Framework
|
||||||
// during enumeration errors). To avoid problems, events are not invoked while a save
|
// during enumeration errors). To avoid problems, events are not invoked while a save
|
||||||
// is in progress.
|
// is in progress.
|
||||||
if (this.IsBetweenCreateEvents || this.IsBetweenSaveEvents)
|
if (this.IsBetweenCreateEvents || this.IsBetweenSaveEvents)
|
||||||
|
{
|
||||||
|
if (!Context.IsSaving)
|
||||||
|
this.OnSaved();
|
||||||
|
else
|
||||||
{
|
{
|
||||||
this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
|
this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
|
@ -428,6 +432,7 @@ namespace StardewModdingAPI.Framework
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
** Update context
|
** Update context
|
||||||
|
|
|
@ -16,9 +16,6 @@ namespace StardewModdingAPI.Patches
|
||||||
/// <summary>A callback to invoke before <see cref="SaveGame.Save"/> runs.</summary>
|
/// <summary>A callback to invoke before <see cref="SaveGame.Save"/> runs.</summary>
|
||||||
private static Action OnSaving;
|
private static Action OnSaving;
|
||||||
|
|
||||||
/// <summary>A callback to invoke before <see cref="SaveGame.Save"/> runs.</summary>
|
|
||||||
private static Action OnSaved;
|
|
||||||
|
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
** Accessors
|
** Accessors
|
||||||
|
@ -32,11 +29,9 @@ namespace StardewModdingAPI.Patches
|
||||||
*********/
|
*********/
|
||||||
/// <summary>Construct an instance.</summary>
|
/// <summary>Construct an instance.</summary>
|
||||||
/// <param name="onSaving">A callback to invoke before <see cref="SaveGame.Save"/> runs.</param>
|
/// <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)
|
||||||
public SaveGamePatch(Action onSaving, Action onSaved)
|
|
||||||
{
|
{
|
||||||
SaveGamePatch.OnSaving = onSaving;
|
SaveGamePatch.OnSaving = onSaving;
|
||||||
SaveGamePatch.OnSaved = onSaved;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,10 +41,8 @@ namespace StardewModdingAPI.Patches
|
||||||
{
|
{
|
||||||
MethodInfo method = AccessTools.Method(typeof(SaveGame), nameof(SaveGame.Save));
|
MethodInfo method = AccessTools.Method(typeof(SaveGame), nameof(SaveGame.Save));
|
||||||
MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(SaveGamePatch.Prefix));
|
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, prefix: new HarmonyMethod(prefix));
|
||||||
harmony.Patch(method, postfix: new HarmonyMethod(postfix));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,13 +58,5 @@ namespace StardewModdingAPI.Patches
|
||||||
SaveGamePatch.OnSaving();
|
SaveGamePatch.OnSaving();
|
||||||
return true;
|
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