isaacscript-common 3.15.0 → 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.
- package/callbacks/postPlayerFatalDamage.lua +27 -1
- package/classes/DefaultMap.lua +6 -4
- package/enums/ModCallbackCustom.d.ts +1 -1
- package/features/deployJSONRoom.lua +62 -17
- package/features/saveDataManager/exports.lua +7 -6
- package/features/saveDataManager/load.lua +7 -5
- package/features/saveDataManager/main.lua +2 -2
- package/features/saveDataManager/merge.lua +12 -16
- package/features/saveDataManager/save.lua +2 -2
- package/features/saveDataManager/serializationBrand.lua +3 -1
- package/functions/ambush.lua +1 -1
- package/functions/array.d.ts +1 -0
- package/functions/array.lua +18 -12
- package/functions/color.lua +6 -7
- package/functions/deepCopy.lua +27 -24
- package/functions/deepCopyTests.lua +23 -27
- package/functions/entity.d.ts +4 -1
- package/functions/entity.lua +22 -25
- package/functions/enums.lua +3 -1
- package/functions/gridEntity.d.ts +3 -3
- package/functions/gridEntity.lua +7 -7
- package/functions/isaacAPIClass.lua +5 -3
- package/functions/jsonHelpers.d.ts +1 -1
- package/functions/jsonHelpers.lua +4 -4
- package/functions/kColor.lua +6 -7
- package/functions/log.d.ts +9 -2
- package/functions/log.lua +30 -21
- package/functions/rng.lua +10 -12
- package/functions/serialization.d.ts +1 -1
- package/functions/serialization.lua +9 -7
- package/functions/table.d.ts +14 -10
- package/functions/table.lua +54 -37
- package/functions/tstlClass.lua +6 -4
- package/functions/types.d.ts +10 -0
- package/functions/types.lua +25 -0
- package/functions/utils.d.ts +0 -2
- package/functions/utils.lua +0 -6
- package/functions/vector.lua +6 -7
- package/index.d.ts +1 -0
- package/index.lua +8 -0
- package/package.json +1 -1
package/functions/deepCopy.lua
CHANGED
|
@@ -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
|
|
110
|
-
return deepCopyTable(nil,
|
|
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,
|
|
127
|
-
if isDefaultMap(nil,
|
|
128
|
-
return deepCopyDefaultMap(nil,
|
|
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,
|
|
131
|
-
return deepCopyMap(nil,
|
|
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,
|
|
134
|
-
return deepCopySet(nil,
|
|
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,
|
|
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,
|
|
144
|
-
return deepCopyTSTLClass(nil,
|
|
146
|
+
if isUserDefinedTSTLClass(nil, luaTable) then
|
|
147
|
+
return deepCopyTSTLClass(nil, luaTable, serializationType, traversalDescription)
|
|
145
148
|
end
|
|
146
|
-
checkMetatable(nil,
|
|
147
|
-
if isSerializedIsaacAPIClass(nil,
|
|
148
|
-
return deserializeIsaacAPIClass(nil,
|
|
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,
|
|
151
|
-
return deepCopyArray(nil,
|
|
153
|
+
if isArray(nil, luaTable) then
|
|
154
|
+
return deepCopyArray(nil, luaTable, serializationType, traversalDescription)
|
|
152
155
|
end
|
|
153
|
-
return deepCopyNormalLuaTable(nil,
|
|
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
|
|
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,
|
|
314
|
+
function deepCopyNormalLuaTable(self, luaTable, serializationType, traversalDescription)
|
|
312
315
|
local newTable = {}
|
|
313
|
-
local ____getCopiedEntries_result_5 = getCopiedEntries(nil,
|
|
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
|
|
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,
|
|
370
|
-
local metatable = getmetatable(
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
153
|
-
|
|
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
|
-
|
|
161
|
-
|
|
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
|
-
|
|
176
|
-
|
|
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
|
-
|
|
205
|
-
|
|
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
|
-
|
|
238
|
-
|
|
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
|
-
|
|
272
|
-
|
|
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.")
|
package/functions/entity.d.ts
CHANGED
|
@@ -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,
|
|
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
|
/**
|
package/functions/entity.lua
CHANGED
|
@@ -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
|
|
20
|
-
local 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
|
-
|
|
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
|
-
|
|
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.
|
package/functions/enums.lua
CHANGED
|
@@ -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
|
|
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[]):
|
|
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
|
|
103
|
+
* @returns An array of the grid entities removed.
|
|
104
104
|
*/
|
|
105
|
-
export declare function removeAllMatchingGridEntities(...gridEntityType: GridEntityType[]):
|
|
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
|
*
|
package/functions/gridEntity.lua
CHANGED
|
@@ -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
|
|
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
|
-
|
|
290
|
+
removedGridEntities[#removedGridEntities + 1] = gridEntity
|
|
291
291
|
end
|
|
292
292
|
end
|
|
293
|
-
if
|
|
293
|
+
if #removedGridEntities > 0 then
|
|
294
294
|
roomUpdateSafe(nil)
|
|
295
295
|
end
|
|
296
|
-
return
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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(
|
|
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(
|
|
9
|
-
return json.encode(
|
|
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,
|
|
31
|
-
local ok, jsonStringOrErrMsg = pcall(tryEncode,
|
|
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
|
package/functions/kColor.lua
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
102
|
+
object,
|
|
104
103
|
table.unpack(KEYS)
|
|
105
|
-
) and
|
|
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)
|
package/functions/log.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
463
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
-
|
|
482
|
-
____exports.log((indentation .. "The size of the table was: ") .. tostring(#
|
|
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(
|
|
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
|
-
|
|
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
|