isaacscript-common 1.2.250 → 1.2.251

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.
@@ -82,7 +82,7 @@ export declare function initArray<T>(defaultValue: T, size: int): T[];
82
82
  * - the table contains all numerical indexes that are contiguous, starting at 1
83
83
  * - the table has no keys (i.e. an "empty" table)
84
84
  */
85
- export declare function isArray(thing: unknown): boolean;
85
+ export declare function isArray(object: unknown): object is unknown[];
86
86
  /** Checks if an array is in the provided 2-dimensional array. */
87
87
  export declare function isArrayInArray<T>(arrayToMatch: T[] | readonly T[], parentArray: Array<T[] | readonly T[]>): boolean;
88
88
  /**
@@ -155,17 +155,17 @@ function ____exports.initArray(self, defaultValue, size)
155
155
  )
156
156
  return array
157
157
  end
158
- function ____exports.isArray(self, thing)
159
- if type(thing) ~= "table" then
158
+ function ____exports.isArray(self, object)
159
+ if type(object) ~= "table" then
160
160
  return false
161
161
  end
162
- local thingTable = thing
163
- local metatable = getmetatable(thingTable)
162
+ local ____table = object
163
+ local metatable = getmetatable(____table)
164
164
  if metatable ~= nil then
165
165
  return false
166
166
  end
167
167
  local numEntries = 0
168
- for key in pairs(thingTable) do
168
+ for key in pairs(____table) do
169
169
  numEntries = numEntries + 1
170
170
  if type(key) ~= "number" then
171
171
  return false
@@ -177,7 +177,7 @@ function ____exports.isArray(self, thing)
177
177
  do
178
178
  local i = 1
179
179
  while i <= numEntries do
180
- local element = thingTable[i]
180
+ local element = ____table[i]
181
181
  if element == nil then
182
182
  return false
183
183
  end
@@ -18,7 +18,7 @@ import { SerializationType } from "../enums/SerializationType";
18
18
  *
19
19
  * It does not support:
20
20
  * - objects with values of `null` (since that transpiles to `nil`)
21
- * - other Isaac API objects (that have a type of "userdata")
21
+ * - other Isaac API objects such as `EntityPtr` (that have a type of "userdata")
22
22
  *
23
23
  * @param value The primitive or object to copy.
24
24
  * @param serializationType Has 3 possible values. Can leave objects as-is, or can serialize objects
@@ -9,7 +9,7 @@ local __TS__ArrayPush = ____lualib.__TS__ArrayPush
9
9
  local __TS__Iterator = ____lualib.__TS__Iterator
10
10
  local __TS__ArraySome = ____lualib.__TS__ArraySome
11
11
  local ____exports = {}
12
- local deepCopyTable, deepCopyDefaultMap, deepCopyMap, deepCopySet, deepCopyTSTLClass, getCopiedEntries, checkMetatable, deepCopyUserdata, COPYABLE_ISAAC_API_CLASS_TYPES_SET
12
+ local deepCopyTable, deepCopyDefaultMap, deepCopyMap, deepCopySet, deepCopyTSTLClass, deepCopyArray, deepCopyNormalLuaTable, getCopiedEntries, checkMetatable, deepCopyUserdata, COPYABLE_ISAAC_API_CLASS_TYPES_SET
13
13
  local ____DefaultMap = require("classes.DefaultMap")
14
14
  local DefaultMap = ____DefaultMap.DefaultMap
15
15
  local ____CopyableIsaacAPIClassType = require("enums.private.CopyableIsaacAPIClassType")
@@ -21,6 +21,8 @@ local ____SerializationType = require("enums.SerializationType")
21
21
  local SerializationType = ____SerializationType.SerializationType
22
22
  local ____constants = require("features.saveDataManager.constants")
23
23
  local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
24
+ local ____array = require("functions.array")
25
+ local isArray = ____array.isArray
24
26
  local ____isaacAPIClass = require("functions.isaacAPIClass")
25
27
  local getIsaacAPIClassType = ____isaacAPIClass.getIsaacAPIClassType
26
28
  local ____log = require("functions.log")
@@ -102,10 +104,10 @@ function deepCopyTable(self, ____table, serializationType, traversalDescription)
102
104
  return deepCopySet(nil, ____table, serializationType, traversalDescription)
103
105
  end
104
106
  if __TS__InstanceOf(____table, WeakMap) then
105
- error("The deep copy function does not support copying the \"WeakMap\" class: " .. traversalDescription)
107
+ error("The deep copy function does not support copying the \"WeakMap\" class for: " .. traversalDescription)
106
108
  end
107
109
  if __TS__InstanceOf(____table, WeakSet) then
108
- error("The deep copy function does not support copying the \"WeakSet\" class: " .. traversalDescription)
110
+ error("The deep copy function does not support copying the \"WeakSet\" class for: " .. traversalDescription)
109
111
  end
110
112
  if isUserDefinedTSTLClass(nil, ____table) then
111
113
  return deepCopyTSTLClass(nil, ____table, serializationType, traversalDescription)
@@ -114,40 +116,31 @@ function deepCopyTable(self, ____table, serializationType, traversalDescription)
114
116
  if isSerializedIsaacAPIClass(nil, ____table) and serializationType == SerializationType.DESERIALIZE then
115
117
  return deserializeIsaacAPIClass(nil, ____table)
116
118
  end
117
- local newTable = {}
118
- local ____getCopiedEntries_result_0 = getCopiedEntries(nil, ____table, serializationType, traversalDescription)
119
- local entries = ____getCopiedEntries_result_0.entries
120
- local convertedNumberKeysToStrings = ____getCopiedEntries_result_0.convertedNumberKeysToStrings
121
- if convertedNumberKeysToStrings then
122
- newTable[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] = ""
123
- end
124
- for ____, ____value in ipairs(entries) do
125
- local key = ____value[1]
126
- local value = ____value[2]
127
- newTable[key] = value
119
+ if isArray(nil, ____table) then
120
+ return deepCopyArray(nil, ____table, serializationType, traversalDescription)
128
121
  end
129
- return newTable
122
+ return deepCopyNormalLuaTable(nil, ____table, serializationType, traversalDescription)
130
123
  end
131
124
  function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescription)
132
- local ____temp_1
125
+ local ____temp_0
133
126
  if __TS__InstanceOf(defaultMap, DefaultMap) then
134
- ____temp_1 = defaultMap:getConstructorArg()
127
+ ____temp_0 = defaultMap:getConstructorArg()
135
128
  else
136
- ____temp_1 = nil
129
+ ____temp_0 = nil
137
130
  end
138
- local constructorArg = ____temp_1
131
+ local constructorArg = ____temp_0
139
132
  local newDefaultMap
140
133
  repeat
141
- local ____switch25 = serializationType
142
- local ____cond25 = ____switch25 == SerializationType.NONE
143
- if ____cond25 then
134
+ local ____switch23 = serializationType
135
+ local ____cond23 = ____switch23 == SerializationType.NONE
136
+ if ____cond23 then
144
137
  do
145
138
  newDefaultMap = __TS__New(DefaultMap, constructorArg)
146
139
  break
147
140
  end
148
141
  end
149
- ____cond25 = ____cond25 or ____switch25 == SerializationType.SERIALIZE
150
- if ____cond25 then
142
+ ____cond23 = ____cond23 or ____switch23 == SerializationType.SERIALIZE
143
+ if ____cond23 then
151
144
  do
152
145
  if type(constructorArg) ~= "boolean" and type(constructorArg) ~= "number" and type(constructorArg) ~= "string" then
153
146
  return deepCopyMap(nil, defaultMap, serializationType, traversalDescription)
@@ -158,8 +151,8 @@ function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescri
158
151
  break
159
152
  end
160
153
  end
161
- ____cond25 = ____cond25 or ____switch25 == SerializationType.DESERIALIZE
162
- if ____cond25 then
154
+ ____cond23 = ____cond23 or ____switch23 == SerializationType.DESERIALIZE
155
+ if ____cond23 then
163
156
  do
164
157
  if __TS__InstanceOf(defaultMap, DefaultMap) then
165
158
  error(("The deep copy function failed to deserialize a default map of \"" .. traversalDescription) .. "\", since it was not a Lua table.")
@@ -178,9 +171,9 @@ function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescri
178
171
  end
179
172
  end
180
173
  until true
181
- local ____getCopiedEntries_result_2 = getCopiedEntries(nil, defaultMap, serializationType, traversalDescription)
182
- local entries = ____getCopiedEntries_result_2.entries
183
- local convertedNumberKeysToStrings = ____getCopiedEntries_result_2.convertedNumberKeysToStrings
174
+ local ____getCopiedEntries_result_1 = getCopiedEntries(nil, defaultMap, serializationType, traversalDescription)
175
+ local entries = ____getCopiedEntries_result_1.entries
176
+ local convertedNumberKeysToStrings = ____getCopiedEntries_result_1.convertedNumberKeysToStrings
184
177
  if convertedNumberKeysToStrings then
185
178
  if __TS__InstanceOf(newDefaultMap, DefaultMap) then
186
179
  newDefaultMap:set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "")
@@ -207,9 +200,9 @@ function deepCopyMap(self, map, serializationType, traversalDescription)
207
200
  else
208
201
  newMap = __TS__New(Map)
209
202
  end
210
- local ____getCopiedEntries_result_3 = getCopiedEntries(nil, map, serializationType, traversalDescription)
211
- local entries = ____getCopiedEntries_result_3.entries
212
- local convertedNumberKeysToStrings = ____getCopiedEntries_result_3.convertedNumberKeysToStrings
203
+ local ____getCopiedEntries_result_2 = getCopiedEntries(nil, map, serializationType, traversalDescription)
204
+ local entries = ____getCopiedEntries_result_2.entries
205
+ local convertedNumberKeysToStrings = ____getCopiedEntries_result_2.convertedNumberKeysToStrings
213
206
  if convertedNumberKeysToStrings then
214
207
  if __TS__InstanceOf(newMap, Map) then
215
208
  newMap:set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "")
@@ -236,9 +229,9 @@ function deepCopySet(self, set, serializationType, traversalDescription)
236
229
  else
237
230
  newSet = __TS__New(Set)
238
231
  end
239
- local ____getCopiedEntries_result_4 = getCopiedEntries(nil, set, serializationType, traversalDescription)
240
- local entries = ____getCopiedEntries_result_4.entries
241
- local convertedNumberKeysToStrings = ____getCopiedEntries_result_4.convertedNumberKeysToStrings
232
+ local ____getCopiedEntries_result_3 = getCopiedEntries(nil, set, serializationType, traversalDescription)
233
+ local entries = ____getCopiedEntries_result_3.entries
234
+ local convertedNumberKeysToStrings = ____getCopiedEntries_result_3.convertedNumberKeysToStrings
242
235
  if convertedNumberKeysToStrings then
243
236
  if __TS__InstanceOf(newSet, Set) then
244
237
  error("The deep copy function cannot convert number keys to strings for a Set.")
@@ -263,9 +256,9 @@ function deepCopyTSTLClass(self, tstlClass, serializationType, traversalDescript
263
256
  else
264
257
  newClass = newTSTLClass(nil, tstlClass)
265
258
  end
266
- local ____getCopiedEntries_result_5 = getCopiedEntries(nil, tstlClass, serializationType, traversalDescription)
267
- local entries = ____getCopiedEntries_result_5.entries
268
- local convertedNumberKeysToStrings = ____getCopiedEntries_result_5.convertedNumberKeysToStrings
259
+ local ____getCopiedEntries_result_4 = getCopiedEntries(nil, tstlClass, serializationType, traversalDescription)
260
+ local entries = ____getCopiedEntries_result_4.entries
261
+ local convertedNumberKeysToStrings = ____getCopiedEntries_result_4.convertedNumberKeysToStrings
269
262
  if convertedNumberKeysToStrings then
270
263
  newClass[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] = ""
271
264
  end
@@ -276,6 +269,29 @@ function deepCopyTSTLClass(self, tstlClass, serializationType, traversalDescript
276
269
  end
277
270
  return newClass
278
271
  end
272
+ function deepCopyArray(self, array, serializationType, traversalDescription)
273
+ local newArray = {}
274
+ for ____, value in ipairs(array) do
275
+ local newValue = ____exports.deepCopy(nil, value, serializationType, traversalDescription)
276
+ __TS__ArrayPush(newArray, newValue)
277
+ end
278
+ return newArray
279
+ end
280
+ function deepCopyNormalLuaTable(self, ____table, serializationType, traversalDescription)
281
+ local newTable = {}
282
+ local ____getCopiedEntries_result_5 = getCopiedEntries(nil, ____table, serializationType, traversalDescription)
283
+ local entries = ____getCopiedEntries_result_5.entries
284
+ local convertedNumberKeysToStrings = ____getCopiedEntries_result_5.convertedNumberKeysToStrings
285
+ if convertedNumberKeysToStrings then
286
+ newTable[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] = ""
287
+ end
288
+ for ____, ____value in ipairs(entries) do
289
+ local key = ____value[1]
290
+ local value = ____value[2]
291
+ newTable[key] = value
292
+ end
293
+ return newTable
294
+ end
279
295
  function getCopiedEntries(self, object, serializationType, traversalDescription)
280
296
  local entries = {}
281
297
  if __TS__InstanceOf(object, Map) or __TS__InstanceOf(object, Set) then
@@ -304,14 +320,14 @@ function getCopiedEntries(self, object, serializationType, traversalDescription)
304
320
  local value = ____value[2]
305
321
  do
306
322
  if isSerializationBrand(nil, key) then
307
- goto __continue73
323
+ goto __continue78
308
324
  end
309
325
  traversalDescription = getTraversalDescription(nil, key, traversalDescription)
310
326
  local newValue = ____exports.deepCopy(nil, value, serializationType, traversalDescription)
311
327
  local keyToUse = convertNumberKeysToStrings and tostring(key) or key
312
328
  __TS__ArrayPush(copiedEntries, {keyToUse, newValue})
313
329
  end
314
- ::__continue73::
330
+ ::__continue78::
315
331
  end
316
332
  return {entries = copiedEntries, convertedNumberKeysToStrings = convertNumberKeysToStrings}
317
333
  end
@@ -31,7 +31,7 @@ function ____exports.copyIsaacAPIClass(self, isaacAPIClass, serializationType)
31
31
  end
32
32
  local isaacAPIClassType = getIsaacAPIClassType(nil, isaacAPIClass)
33
33
  if isaacAPIClassType == nil then
34
- error("Failed to copy an Isaac API class due to it not having a class type.")
34
+ error("Failed to copy an Isaac API class since it does not have a class type.")
35
35
  end
36
36
  local copyableIsaacAPIClassType = isaacAPIClassType
37
37
  local copyFunction = ISAAC_API_CLASS_TYPE_TO_COPY_FUNCTION[copyableIsaacAPIClassType]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.250",
3
+ "version": "1.2.251",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",