isaacscript-common 3.15.2 → 3.15.3

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.
Files changed (40) hide show
  1. package/callbacks/postPlayerFatalDamage.lua +3 -3
  2. package/classes/DefaultMap.lua +6 -4
  3. package/enums/ModCallbackCustom.d.ts +1 -1
  4. package/features/deployJSONRoom.lua +62 -17
  5. package/features/saveDataManager/exports.lua +7 -6
  6. package/features/saveDataManager/load.lua +7 -5
  7. package/features/saveDataManager/main.lua +2 -2
  8. package/features/saveDataManager/merge.lua +12 -16
  9. package/features/saveDataManager/save.lua +2 -2
  10. package/features/saveDataManager/serializationBrand.lua +3 -1
  11. package/functions/array.d.ts +1 -0
  12. package/functions/array.lua +18 -12
  13. package/functions/color.lua +6 -7
  14. package/functions/deepCopy.lua +27 -24
  15. package/functions/deepCopyTests.lua +23 -27
  16. package/functions/entity.d.ts +4 -1
  17. package/functions/entity.lua +22 -25
  18. package/functions/enums.lua +3 -1
  19. package/functions/gridEntity.d.ts +3 -3
  20. package/functions/gridEntity.lua +7 -7
  21. package/functions/isaacAPIClass.lua +5 -3
  22. package/functions/jsonHelpers.d.ts +1 -1
  23. package/functions/jsonHelpers.lua +4 -4
  24. package/functions/kColor.lua +6 -7
  25. package/functions/log.d.ts +9 -2
  26. package/functions/log.lua +30 -21
  27. package/functions/rng.lua +10 -12
  28. package/functions/serialization.d.ts +1 -1
  29. package/functions/serialization.lua +9 -7
  30. package/functions/table.d.ts +14 -10
  31. package/functions/table.lua +54 -37
  32. package/functions/tstlClass.lua +6 -4
  33. package/functions/types.d.ts +10 -0
  34. package/functions/types.lua +25 -0
  35. package/functions/utils.d.ts +0 -2
  36. package/functions/utils.lua +0 -6
  37. package/functions/vector.lua +6 -7
  38. package/index.d.ts +1 -0
  39. package/index.lua +8 -0
  40. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__TypeOf = ____lualib.__TS__TypeOf
2
3
  local Map = ____lualib.Map
3
4
  local __TS__New = ____lualib.__TS__New
4
5
  local Set = ____lualib.Set
@@ -20,12 +21,15 @@ local ____tstlClass = require("functions.tstlClass")
20
21
  local isDefaultMap = ____tstlClass.isDefaultMap
21
22
  local isTSTLMap = ____tstlClass.isTSTLMap
22
23
  local isTSTLSet = ____tstlClass.isTSTLSet
24
+ local ____types = require("functions.types")
25
+ local isNumber = ____types.isNumber
26
+ local isString = ____types.isString
27
+ local isTable = ____types.isTable
23
28
  function copiedObjectIsTable(self)
24
29
  local oldObject = {abc = "def"}
25
30
  local newObject = deepCopy(nil, oldObject)
26
- local newObjectType = type(newObject)
27
- if newObjectType ~= "table" then
28
- error("The copied object is not a table.")
31
+ if not isTable(nil, newObject) then
32
+ error("The copied object had a type of: " .. __TS__TypeOf(newObject))
29
33
  end
30
34
  end
31
35
  function copiedObjectHasKeyAndValueString(self)
@@ -38,9 +42,8 @@ function copiedObjectHasKeyAndValueString(self)
38
42
  if value == nil then
39
43
  error("The copied object did not have a key of: " .. keyToLookFor)
40
44
  end
41
- local valueType = type(value)
42
- if valueType ~= "string" then
43
- error("The copied object had a value type of: " .. valueType)
45
+ if not isString(nil, value) then
46
+ error("The copied object had a value type of: " .. __TS__TypeOf(value))
44
47
  end
45
48
  if value ~= valueToLookFor then
46
49
  error("The copied object had a value of: " .. value)
@@ -57,9 +60,8 @@ function copiedTableHasKeyAndValueNumber(self)
57
60
  if value == nil then
58
61
  error("The copied object did not have a key of: " .. tostring(keyToLookFor))
59
62
  end
60
- local valueType = type(value)
61
- if valueType ~= "number" then
62
- error("The copied object had a value type of: " .. valueType)
63
+ if not isNumber(nil, value) then
64
+ error("The copied object had a value type of: " .. __TS__TypeOf(value))
63
65
  end
64
66
  if value ~= valueToLookFor then
65
67
  error("The copied object had a value of: " .. tostring(value))
@@ -149,17 +151,15 @@ function copiedObjectHasChildObject(self)
149
151
  if childObject == nil then
150
152
  error("Failed to find the child object at index: " .. childObjectIndex)
151
153
  end
152
- local childObjectType = type(childObject)
153
- if childObjectType ~= "table" then
154
- error("The copied child object was not a table.")
154
+ if not isTable(nil, childObject) then
155
+ error("The copied child object had a type of: " .. __TS__TypeOf(childObject))
155
156
  end
156
157
  local value = childObject[keyToLookFor]
157
158
  if value == nil then
158
159
  error("The child object did not have a key of: " .. keyToLookFor)
159
160
  end
160
- local valueType = type(value)
161
- if valueType ~= "string" then
162
- error("The child object value had a type of: " .. valueType)
161
+ if not isString(nil, value) then
162
+ error("The child object value had a type of: " .. __TS__TypeOf(value))
163
163
  end
164
164
  if value ~= valueToLookFor then
165
165
  error("The child object value was: " .. valueToLookFor)
@@ -172,9 +172,8 @@ function copiedMapIsMap(self)
172
172
  oldMap:set(keyToLookFor, valueToLookFor)
173
173
  local newObject = deepCopy(nil, oldMap)
174
174
  local newMap = newObject
175
- local newMapType = type(newMap)
176
- if newMapType ~= "table" then
177
- error("The copied Map was not a table.")
175
+ if not isTable(nil, newMap) then
176
+ error("The copied Map had a type of: " .. __TS__TypeOf(newMap))
178
177
  end
179
178
  if not isTSTLMap(nil, newMap) then
180
179
  error("The copied Map was not a Map.")
@@ -201,9 +200,8 @@ function copiedSetIsSet(self)
201
200
  oldSet:add(valueToLookFor)
202
201
  local newTable = deepCopy(nil, oldSet)
203
202
  local newSet = newTable
204
- local newSetType = type(newSet)
205
- if newSetType ~= "table" then
206
- error("The copied Set was not a table.")
203
+ if not isTable(nil, newSet) then
204
+ error("The copied Set had a type of: " .. __TS__TypeOf(newSet))
207
205
  end
208
206
  if not isTSTLSet(nil, newSet) then
209
207
  error("The copied Set was not a Map.")
@@ -234,9 +232,8 @@ function copiedMapHasChildMap(self)
234
232
  if newChildMap == nil then
235
233
  error("The copied Map did not have a child map at key: " .. keyToLookFor)
236
234
  end
237
- local newChildMapType = type(newChildMap)
238
- if newChildMapType ~= "table" then
239
- error("The copied child Map had a type of: " .. newChildMapType)
235
+ if not isTable(nil, newChildMap) then
236
+ error("The copied child Map had a type of: " .. __TS__TypeOf(newChildMap))
240
237
  end
241
238
  if not isTSTLMap(nil, newChildMap) then
242
239
  error("The copied child Map was not a Map.")
@@ -268,9 +265,8 @@ function copiedDefaultMapHasChildDefaultMap(self)
268
265
  if newChildMap == nil then
269
266
  error("The copied DefaultMap did not have a child map at key: " .. parentMapKey)
270
267
  end
271
- local newChildMapType = type(newChildMap)
272
- if newChildMapType ~= "table" then
273
- error("The copied child DefaultMap had a type of: " .. newChildMapType)
268
+ if not isTable(nil, newChildMap) then
269
+ error("The copied child DefaultMap had a type of: " .. __TS__TypeOf(newChildMap))
274
270
  end
275
271
  if not isDefaultMap(nil, newChildMap) then
276
272
  error("The copied child DefaultMap was not a DefaultMap.")
@@ -65,8 +65,11 @@ export declare function getEntities(entityType?: EntityType, variant?: number, s
65
65
  /**
66
66
  * Helper function to get all the fields on an entity. For example, this is useful for comparing it
67
67
  * to another entity later.
68
+ *
69
+ * This function will only get fields that are equal to booleans, numbers, or strings, as comparing
70
+ * other types is non-trivial.
68
71
  */
69
- export declare function getEntityFields(entity: Entity): LuaTable<string, unknown>;
72
+ export declare function getEntityFields(entity: Entity): LuaTable<string, boolean | number | string>;
70
73
  /** Helper function to return a string containing the entity's type, variant, and sub-type. */
71
74
  export declare function getEntityID(entity: Entity): string;
72
75
  /**
@@ -4,6 +4,7 @@ local __TS__New = ____lualib.__TS__New
4
4
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
5
5
  local __TS__StringSplit = ____lualib.__TS__StringSplit
6
6
  local ____exports = {}
7
+ local setPrimitiveEntityFields
7
8
  local ____cachedClasses = require("cachedClasses")
8
9
  local game = ____cachedClasses.game
9
10
  local ____constants = require("constants")
@@ -16,8 +17,21 @@ local ____random = require("functions.random")
16
17
  local getRandom = ____random.getRandom
17
18
  local ____rng = require("functions.rng")
18
19
  local newRNG = ____rng.newRNG
19
- local ____utils = require("functions.utils")
20
- local isPrimitive = ____utils.isPrimitive
20
+ local ____types = require("functions.types")
21
+ local isPrimitive = ____types.isPrimitive
22
+ function setPrimitiveEntityFields(self, entity, metatable, entityFields)
23
+ local propGetTable = metatable.__propget
24
+ if propGetTable == nil then
25
+ error("Failed to get the \"__propget\" table for an entity.")
26
+ end
27
+ for key in pairs(propGetTable) do
28
+ local indexKey = key
29
+ local value = entity[indexKey]
30
+ if isPrimitive(nil, value) then
31
+ entityFields[indexKey] = value
32
+ end
33
+ end
34
+ end
21
35
  --- Helper function to remove all of the entities in the supplied array.
22
36
  --
23
37
  -- @param entities The array of entities to remove.
@@ -162,23 +176,16 @@ function ____exports.getEntities(self, entityType, variant, subType, ignoreFrien
162
176
  end
163
177
  --- Helper function to get all the fields on an entity. For example, this is useful for comparing it
164
178
  -- to another entity later.
179
+ --
180
+ -- This function will only get fields that are equal to booleans, numbers, or strings, as comparing
181
+ -- other types is non-trivial.
165
182
  function ____exports.getEntityFields(self, entity)
183
+ local entityFields = {}
166
184
  local metatable = getmetatable(entity)
167
185
  if metatable == nil then
168
186
  error("Failed to get the metatable for an entity.")
169
187
  end
170
- local propGetTable = metatable.__propget
171
- if propGetTable == nil then
172
- error("Failed to get the \"__propget\" table for an entity.")
173
- end
174
- local entityFields = {}
175
- for key in pairs(propGetTable) do
176
- local indexKey = key
177
- local value = entity[indexKey]
178
- if isPrimitive(nil, value) then
179
- entityFields[indexKey] = value
180
- end
181
- end
188
+ setPrimitiveEntityFields(nil, entity, metatable, entityFields)
182
189
  local className = getIsaacAPIClassName(nil, entity)
183
190
  if className == "Entity" then
184
191
  return entityFields
@@ -187,17 +194,7 @@ function ____exports.getEntityFields(self, entity)
187
194
  if parentTable == nil then
188
195
  error("Failed to get the \"__parent\" table for an entity.")
189
196
  end
190
- local parentPropGetTable = parentTable.__propget
191
- if parentPropGetTable == nil then
192
- error("Failed to get the parent's \"__propget\" table for an entity.")
193
- end
194
- for key in pairs(parentPropGetTable) do
195
- local indexKey = key
196
- local value = entity[indexKey]
197
- if isPrimitive(nil, value) then
198
- entityFields[indexKey] = value
199
- end
200
- end
197
+ setPrimitiveEntityFields(nil, entity, parentTable, entityFields)
201
198
  return entityFields
202
199
  end
203
200
  --- Helper function to return a string containing the entity's type, variant, and sub-type.
@@ -6,6 +6,8 @@ local ____array = require("functions.array")
6
6
  local getRandomArrayElement = ____array.getRandomArrayElement
7
7
  local ____rng = require("functions.rng")
8
8
  local getRandomSeed = ____rng.getRandomSeed
9
+ local ____types = require("functions.types")
10
+ local isString = ____types.isString
9
11
  --- TypeScriptToLua will transpile TypeScript enums to Lua tables that have a double mapping. Thus,
10
12
  -- when you iterate over them, you will get both the names of the enums and the values of the enums,
11
13
  -- in a random order. Use this helper function to get the entries of the enum with the reverse
@@ -24,7 +26,7 @@ local getRandomSeed = ____rng.getRandomSeed
24
26
  function ____exports.getEnumEntries(self, transpiledEnum)
25
27
  local enumEntries = {}
26
28
  for key, value in pairs(transpiledEnum) do
27
- if type(key) == "string" then
29
+ if isString(nil, key) then
28
30
  enumEntries[#enumEntries + 1] = {key, value}
29
31
  end
30
32
  end
@@ -85,7 +85,7 @@ export declare function isPostBossVoidPortal(gridEntity: GridEntity): boolean;
85
85
  *
86
86
  * @returns True if one or more grid entities were removed, false otherwise.
87
87
  */
88
- export declare function removeAllGridExcept(...gridEntityTypes: GridEntityType[]): boolean;
88
+ export declare function removeAllGridExcept(...gridEntityTypes: GridEntityType[]): GridEntity[];
89
89
  /**
90
90
  * Helper function to remove all of the grid entities in the room that match the grid entity types
91
91
  * provided.
@@ -100,9 +100,9 @@ export declare function removeAllGridExcept(...gridEntityTypes: GridEntityType[]
100
100
  * );
101
101
  * ```
102
102
  *
103
- * @returns True if one or more grid entities were removed, false otherwise.
103
+ * @returns An array of the grid entities removed.
104
104
  */
105
- export declare function removeAllMatchingGridEntities(...gridEntityType: GridEntityType[]): boolean;
105
+ export declare function removeAllMatchingGridEntities(...gridEntityType: GridEntityType[]): GridEntity[];
106
106
  /**
107
107
  * Helper function to remove a grid entity simply by providing the grid entity object.
108
108
  *
@@ -282,18 +282,18 @@ function ____exports.removeAllGridExcept(self, ...)
282
282
  local gridEntityTypes = {...}
283
283
  local gridEntityTypeExceptions = __TS__New(Set, gridEntityTypes)
284
284
  local gridEntities = ____exports.getGridEntities(nil)
285
- local removedOneOrMoreGridEntities = false
285
+ local removedGridEntities = {}
286
286
  for ____, gridEntity in ipairs(gridEntities) do
287
287
  local gridEntityType = gridEntity:GetType()
288
288
  if not gridEntityTypeExceptions:has(gridEntityType) then
289
289
  ____exports.removeGrid(nil, gridEntity, false)
290
- removedOneOrMoreGridEntities = true
290
+ removedGridEntities[#removedGridEntities + 1] = gridEntity
291
291
  end
292
292
  end
293
- if removedOneOrMoreGridEntities then
293
+ if #removedGridEntities > 0 then
294
294
  roomUpdateSafe(nil)
295
295
  end
296
- return removedOneOrMoreGridEntities
296
+ return removedGridEntities
297
297
  end
298
298
  --- Helper function to remove all of the grid entities in the room that match the grid entity types
299
299
  -- provided.
@@ -308,17 +308,17 @@ end
308
308
  -- );
309
309
  -- ```
310
310
  --
311
- -- @returns True if one or more grid entities were removed, false otherwise.
311
+ -- @returns An array of the grid entities removed.
312
312
  function ____exports.removeAllMatchingGridEntities(self, ...)
313
313
  local gridEntities = ____exports.getGridEntities(nil, ...)
314
314
  if #gridEntities == 0 then
315
- return false
315
+ return {}
316
316
  end
317
317
  for ____, gridEntity in ipairs(gridEntities) do
318
318
  ____exports.removeGrid(nil, gridEntity, false)
319
319
  end
320
320
  roomUpdateSafe(nil)
321
- return true
321
+ return gridEntities
322
322
  end
323
323
  --- Helper function to make a grid entity invisible. This is accomplished by setting its sprite to an
324
324
  -- empty/missing PNG file.
@@ -1,6 +1,9 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
3
3
  local ____exports = {}
4
+ local ____types = require("functions.types")
5
+ local isString = ____types.isString
6
+ local isUserdata = ____types.isUserdata
4
7
  --- Helper function to get the name of a class from the Isaac API. This is contained within the
5
8
  -- "__type" metatable key.
6
9
  --
@@ -9,8 +12,7 @@ local ____exports = {}
9
12
  -- Returns undefined if the object is not of type `userdata` or if the "__type" metatable key does
10
13
  -- not exist.
11
14
  function ____exports.getIsaacAPIClassName(self, object)
12
- local objectType = type(object)
13
- if objectType ~= "userdata" then
15
+ if not isUserdata(nil, object) then
14
16
  return nil
15
17
  end
16
18
  local metatable = getmetatable(object)
@@ -18,7 +20,7 @@ function ____exports.getIsaacAPIClassName(self, object)
18
20
  return nil
19
21
  end
20
22
  local classType = metatable.__type
21
- if type(classType) ~= "string" then
23
+ if not isString(nil, classType) then
22
24
  return nil
23
25
  end
24
26
  return classType
@@ -15,4 +15,4 @@ export declare function jsonDecode(jsonString: string): LuaTable<AnyNotNil, unkn
15
15
  * fails, it will throw an error to prevent writing a blank string or corrupted data to a user's
16
16
  * "save#.dat" file.
17
17
  */
18
- export declare function jsonEncode(table: unknown): string;
18
+ export declare function jsonEncode(luaTable: unknown): string;
@@ -5,8 +5,8 @@ local logError = ____log.logError
5
5
  local function tryDecode(jsonString)
6
6
  return json.decode(jsonString)
7
7
  end
8
- local function tryEncode(____table)
9
- return json.encode(____table)
8
+ local function tryEncode(luaTable)
9
+ return json.encode(luaTable)
10
10
  end
11
11
  --- Converts a JSON string to a Lua table.
12
12
  --
@@ -27,8 +27,8 @@ end
27
27
  -- In most cases, this function will be used for writing data to a "save#.dat" file. If encoding
28
28
  -- fails, it will throw an error to prevent writing a blank string or corrupted data to a user's
29
29
  -- "save#.dat" file.
30
- function ____exports.jsonEncode(self, ____table)
31
- local ok, jsonStringOrErrMsg = pcall(tryEncode, ____table)
30
+ function ____exports.jsonEncode(self, luaTable)
31
+ local ok, jsonStringOrErrMsg = pcall(tryEncode, luaTable)
32
32
  if not ok then
33
33
  error("Failed to convert the Lua table to JSON: " .. jsonStringOrErrMsg)
34
34
  end
@@ -11,6 +11,8 @@ local ____table = require("functions.table")
11
11
  local copyValuesToTable = ____table.copyValuesToTable
12
12
  local getNumbersFromTable = ____table.getNumbersFromTable
13
13
  local tableHasKeys = ____table.tableHasKeys
14
+ local ____types = require("functions.types")
15
+ local isTable = ____types.isTable
14
16
  local ____utils = require("functions.utils")
15
17
  local ensureAllCases = ____utils.ensureAllCases
16
18
  --- Helper function to check if something is an instantiated KColor object.
@@ -54,8 +56,7 @@ function ____exports.copyKColor(self, kColor, serializationType)
54
56
  ____cond3 = ____cond3 or ____switch3 == SerializationType.DESERIALIZE
55
57
  if ____cond3 then
56
58
  do
57
- local kColorType = type(kColor)
58
- if ____exports.isKColor(nil, kColor) or kColorType ~= "table" then
59
+ if not isTable(nil, kColor) then
59
60
  error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
60
61
  end
61
62
  local r, g, b, a = table.unpack(getNumbersFromTable(
@@ -93,16 +94,14 @@ end
93
94
  --- Used to determine is the given table is a serialized `KColor` object created by the save data
94
95
  -- manager and/or the `deepCopy` function.
95
96
  function ____exports.isSerializedKColor(self, object)
96
- local objectType = type(object)
97
- if objectType ~= "table" then
97
+ if not isTable(nil, object) then
98
98
  return false
99
99
  end
100
- local ____table = object
101
100
  return tableHasKeys(
102
101
  nil,
103
- ____table,
102
+ object,
104
103
  table.unpack(KEYS)
105
- ) and ____table[SerializationBrand.K_COLOR] ~= nil
104
+ ) and object[SerializationBrand.K_COLOR] ~= nil
106
105
  end
107
106
  function ____exports.kColorEquals(self, kColor1, kColor2)
108
107
  return isaacAPIClassEquals(nil, kColor1, kColor2, KEYS)
@@ -59,12 +59,19 @@ export declare function logSeedEffects(this: void): void;
59
59
  export declare function logSet(this: void, set: Set<AnyNotNil>): void;
60
60
  /** Helper function for logging every sound effect that is currently playing. */
61
61
  export declare function logSounds(this: void): void;
62
- export declare function logTable(this: void, table: unknown, parentTables?: number): void;
62
+ /**
63
+ * Helper function for logging every key and value of a table. This is a deep log; the function will
64
+ * recursively call itself if it counters a table within a table.
65
+ *
66
+ * This function will only work on tables that have string keys (because it logs the keys in order,
67
+ * instead of randomly). It will throw a runtime error if it encounters a non-string key.
68
+ */
69
+ export declare function logTable(this: void, luaTable: unknown, parentTables?: number): void;
63
70
  /**
64
71
  * Helper function to print out the differences between the entries of two tables. Note that this
65
72
  * will only do a shallow comparison.
66
73
  */
67
- export declare function logTableDifferences<K, V>(table1: LuaTable<K, V>, table2: LuaTable<K, V>): void;
74
+ export declare function logTableDifferences<K, V>(this: void, table1: LuaTable<K, V>, table2: LuaTable<K, V>): void;
68
75
  /** Helper function for printing out every tear flag that is turned on. Useful when debugging. */
69
76
  export declare function logTearFlags(this: void, flags: TearFlag | BitFlags<TearFlag>): void;
70
77
  /** Helper function for printing out every use flag that is turned on. Useful when debugging. */
package/functions/log.lua CHANGED
@@ -5,6 +5,7 @@ local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
5
5
  local Map = ____lualib.Map
6
6
  local __TS__Spread = ____lualib.__TS__Spread
7
7
  local __TS__ArraySort = ____lualib.__TS__ArraySort
8
+ local __TS__TypeOf = ____lualib.__TS__TypeOf
8
9
  local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
9
10
  local ____exports = {}
10
11
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
@@ -49,8 +50,13 @@ local getRoomListIndex = ____roomData.getRoomListIndex
49
50
  local ____set = require("functions.set")
50
51
  local combineSets = ____set.combineSets
51
52
  local getSortedSetValues = ____set.getSortedSetValues
53
+ local ____table = require("functions.table")
54
+ local iterateTableInOrder = ____table.iterateTableInOrder
52
55
  local ____trinkets = require("functions.trinkets")
53
56
  local getTrinketName = ____trinkets.getTrinketName
57
+ local ____types = require("functions.types")
58
+ local isTable = ____types.isTable
59
+ local isUserdata = ____types.isUserdata
54
60
  local ____utils = require("functions.utils")
55
61
  local printConsole = ____utils.printConsole
56
62
  local ____vector = require("functions.vector")
@@ -447,7 +453,12 @@ function ____exports.logSounds()
447
453
  end
448
454
  end
449
455
  end
450
- function ____exports.logTable(____table, parentTables)
456
+ --- Helper function for logging every key and value of a table. This is a deep log; the function will
457
+ -- recursively call itself if it counters a table within a table.
458
+ --
459
+ -- This function will only work on tables that have string keys (because it logs the keys in order,
460
+ -- instead of randomly). It will throw a runtime error if it encounters a non-string key.
461
+ function ____exports.logTable(luaTable, parentTables)
451
462
  if parentTables == nil then
452
463
  parentTables = 0
453
464
  end
@@ -459,31 +470,29 @@ function ____exports.logTable(____table, parentTables)
459
470
  " ",
460
471
  math.floor(numSpaces)
461
472
  )
462
- local tableType = type(____table)
463
- if tableType ~= "table" then
464
- ____exports.log(((indentation .. "n/a (encountered a variable of type \"") .. tableType) .. "\" instead of a table)")
473
+ if not isTable(nil, luaTable) then
474
+ ____exports.log(((indentation .. "n/a (encountered a variable of type \"") .. __TS__TypeOf(luaTable)) .. "\" instead of a table)")
465
475
  return
466
476
  end
467
- local luaTable = ____table
468
- local keys = __TS__ObjectKeys(luaTable)
469
- __TS__ArraySort(keys)
470
- for ____, key in ipairs(keys) do
471
- local value = luaTable[key]
472
- ____exports.log(((indentation .. key) .. " --> ") .. tostring(value))
473
- local valueType = type(value)
474
- if valueType == "table" then
475
- if key == "__class" then
476
- ____exports.log(indentation .. "(skipping enumerating this key to avoid infinite recursion)")
477
- else
478
- ____exports.logTable(value, parentTables + 1)
477
+ iterateTableInOrder(
478
+ nil,
479
+ luaTable,
480
+ function(____, key, value)
481
+ ____exports.log(((indentation .. tostring(key)) .. " --> ") .. tostring(value))
482
+ if isTable(nil, value) then
483
+ if key == "__class" then
484
+ ____exports.log(indentation .. " (skipping enumerating this key to avoid infinite recursion)")
485
+ else
486
+ ____exports.logTable(value, parentTables + 1)
487
+ end
479
488
  end
480
489
  end
481
- end
482
- ____exports.log((indentation .. "The size of the table was: ") .. tostring(#keys))
490
+ )
491
+ ____exports.log((indentation .. "The size of the table was: ") .. tostring(#luaTable))
483
492
  end
484
493
  --- Helper function to print out the differences between the entries of two tables. Note that this
485
494
  -- will only do a shallow comparison.
486
- function ____exports.logTableDifferences(self, table1, table2)
495
+ function ____exports.logTableDifferences(table1, table2)
487
496
  ____exports.log("Comparing two Lua tables:")
488
497
  local table1Keys = __TS__ObjectKeys(table1)
489
498
  local table1KeysSet = __TS__New(Set, table1Keys)
@@ -517,8 +526,7 @@ end
517
526
  --- Helper function to enumerate all of the properties of a "userdata" object (i.e. an object from
518
527
  -- the Isaac API).
519
528
  function ____exports.logUserdata(userdata)
520
- local userdataType = type(userdata)
521
- if userdataType ~= "userdata" then
529
+ if isUserdata(nil, userdata) then
522
530
  ____exports.log("Userdata: [not userdata]")
523
531
  return
524
532
  end
@@ -569,6 +577,7 @@ function ____exports.setLogFunctionsGlobal(self)
569
577
  globals.logSet = ____exports.logSet
570
578
  globals.logSounds = ____exports.logSounds
571
579
  globals.logTable = ____exports.logTable
580
+ globals.logTableDifferences = ____exports.logTableDifferences
572
581
  globals.logTearFlags = ____exports.logTearFlags
573
582
  globals.logUseFlags = ____exports.logUseFlags
574
583
  globals.logUserdata = ____exports.logUserdata
package/functions/rng.lua CHANGED
@@ -1,4 +1,5 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__TypeOf = ____lualib.__TS__TypeOf
2
3
  local __TS__ObjectValues = ____lualib.__TS__ObjectValues
3
4
  local ____exports = {}
4
5
  local RECOMMENDED_SHIFT_IDX, OBJECT_NAME
@@ -14,6 +15,8 @@ local isIsaacAPIClassOfType = ____isaacAPIClass.isIsaacAPIClassOfType
14
15
  local ____table = require("functions.table")
15
16
  local getNumbersFromTable = ____table.getNumbersFromTable
16
17
  local tableHasKeys = ____table.tableHasKeys
18
+ local ____types = require("functions.types")
19
+ local isTable = ____types.isTable
17
20
  local ____utils = require("functions.utils")
18
21
  local ensureAllCases = ____utils.ensureAllCases
19
22
  --- Helper function to get a random `Seed` value to be used in spawning entities and so on. Use this
@@ -86,8 +89,7 @@ function ____exports.copyRNG(self, rng, serializationType)
86
89
  ____cond3 = ____cond3 or ____switch3 == SerializationType.DESERIALIZE
87
90
  if ____cond3 then
88
91
  do
89
- local rngType = type(rng)
90
- if ____exports.isRNG(nil, rng) or rngType ~= "table" then
92
+ if not isTable(nil, rng) then
91
93
  error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
92
94
  end
93
95
  local seedNumber = table.unpack(getNumbersFromTable(
@@ -110,16 +112,14 @@ end
110
112
  --- Used to determine is the given table is a serialized `RNG` object created by the save data
111
113
  -- manager and/or the `deepCopy` function.
112
114
  function ____exports.isSerializedRNG(self, object)
113
- local objectType = type(object)
114
- if objectType ~= "table" then
115
+ if not isTable(nil, object) then
115
116
  return false
116
117
  end
117
- local ____table = object
118
118
  return tableHasKeys(
119
119
  nil,
120
- ____table,
120
+ object,
121
121
  table.unpack(KEYS)
122
- ) and ____table[SerializationBrand.RNG] ~= nil
122
+ ) and object[SerializationBrand.RNG] ~= nil
123
123
  end
124
124
  function ____exports.rngEquals(self, rng1, rng2)
125
125
  return isaacAPIClassEquals(nil, rng1, rng2, KEYS)
@@ -127,12 +127,10 @@ end
127
127
  --- Helper function to iterate over the provided object and set the seed for all of the values that
128
128
  -- are RNG objects equal to a particular seed.
129
129
  function ____exports.setAllRNGToSeed(self, object, seed)
130
- local objectType = type(object)
131
- if objectType ~= "table" then
132
- error("Failed to iterate over the object containing RNG objects since the type of the provided object was: " .. objectType)
130
+ if not isTable(nil, object) then
131
+ error("Failed to iterate over the object containing RNG objects since the type of the provided object was: " .. __TS__TypeOf(object))
133
132
  end
134
- local ____table = object
135
- for ____, value in ipairs(__TS__ObjectValues(____table)) do
133
+ for ____, value in ipairs(__TS__ObjectValues(table)) do
136
134
  if ____exports.isRNG(nil, value) then
137
135
  ____exports.setSeed(nil, value, seed)
138
136
  end
@@ -5,7 +5,7 @@ export declare function copyIsaacAPIClass(isaacAPIClass: unknown, serializationT
5
5
  * Deserialization is a special case, so we make a dedicated function for this.
6
6
  *
7
7
  * There is no need for a corresponding "serializeIsaacAPIClass" function because the
8
- * "copyIsaacAPIClass" function can handles all serialization types.
8
+ * "copyIsaacAPIClass" function can handle all serialization types.
9
9
  */
10
10
  export declare function deserializeIsaacAPIClass(serializedIsaacAPIClass: SerializedIsaacAPIClass): unknown;
11
11
  export declare function isSerializedIsaacAPIClass(object: unknown): object is SerializedIsaacAPIClass;
@@ -1,4 +1,5 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__TypeOf = ____lualib.__TS__TypeOf
2
3
  local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
3
4
  local __TS__ObjectValues = ____lualib.__TS__ObjectValues
4
5
  local __TS__ArraySome = ____lualib.__TS__ArraySome
@@ -14,6 +15,9 @@ local ____serializedIsaacAPIClassTypeToIdentityFunction = require("objects.seria
14
15
  local SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION = ____serializedIsaacAPIClassTypeToIdentityFunction.SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION
15
16
  local ____isaacAPIClass = require("functions.isaacAPIClass")
16
17
  local getIsaacAPIClassName = ____isaacAPIClass.getIsaacAPIClassName
18
+ local ____types = require("functions.types")
19
+ local isTable = ____types.isTable
20
+ local isUserdata = ____types.isUserdata
17
21
  function getSerializedTableType(self, serializedIsaacAPIClass)
18
22
  for ____, ____value in ipairs(__TS__ObjectEntries(ISAAC_API_CLASS_TYPE_TO_BRAND)) do
19
23
  local copyableIsaacAPIClassType = ____value[1]
@@ -25,9 +29,8 @@ function getSerializedTableType(self, serializedIsaacAPIClass)
25
29
  return nil
26
30
  end
27
31
  function ____exports.copyIsaacAPIClass(self, isaacAPIClass, serializationType)
28
- local objectType = type(isaacAPIClass)
29
- if objectType ~= "userdata" then
30
- error("Failed to copy an Isaac API class since the provided object was of type: " .. objectType)
32
+ if not isUserdata(nil, isaacAPIClass) then
33
+ error("Failed to copy an Isaac API class since the provided object was of type: " .. __TS__TypeOf(isaacAPIClass))
31
34
  end
32
35
  local isaacAPIClassType = getIsaacAPIClassName(nil, isaacAPIClass)
33
36
  if isaacAPIClassType == nil then
@@ -43,11 +46,10 @@ end
43
46
  --- Deserialization is a special case, so we make a dedicated function for this.
44
47
  --
45
48
  -- There is no need for a corresponding "serializeIsaacAPIClass" function because the
46
- -- "copyIsaacAPIClass" function can handles all serialization types.
49
+ -- "copyIsaacAPIClass" function can handle all serialization types.
47
50
  function ____exports.deserializeIsaacAPIClass(self, serializedIsaacAPIClass)
48
- local objectType = type(serializedIsaacAPIClass)
49
- if objectType ~= "table" then
50
- error("Failed to deserialize an Isaac API class since the provided object was of type: " .. objectType)
51
+ if not isTable(nil, serializedIsaacAPIClass) then
52
+ error("Failed to deserialize an Isaac API class since the provided object was of type: " .. __TS__TypeOf(serializedIsaacAPIClass))
51
53
  end
52
54
  local copyableIsaacAPIClassType = getSerializedTableType(nil, serializedIsaacAPIClass)
53
55
  if copyableIsaacAPIClassType == nil then