isaacscript-common 3.15.2 → 3.16.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.
Files changed (47) hide show
  1. package/callbacks/postPlayerFatalDamage.lua +3 -3
  2. package/callbacks/postSlotDestroyed.lua +9 -7
  3. package/callbacks/subscriptions/postSlotDestroyed.d.ts +4 -2
  4. package/callbacks/subscriptions/postSlotDestroyed.lua +8 -4
  5. package/classes/DefaultMap.lua +6 -4
  6. package/constants.d.ts +2 -0
  7. package/constants.lua +2 -0
  8. package/enums/ModCallbackCustom.d.ts +10 -8
  9. package/enums/SlotDestructionType.d.ts +4 -0
  10. package/enums/SlotDestructionType.lua +7 -0
  11. package/features/deployJSONRoom.lua +62 -17
  12. package/features/saveDataManager/exports.lua +7 -6
  13. package/features/saveDataManager/load.lua +7 -5
  14. package/features/saveDataManager/main.lua +2 -2
  15. package/features/saveDataManager/merge.lua +12 -16
  16. package/features/saveDataManager/save.lua +2 -2
  17. package/features/saveDataManager/serializationBrand.lua +3 -1
  18. package/functions/array.d.ts +1 -0
  19. package/functions/array.lua +18 -12
  20. package/functions/color.lua +6 -7
  21. package/functions/deepCopy.lua +27 -24
  22. package/functions/deepCopyTests.lua +23 -27
  23. package/functions/entity.d.ts +4 -1
  24. package/functions/entity.lua +22 -25
  25. package/functions/enums.lua +3 -1
  26. package/functions/gridEntity.d.ts +3 -3
  27. package/functions/gridEntity.lua +7 -7
  28. package/functions/isaacAPIClass.lua +5 -3
  29. package/functions/jsonHelpers.d.ts +1 -1
  30. package/functions/jsonHelpers.lua +4 -4
  31. package/functions/kColor.lua +6 -7
  32. package/functions/log.d.ts +9 -2
  33. package/functions/log.lua +30 -21
  34. package/functions/rng.lua +10 -12
  35. package/functions/serialization.d.ts +1 -1
  36. package/functions/serialization.lua +9 -7
  37. package/functions/table.d.ts +14 -10
  38. package/functions/table.lua +54 -37
  39. package/functions/tstlClass.lua +6 -4
  40. package/functions/types.d.ts +10 -0
  41. package/functions/types.lua +25 -0
  42. package/functions/utils.d.ts +0 -2
  43. package/functions/utils.lua +0 -6
  44. package/functions/vector.lua +6 -7
  45. package/index.d.ts +1 -0
  46. package/index.lua +8 -0
  47. package/package.json +2 -2
@@ -8,6 +8,7 @@ local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
8
8
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
9
9
  local __TS__ArraySort = ____lualib.__TS__ArraySort
10
10
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
11
+ local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
11
12
  local __TS__ArraySome = ____lualib.__TS__ArraySome
12
13
  local __TS__ArrayReduce = ____lualib.__TS__ArrayReduce
13
14
  local ____exports = {}
@@ -17,6 +18,9 @@ local ____rng = require("functions.rng")
17
18
  local getRandomSeed = ____rng.getRandomSeed
18
19
  local isRNG = ____rng.isRNG
19
20
  local newRNG = ____rng.newRNG
21
+ local ____types = require("functions.types")
22
+ local isNumber = ____types.isNumber
23
+ local isTable = ____types.isTable
20
24
  local ____utils = require("functions.utils")
21
25
  local erange = ____utils.erange
22
26
  local ____repeat = ____utils["repeat"]
@@ -193,6 +197,7 @@ function ____exports.copyArray(self, oldArray, numElements)
193
197
  end
194
198
  return newArray
195
199
  end
200
+ --- Helper function to remove all of the elements in an array in-place.
196
201
  function ____exports.emptyArray(self, array)
197
202
  __TS__ArraySplice(array, 0, #array)
198
203
  end
@@ -278,28 +283,29 @@ end
278
283
  -- - the table contains all numerical indexes that are contiguous, starting at 1
279
284
  -- - the table has no keys (i.e. an "empty" table)
280
285
  function ____exports.isArray(self, object)
281
- if type(object) ~= "table" then
286
+ if not isTable(nil, object) then
282
287
  return false
283
288
  end
284
- local ____table = object
285
- local metatable = getmetatable(____table)
289
+ local metatable = getmetatable(object)
286
290
  if metatable ~= nil then
287
291
  return false
288
292
  end
289
- local numEntries = 0
290
- for key in pairs(____table) do
291
- numEntries = numEntries + 1
292
- if type(key) ~= "number" then
293
- return false
294
- end
293
+ local keys = __TS__ObjectKeys(object)
294
+ local hasAllNumberKeys = __TS__ArrayEvery(
295
+ keys,
296
+ function(____, key) return isNumber(nil, key) end
297
+ )
298
+ if not hasAllNumberKeys then
299
+ return false
295
300
  end
296
- if numEntries == 0 then
301
+ local tableLength = #object
302
+ if tableLength == 0 then
297
303
  return true
298
304
  end
299
305
  do
300
306
  local i = 1
301
- while i <= numEntries do
302
- local element = ____table[i]
307
+ while i <= tableLength do
308
+ local element = object[i]
303
309
  if element == nil then
304
310
  return false
305
311
  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 Color object.
@@ -73,8 +75,7 @@ function ____exports.copyColor(self, color, serializationType)
73
75
  ____cond4 = ____cond4 or ____switch4 == SerializationType.DESERIALIZE
74
76
  if ____cond4 then
75
77
  do
76
- local colorType = type(color)
77
- if ____exports.isColor(nil, color) or colorType ~= "table" then
78
+ if not isTable(nil, color) then
78
79
  error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
79
80
  end
80
81
  local r, g, b, a, ro, go, bo = table.unpack(getNumbersFromTable(
@@ -117,15 +118,13 @@ end
117
118
  --- Used to determine is the given table is a serialized `Color` object created by the save data
118
119
  -- manager and/or the `deepCopy` function.
119
120
  function ____exports.isSerializedColor(self, object)
120
- local objectType = type(object)
121
- if objectType ~= "table" then
121
+ if not isTable(nil, object) then
122
122
  return false
123
123
  end
124
- local ____table = object
125
124
  return tableHasKeys(
126
125
  nil,
127
- ____table,
126
+ object,
128
127
  table.unpack(KEYS)
129
- ) and ____table[SerializationBrand.COLOR] ~= nil
128
+ ) and object[SerializationBrand.COLOR] ~= nil
130
129
  end
131
130
  return ____exports
@@ -39,6 +39,9 @@ local isTSTLMap = ____tstlClass.isTSTLMap
39
39
  local isTSTLSet = ____tstlClass.isTSTLSet
40
40
  local isUserDefinedTSTLClass = ____tstlClass.isUserDefinedTSTLClass
41
41
  local newTSTLClass = ____tstlClass.newTSTLClass
42
+ local ____types = require("functions.types")
43
+ local isNumber = ____types.isNumber
44
+ local isPrimitive = ____types.isPrimitive
42
45
  local ____utils = require("functions.utils")
43
46
  local ensureAllCases = ____utils.ensureAllCases
44
47
  local getTraversalDescription = ____utils.getTraversalDescription
@@ -106,8 +109,8 @@ function ____exports.deepCopy(self, value, serializationType, traversalDescripti
106
109
  ____cond6 = ____cond6 or ____switch6 == "table"
107
110
  if ____cond6 then
108
111
  do
109
- local valueTable = value
110
- return deepCopyTable(nil, valueTable, serializationType, traversalDescription)
112
+ local luaTable = value
113
+ return deepCopyTable(nil, luaTable, serializationType, traversalDescription)
111
114
  end
112
115
  end
113
116
  ____cond6 = ____cond6 or ____switch6 == "userdata"
@@ -123,34 +126,34 @@ function ____exports.deepCopy(self, value, serializationType, traversalDescripti
123
126
  end
124
127
  until true
125
128
  end
126
- function deepCopyTable(self, ____table, serializationType, traversalDescription)
127
- if isDefaultMap(nil, ____table) or ____table[SerializationBrand.DEFAULT_MAP] ~= nil then
128
- return deepCopyDefaultMap(nil, ____table, serializationType, traversalDescription)
129
+ function deepCopyTable(self, luaTable, serializationType, traversalDescription)
130
+ if isDefaultMap(nil, luaTable) or luaTable[SerializationBrand.DEFAULT_MAP] ~= nil then
131
+ return deepCopyDefaultMap(nil, luaTable, serializationType, traversalDescription)
129
132
  end
130
- if isTSTLMap(nil, ____table) or ____table[SerializationBrand.MAP] ~= nil then
131
- return deepCopyMap(nil, ____table, serializationType, traversalDescription)
133
+ if isTSTLMap(nil, luaTable) or luaTable[SerializationBrand.MAP] ~= nil then
134
+ return deepCopyMap(nil, luaTable, serializationType, traversalDescription)
132
135
  end
133
- if isTSTLSet(nil, ____table) or ____table[SerializationBrand.SET] ~= nil then
134
- return deepCopySet(nil, ____table, serializationType, traversalDescription)
136
+ if isTSTLSet(nil, luaTable) or luaTable[SerializationBrand.SET] ~= nil then
137
+ return deepCopySet(nil, luaTable, serializationType, traversalDescription)
135
138
  end
136
- local className = getTSTLClassName(nil, ____table)
139
+ local className = getTSTLClassName(nil, luaTable)
137
140
  if className == "WeakMap" then
138
141
  error("The deep copy function does not support copying the \"WeakMap\" class for: " .. traversalDescription)
139
142
  end
140
143
  if className == "WeakSet" then
141
144
  error("The deep copy function does not support copying the \"WeakSet\" class for: " .. traversalDescription)
142
145
  end
143
- if isUserDefinedTSTLClass(nil, ____table) then
144
- return deepCopyTSTLClass(nil, ____table, serializationType, traversalDescription)
146
+ if isUserDefinedTSTLClass(nil, luaTable) then
147
+ return deepCopyTSTLClass(nil, luaTable, serializationType, traversalDescription)
145
148
  end
146
- checkMetatable(nil, ____table, traversalDescription)
147
- if isSerializedIsaacAPIClass(nil, ____table) and serializationType == SerializationType.DESERIALIZE then
148
- return deserializeIsaacAPIClass(nil, ____table)
149
+ checkMetatable(nil, luaTable, traversalDescription)
150
+ if isSerializedIsaacAPIClass(nil, luaTable) and serializationType == SerializationType.DESERIALIZE then
151
+ return deserializeIsaacAPIClass(nil, luaTable)
149
152
  end
150
- if isArray(nil, ____table) then
151
- return deepCopyArray(nil, ____table, serializationType, traversalDescription)
153
+ if isArray(nil, luaTable) then
154
+ return deepCopyArray(nil, luaTable, serializationType, traversalDescription)
152
155
  end
153
- return deepCopyNormalLuaTable(nil, ____table, serializationType, traversalDescription)
156
+ return deepCopyNormalLuaTable(nil, luaTable, serializationType, traversalDescription)
154
157
  end
155
158
  function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescription)
156
159
  local ____isDefaultMap_result_0
@@ -173,7 +176,7 @@ function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescri
173
176
  ____cond23 = ____cond23 or ____switch23 == SerializationType.SERIALIZE
174
177
  if ____cond23 then
175
178
  do
176
- if type(constructorArg) ~= "boolean" and type(constructorArg) ~= "number" and type(constructorArg) ~= "string" then
179
+ if not isPrimitive(nil, constructorArg) then
177
180
  return deepCopyMap(nil, defaultMap, serializationType, traversalDescription)
178
181
  end
179
182
  newDefaultMap = {}
@@ -308,9 +311,9 @@ function deepCopyArray(self, array, serializationType, traversalDescription)
308
311
  end
309
312
  return newArray
310
313
  end
311
- function deepCopyNormalLuaTable(self, ____table, serializationType, traversalDescription)
314
+ function deepCopyNormalLuaTable(self, luaTable, serializationType, traversalDescription)
312
315
  local newTable = {}
313
- local ____getCopiedEntries_result_5 = getCopiedEntries(nil, ____table, serializationType, traversalDescription)
316
+ local ____getCopiedEntries_result_5 = getCopiedEntries(nil, luaTable, serializationType, traversalDescription)
314
317
  local entries = ____getCopiedEntries_result_5.entries
315
318
  local convertedNumberKeysToStrings = ____getCopiedEntries_result_5.convertedNumberKeysToStrings
316
319
  if convertedNumberKeysToStrings then
@@ -345,7 +348,7 @@ function getCopiedEntries(self, object, serializationType, traversalDescription)
345
348
  function(____, ____bindingPattern0)
346
349
  local key
347
350
  key = ____bindingPattern0[1]
348
- return type(key) == "number"
351
+ return isNumber(nil, key)
349
352
  end
350
353
  )
351
354
  local convertNumberKeysToStrings = serializationType == SerializationType.SERIALIZE and hasNumberKeys
@@ -366,8 +369,8 @@ function getCopiedEntries(self, object, serializationType, traversalDescription)
366
369
  end
367
370
  return {entries = copiedEntries, convertedNumberKeysToStrings = convertNumberKeysToStrings}
368
371
  end
369
- function checkMetatable(self, ____table, traversalDescription)
370
- local metatable = getmetatable(____table)
372
+ function checkMetatable(self, luaTable, traversalDescription)
373
+ local metatable = getmetatable(luaTable)
371
374
  if metatable == nil then
372
375
  return
373
376
  end
@@ -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. */