isaacscript-common 2.0.30 → 2.0.31

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.
@@ -0,0 +1,7 @@
1
+ export declare enum SaveDataKey {
2
+ PERSISTENT = "persistent",
3
+ RUN = "run",
4
+ LEVEL = "level",
5
+ ROOM = "room"
6
+ }
7
+ export declare const RESETTABLE_SAVE_DATA_KEYS: ReadonlySet<SaveDataKey>;
@@ -0,0 +1,11 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Set = ____lualib.Set
3
+ local __TS__New = ____lualib.__TS__New
4
+ local ____exports = {}
5
+ ____exports.SaveDataKey = {}
6
+ ____exports.SaveDataKey.PERSISTENT = "persistent"
7
+ ____exports.SaveDataKey.RUN = "run"
8
+ ____exports.SaveDataKey.LEVEL = "level"
9
+ ____exports.SaveDataKey.ROOM = "room"
10
+ ____exports.RESETTABLE_SAVE_DATA_KEYS = __TS__New(Set, {____exports.SaveDataKey.RUN, ____exports.SaveDataKey.LEVEL, ____exports.SaveDataKey.ROOM})
11
+ return ____exports
@@ -105,3 +105,24 @@ export declare function saveDataManagerSave(): void;
105
105
  * e.g. `l print(g.feature1.foo)`
106
106
  */
107
107
  export declare function saveDataManagerSetGlobal(): void;
108
+ /**
109
+ * The save data manager will automatically reset variables at the appropriate times (i.e. when a
110
+ * player enters a new room). Use this function to explicitly force the save data manager to reset a
111
+ * specific variable group.
112
+ *
113
+ * For example:
114
+ *
115
+ * ```
116
+ * const v = {
117
+ * room: {
118
+ * foo: 123,
119
+ * },
120
+ * };
121
+ *
122
+ * saveDataManager("file1", v);
123
+ *
124
+ * // Then, later on, to explicit reset all of the "room" variables:
125
+ * saveDataManagerReset("file1", "room");
126
+ * ```
127
+ */
128
+ export declare function saveDataManagerReset(key: string, childObjectKey: string): void;
@@ -13,6 +13,7 @@ local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_N
13
13
  local ____main = require("features.saveDataManager.main")
14
14
  local forceSaveDataManagerLoad = ____main.forceSaveDataManagerLoad
15
15
  local forceSaveDataManagerSave = ____main.forceSaveDataManagerSave
16
+ local restoreDefaultSaveData = ____main.restoreDefaultSaveData
16
17
  local ____maps = require("features.saveDataManager.maps")
17
18
  local saveDataConditionalFuncMap = ____maps.saveDataConditionalFuncMap
18
19
  local saveDataDefaultsMap = ____maps.saveDataDefaultsMap
@@ -50,4 +51,16 @@ function ____exports.saveDataManagerSetGlobal(self)
50
51
  g = saveDataMap
51
52
  gd = saveDataDefaultsMap
52
53
  end
54
+ function ____exports.saveDataManagerReset(self, key, childObjectKey)
55
+ errorIfFeaturesNotInitialized(nil, SAVE_DATA_MANAGER_FEATURE_NAME)
56
+ local keyType = type(key)
57
+ if keyType ~= "string" then
58
+ error((("The " .. SAVE_DATA_MANAGER_FEATURE_NAME) .. " requires that keys are strings. You tried to use a key of type: ") .. keyType)
59
+ end
60
+ local saveData = saveDataMap[key]
61
+ if saveData == nil then
62
+ error((("The " .. SAVE_DATA_MANAGER_FEATURE_NAME) .. " is not managing save data for a key of: ") .. key)
63
+ end
64
+ restoreDefaultSaveData(nil, key, saveData, childObjectKey)
65
+ end
53
66
  return ____exports
@@ -1 +1,3 @@
1
- export {};
1
+ import { SaveDataKey } from "../../enums/private/SaveDataKey";
2
+ import { SaveData } from "../../types/private/SaveData";
3
+ export declare function restoreDefaultSaveData(subscriberName: string, saveData: SaveData, saveDataKey: SaveDataKey): void;
@@ -8,8 +8,9 @@ local ____cachedClasses = require("cachedClasses")
8
8
  local game = ____cachedClasses.game
9
9
  local ____ModCallbackCustom = require("enums.ModCallbackCustom")
10
10
  local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
11
- local ____SaveDataKeys = require("enums.private.SaveDataKeys")
12
- local SaveDataKeys = ____SaveDataKeys.SaveDataKeys
11
+ local ____SaveDataKey = require("enums.private.SaveDataKey")
12
+ local RESETTABLE_SAVE_DATA_KEYS = ____SaveDataKey.RESETTABLE_SAVE_DATA_KEYS
13
+ local SaveDataKey = ____SaveDataKey.SaveDataKey
13
14
  local ____SerializationType = require("enums.SerializationType")
14
15
  local SerializationType = ____SerializationType.SerializationType
15
16
  local ____deepCopy = require("functions.deepCopy")
@@ -52,41 +53,41 @@ function preGameExit(self)
52
53
  loadedDataOnThisRun = false
53
54
  end
54
55
  function postNewLevel(self)
55
- restoreDefaults(nil, SaveDataKeys.LEVEL)
56
+ restoreDefaults(nil, SaveDataKey.LEVEL)
56
57
  end
57
58
  function postNewRoomEarly(self)
58
- restoreDefaults(nil, SaveDataKeys.ROOM)
59
+ restoreDefaults(nil, SaveDataKey.ROOM)
59
60
  end
60
61
  function restoreDefaultsAll(self)
61
- restoreDefaults(nil, SaveDataKeys.RUN)
62
- restoreDefaults(nil, SaveDataKeys.LEVEL)
63
- restoreDefaults(nil, SaveDataKeys.ROOM)
62
+ restoreDefaults(nil, SaveDataKey.RUN)
63
+ restoreDefaults(nil, SaveDataKey.LEVEL)
64
+ restoreDefaults(nil, SaveDataKey.ROOM)
64
65
  end
65
- function restoreDefaults(self, childTableName)
66
- if childTableName ~= SaveDataKeys.RUN and childTableName ~= SaveDataKeys.LEVEL and childTableName ~= SaveDataKeys.ROOM then
67
- error("Unknown child table name of: " .. childTableName)
68
- end
66
+ function restoreDefaults(self, saveDataKey)
69
67
  for subscriberName, saveData in pairs(saveDataMap) do
70
- do
71
- local childTable = saveData[childTableName]
72
- if childTable == nil then
73
- goto __continue14
74
- end
75
- local saveDataDefaults = saveDataDefaultsMap[subscriberName]
76
- if saveDataDefaults == nil then
77
- logError("Failed to find the default copy of the save data for subscriber: " .. subscriberName)
78
- goto __continue14
79
- end
80
- local childTableDefaults = saveDataDefaults[childTableName]
81
- if childTableDefaults == nil then
82
- logError(((("Failed to find the default copy of the child table \"" .. childTableName) .. "\" for subscriber \"") .. subscriberName) .. "\". This error usually means that your save data is out of date. You can try purging all of your save data by deleting the following directory: C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Binding of Isaac Rebirth\\data")
83
- goto __continue14
84
- end
85
- local childTableDefaultsCopy = deepCopy(nil, childTableDefaults, SerializationType.NONE, (subscriberName .. " --> ") .. childTableName)
86
- clearAndCopyAllElements(nil, childTable, childTableDefaultsCopy)
87
- end
88
- ::__continue14::
68
+ ____exports.restoreDefaultSaveData(nil, subscriberName, saveData, saveDataKey)
69
+ end
70
+ end
71
+ function ____exports.restoreDefaultSaveData(self, subscriberName, saveData, saveDataKey)
72
+ if not RESETTABLE_SAVE_DATA_KEYS:has(saveDataKey) then
73
+ error("Unknown save data key name of: " .. saveDataKey)
74
+ end
75
+ local childTable = saveData[saveDataKey]
76
+ if childTable == nil then
77
+ return
78
+ end
79
+ local saveDataDefaults = saveDataDefaultsMap[subscriberName]
80
+ if saveDataDefaults == nil then
81
+ logError("Failed to find the default copy of the save data for subscriber: " .. subscriberName)
82
+ return
83
+ end
84
+ local childTableDefaults = saveDataDefaults[saveDataKey]
85
+ if childTableDefaults == nil then
86
+ logError(((("Failed to find the default copy of the child table \"" .. saveDataKey) .. "\" for subscriber \"") .. subscriberName) .. "\". This error usually means that your save data is out of date. You can try purging all of your save data by deleting the following directory: C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Binding of Isaac Rebirth\\data")
87
+ return
89
88
  end
89
+ local childTableDefaultsCopy = deepCopy(nil, childTableDefaults, SerializationType.NONE, (subscriberName .. " --> ") .. saveDataKey)
90
+ clearAndCopyAllElements(nil, childTable, childTableDefaultsCopy)
90
91
  end
91
92
  function clearAndCopyAllElements(self, oldTable, newTable)
92
93
  clearTable(nil, oldTable)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "2.0.30",
3
+ "version": "2.0.31",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,7 +25,7 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "dependencies": {
28
- "isaac-typescript-definitions": "^2.0.47"
28
+ "isaac-typescript-definitions": "^2.0.48"
29
29
  },
30
30
  "devDependencies": {
31
31
  "isaacscript-lint": "^1.0.159",