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:
Jesse Plamondon-Willard 2018-12-03 19:41:47 -05:00
parent 90ca3d6ba1
commit e16584527c
No known key found for this signature in database
GPG Key ID: 7D7C8097B62033CE
3 changed files with 14 additions and 24 deletions

View File

@ -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

View File

@ -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;
@ -420,13 +420,18 @@ namespace StardewModdingAPI.Framework
// is in progress.
if (this.IsBetweenCreateEvents || this.IsBetweenSaveEvents)
{
this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
base.Update(gameTime);
this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed));
if (!Context.IsSaving)
this.OnSaved();
else
{
this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
base.Update(gameTime);
this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_BeforeCreateSave.Raise();
this.Events.Legacy_BeforeCreateSave.Raise();
#endif
return;
return;
}
}
/*********

View File

@ -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();
}
}
}