allow Read/WriteSaveFile as soon as the save is loaded
This commit is contained in:
parent
7294cb3cc5
commit
4b325f61b3
|
@ -4,6 +4,9 @@
|
|||
* Added `world_clear` console command to remove spawned or placed entities.
|
||||
* Tweaked installer to reduce antivirus false positives.
|
||||
|
||||
* For modders:
|
||||
* You can now use `ReadSaveData` or `WriteSaveData` immediately after the save is loaded, before the in-game world is initialised.
|
||||
|
||||
## 2.9.3
|
||||
* For players:
|
||||
* Fixed errors hovering items in some cases with SMAPI 2.9.2.
|
||||
|
|
|
@ -77,9 +77,9 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
|||
/// <exception cref="InvalidOperationException">The player hasn't loaded a save file yet or isn't the main player.</exception>
|
||||
public TModel ReadSaveData<TModel>(string key) where TModel : class
|
||||
{
|
||||
if (!Context.IsSaveLoaded)
|
||||
if (!Game1.hasLoadedGame)
|
||||
throw new InvalidOperationException($"Can't use {nameof(IMod.Helper)}.{nameof(IModHelper.Data)}.{nameof(this.ReadSaveData)} when a save file isn't loaded.");
|
||||
if (!Context.IsMainPlayer)
|
||||
if (!Game1.IsMasterGame)
|
||||
throw new InvalidOperationException($"Can't use {nameof(IMod.Helper)}.{nameof(IModHelper.Data)}.{nameof(this.ReadSaveData)} because this isn't the main player. (Save files are stored on the main player's computer.)");
|
||||
|
||||
return Game1.CustomData.TryGetValue(this.GetSaveFileKey(key), out string value)
|
||||
|
@ -94,9 +94,9 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
|||
/// <exception cref="InvalidOperationException">The player hasn't loaded a save file yet or isn't the main player.</exception>
|
||||
public void WriteSaveData<TModel>(string key, TModel data) where TModel : class
|
||||
{
|
||||
if (!Context.IsSaveLoaded)
|
||||
if (!Game1.hasLoadedGame)
|
||||
throw new InvalidOperationException($"Can't use {nameof(IMod.Helper)}.{nameof(IModHelper.Data)}.{nameof(this.WriteSaveData)} when a save file isn't loaded.");
|
||||
if (!Context.IsMainPlayer)
|
||||
if (!Game1.IsMasterGame)
|
||||
throw new InvalidOperationException($"Can't use {nameof(IMod.Helper)}.{nameof(IModHelper.Data)}.{nameof(this.ReadSaveData)} because this isn't the main player. (Save files are stored on the main player's computer.)");
|
||||
|
||||
string internalKey = this.GetSaveFileKey(key);
|
||||
|
|
Loading…
Reference in New Issue