isaacscript-common 1.2.7 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,12 +50,17 @@ import { SaveData } from "../../types/SaveData";
50
50
  * }
51
51
  * ```
52
52
  *
53
- * - Save data is loaded from disk in the MC_POST_PLAYER_INIT callback
54
- * (i.e. the first callback that can possibly run).
53
+ * - Save data is loaded from disk in the MC_POST_PLAYER_INIT callback (i.e. the first callback that
54
+ * can possibly run).
55
55
  * - Save data is recorded to disk in the MC_PRE_GAME_EXIT callback.
56
56
  *
57
57
  * Note that before using the save data manager, you must call the [[`upgradeMod`]] function.
58
58
  *
59
+ * If you want the save data manager to load data before the MC_POST_PLAYER_INIT callback (i.e. in
60
+ * the main menu), then you should explicitly call the [[`saveDataManagerLoad`]] function. (The save
61
+ * data manager cannot do this on its own because it cannot know when your mod features are finished
62
+ * initializing.)
63
+ *
59
64
  * Finally, some features may have variables that need to be automatically reset per run/level, but
60
65
  * not saved to disk on game exit. (For example, if they contain functions or other non-serializable
61
66
  * data.) For these cases, set a special key of "dontSave" alongside "run", "level", and so forth.
@@ -65,8 +70,8 @@ import { SaveData } from "../../types/SaveData";
65
70
  * @param saveData An object that corresponds to the `SaveData` interface. The object is
66
71
  * conventionally called "v" for brevity (which is short for "local variables").
67
72
  * @param conditionalFunc An optional function to run upon saving this key to disk. If the function
68
- * is false, the key will not be written to disk. This allows mod features to avoid cluttering the
69
- * "save#.dat" file with unnecessary keys.
73
+ * returns false, the key will not be written to disk. This allows mod features to avoid cluttering
74
+ * the "save#.dat" file with unnecessary keys.
70
75
  */
71
76
  export declare function saveDataManager(key: string, saveData: SaveData, conditionalFunc?: () => boolean): void;
72
77
  /**
@@ -75,6 +80,14 @@ export declare function saveDataManager(key: string, saveData: SaveData, conditi
75
80
  * of its variables to disk immediately.
76
81
  */
77
82
  export declare function saveDataManagerSave(): void;
83
+ /**
84
+ * The save data manager will automatically load variables from disk at the appropriate times (i.e.
85
+ * when a new run is started). Use this function to explicitly force the save data manager to load
86
+ * all of its variables from disk immediately.
87
+ *
88
+ * Note that doing this will overwrite current data, which can potentially result in lost state.
89
+ */
90
+ export declare function saveDataManagerLoad(): void;
78
91
  /**
79
92
  * Sets the global variable of "g" equal to all of the save data variables for this mod.
80
93
  * Sets the global variable of "gd" equal to all of the save data default variables for this mod.
@@ -10,6 +10,7 @@ local deepCopy = ____deepCopy.deepCopy
10
10
  local SerializationType = ____deepCopy.SerializationType
11
11
  local ____main = require("features.saveDataManager.main")
12
12
  local FEATURE_NAME = ____main.FEATURE_NAME
13
+ local forceSaveDataManagerLoad = ____main.forceSaveDataManagerLoad
13
14
  local forceSaveDataManagerSave = ____main.forceSaveDataManagerSave
14
15
  local isSaveDataManagerInitialized = ____main.isSaveDataManagerInitialized
15
16
  local ____maps = require("features.saveDataManager.maps")
@@ -48,6 +49,13 @@ function ____exports.saveDataManagerSave(self)
48
49
  end
49
50
  forceSaveDataManagerSave(nil)
50
51
  end
52
+ function ____exports.saveDataManagerLoad(self)
53
+ if not isSaveDataManagerInitialized(nil) then
54
+ local msg = getUpgradeErrorMsg(nil, FEATURE_NAME)
55
+ error(msg)
56
+ end
57
+ forceSaveDataManagerLoad(nil)
58
+ end
51
59
  function ____exports.saveDataManagerSetGlobal(self)
52
60
  g = saveDataMap
53
61
  gd = saveDataDefaultsMap
@@ -109,4 +109,10 @@ function ____exports.forceSaveDataManagerSave(self)
109
109
  end
110
110
  saveToDisk(nil, mod, saveDataMap, saveDataConditionalFuncMap)
111
111
  end
112
+ function ____exports.forceSaveDataManagerLoad(self)
113
+ if mod == nil then
114
+ return
115
+ end
116
+ loadFromDisk(nil, mod, saveDataMap)
117
+ end
112
118
  return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@zamiell/typescript-to-lua": "^1.4.0",
29
- "isaac-typescript-definitions": "^1.0.335",
29
+ "isaac-typescript-definitions": "^1.0.336",
30
30
  "isaacscript-lint": "^1.0.79",
31
31
  "isaacscript-tsconfig": "^1.1.8",
32
32
  "typedoc": "^0.22.11",