isaacscript-common 20.6.0 → 20.7.0

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.
package/dist/index.d.ts CHANGED
@@ -7971,6 +7971,9 @@ export declare function isTransformationFlying(playerForm: PlayerForm): boolean;
7971
7971
  /** For `PickupVariant.TRINKET` (350). */
7972
7972
  export declare function isTrinket(pickup: EntityPickup): pickup is EntityPickupTrinket;
7973
7973
 
7974
+ /** Helper function to check if a given table is a class table created by TypeScriptToLua. */
7975
+ export declare function isTSTLClass(object: unknown): object is TSTLClass;
7976
+
7974
7977
  /**
7975
7978
  * Helper function to determine if a given object is a TypeScriptToLua `Map`.
7976
7979
  *
@@ -7991,9 +7994,6 @@ export declare function isTSTLSet(object: unknown): object is Set<AnyNotNil>;
7991
7994
 
7992
7995
  export declare function isUserdata(variable: unknown): variable is LuaUserdata;
7993
7996
 
7994
- /** TypeScriptToLua classes are Lua tables that have a metatable with a certain amount of keys. */
7995
- export declare function isUserDefinedTSTLClass(object: unknown): object is TSTLClass;
7996
-
7997
7997
  export declare function isValidCollectibleType(collectibleType: CollectibleType): boolean;
7998
7998
 
7999
7999
  /**
@@ -8484,10 +8484,12 @@ export declare function logSounds(): void;
8484
8484
 
8485
8485
  /**
8486
8486
  * Helper function for logging every key and value of a Lua table. This is a deep log; the function
8487
- * will recursively call itself if it counters a table within a table.
8487
+ * will recursively call itself if it encounters a table within a table.
8488
8488
  *
8489
8489
  * This function will only work on tables that have string keys (because it logs the keys in order,
8490
8490
  * instead of randomly). It will throw a run-time error if it encounters a non-string key.
8491
+ *
8492
+ * In order to prevent infinite recursion, this function will not log deeper than 10 nested tables.
8491
8493
  */
8492
8494
  export declare function logTable(luaTable: unknown, parentTables?: number): void;
8493
8495
 
@@ -11386,29 +11388,12 @@ declare class ModdedElementSets extends Feature {
11386
11388
  * mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
11387
11389
  * that automatically subscribe to callbacks.
11388
11390
  *
11389
- * If your feature has variables that are managed by the save data manager, put them as a `v` class
11390
- * member and they will automatically be registered with the save data manager when the class is
11391
- * instantiated.
11392
- *
11393
- * For example:
11394
- *
11395
- * ```ts
11396
- * export class MyFeature extends ModFeature {
11397
- * v = {
11398
- * run: {
11399
- * foo: 123,
11400
- * }
11401
- * }
11402
- *
11403
- * @Callback(ModCallback.POST_GAME_STARTED)
11404
- * postGameStarted(isContinued: boolean): void {
11405
- * Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
11406
- * }
11407
- * }
11408
- * ```
11391
+ * When instantiating a mod feature class, you must pass your upgraded mod as the first argument to
11392
+ * the constructor.
11409
11393
  *
11410
- * When instantiating a feature class, you must pass your upgraded mod as the first argument to the
11411
- * constructor.
11394
+ * If your feature has variables that are managed by the save data manager, you need to explicitly
11395
+ * register them with the save data manager yourself in your class constructor. (It can't be
11396
+ * automatically done because parent classes don't have access to child class properties.)
11412
11397
  *
11413
11398
  * In almost all cases, you will want the callback functions to be immediately subscribed after
11414
11399
  * instantiating the class. However, if this is not the case, you can pass `false` as the optional
@@ -11627,7 +11612,7 @@ export declare function newPickingUpItem(): PickingUpItem;
11627
11612
  export declare function newPlayerHealth(): PlayerHealth;
11628
11613
 
11629
11614
  /**
11630
- * Helper function to initialize an RNG object using Blade's recommended shift index.
11615
+ * Helper function to initialize a new RNG object using Blade's recommended shift index.
11631
11616
  *
11632
11617
  * @param seed The seed to initialize it with. Default is `getRandomSeed()`.
11633
11618
  */
@@ -13533,7 +13518,8 @@ declare class SaveDataManager extends Feature {
13533
13518
  *
13534
13519
  * @param key The name of the file or feature that is submitting data to be managed by the save
13535
13520
  * data manager. The save data manager will throw an error if the key is already
13536
- * registered.
13521
+ * registered. Note that you can also pass a TSTL class instead of a string and the
13522
+ * save data manager will use the name of the class as the key.
13537
13523
  * @param v An object that corresponds to the `SaveData` interface. The object is conventionally
13538
13524
  * called "v" for brevity. ("v" is short for "local variables").
13539
13525
  * @param conditionalFunc Optional. A function to run to check if this save data should be written
@@ -13546,9 +13532,9 @@ declare class SaveDataManager extends Feature {
13546
13532
  * data. (Specifying `false` will allow you to use non-serializable objects
13547
13533
  * in your save data, such as `EntityPtr`.
13548
13534
  */
13549
- saveDataManager<Persistent, Run, Level>(key: string, // This is the overload for the standard case with serializable data.
13535
+ saveDataManager<Persistent, Run, Level>(key: unknown, // This is the overload for the standard case with serializable data.
13550
13536
  v: SaveData<Persistent, Run, Level>, conditionalFunc?: () => boolean): void;
13551
- saveDataManager(key: string, // This is the overload for the case when saving data is disabled.
13537
+ saveDataManager(key: unknown, // This is the overload for the case when saving data is disabled.
13552
13538
  v: SaveData, conditionalFunc: false): void;
13553
13539
  /**
13554
13540
  * Recursively traverses an object, collecting all of the class constructors that it encounters.
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 20.6.0
3
+ isaacscript-common 20.7.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -20541,6 +20541,10 @@ function ____exports.isDefaultMap(self, object)
20541
20541
  local className = ____exports.getTSTLClassName(nil, object)
20542
20542
  return className == "DefaultMap"
20543
20543
  end
20544
+ function ____exports.isTSTLClass(self, object)
20545
+ local tstlClassName = ____exports.getTSTLClassName(nil, object)
20546
+ return tstlClassName ~= nil
20547
+ end
20544
20548
  function ____exports.isTSTLMap(self, object)
20545
20549
  local className = ____exports.getTSTLClassName(nil, object)
20546
20550
  return className == "Map"
@@ -20549,10 +20553,6 @@ function ____exports.isTSTLSet(self, object)
20549
20553
  local className = ____exports.getTSTLClassName(nil, object)
20550
20554
  return className == "Set"
20551
20555
  end
20552
- function ____exports.isUserDefinedTSTLClass(self, object)
20553
- local tstlClassName = ____exports.getTSTLClassName(nil, object)
20554
- return tstlClassName ~= nil
20555
- end
20556
20556
  function ____exports.newTSTLClass(self, oldClass)
20557
20557
  local constructor = ____exports.getTSTLClassConstructor(nil, oldClass)
20558
20558
  if constructor == nil then
@@ -28091,6 +28091,8 @@ function ____exports.logTable(self, luaTable, parentTables)
28091
28091
  end
28092
28092
  if parentTables == 0 then
28093
28093
  log(nil, "Printing out a Lua table:")
28094
+ elseif parentTables > 10 then
28095
+ return
28094
28096
  end
28095
28097
  local numSpaces = (parentTables + 1) * 2
28096
28098
  local indentation = string.rep(
@@ -36832,6 +36834,7 @@ local ____stage = require("src.functions.stage")
36832
36834
  local onFirstFloor = ____stage.onFirstFloor
36833
36835
  local ____tstlClass = require("src.functions.tstlClass")
36834
36836
  local getTSTLClassName = ____tstlClass.getTSTLClassName
36837
+ local isTSTLClass = ____tstlClass.isTSTLClass
36835
36838
  local ____types = require("src.functions.types")
36836
36839
  local isString = ____types.isString
36837
36840
  local isTable = ____types.isTable
@@ -36909,8 +36912,15 @@ function SaveDataManager.prototype.____constructor(self, mod)
36909
36912
  self.mod = mod
36910
36913
  end
36911
36914
  function SaveDataManager.prototype.saveDataManager(self, key, v, conditionalFunc)
36915
+ if isTSTLClass(nil, key) then
36916
+ local className = getTSTLClassName(nil, key)
36917
+ if className == nil then
36918
+ error("Failed to get the class name for the submitted class (as part of the \"key\" parameter) when registering new data with the save data manager.")
36919
+ end
36920
+ key = className
36921
+ end
36912
36922
  if not isString(nil, key) then
36913
- error("The save data manager requires that keys are strings. You tried to use a key of type: " .. __TS__TypeOf(key))
36923
+ error("The save data manager requires that keys are strings or TSTL classes. You tried to use a key of type: " .. __TS__TypeOf(key))
36914
36924
  end
36915
36925
  if self.saveDataMap[key] ~= nil then
36916
36926
  error("The save data manager is already managing save data for a key of: " .. key)
@@ -49795,7 +49805,7 @@ local __TS__Class = ____lualib.__TS__Class
49795
49805
  local Map = ____lualib.Map
49796
49806
  local __TS__New = ____lualib.__TS__New
49797
49807
  local ____exports = {}
49798
- local initDecoratedCallbacks, addCallback, removeCallback, initSaveDataManager, WRAPPED_CALLBACK_METHODS_KEY, WRAPPED_CUSTOM_CALLBACK_METHODS_KEY
49808
+ local initDecoratedCallbacks, addCallback, removeCallback, WRAPPED_CALLBACK_METHODS_KEY, WRAPPED_CUSTOM_CALLBACK_METHODS_KEY
49799
49809
  local ____array = require("src.functions.array")
49800
49810
  local isArray = ____array.isArray
49801
49811
  local ____tstlClass = require("src.functions.tstlClass")
@@ -49804,7 +49814,6 @@ local getTSTLClassName = ____tstlClass.getTSTLClassName
49804
49814
  local ____types = require("src.functions.types")
49805
49815
  local isFunction = ____types.isFunction
49806
49816
  local isNumber = ____types.isNumber
49807
- local isTable = ____types.isTable
49808
49817
  function initDecoratedCallbacks(self, modFeature, constructor, tstlClassName, vanilla, init)
49809
49818
  local modFeatureConstructor = constructor
49810
49819
  local callbackTuplesKey = vanilla and ____exports.MOD_FEATURE_CALLBACKS_KEY or ____exports.MOD_FEATURE_CUSTOM_CALLBACKS_KEY
@@ -49916,30 +49925,6 @@ function removeCallback(self, modFeatureConstructor, mod, modCallback, vanilla)
49916
49925
  mod:RemoveCallbackCustom(modCallback, wrappedCallback)
49917
49926
  end
49918
49927
  end
49919
- function initSaveDataManager(self, modFeature, tstlClassName, init)
49920
- local ____modFeature_0 = modFeature
49921
- local v = ____modFeature_0.v
49922
- if v == nil then
49923
- return
49924
- end
49925
- if not isTable(nil, v) then
49926
- error("Failed to initialize a mod feature class due to having a \"v\" property that is not an object. (The \"v\" property is supposed to be an object that holds the variables for the class, managed by the save data manager.)")
49927
- end
49928
- local mod = modFeature.mod
49929
- local saveDataManagerMethodName = init and "saveDataManager" or "saveDataManagerRemove"
49930
- local saveDataManagerMethod = mod[saveDataManagerMethodName]
49931
- if saveDataManagerMethod == nil then
49932
- error("Failed to initialize a mod feature class due to having a \"v\" object and not having the save data manager initialized. You must pass \"ISCFeature.SAVE_DATA_MANAGER\" to the \"upgradeMod\" function.")
49933
- end
49934
- if type(saveDataManagerMethod) ~= "function" then
49935
- error(("The \"" .. saveDataManagerMethodName) .. "\" property of the \"ModUpgraded\" object was not a function.")
49936
- end
49937
- if init then
49938
- saveDataManagerMethod(nil, tstlClassName, v)
49939
- else
49940
- saveDataManagerMethod(nil, tstlClassName)
49941
- end
49942
- end
49943
49928
  ____exports.MOD_FEATURE_CALLBACKS_KEY = "__callbacks"
49944
49929
  ____exports.MOD_FEATURE_CUSTOM_CALLBACKS_KEY = "__customCallbacks"
49945
49930
  WRAPPED_CALLBACK_METHODS_KEY = "__wrappedCallbackMethods"
@@ -49990,7 +49975,6 @@ function ModFeature.prototype.init(self, init)
49990
49975
  false,
49991
49976
  init
49992
49977
  )
49993
- initSaveDataManager(nil, self, tstlClassName, init)
49994
49978
  end
49995
49979
  function ModFeature.prototype.uninit(self)
49996
49980
  self:init(false)
@@ -8,29 +8,12 @@ export declare const MOD_FEATURE_CUSTOM_CALLBACKS_KEY = "__customCallbacks";
8
8
  * mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
9
9
  * that automatically subscribe to callbacks.
10
10
  *
11
- * If your feature has variables that are managed by the save data manager, put them as a `v` class
12
- * member and they will automatically be registered with the save data manager when the class is
13
- * instantiated.
11
+ * When instantiating a mod feature class, you must pass your upgraded mod as the first argument to
12
+ * the constructor.
14
13
  *
15
- * For example:
16
- *
17
- * ```ts
18
- * export class MyFeature extends ModFeature {
19
- * v = {
20
- * run: {
21
- * foo: 123,
22
- * }
23
- * }
24
- *
25
- * @Callback(ModCallback.POST_GAME_STARTED)
26
- * postGameStarted(isContinued: boolean): void {
27
- * Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
28
- * }
29
- * }
30
- * ```
31
- *
32
- * When instantiating a feature class, you must pass your upgraded mod as the first argument to the
33
- * constructor.
14
+ * If your feature has variables that are managed by the save data manager, you need to explicitly
15
+ * register them with the save data manager yourself in your class constructor. (It can't be
16
+ * automatically done because parent classes don't have access to child class properties.)
34
17
  *
35
18
  * In almost all cases, you will want the callback functions to be immediately subscribed after
36
19
  * instantiating the class. However, if this is not the case, you can pass `false` as the optional
@@ -1 +1 @@
1
- {"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AA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;OAwBG;IACH,SAAS,CAAC,yBAAyB,EAC/B,CAAC,CAAC,CAAC,SAAS,OAAO,EACjB,OAAO,EAAE,CAAC,EACV,WAAW,EAAE,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,iBAAiB,EAC7D,GAAG,YAAY,EAAE,OAAO,EAAE,KACvB,OAAO,CAAC,GACb,IAAI,CAAQ;IAEhB;;;;;;OAMG;IACI,WAAW,UAAS;gBAEf,GAAG,EAAE,eAAe,EAAE,IAAI,UAAO;IAQ7C;;;;;OAKG;IACI,IAAI,CAAC,IAAI,UAAO,GAAG,IAAI;IAoB9B;;;;;;OAMG;IACI,MAAM,IAAI,IAAI;CAGtB"}
@@ -3,7 +3,7 @@ local __TS__Class = ____lualib.__TS__Class
3
3
  local Map = ____lualib.Map
4
4
  local __TS__New = ____lualib.__TS__New
5
5
  local ____exports = {}
6
- local initDecoratedCallbacks, addCallback, removeCallback, initSaveDataManager, WRAPPED_CALLBACK_METHODS_KEY, WRAPPED_CUSTOM_CALLBACK_METHODS_KEY
6
+ local initDecoratedCallbacks, addCallback, removeCallback, WRAPPED_CALLBACK_METHODS_KEY, WRAPPED_CUSTOM_CALLBACK_METHODS_KEY
7
7
  local ____array = require("src.functions.array")
8
8
  local isArray = ____array.isArray
9
9
  local ____tstlClass = require("src.functions.tstlClass")
@@ -12,7 +12,6 @@ local getTSTLClassName = ____tstlClass.getTSTLClassName
12
12
  local ____types = require("src.functions.types")
13
13
  local isFunction = ____types.isFunction
14
14
  local isNumber = ____types.isNumber
15
- local isTable = ____types.isTable
16
15
  function initDecoratedCallbacks(self, modFeature, constructor, tstlClassName, vanilla, init)
17
16
  local modFeatureConstructor = constructor
18
17
  local callbackTuplesKey = vanilla and ____exports.MOD_FEATURE_CALLBACKS_KEY or ____exports.MOD_FEATURE_CUSTOM_CALLBACKS_KEY
@@ -124,30 +123,6 @@ function removeCallback(self, modFeatureConstructor, mod, modCallback, vanilla)
124
123
  mod:RemoveCallbackCustom(modCallback, wrappedCallback)
125
124
  end
126
125
  end
127
- function initSaveDataManager(self, modFeature, tstlClassName, init)
128
- local ____modFeature_0 = modFeature
129
- local v = ____modFeature_0.v
130
- if v == nil then
131
- return
132
- end
133
- if not isTable(nil, v) then
134
- error("Failed to initialize a mod feature class due to having a \"v\" property that is not an object. (The \"v\" property is supposed to be an object that holds the variables for the class, managed by the save data manager.)")
135
- end
136
- local mod = modFeature.mod
137
- local saveDataManagerMethodName = init and "saveDataManager" or "saveDataManagerRemove"
138
- local saveDataManagerMethod = mod[saveDataManagerMethodName]
139
- if saveDataManagerMethod == nil then
140
- error("Failed to initialize a mod feature class due to having a \"v\" object and not having the save data manager initialized. You must pass \"ISCFeature.SAVE_DATA_MANAGER\" to the \"upgradeMod\" function.")
141
- end
142
- if type(saveDataManagerMethod) ~= "function" then
143
- error(("The \"" .. saveDataManagerMethodName) .. "\" property of the \"ModUpgraded\" object was not a function.")
144
- end
145
- if init then
146
- saveDataManagerMethod(nil, tstlClassName, v)
147
- else
148
- saveDataManagerMethod(nil, tstlClassName)
149
- end
150
- end
151
126
  ____exports.MOD_FEATURE_CALLBACKS_KEY = "__callbacks"
152
127
  ____exports.MOD_FEATURE_CUSTOM_CALLBACKS_KEY = "__customCallbacks"
153
128
  WRAPPED_CALLBACK_METHODS_KEY = "__wrappedCallbackMethods"
@@ -156,29 +131,12 @@ WRAPPED_CUSTOM_CALLBACK_METHODS_KEY = "__wrappedCustomCallbacksMethods"
156
131
  -- mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
157
132
  -- that automatically subscribe to callbacks.
158
133
  --
159
- -- If your feature has variables that are managed by the save data manager, put them as a `v` class
160
- -- member and they will automatically be registered with the save data manager when the class is
161
- -- instantiated.
162
- --
163
- -- For example:
164
- --
165
- -- ```ts
166
- -- export class MyFeature extends ModFeature {
167
- -- v = {
168
- -- run: {
169
- -- foo: 123,
170
- -- }
171
- -- }
172
- --
173
- -- @Callback (ModCallback.POST_GAME_STARTED)
174
- -- postGameStarted(isContinued: boolean): void {
175
- -- Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
176
- -- }
177
- -- }
178
- -- ```
134
+ -- When instantiating a mod feature class, you must pass your upgraded mod as the first argument to
135
+ -- the constructor.
179
136
  --
180
- -- When instantiating a feature class, you must pass your upgraded mod as the first argument to the
181
- -- constructor.
137
+ -- If your feature has variables that are managed by the save data manager, you need to explicitly
138
+ -- register them with the save data manager yourself in your class constructor. (It can't be
139
+ -- automatically done because parent classes don't have access to child class properties.)
182
140
  --
183
141
  -- In almost all cases, you will want the callback functions to be immediately subscribed after
184
142
  -- instantiating the class. However, if this is not the case, you can pass `false` as the optional
@@ -229,7 +187,6 @@ function ModFeature.prototype.init(self, init)
229
187
  false,
230
188
  init
231
189
  )
232
- initSaveDataManager(nil, self, tstlClassName, init)
233
190
  end
234
191
  function ModFeature.prototype.uninit(self)
235
192
  self:init(false)
@@ -130,7 +130,8 @@ export declare class SaveDataManager extends Feature {
130
130
  *
131
131
  * @param key The name of the file or feature that is submitting data to be managed by the save
132
132
  * data manager. The save data manager will throw an error if the key is already
133
- * registered.
133
+ * registered. Note that you can also pass a TSTL class instead of a string and the
134
+ * save data manager will use the name of the class as the key.
134
135
  * @param v An object that corresponds to the `SaveData` interface. The object is conventionally
135
136
  * called "v" for brevity. ("v" is short for "local variables").
136
137
  * @param conditionalFunc Optional. A function to run to check if this save data should be written
@@ -143,9 +144,9 @@ export declare class SaveDataManager extends Feature {
143
144
  * data. (Specifying `false` will allow you to use non-serializable objects
144
145
  * in your save data, such as `EntityPtr`.
145
146
  */
146
- saveDataManager<Persistent, Run, Level>(key: string, // This is the overload for the standard case with serializable data.
147
+ saveDataManager<Persistent, Run, Level>(key: unknown, // This is the overload for the standard case with serializable data.
147
148
  v: SaveData<Persistent, Run, Level>, conditionalFunc?: () => boolean): void;
148
- saveDataManager(key: string, // This is the overload for the case when saving data is disabled.
149
+ saveDataManager(key: unknown, // This is the overload for the case when saving data is disabled.
149
150
  v: SaveData, conditionalFunc: false): void;
150
151
  /**
151
152
  * Recursively traverses an object, collecting all of the class constructors that it encounters.
@@ -1 +1 @@
1
- {"version":3,"file":"SaveDataManager.d.ts","sourceRoot":"","sources":["../../../../../src/classes/features/other/SaveDataManager.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAMzD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAsBhD,qBAAa,eAAgB,SAAQ,OAAO;IAC1C;;;OAGG;IACH,OAAO,CAAC,GAAG,CAAM;IAEjB;;;;OAIG;IACH,OAAO,CAAC,WAAW,CAAkC;IAErD;;;OAGG;IACH,OAAO,CAAC,mBAAmB,CAAkC;IAE7D;;;OAGG;IACH,OAAO,CAAC,0BAA0B,CAAuC;IAEzE;;;;;;OAMG;IACH,OAAO,CAAC,2BAA2B,CAAkC;IAErE;;;OAGG;IACH,OAAO,CAAC,iBAAiB,CAAkC;IAG3D,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,qCAAqC,CAAS;IAiCtD,OAAO,CAAC,2BAA2B,CAUjC;IAGF,OAAO,CAAC,cAAc,CA0BpB;IAGF,OAAO,CAAC,WAAW,CAajB;IAGF,OAAO,CAAC,YAAY,CAYlB;IAGF,OAAO,CAAC,gBAAgB,CAuBtB;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkGG;IACI,eAAe,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,EAC3C,GAAG,EAAE,MAAM,EAAE,qEAAqE;IAClF,CAAC,EAAE,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,CAAC,EACnC,eAAe,CAAC,EAAE,MAAM,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,6 +26,7 @@ local ____stage = require("src.functions.stage")
26
26
  local onFirstFloor = ____stage.onFirstFloor
27
27
  local ____tstlClass = require("src.functions.tstlClass")
28
28
  local getTSTLClassName = ____tstlClass.getTSTLClassName
29
+ local isTSTLClass = ____tstlClass.isTSTLClass
29
30
  local ____types = require("src.functions.types")
30
31
  local isString = ____types.isString
31
32
  local isTable = ____types.isTable
@@ -103,8 +104,15 @@ function SaveDataManager.prototype.____constructor(self, mod)
103
104
  self.mod = mod
104
105
  end
105
106
  function SaveDataManager.prototype.saveDataManager(self, key, v, conditionalFunc)
107
+ if isTSTLClass(nil, key) then
108
+ local className = getTSTLClassName(nil, key)
109
+ if className == nil then
110
+ error("Failed to get the class name for the submitted class (as part of the \"key\" parameter) when registering new data with the save data manager.")
111
+ end
112
+ key = className
113
+ end
106
114
  if not isString(nil, key) then
107
- error("The save data manager requires that keys are strings. You tried to use a key of type: " .. __TS__TypeOf(key))
115
+ error("The save data manager requires that keys are strings or TSTL classes. You tried to use a key of type: " .. __TS__TypeOf(key))
108
116
  end
109
117
  if self.saveDataMap[key] ~= nil then
110
118
  error("The save data manager is already managing save data for a key of: " .. key)
@@ -46,10 +46,12 @@ export declare function logSet(set: Set<AnyNotNil> | ReadonlySet<AnyNotNil>): vo
46
46
  export declare function logSounds(): void;
47
47
  /**
48
48
  * Helper function for logging every key and value of a Lua table. This is a deep log; the function
49
- * will recursively call itself if it counters a table within a table.
49
+ * will recursively call itself if it encounters a table within a table.
50
50
  *
51
51
  * This function will only work on tables that have string keys (because it logs the keys in order,
52
52
  * instead of randomly). It will throw a run-time error if it encounters a non-string key.
53
+ *
54
+ * In order to prevent infinite recursion, this function will not log deeper than 10 nested tables.
53
55
  */
54
56
  export declare function logTable(luaTable: unknown, parentTables?: number): void;
55
57
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"logMisc.d.ts","sourceRoot":"","sources":["../../../src/functions/logMisc.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,eAAe,EACf,UAAU,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BAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,IAAI,CAG7D"}
@@ -388,16 +388,20 @@ function ____exports.logSounds(self)
388
388
  end
389
389
  end
390
390
  --- Helper function for logging every key and value of a Lua table. This is a deep log; the function
391
- -- will recursively call itself if it counters a table within a table.
391
+ -- will recursively call itself if it encounters a table within a table.
392
392
  --
393
393
  -- This function will only work on tables that have string keys (because it logs the keys in order,
394
394
  -- instead of randomly). It will throw a run-time error if it encounters a non-string key.
395
+ --
396
+ -- In order to prevent infinite recursion, this function will not log deeper than 10 nested tables.
395
397
  function ____exports.logTable(self, luaTable, parentTables)
396
398
  if parentTables == nil then
397
399
  parentTables = 0
398
400
  end
399
401
  if parentTables == 0 then
400
402
  log(nil, "Printing out a Lua table:")
403
+ elseif parentTables > 10 then
404
+ return
401
405
  end
402
406
  local numSpaces = (parentTables + 1) * 2
403
407
  local indentation = string.rep(
@@ -25,7 +25,7 @@ export declare function isRNG(object: unknown): object is RNG;
25
25
  */
26
26
  export declare function isSerializedRNG(object: unknown): object is SerializedRNG;
27
27
  /**
28
- * Helper function to initialize an RNG object using Blade's recommended shift index.
28
+ * Helper function to initialize a new RNG object using Blade's recommended shift index.
29
29
  *
30
30
  * @param seed The seed to initialize it with. Default is `getRandomSeed()`.
31
31
  */
@@ -26,7 +26,7 @@ end
26
26
  function ____exports.isRNG(self, object)
27
27
  return isIsaacAPIClassOfType(nil, object, OBJECT_NAME)
28
28
  end
29
- --- Helper function to initialize an RNG object using Blade's recommended shift index.
29
+ --- Helper function to initialize a new RNG object using Blade's recommended shift index.
30
30
  --
31
31
  -- @param seed The seed to initialize it with. Default is `getRandomSeed()`.
32
32
  function ____exports.newRNG(self, seed)
@@ -27,6 +27,8 @@ export declare function getTSTLClassName(object: unknown): string | undefined;
27
27
  * their own copies of the entire lualib and thus their own instantiated version of a `Map`.
28
28
  */
29
29
  export declare function isDefaultMap(object: unknown): object is DefaultMap<AnyNotNil, unknown>;
30
+ /** Helper function to check if a given table is a class table created by TypeScriptToLua. */
31
+ export declare function isTSTLClass(object: unknown): object is TSTLClass;
30
32
  /**
31
33
  * Helper function to determine if a given object is a TypeScriptToLua `Map`.
32
34
  *
@@ -43,8 +45,6 @@ export declare function isTSTLMap(object: unknown): object is Map<AnyNotNil, unk
43
45
  * `Set`.
44
46
  */
45
47
  export declare function isTSTLSet(object: unknown): object is Set<AnyNotNil>;
46
- /** TypeScriptToLua classes are Lua tables that have a metatable with a certain amount of keys. */
47
- export declare function isUserDefinedTSTLClass(object: unknown): object is TSTLClass;
48
48
  /**
49
49
  * Initializes a new TypeScriptToLua class in the situation where you do not know what kind of class
50
50
  * it is. This function requires that you provide an instantiated class of the same type, as it will
@@ -1 +1 @@
1
- {"version":3,"file":"tstlClass.d.ts","sourceRoot":"","sources":["../../../src/functions/tstlClass.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,OAAO,GACd,kBAAkB,CAAC,aAAa,CAAC,GAAG,SAAS,CAW/C;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOpE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAG1C;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAG5E;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,GAAG,CAAC,SAAS,CAAC,CAGnE;AAED,kGAAkG;AAClG,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,SAAS,CAG3E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS,CAiB3D"}
1
+ {"version":3,"file":"tstlClass.d.ts","sourceRoot":"","sources":["../../../src/functions/tstlClass.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,OAAO,GACd,kBAAkB,CAAC,aAAa,CAAC,GAAG,SAAS,CAW/C;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOpE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAG1C;AAED,6FAA6F;AAC7F,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,SAAS,CAGhE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAG5E;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,GAAG,CAAC,SAAS,CAAC,CAGnE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS,CAiB3D"}
@@ -38,6 +38,11 @@ function ____exports.isDefaultMap(self, object)
38
38
  local className = ____exports.getTSTLClassName(nil, object)
39
39
  return className == "DefaultMap"
40
40
  end
41
+ --- Helper function to check if a given table is a class table created by TypeScriptToLua.
42
+ function ____exports.isTSTLClass(self, object)
43
+ local tstlClassName = ____exports.getTSTLClassName(nil, object)
44
+ return tstlClassName ~= nil
45
+ end
41
46
  --- Helper function to determine if a given object is a TypeScriptToLua `Map`.
42
47
  --
43
48
  -- It is not reliable to use the `instanceof` operator to determine this because each Lua module
@@ -56,11 +61,6 @@ function ____exports.isTSTLSet(self, object)
56
61
  local className = ____exports.getTSTLClassName(nil, object)
57
62
  return className == "Set"
58
63
  end
59
- --- TypeScriptToLua classes are Lua tables that have a metatable with a certain amount of keys.
60
- function ____exports.isUserDefinedTSTLClass(self, object)
61
- local tstlClassName = ____exports.getTSTLClassName(nil, object)
62
- return tstlClassName ~= nil
63
- end
64
64
  --- Initializes a new TypeScriptToLua class in the situation where you do not know what kind of class
65
65
  -- it is. This function requires that you provide an instantiated class of the same type, as it will
66
66
  -- use the class constructor that is present on the other object's metatable to initialize the new
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "20.6.0",
3
+ "version": "20.7.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -5,7 +5,7 @@ import {
5
5
  getTSTLClassConstructor,
6
6
  getTSTLClassName,
7
7
  } from "../functions/tstlClass";
8
- import { isFunction, isNumber, isTable } from "../functions/types";
8
+ import { isFunction, isNumber } from "../functions/types";
9
9
  import { TSTLClassMetatable } from "../interfaces/TSTLClassMetatable";
10
10
  import { AnyFunction } from "../types/AnyFunction";
11
11
  import { ModUpgradedBase } from "./ModUpgradedBase";
@@ -41,29 +41,12 @@ type ModFeatureConstructor = TSTLClassMetatable["constructor"] & {
41
41
  * mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
42
42
  * that automatically subscribe to callbacks.
43
43
  *
44
- * If your feature has variables that are managed by the save data manager, put them as a `v` class
45
- * member and they will automatically be registered with the save data manager when the class is
46
- * instantiated.
44
+ * When instantiating a mod feature class, you must pass your upgraded mod as the first argument to
45
+ * the constructor.
47
46
  *
48
- * For example:
49
- *
50
- * ```ts
51
- * export class MyFeature extends ModFeature {
52
- * v = {
53
- * run: {
54
- * foo: 123,
55
- * }
56
- * }
57
- *
58
- * @Callback(ModCallback.POST_GAME_STARTED)
59
- * postGameStarted(isContinued: boolean): void {
60
- * Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
61
- * }
62
- * }
63
- * ```
64
- *
65
- * When instantiating a feature class, you must pass your upgraded mod as the first argument to the
66
- * constructor.
47
+ * If your feature has variables that are managed by the save data manager, you need to explicitly
48
+ * register them with the save data manager yourself in your class constructor. (It can't be
49
+ * automatically done because parent classes don't have access to child class properties.)
67
50
  *
68
51
  * In almost all cases, you will want the callback functions to be immediately subscribed after
69
52
  * instantiating the class. However, if this is not the case, you can pass `false` as the optional
@@ -147,7 +130,6 @@ export class ModFeature {
147
130
 
148
131
  initDecoratedCallbacks(this, constructor, tstlClassName, true, init);
149
132
  initDecoratedCallbacks(this, constructor, tstlClassName, false, init);
150
- initSaveDataManager(this, tstlClassName, init);
151
133
  }
152
134
 
153
135
  /**
@@ -334,46 +316,3 @@ function removeCallback(
334
316
  (mod.RemoveCallbackCustom as AnyFunction)(modCallback, wrappedCallback);
335
317
  }
336
318
  }
337
-
338
- function initSaveDataManager(
339
- modFeature: ModFeature,
340
- tstlClassName: string,
341
- init: boolean,
342
- ) {
343
- // Do nothing if this class does not have any variables.
344
- const { v } = modFeature as unknown as Record<string, unknown>;
345
- if (v === undefined) {
346
- return;
347
- }
348
-
349
- if (!isTable(v)) {
350
- error(
351
- 'Failed to initialize a mod feature class due to having a "v" property that is not an object. (The "v" property is supposed to be an object that holds the variables for the class, managed by the save data manager.)',
352
- );
353
- }
354
-
355
- // Do nothing if we have not enabled the save data manager.
356
- // eslint-disable-next-line @typescript-eslint/dot-notation
357
- const mod = modFeature["mod"] as unknown as Record<string, unknown>;
358
- const saveDataManagerMethodName = init
359
- ? "saveDataManager"
360
- : "saveDataManagerRemove";
361
- const saveDataManagerMethod = mod[saveDataManagerMethodName];
362
- if (saveDataManagerMethod === undefined) {
363
- error(
364
- 'Failed to initialize a mod feature class due to having a "v" object and not having the save data manager initialized. You must pass "ISCFeature.SAVE_DATA_MANAGER" to the "upgradeMod" function.',
365
- );
366
- }
367
-
368
- if (typeof saveDataManagerMethod !== "function") {
369
- error(
370
- `The "${saveDataManagerMethodName}" property of the "ModUpgraded" object was not a function.`,
371
- );
372
- }
373
-
374
- if (init) {
375
- saveDataManagerMethod(tstlClassName, v);
376
- } else {
377
- saveDataManagerMethod(tstlClassName);
378
- }
379
- }
@@ -11,7 +11,7 @@ import { SaveDataKey } from "../../../enums/SaveDataKey";
11
11
  import { SerializationType } from "../../../enums/SerializationType";
12
12
  import { deepCopy } from "../../../functions/deepCopy";
13
13
  import { onFirstFloor } from "../../../functions/stage";
14
- import { getTSTLClassName } from "../../../functions/tstlClass";
14
+ import { getTSTLClassName, isTSTLClass } from "../../../functions/tstlClass";
15
15
  import { isString, isTable } from "../../../functions/types";
16
16
  import { SaveData } from "../../../interfaces/SaveData";
17
17
  import { AnyClass } from "../../../types/AnyClass";
@@ -297,7 +297,8 @@ export class SaveDataManager extends Feature {
297
297
  *
298
298
  * @param key The name of the file or feature that is submitting data to be managed by the save
299
299
  * data manager. The save data manager will throw an error if the key is already
300
- * registered.
300
+ * registered. Note that you can also pass a TSTL class instead of a string and the
301
+ * save data manager will use the name of the class as the key.
301
302
  * @param v An object that corresponds to the `SaveData` interface. The object is conventionally
302
303
  * called "v" for brevity. ("v" is short for "local variables").
303
304
  * @param conditionalFunc Optional. A function to run to check if this save data should be written
@@ -311,24 +312,35 @@ export class SaveDataManager extends Feature {
311
312
  * in your save data, such as `EntityPtr`.
312
313
  */
313
314
  public saveDataManager<Persistent, Run, Level>(
314
- key: string, // This is the overload for the standard case with serializable data.
315
+ key: unknown, // This is the overload for the standard case with serializable data.
315
316
  v: SaveData<Persistent, Run, Level>,
316
317
  conditionalFunc?: () => boolean,
317
318
  ): void;
318
319
  public saveDataManager(
319
- key: string, // This is the overload for the case when saving data is disabled.
320
+ key: unknown, // This is the overload for the case when saving data is disabled.
320
321
  v: SaveData,
321
322
  conditionalFunc: false,
322
323
  ): void;
323
324
  @Exported
324
325
  public saveDataManager<Persistent, Run, Level>(
325
- key: string,
326
+ key: unknown,
326
327
  v: SaveData<Persistent, Run, Level>,
327
328
  conditionalFunc?: (() => boolean) | false,
328
329
  ): void {
330
+ if (isTSTLClass(key)) {
331
+ const className = getTSTLClassName(key);
332
+ if (className === undefined) {
333
+ error(
334
+ 'Failed to get the class name for the submitted class (as part of the "key" parameter) when registering new data with the save data manager.',
335
+ );
336
+ }
337
+
338
+ key = className;
339
+ }
340
+
329
341
  if (!isString(key)) {
330
342
  error(
331
- `The save data manager requires that keys are strings. You tried to use a key of type: ${typeof key}`,
343
+ `The save data manager requires that keys are strings or TSTL classes. You tried to use a key of type: ${typeof key}`,
332
344
  );
333
345
  }
334
346
 
@@ -326,14 +326,18 @@ export function logSounds(): void {
326
326
 
327
327
  /**
328
328
  * Helper function for logging every key and value of a Lua table. This is a deep log; the function
329
- * will recursively call itself if it counters a table within a table.
329
+ * will recursively call itself if it encounters a table within a table.
330
330
  *
331
331
  * This function will only work on tables that have string keys (because it logs the keys in order,
332
332
  * instead of randomly). It will throw a run-time error if it encounters a non-string key.
333
+ *
334
+ * In order to prevent infinite recursion, this function will not log deeper than 10 nested tables.
333
335
  */
334
336
  export function logTable(luaTable: unknown, parentTables = 0): void {
335
337
  if (parentTables === 0) {
336
338
  log("Printing out a Lua table:");
339
+ } else if (parentTables > 10) {
340
+ return;
337
341
  }
338
342
 
339
343
  const numSpaces = (parentTables + 1) * 2; // 2, 4, 6, etc.
@@ -83,7 +83,7 @@ export function isSerializedRNG(object: unknown): object is SerializedRNG {
83
83
  }
84
84
 
85
85
  /**
86
- * Helper function to initialize an RNG object using Blade's recommended shift index.
86
+ * Helper function to initialize a new RNG object using Blade's recommended shift index.
87
87
  *
88
88
  * @param seed The seed to initialize it with. Default is `getRandomSeed()`.
89
89
  */
@@ -56,6 +56,12 @@ export function isDefaultMap(
56
56
  return className === "DefaultMap";
57
57
  }
58
58
 
59
+ /** Helper function to check if a given table is a class table created by TypeScriptToLua. */
60
+ export function isTSTLClass(object: unknown): object is TSTLClass {
61
+ const tstlClassName = getTSTLClassName(object);
62
+ return tstlClassName !== undefined;
63
+ }
64
+
59
65
  /**
60
66
  * Helper function to determine if a given object is a TypeScriptToLua `Map`.
61
67
  *
@@ -80,12 +86,6 @@ export function isTSTLSet(object: unknown): object is Set<AnyNotNil> {
80
86
  return className === "Set";
81
87
  }
82
88
 
83
- /** TypeScriptToLua classes are Lua tables that have a metatable with a certain amount of keys. */
84
- export function isUserDefinedTSTLClass(object: unknown): object is TSTLClass {
85
- const tstlClassName = getTSTLClassName(object);
86
- return tstlClassName !== undefined;
87
- }
88
-
89
89
  /**
90
90
  * Initializes a new TypeScriptToLua class in the situation where you do not know what kind of class
91
91
  * it is. This function requires that you provide an instantiated class of the same type, as it will