isaacscript-common 1.2.250 → 1.2.253
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/features/saveDataManager/merge.lua +11 -17
- package/dist/functions/array.d.ts +1 -1
- package/dist/functions/array.lua +6 -6
- package/dist/functions/deepCopy.d.ts +1 -1
- package/dist/functions/deepCopy.lua +56 -40
- package/dist/functions/familiars.d.ts +27 -18
- package/dist/functions/familiars.lua +14 -49
- package/dist/functions/serialization.lua +1 -1
- package/dist/functions/utils.d.ts +5 -0
- package/dist/functions/utils.lua +5 -0
- package/package.json +2 -2
|
@@ -36,7 +36,9 @@ function ____exports.merge(self, oldObject, newTable, traversalDescription)
|
|
|
36
36
|
if newTableType ~= "table" then
|
|
37
37
|
error("The second argument given to the merge function is not a table.")
|
|
38
38
|
end
|
|
39
|
-
if
|
|
39
|
+
if isArray(nil, oldObject) and isArray(nil, newTable) then
|
|
40
|
+
local oldTable = oldObject
|
|
41
|
+
mergeArray(nil, oldTable, newTable)
|
|
40
42
|
return
|
|
41
43
|
end
|
|
42
44
|
if __TS__InstanceOf(oldObject, Map) or __TS__InstanceOf(oldObject, Set) then
|
|
@@ -45,16 +47,11 @@ function ____exports.merge(self, oldObject, newTable, traversalDescription)
|
|
|
45
47
|
mergeTable(nil, oldObject, newTable, traversalDescription)
|
|
46
48
|
end
|
|
47
49
|
end
|
|
48
|
-
function mergeArray(self,
|
|
49
|
-
local oldArray = oldObject
|
|
50
|
-
if not isArray(nil, oldArray) or not isArray(nil, newTable) then
|
|
51
|
-
return false
|
|
52
|
-
end
|
|
50
|
+
function mergeArray(self, oldArray, newArray)
|
|
53
51
|
clearTable(nil, oldArray)
|
|
54
|
-
for key, value in pairs(
|
|
52
|
+
for key, value in pairs(newArray) do
|
|
55
53
|
oldArray[key] = value
|
|
56
54
|
end
|
|
57
|
-
return true
|
|
58
55
|
end
|
|
59
56
|
function mergeTSTLObject(self, oldObject, newTable, traversalDescription)
|
|
60
57
|
oldObject:clear()
|
|
@@ -62,13 +59,13 @@ function mergeTSTLObject(self, oldObject, newTable, traversalDescription)
|
|
|
62
59
|
for key, value in pairs(newTable) do
|
|
63
60
|
do
|
|
64
61
|
if isSerializationBrand(nil, key) then
|
|
65
|
-
goto
|
|
62
|
+
goto __continue12
|
|
66
63
|
end
|
|
67
64
|
local keyToUse = key
|
|
68
65
|
if convertStringKeysToNumbers then
|
|
69
66
|
local numberKey = tonumber(key)
|
|
70
67
|
if numberKey == nil then
|
|
71
|
-
goto
|
|
68
|
+
goto __continue12
|
|
72
69
|
end
|
|
73
70
|
keyToUse = numberKey
|
|
74
71
|
end
|
|
@@ -85,13 +82,10 @@ function mergeTSTLObject(self, oldObject, newTable, traversalDescription)
|
|
|
85
82
|
oldObject:add(keyToUse)
|
|
86
83
|
end
|
|
87
84
|
end
|
|
88
|
-
::
|
|
85
|
+
::__continue12::
|
|
89
86
|
end
|
|
90
87
|
end
|
|
91
88
|
function mergeTable(self, oldTable, newTable, traversalDescription)
|
|
92
|
-
if SAVE_DATA_MANAGER_DEBUG then
|
|
93
|
-
log("merge is operating on a table. Iterating through the keys...")
|
|
94
|
-
end
|
|
95
89
|
for key, value in pairs(newTable) do
|
|
96
90
|
do
|
|
97
91
|
if SAVE_DATA_MANAGER_DEBUG then
|
|
@@ -99,7 +93,7 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
|
|
|
99
93
|
log((("merge is merging: " .. traversalDescription) .. " --> ") .. valueToPrint)
|
|
100
94
|
end
|
|
101
95
|
if isSerializationBrand(nil, key) then
|
|
102
|
-
goto
|
|
96
|
+
goto __continue21
|
|
103
97
|
end
|
|
104
98
|
if isSerializedIsaacAPIClass(nil, value) then
|
|
105
99
|
if SAVE_DATA_MANAGER_DEBUG then
|
|
@@ -107,7 +101,7 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
|
|
|
107
101
|
end
|
|
108
102
|
local deserializedObject = deserializeIsaacAPIClass(nil, value)
|
|
109
103
|
oldTable[key] = deserializedObject
|
|
110
|
-
goto
|
|
104
|
+
goto __continue21
|
|
111
105
|
end
|
|
112
106
|
local valueType = type(value)
|
|
113
107
|
if valueType == "table" then
|
|
@@ -123,7 +117,7 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
|
|
|
123
117
|
oldTable[key] = value
|
|
124
118
|
end
|
|
125
119
|
end
|
|
126
|
-
::
|
|
120
|
+
::__continue21::
|
|
127
121
|
end
|
|
128
122
|
end
|
|
129
123
|
return ____exports
|
|
@@ -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(
|
|
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
|
/**
|
package/dist/functions/array.lua
CHANGED
|
@@ -155,17 +155,17 @@ function ____exports.initArray(self, defaultValue, size)
|
|
|
155
155
|
)
|
|
156
156
|
return array
|
|
157
157
|
end
|
|
158
|
-
function ____exports.isArray(self,
|
|
159
|
-
if type(
|
|
158
|
+
function ____exports.isArray(self, object)
|
|
159
|
+
if type(object) ~= "table" then
|
|
160
160
|
return false
|
|
161
161
|
end
|
|
162
|
-
local
|
|
163
|
-
local metatable = getmetatable(
|
|
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(
|
|
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 =
|
|
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
|
-
|
|
118
|
-
|
|
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
|
|
122
|
+
return deepCopyNormalLuaTable(nil, ____table, serializationType, traversalDescription)
|
|
130
123
|
end
|
|
131
124
|
function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescription)
|
|
132
|
-
local
|
|
125
|
+
local ____temp_0
|
|
133
126
|
if __TS__InstanceOf(defaultMap, DefaultMap) then
|
|
134
|
-
|
|
127
|
+
____temp_0 = defaultMap:getConstructorArg()
|
|
135
128
|
else
|
|
136
|
-
|
|
129
|
+
____temp_0 = nil
|
|
137
130
|
end
|
|
138
|
-
local constructorArg =
|
|
131
|
+
local constructorArg = ____temp_0
|
|
139
132
|
local newDefaultMap
|
|
140
133
|
repeat
|
|
141
|
-
local
|
|
142
|
-
local
|
|
143
|
-
if
|
|
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
|
-
|
|
150
|
-
if
|
|
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
|
-
|
|
162
|
-
if
|
|
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
|
|
182
|
-
local entries =
|
|
183
|
-
local 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
|
|
211
|
-
local entries =
|
|
212
|
-
local 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
|
|
240
|
-
local entries =
|
|
241
|
-
local 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
|
|
267
|
-
local entries =
|
|
268
|
-
local 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
|
|
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
|
-
::
|
|
330
|
+
::__continue78::
|
|
315
331
|
end
|
|
316
332
|
return {entries = copiedEntries, convertedNumberKeysToStrings = convertNumberKeysToStrings}
|
|
317
333
|
end
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
/// <reference types="isaac-typescript-definitions" />
|
|
2
2
|
/**
|
|
3
|
-
* Helper function to add and remove familiars based on a target amount that you specify.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* Helper function to add and remove familiars based on a target amount that you specify.
|
|
4
|
+
*
|
|
5
|
+
* This is a convenience wrapper around the `EntityPlayer.CheckFamiliar` method. Use this helper
|
|
6
|
+
* function instead so that you do not have to retrieve the `ItemConfigItem` and so that you do not
|
|
7
|
+
* specify an incorrect RNG object. (The vanilla method is bugged in that it does not increment the
|
|
8
|
+
* RNG object; see the documentation of the method for more details.)
|
|
7
9
|
*
|
|
8
10
|
* This function is meant to be called in the EvaluateCache callback (when the cache flag is equal
|
|
9
11
|
* to `CacheFlag.CACHE_FAMILIARS`).
|
|
10
12
|
*
|
|
11
|
-
* Note that this function is only meant to be used in special circumstances
|
|
12
|
-
*
|
|
13
|
+
* Note that this function is only meant to be used in special circumstances where the familiar
|
|
14
|
+
* count is completely custom and does not correspond to the amount of collectibles. For the general
|
|
15
|
+
* case, use the `checkFamiliarFromCollectibles` helper function instead.
|
|
16
|
+
*
|
|
17
|
+
* Note that this will spawn familiars with a completely random `InitSeed`. When calculating random
|
|
18
|
+
* events for this familiar, you should use a data structure that maps familiar `InitSeed` to RNG
|
|
19
|
+
* objects that are initialized based on the seed from
|
|
20
|
+
* `EntityPlayer.GetCollectibleRNG(collectibleType)`.
|
|
13
21
|
*
|
|
14
22
|
* @param player The player that owns the familiars.
|
|
15
23
|
* @param collectibleType The collectible type of the collectible associated with this familiar.
|
|
16
|
-
* @param
|
|
17
|
-
*
|
|
24
|
+
* @param targetCount The number of familiars that should exist. This function will add or remove
|
|
25
|
+
* familiars until it matches the target count.
|
|
18
26
|
* @param familiarVariant The variant of the familiar to spawn or remove.
|
|
19
27
|
* @param familiarSubType Optional. The sub-type of the familiar to spawn or remove. If not
|
|
20
28
|
* specified, it will search for existing familiars of all sub-types, and spawn new familiars with a
|
|
21
29
|
* sub-type of 0.
|
|
22
|
-
* @returns The amount of familiars that were added or removed. For example, the player has 0
|
|
23
|
-
* collectibles and there were 2 familiars, this function would remove the 2 familiars and return
|
|
24
|
-
* -2.
|
|
25
30
|
*/
|
|
26
|
-
export declare function checkFamiliar(player: EntityPlayer, collectibleType: int,
|
|
31
|
+
export declare function checkFamiliar(player: EntityPlayer, collectibleType: int, targetCount: int, familiarVariant: int, familiarSubType?: int): void;
|
|
27
32
|
/**
|
|
28
33
|
* Helper function to add and remove familiars based on the amount of associated collectibles that a
|
|
29
|
-
* player has.
|
|
30
|
-
*
|
|
34
|
+
* player has.
|
|
35
|
+
*
|
|
36
|
+
* Use this helper function instead of invoking the `EntityPlayer.CheckFamiliar` method directly so
|
|
37
|
+
* that the target count is handled automatically.
|
|
31
38
|
*
|
|
32
39
|
* This function is meant to be called in the EvaluateCache callback (when the cache flag is equal
|
|
33
40
|
* to `CacheFlag.CACHE_FAMILIARS`).
|
|
@@ -37,15 +44,17 @@ export declare function checkFamiliar(player: EntityPlayer, collectibleType: int
|
|
|
37
44
|
* Manual). If you instead need to have a custom amount of familiars, use the `checkFamiliars`
|
|
38
45
|
* function instead.
|
|
39
46
|
*
|
|
47
|
+
* Note that this will spawn familiars with a completely random `InitSeed`. When calculating random
|
|
48
|
+
* events for this familiar, you should use a data structure that maps familiar `InitSeed` to RNG
|
|
49
|
+
* objects that are initialized based on the seed from
|
|
50
|
+
* `EntityPlayer.GetCollectibleRNG(collectibleType)`.
|
|
51
|
+
*
|
|
40
52
|
* @param player The player that owns the familiars and collectibles.
|
|
41
53
|
* @param collectibleType The collectible type of the collectible associated with this familiar.
|
|
42
54
|
* @param familiarVariant The variant of the familiar to spawn or remove.
|
|
43
55
|
* @param familiarSubType Optional. The sub-type of the familiar to spawn or remove. If not
|
|
44
56
|
* specified, it will search for existing familiars of all sub-types, and spawn new familiars with a
|
|
45
57
|
* sub-type of 0.
|
|
46
|
-
* @returns The amount of familiars that were added or removed. For example, the player has 0
|
|
47
|
-
* collectibles and there were 2 familiars, this function would remove the 2 familiars and return
|
|
48
|
-
* -2.
|
|
49
58
|
*/
|
|
50
|
-
export declare function checkFamiliarFromCollectibles(player: EntityPlayer, collectibleType: int, familiarVariant: int, familiarSubType?: int):
|
|
59
|
+
export declare function checkFamiliarFromCollectibles(player: EntityPlayer, collectibleType: int, familiarVariant: int, familiarSubType?: int): void;
|
|
51
60
|
export declare function isFamiliarThatShootsPlayerTears(familiar: EntityFamiliar): boolean;
|
|
@@ -1,64 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
|
|
1
|
+
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
3
2
|
local ____exports = {}
|
|
3
|
+
local ____cachedClasses = require("cachedClasses")
|
|
4
|
+
local itemConfig = ____cachedClasses.itemConfig
|
|
4
5
|
local ____familiarsThatShootPlayerTearsSet = require("sets.familiarsThatShootPlayerTearsSet")
|
|
5
6
|
local FAMILIARS_THAT_SHOOT_PLAYER_TEARS_SET = ____familiarsThatShootPlayerTearsSet.FAMILIARS_THAT_SHOOT_PLAYER_TEARS_SET
|
|
6
|
-
|
|
7
|
-
local
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
local ____repeat = ____utils["repeat"]
|
|
15
|
-
function ____exports.checkFamiliar(self, player, collectibleType, numTargetFamiliars, familiarVariant, familiarSubType)
|
|
16
|
-
local familiarSubTypeToSearchFor = familiarSubType == nil and -1 or familiarSubType
|
|
17
|
-
local playerPtrHash = GetPtrHash(player)
|
|
18
|
-
local familiars = getFamiliars(nil, familiarVariant, familiarSubTypeToSearchFor)
|
|
19
|
-
local familiarsForThisPlayer = __TS__ArrayFilter(
|
|
20
|
-
familiars,
|
|
21
|
-
function(____, familiar) return GetPtrHash(familiar.Player) == playerPtrHash end
|
|
22
|
-
)
|
|
23
|
-
if #familiarsForThisPlayer == numTargetFamiliars then
|
|
24
|
-
return 0
|
|
25
|
-
end
|
|
26
|
-
if #familiarsForThisPlayer > numTargetFamiliars then
|
|
27
|
-
local numFamiliarsToRemove = #familiarsForThisPlayer - numTargetFamiliars
|
|
28
|
-
local familiarsToRemove = copyArray(nil, familiarsForThisPlayer, numFamiliarsToRemove)
|
|
29
|
-
removeEntities(nil, familiarsToRemove)
|
|
30
|
-
return numFamiliarsToRemove * -1
|
|
31
|
-
end
|
|
32
|
-
local numFamiliarsToSpawn = numTargetFamiliars - #familiarsForThisPlayer
|
|
33
|
-
local collectibleRNG = player:GetCollectibleRNG(collectibleType)
|
|
34
|
-
local familiarSubTypeToUse = familiarSubType == nil and 0 or familiarSubType
|
|
35
|
-
____repeat(
|
|
36
|
-
nil,
|
|
37
|
-
numFamiliarsToSpawn,
|
|
38
|
-
function()
|
|
39
|
-
local seed = collectibleRNG:Next()
|
|
40
|
-
local familiar = spawnFamiliarWithSeed(
|
|
41
|
-
nil,
|
|
42
|
-
familiarVariant,
|
|
43
|
-
familiarSubTypeToUse,
|
|
44
|
-
player.Position,
|
|
45
|
-
seed
|
|
46
|
-
)
|
|
47
|
-
familiar.Player = player
|
|
48
|
-
end
|
|
7
|
+
function ____exports.checkFamiliar(self, player, collectibleType, targetCount, familiarVariant, familiarSubType)
|
|
8
|
+
local itemConfigItem = itemConfig:GetCollectible(collectibleType)
|
|
9
|
+
player:CheckFamiliar(
|
|
10
|
+
familiarVariant,
|
|
11
|
+
targetCount,
|
|
12
|
+
RNG(),
|
|
13
|
+
itemConfigItem,
|
|
14
|
+
familiarSubType
|
|
49
15
|
)
|
|
50
|
-
return numFamiliarsToSpawn
|
|
51
16
|
end
|
|
52
17
|
function ____exports.checkFamiliarFromCollectibles(self, player, collectibleType, familiarVariant, familiarSubType)
|
|
53
18
|
local numCollectibles = player:GetCollectibleNum(collectibleType)
|
|
54
19
|
local effects = player:GetEffects()
|
|
55
20
|
local numCollectibleEffects = effects:GetCollectibleEffectNum(collectibleType)
|
|
56
|
-
local
|
|
57
|
-
|
|
21
|
+
local targetCount = numCollectibles + numCollectibleEffects
|
|
22
|
+
____exports.checkFamiliar(
|
|
58
23
|
nil,
|
|
59
24
|
player,
|
|
60
25
|
collectibleType,
|
|
61
|
-
|
|
26
|
+
targetCount,
|
|
62
27
|
familiarVariant,
|
|
63
28
|
familiarSubType
|
|
64
29
|
)
|
|
@@ -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
|
|
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]
|
|
@@ -92,6 +92,11 @@ export declare function hexToKColor(hexString: string, alpha: float): KColor;
|
|
|
92
92
|
* is enabled or not.
|
|
93
93
|
*/
|
|
94
94
|
export declare function isLuaDebugEnabled(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Since this is a UI element, we do not want to draw it in water reflections. `renderOffset` will
|
|
97
|
+
* be a non-zero value in reflections.
|
|
98
|
+
*/
|
|
99
|
+
export declare function isReflectionRender(renderOffset: Vector): boolean;
|
|
95
100
|
/**
|
|
96
101
|
* Helper function to print something to the in-game console. Use this instead of invoking the
|
|
97
102
|
* `Isaac.ConsoleOutput` method directly because it will automatically insert a newline at the end
|
package/dist/functions/utils.lua
CHANGED
|
@@ -66,6 +66,11 @@ end
|
|
|
66
66
|
function ____exports.isLuaDebugEnabled(self)
|
|
67
67
|
return package ~= nil
|
|
68
68
|
end
|
|
69
|
+
function ____exports.isReflectionRender(self, renderOffset)
|
|
70
|
+
local x = math.floor(renderOffset.X + 0.5)
|
|
71
|
+
local y = math.floor(renderOffset.Y + 0.5)
|
|
72
|
+
return x ~= 0 or y ~= 0
|
|
73
|
+
end
|
|
69
74
|
function ____exports.printConsole(self, msg)
|
|
70
75
|
Isaac.ConsoleOutput(msg .. "\n")
|
|
71
76
|
end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.253",
|
|
4
4
|
"description": "Helper functions for IsaacScript mods",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist/**/*.d.ts"
|
|
26
26
|
],
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"isaac-typescript-definitions": "^1.0.
|
|
28
|
+
"isaac-typescript-definitions": "^1.0.389",
|
|
29
29
|
"isaacscript-lint": "^1.0.99",
|
|
30
30
|
"isaacscript-tsconfig": "^1.1.8",
|
|
31
31
|
"typedoc": "^0.22.13",
|