isaacscript-common 1.2.249 → 1.2.252

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 (29) hide show
  1. package/dist/enums/private/CopyableIsaacAPIClassType.d.ts +7 -0
  2. package/dist/enums/private/CopyableIsaacAPIClassType.lua +8 -0
  3. package/dist/enums/private/SerializationBrand.d.ts +19 -9
  4. package/dist/enums/private/SerializationBrand.lua +2 -2
  5. package/dist/features/saveDataManager/exports.lua +1 -2
  6. package/dist/features/saveDataManager/main.lua +2 -3
  7. package/dist/features/saveDataManager/merge.lua +11 -17
  8. package/dist/functions/array.d.ts +1 -1
  9. package/dist/functions/array.lua +6 -6
  10. package/dist/functions/deepCopy.d.ts +9 -6
  11. package/dist/functions/deepCopy.lua +285 -147
  12. package/dist/functions/familiars.d.ts +27 -18
  13. package/dist/functions/familiars.lua +14 -49
  14. package/dist/functions/log.d.ts +1 -1
  15. package/dist/functions/serialization.d.ts +5 -6
  16. package/dist/functions/serialization.lua +11 -28
  17. package/dist/functions/table.d.ts +1 -1
  18. package/dist/functions/tstlClass.d.ts +10 -5
  19. package/dist/functions/tstlClass.lua +11 -3
  20. package/dist/functions/utils.d.ts +1 -2
  21. package/dist/objects/isaacAPIClassTypeToBrand.d.ts +2 -2
  22. package/dist/objects/isaacAPIClassTypeToBrand.lua +3 -3
  23. package/dist/objects/isaacAPIClassTypeToCopyFunction.d.ts +2 -2
  24. package/dist/objects/isaacAPIClassTypeToCopyFunction.lua +3 -3
  25. package/dist/objects/serializedIsaacAPIClassTypeToIdentityFunction.d.ts +2 -2
  26. package/dist/objects/serializedIsaacAPIClassTypeToIdentityFunction.lua +3 -3
  27. package/dist/types/private/SaveData.d.ts +4 -0
  28. package/dist/types/private/TSTLClass.d.ts +1 -1
  29. package/package.json +3 -3
@@ -0,0 +1,7 @@
1
+ /** This must match the enumeration in the JSDoc comments for `deepCopy` and `merge`. */
2
+ export declare enum CopyableIsaacAPIClassType {
3
+ COLOR = "Color",
4
+ KCOLOR = "KColor",
5
+ RNG = "RNG",
6
+ VECTOR = "Vector"
7
+ }
@@ -0,0 +1,8 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ ____exports.CopyableIsaacAPIClassType = CopyableIsaacAPIClassType or ({})
4
+ ____exports.CopyableIsaacAPIClassType.COLOR = "Color"
5
+ ____exports.CopyableIsaacAPIClassType.KCOLOR = "KColor"
6
+ ____exports.CopyableIsaacAPIClassType.RNG = "RNG"
7
+ ____exports.CopyableIsaacAPIClassType.VECTOR = "Vector"
8
+ return ____exports
@@ -1,4 +1,3 @@
1
- /// <reference types="typescript-to-lua/language-extensions" />
2
1
  /**
3
2
  * During serialization, we write an arbitrary string key to the object with a value of an empty
4
3
  * string. This is used during deserialization to instantiate the correct type of object.
@@ -8,6 +7,12 @@
8
7
  */
9
8
  export declare enum SerializationBrand {
10
9
  DEFAULT_MAP = "__TSTL_DEFAULT_MAP",
10
+ MAP = "__TSTL_MAP",
11
+ SET = "__TSTL_SET",
12
+ COLOR = "__COLOR",
13
+ KCOLOR = "__KCOLOR",
14
+ RNG = "__RNG",
15
+ VECTOR = "__VECTOR",
11
16
  /**
12
17
  * This is set to the value that represents the default value (instead of an empty string like the
13
18
  * other brands are).
@@ -17,12 +22,17 @@ export declare enum SerializationBrand {
17
22
  * object.
18
23
  */
19
24
  DEFAULT_MAP_VALUE = "__TSTL_DEFAULT_MAP_VALUE",
20
- MAP = "__TSTL_MAP",
21
- SET = "__TSTL_SET",
22
- OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS",
23
- COLOR = "__COLOR",
24
- KCOLOR = "__KCOLOR",
25
- RNG = "__RNG",
26
- VECTOR = "__VECTOR"
25
+ /**
26
+ * The JSON library is unable to distinguish between a maps with number keys and an array. It will
27
+ * assume that both of these are an array. Thus, in the case of a map with number keys, it will
28
+ * insert null in every empty spot, leading to crashes.
29
+ *
30
+ * For example, a map with keys of 5 and 10 would be converted to the following array:
31
+ * `[null, null, null, null, "myValueForKey5", null, null, null, null, "myValueForKey10"]`
32
+ *
33
+ * The deep copier works around this by converting number keys to strings. It inserts this brand
34
+ * to keep track of the mutation.
35
+ */
36
+ OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS"
27
37
  }
28
- export declare function isSerializationBrand(key: AnyNotNil): boolean;
38
+ export declare function isSerializationBrand(key: unknown): boolean;
@@ -6,14 +6,14 @@ local ____utils = require("functions.utils")
6
6
  local getEnumValues = ____utils.getEnumValues
7
7
  ____exports.SerializationBrand = SerializationBrand or ({})
8
8
  ____exports.SerializationBrand.DEFAULT_MAP = "__TSTL_DEFAULT_MAP"
9
- ____exports.SerializationBrand.DEFAULT_MAP_VALUE = "__TSTL_DEFAULT_MAP_VALUE"
10
9
  ____exports.SerializationBrand.MAP = "__TSTL_MAP"
11
10
  ____exports.SerializationBrand.SET = "__TSTL_SET"
12
- ____exports.SerializationBrand.OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS"
13
11
  ____exports.SerializationBrand.COLOR = "__COLOR"
14
12
  ____exports.SerializationBrand.KCOLOR = "__KCOLOR"
15
13
  ____exports.SerializationBrand.RNG = "__RNG"
16
14
  ____exports.SerializationBrand.VECTOR = "__VECTOR"
15
+ ____exports.SerializationBrand.DEFAULT_MAP_VALUE = "__TSTL_DEFAULT_MAP_VALUE"
16
+ ____exports.SerializationBrand.OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS"
17
17
  local SERIALIZATION_BRANDS = getEnumValues(nil, ____exports.SerializationBrand)
18
18
  local SERIALIZATION_BRAND_SET = __TS__New(Set, SERIALIZATION_BRANDS)
19
19
  function ____exports.isSerializationBrand(self, key)
@@ -32,8 +32,7 @@ function ____exports.saveDataManager(self, key, v, conditionalFunc)
32
32
  conditionalFunc = function() return false end
33
33
  end
34
34
  local saveDataTable = v
35
- local saveDataTableCopy = deepCopy(nil, saveDataTable, SerializationType.NONE, key)
36
- local saveDataCopy = saveDataTableCopy
35
+ local saveDataCopy = deepCopy(nil, saveDataTable, SerializationType.NONE, key)
37
36
  saveDataDefaultsMap[key] = saveDataCopy
38
37
  if conditionalFunc ~= nil then
39
38
  saveDataConditionalFuncMap:set(key, conditionalFunc)
@@ -80,9 +80,8 @@ function restoreDefaults(self, childTableName)
80
80
  logError(((("Failed to find the default copy of the child table \"" .. childTableName) .. "\" for subscriber \"") .. subscriberName) .. "\". This error usually means that your save data is out of date. You can try purging all of your save data by deleting the following directory: C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Binding of Isaac Rebirth\\data")
81
81
  goto __continue14
82
82
  end
83
- local childTableDefaultsTable = childTableDefaults
84
- local childTableDefaultsTableCopy = deepCopy(nil, childTableDefaultsTable, SerializationType.NONE, (subscriberName .. " --> ") .. childTableName)
85
- clearAndCopyAllElements(nil, childTable, childTableDefaultsTableCopy)
83
+ local childTableDefaultsCopy = deepCopy(nil, childTableDefaults, SerializationType.NONE, (subscriberName .. " --> ") .. childTableName)
84
+ clearAndCopyAllElements(nil, childTable, childTableDefaultsCopy)
86
85
  end
87
86
  ::__continue14::
88
87
  end
@@ -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 mergeArray(nil, oldObject, newTable) then
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, oldObject, newTable)
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(newTable) do
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 __continue13
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 __continue13
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
- ::__continue13::
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 __continue23
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 __continue23
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
- ::__continue23::
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(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
@@ -1,4 +1,3 @@
1
- /// <reference types="typescript-to-lua/language-extensions" />
2
1
  import { SerializationType } from "../enums/SerializationType";
3
2
  /**
4
3
  * deepCopy is a semi-generic deep cloner. It will recursively copy all of the values so that none
@@ -6,6 +5,7 @@ import { SerializationType } from "../enums/SerializationType";
6
5
  *
7
6
  * It supports the following object types:
8
7
  *
8
+ * - Primitives (i.e. strings, numbers, and booleans)
9
9
  * - `LuaTable` / basic TSTL objects
10
10
  * - TSTL `Map`
11
11
  * - TSTL `Set`
@@ -16,10 +16,13 @@ import { SerializationType } from "../enums/SerializationType";
16
16
  * - Isaac `RNG` objects
17
17
  * - Isaac `Vector` objects
18
18
  *
19
- * @param oldObject The object to copy.
20
- * @param serializationType Has 3 possible values. Can leave TypeScriptToLua objects as-is, or can
21
- * serialize objects to Lua tables, or can deserialize Lua tables to objects. Default is
22
- * `SerializationType.NONE`.
19
+ * It does not support:
20
+ * - objects with values of `null` (since that transpiles to `nil`)
21
+ * - other Isaac API objects such as `EntityPtr` (that have a type of "userdata")
22
+ *
23
+ * @param value The primitive or object to copy.
24
+ * @param serializationType Has 3 possible values. Can leave objects as-is, or can serialize objects
25
+ * to Lua tables, or can deserialize Lua tables to objects. Default is `SerializationType.NONE`.
23
26
  * @param traversalDescription Used to track the current key that we are operating on.
24
27
  */
25
- export declare function deepCopy(oldObject: LuaTable<AnyNotNil, unknown> | Map<AnyNotNil, unknown> | Set<AnyNotNil>, serializationType?: SerializationType, traversalDescription?: string): LuaTable<AnyNotNil, unknown> | Map<AnyNotNil, unknown> | Set<AnyNotNil>;
28
+ export declare function deepCopy(value: unknown, serializationType?: SerializationType, traversalDescription?: string): unknown;
@@ -1,13 +1,19 @@
1
1
  local ____lualib = require("lualib_bundle")
2
- local Map = ____lualib.Map
3
- local __TS__InstanceOf = ____lualib.__TS__InstanceOf
4
2
  local Set = ____lualib.Set
5
3
  local __TS__New = ____lualib.__TS__New
4
+ local __TS__InstanceOf = ____lualib.__TS__InstanceOf
5
+ local Map = ____lualib.Map
6
+ local WeakMap = ____lualib.WeakMap
7
+ local WeakSet = ____lualib.WeakSet
8
+ local __TS__ArrayPush = ____lualib.__TS__ArrayPush
6
9
  local __TS__Iterator = ____lualib.__TS__Iterator
10
+ local __TS__ArraySome = ____lualib.__TS__ArraySome
7
11
  local ____exports = {}
8
- local checkMetatable, deepCopyValue, validateValue, getNewValue
12
+ local deepCopyTable, deepCopyDefaultMap, deepCopyMap, deepCopySet, deepCopyTSTLClass, deepCopyArray, deepCopyNormalLuaTable, getCopiedEntries, checkMetatable, deepCopyUserdata, COPYABLE_ISAAC_API_CLASS_TYPES_SET
9
13
  local ____DefaultMap = require("classes.DefaultMap")
10
14
  local DefaultMap = ____DefaultMap.DefaultMap
15
+ local ____CopyableIsaacAPIClassType = require("enums.private.CopyableIsaacAPIClassType")
16
+ local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
11
17
  local ____SerializationBrand = require("enums.private.SerializationBrand")
12
18
  local isSerializationBrand = ____SerializationBrand.isSerializationBrand
13
19
  local SerializationBrand = ____SerializationBrand.SerializationBrand
@@ -15,19 +21,24 @@ local ____SerializationType = require("enums.SerializationType")
15
21
  local SerializationType = ____SerializationType.SerializationType
16
22
  local ____constants = require("features.saveDataManager.constants")
17
23
  local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
24
+ local ____array = require("functions.array")
25
+ local isArray = ____array.isArray
26
+ local ____isaacAPIClass = require("functions.isaacAPIClass")
27
+ local getIsaacAPIClassType = ____isaacAPIClass.getIsaacAPIClassType
18
28
  local ____log = require("functions.log")
19
29
  local log = ____log.log
20
30
  local ____serialization = require("functions.serialization")
21
31
  local copyIsaacAPIClass = ____serialization.copyIsaacAPIClass
22
32
  local deserializeIsaacAPIClass = ____serialization.deserializeIsaacAPIClass
23
- local isSerializableIsaacAPIClass = ____serialization.isSerializableIsaacAPIClass
24
33
  local isSerializedIsaacAPIClass = ____serialization.isSerializedIsaacAPIClass
25
34
  local ____tstlClass = require("functions.tstlClass")
26
- local isTSTLClass = ____tstlClass.isTSTLClass
35
+ local isUserDefinedTSTLClass = ____tstlClass.isUserDefinedTSTLClass
27
36
  local newTSTLClass = ____tstlClass.newTSTLClass
28
37
  local ____utils = require("functions.utils")
38
+ local ensureAllCases = ____utils.ensureAllCases
39
+ local getEnumValues = ____utils.getEnumValues
29
40
  local getTraversalDescription = ____utils.getTraversalDescription
30
- function ____exports.deepCopy(self, oldObject, serializationType, traversalDescription)
41
+ function ____exports.deepCopy(self, value, serializationType, traversalDescription)
31
42
  if serializationType == nil then
32
43
  serializationType = SerializationType.NONE
33
44
  end
@@ -41,178 +52,305 @@ function ____exports.deepCopy(self, oldObject, serializationType, traversalDescr
41
52
  elseif serializationType == SerializationType.DESERIALIZE then
42
53
  logString = logString .. " (deserializing)"
43
54
  end
55
+ logString = logString .. ": " .. tostring(value)
44
56
  log(logString)
45
57
  end
46
- local oldObjectType = type(oldObject)
47
- if oldObjectType ~= "table" then
48
- error(("The deepCopy function was given a " .. oldObjectType) .. " instead of a table.")
49
- end
50
- local oldTable = oldObject
51
- local isClass = isTSTLClass(nil, oldTable)
52
- local hasTSTLDefaultMapBrand = false
53
- local hasTSTLMapBrand = false
54
- local hasTSTLSetBrand = false
55
- if not __TS__InstanceOf(oldObject, Map) and not __TS__InstanceOf(oldObject, Set) and not isClass then
56
- checkMetatable(nil, oldTable, traversalDescription)
57
- hasTSTLDefaultMapBrand = oldTable[SerializationBrand.DEFAULT_MAP] ~= nil
58
- hasTSTLMapBrand = oldTable[SerializationBrand.MAP] ~= nil
59
- hasTSTLSetBrand = oldTable[SerializationBrand.SET] ~= nil
60
- end
61
- local newObject
62
- if serializationType == SerializationType.NONE and __TS__InstanceOf(oldObject, DefaultMap) then
63
- local oldDefaultMap = oldObject
64
- local constructorArg = oldDefaultMap:getConstructorArg()
65
- newObject = __TS__New(DefaultMap, constructorArg)
66
- elseif serializationType == SerializationType.DESERIALIZE and hasTSTLDefaultMapBrand then
67
- local defaultValue = oldTable[SerializationBrand.DEFAULT_MAP_VALUE]
68
- if type(defaultValue) ~= "boolean" and type(defaultValue) ~= "number" and type(defaultValue) ~= "string" then
69
- error("The deepCopy function failed to get a valid default value for a DefaultMap object when deserializing.")
70
- else
71
- newObject = __TS__New(DefaultMap, defaultValue)
72
- end
73
- elseif serializationType == SerializationType.NONE and __TS__InstanceOf(oldObject, Map) or serializationType == SerializationType.DESERIALIZE and hasTSTLMapBrand then
74
- newObject = __TS__New(Map)
75
- elseif serializationType == SerializationType.NONE and __TS__InstanceOf(oldObject, Set) or serializationType == SerializationType.DESERIALIZE and hasTSTLSetBrand then
76
- newObject = __TS__New(Set)
77
- elseif serializationType == SerializationType.NONE and isClass then
78
- local oldTSTLClass = oldObject
79
- newObject = newTSTLClass(nil, oldTSTLClass)
58
+ local valueType = type(value)
59
+ repeat
60
+ local ____switch6 = valueType
61
+ local ____cond6 = ____switch6 == "nil" or ____switch6 == "boolean" or ____switch6 == "number" or ____switch6 == "string"
62
+ if ____cond6 then
63
+ do
64
+ return value
65
+ end
66
+ end
67
+ ____cond6 = ____cond6 or (____switch6 == "function" or ____switch6 == "thread")
68
+ if ____cond6 then
69
+ do
70
+ if serializationType == SerializationType.SERIALIZE then
71
+ error((("The deep copy function does not support serialization of \"" .. traversalDescription) .. "\", since it is type: ") .. valueType)
72
+ end
73
+ return value
74
+ end
75
+ end
76
+ ____cond6 = ____cond6 or ____switch6 == "table"
77
+ if ____cond6 then
78
+ do
79
+ local valueTable = value
80
+ return deepCopyTable(nil, valueTable, serializationType, traversalDescription)
81
+ end
82
+ end
83
+ ____cond6 = ____cond6 or ____switch6 == "userdata"
84
+ if ____cond6 then
85
+ do
86
+ return deepCopyUserdata(nil, value, serializationType, traversalDescription)
87
+ end
88
+ end
89
+ do
90
+ do
91
+ return ensureAllCases(nil, valueType)
92
+ end
93
+ end
94
+ until true
95
+ end
96
+ function deepCopyTable(self, ____table, serializationType, traversalDescription)
97
+ if __TS__InstanceOf(____table, DefaultMap) or ____table[SerializationBrand.DEFAULT_MAP] ~= nil then
98
+ return deepCopyDefaultMap(nil, ____table, serializationType, traversalDescription)
99
+ end
100
+ if __TS__InstanceOf(____table, Map) or ____table[SerializationBrand.MAP] ~= nil then
101
+ return deepCopyMap(nil, ____table, serializationType, traversalDescription)
102
+ end
103
+ if __TS__InstanceOf(____table, Set) or ____table[SerializationBrand.SET] ~= nil then
104
+ return deepCopySet(nil, ____table, serializationType, traversalDescription)
105
+ end
106
+ if __TS__InstanceOf(____table, WeakMap) then
107
+ error("The deep copy function does not support copying the \"WeakMap\" class for: " .. traversalDescription)
108
+ end
109
+ if __TS__InstanceOf(____table, WeakSet) then
110
+ error("The deep copy function does not support copying the \"WeakSet\" class for: " .. traversalDescription)
111
+ end
112
+ if isUserDefinedTSTLClass(nil, ____table) then
113
+ return deepCopyTSTLClass(nil, ____table, serializationType, traversalDescription)
114
+ end
115
+ checkMetatable(nil, ____table, traversalDescription)
116
+ if isSerializedIsaacAPIClass(nil, ____table) and serializationType == SerializationType.DESERIALIZE then
117
+ return deserializeIsaacAPIClass(nil, ____table)
118
+ end
119
+ if isArray(nil, ____table) then
120
+ return deepCopyArray(nil, ____table, serializationType, traversalDescription)
121
+ end
122
+ return deepCopyNormalLuaTable(nil, ____table, serializationType, traversalDescription)
123
+ end
124
+ function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescription)
125
+ local ____temp_0
126
+ if __TS__InstanceOf(defaultMap, DefaultMap) then
127
+ ____temp_0 = defaultMap:getConstructorArg()
80
128
  else
81
- newObject = {}
129
+ ____temp_0 = nil
82
130
  end
83
- if serializationType == SerializationType.SERIALIZE then
84
- local newTable = newObject
85
- if __TS__InstanceOf(oldObject, DefaultMap) then
86
- newTable[SerializationBrand.DEFAULT_MAP] = ""
87
- local oldDefaultMap = oldObject
88
- local defaultValue = oldDefaultMap:getConstructorArg()
89
- if type(defaultValue) == "boolean" or type(defaultValue) == "number" or type(defaultValue) == "string" then
90
- newTable[SerializationBrand.DEFAULT_MAP_VALUE] = defaultValue
131
+ local constructorArg = ____temp_0
132
+ local newDefaultMap
133
+ repeat
134
+ local ____switch23 = serializationType
135
+ local ____cond23 = ____switch23 == SerializationType.NONE
136
+ if ____cond23 then
137
+ do
138
+ newDefaultMap = __TS__New(DefaultMap, constructorArg)
139
+ break
91
140
  end
92
- elseif __TS__InstanceOf(oldObject, Map) then
93
- newTable[SerializationBrand.MAP] = ""
94
- elseif __TS__InstanceOf(oldObject, Set) then
95
- newTable[SerializationBrand.SET] = ""
96
141
  end
97
- end
98
- if __TS__InstanceOf(oldObject, Map) then
99
- for ____, ____value in __TS__Iterator(oldObject:entries()) do
100
- local key = ____value[1]
101
- local value = ____value[2]
142
+ ____cond23 = ____cond23 or ____switch23 == SerializationType.SERIALIZE
143
+ if ____cond23 then
102
144
  do
103
- if isSerializationBrand(nil, key) then
104
- goto __continue22
145
+ if type(constructorArg) ~= "boolean" and type(constructorArg) ~= "number" and type(constructorArg) ~= "string" then
146
+ return deepCopyMap(nil, defaultMap, serializationType, traversalDescription)
105
147
  end
106
- deepCopyValue(
107
- nil,
108
- oldObject,
109
- newObject,
110
- key,
111
- value,
112
- traversalDescription,
113
- serializationType
114
- )
148
+ newDefaultMap = {}
149
+ newDefaultMap[SerializationBrand.DEFAULT_MAP] = ""
150
+ newDefaultMap[SerializationBrand.DEFAULT_MAP_VALUE] = constructorArg
151
+ break
115
152
  end
116
- ::__continue22::
117
153
  end
118
- elseif __TS__InstanceOf(oldObject, Set) then
119
- for ____, key in __TS__Iterator(oldObject:values()) do
154
+ ____cond23 = ____cond23 or ____switch23 == SerializationType.DESERIALIZE
155
+ if ____cond23 then
120
156
  do
121
- if isSerializationBrand(nil, key) then
122
- goto __continue26
157
+ if __TS__InstanceOf(defaultMap, DefaultMap) then
158
+ error(("The deep copy function failed to deserialize a default map of \"" .. traversalDescription) .. "\", since it was not a Lua table.")
159
+ end
160
+ local defaultMapValue = defaultMap[SerializationBrand.DEFAULT_MAP_VALUE]
161
+ if defaultMapValue == nil then
162
+ error((("The deep copy function failed to deserialize a default map of \"" .. traversalDescription) .. "\", since there was no serialization brand of: ") .. SerializationBrand.DEFAULT_MAP_VALUE)
123
163
  end
124
- local value = ""
125
- deepCopyValue(
126
- nil,
127
- oldObject,
128
- newObject,
129
- key,
130
- value,
131
- traversalDescription,
132
- serializationType
133
- )
164
+ newDefaultMap = __TS__New(DefaultMap, defaultMapValue)
165
+ break
134
166
  end
135
- ::__continue26::
136
167
  end
137
- else
138
- for key, value in pairs(oldObject) do
168
+ do
139
169
  do
140
- if isSerializationBrand(nil, key) then
141
- goto __continue30
142
- end
143
- deepCopyValue(
144
- nil,
145
- oldObject,
146
- newObject,
147
- key,
148
- value,
149
- traversalDescription,
150
- serializationType
151
- )
170
+ return ensureAllCases(nil, serializationType)
152
171
  end
153
- ::__continue30::
172
+ end
173
+ until true
174
+ local ____getCopiedEntries_result_1 = getCopiedEntries(nil, defaultMap, serializationType, traversalDescription)
175
+ local entries = ____getCopiedEntries_result_1.entries
176
+ local convertedNumberKeysToStrings = ____getCopiedEntries_result_1.convertedNumberKeysToStrings
177
+ if convertedNumberKeysToStrings then
178
+ if __TS__InstanceOf(newDefaultMap, DefaultMap) then
179
+ newDefaultMap:set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "")
180
+ else
181
+ newDefaultMap[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] = ""
154
182
  end
155
183
  end
156
- return newObject
184
+ for ____, ____value in ipairs(entries) do
185
+ local key = ____value[1]
186
+ local value = ____value[2]
187
+ if __TS__InstanceOf(newDefaultMap, DefaultMap) then
188
+ newDefaultMap:set(key, value)
189
+ else
190
+ newDefaultMap[key] = value
191
+ end
192
+ end
193
+ return newDefaultMap
157
194
  end
158
- function checkMetatable(self, ____table, traversalDescription)
159
- local metatable = getmetatable(____table)
160
- if metatable == nil then
161
- return
195
+ function deepCopyMap(self, map, serializationType, traversalDescription)
196
+ local newMap
197
+ if serializationType == SerializationType.SERIALIZE then
198
+ newMap = {}
199
+ newMap[SerializationBrand.MAP] = ""
200
+ else
201
+ newMap = __TS__New(Map)
162
202
  end
163
- local tableDescription = traversalDescription == "" and "the table to copy" or ("\"" .. traversalDescription) .. "\""
164
- error(("The deepCopy function detected that \"" .. tableDescription) .. "\" has a metatable. Copying tables with metatables is not supported, unless they are explicitly handled by the save data manager. (e.g. Vectors, TypeScriptToLua Maps, etc.)")
203
+ local ____getCopiedEntries_result_2 = getCopiedEntries(nil, map, serializationType, traversalDescription)
204
+ local entries = ____getCopiedEntries_result_2.entries
205
+ local convertedNumberKeysToStrings = ____getCopiedEntries_result_2.convertedNumberKeysToStrings
206
+ if convertedNumberKeysToStrings then
207
+ if __TS__InstanceOf(newMap, Map) then
208
+ newMap:set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "")
209
+ else
210
+ newMap[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] = ""
211
+ end
212
+ end
213
+ for ____, ____value in ipairs(entries) do
214
+ local key = ____value[1]
215
+ local value = ____value[2]
216
+ if __TS__InstanceOf(newMap, Map) then
217
+ newMap:set(key, value)
218
+ else
219
+ newMap[key] = value
220
+ end
221
+ end
222
+ return newMap
165
223
  end
166
- function deepCopyValue(self, oldObject, newObject, key, value, traversalDescription, serializationType)
167
- local valueType = type(value)
168
- validateValue(nil, value, valueType, traversalDescription)
169
- local convertNumberKeysToString = false
170
- local isTSTLObject = __TS__InstanceOf(oldObject, Map) or __TS__InstanceOf(oldObject, Set)
171
- local keyType = type(key)
172
- if serializationType == SerializationType.SERIALIZE and isTSTLObject and keyType == "number" then
173
- convertNumberKeysToString = true
174
- local newTable = newObject
175
- newTable[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] = ""
176
- if SAVE_DATA_MANAGER_DEBUG then
177
- log("deepCopy is converting a TSTL map with number keys to strings.")
224
+ function deepCopySet(self, set, serializationType, traversalDescription)
225
+ local newSet
226
+ if serializationType == SerializationType.SERIALIZE then
227
+ newSet = {}
228
+ newSet[SerializationBrand.SET] = ""
229
+ else
230
+ newSet = __TS__New(Set)
231
+ end
232
+ local ____getCopiedEntries_result_3 = getCopiedEntries(nil, set, serializationType, traversalDescription)
233
+ local entries = ____getCopiedEntries_result_3.entries
234
+ local convertedNumberKeysToStrings = ____getCopiedEntries_result_3.convertedNumberKeysToStrings
235
+ if convertedNumberKeysToStrings then
236
+ if __TS__InstanceOf(newSet, Set) then
237
+ error("The deep copy function cannot convert number keys to strings for a Set.")
238
+ else
239
+ newSet[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] = ""
178
240
  end
179
241
  end
180
- local newValue = getNewValue(
181
- nil,
182
- key,
183
- value,
184
- traversalDescription,
185
- serializationType
186
- )
187
- if __TS__InstanceOf(newObject, Map) then
188
- newObject:set(key, newValue)
189
- elseif __TS__InstanceOf(newObject, Set) then
190
- newObject:add(key)
242
+ for ____, ____value in ipairs(entries) do
243
+ local key = ____value[1]
244
+ if __TS__InstanceOf(newSet, Set) then
245
+ newSet:add(key)
246
+ else
247
+ newSet[key] = ""
248
+ end
249
+ end
250
+ return newSet
251
+ end
252
+ function deepCopyTSTLClass(self, tstlClass, serializationType, traversalDescription)
253
+ local newClass
254
+ if serializationType == SerializationType.SERIALIZE then
255
+ newClass = {}
191
256
  else
192
- local keyToUse = convertNumberKeysToString and tostring(key) or key
193
- newObject[keyToUse] = newValue
257
+ newClass = newTSTLClass(nil, tstlClass)
258
+ end
259
+ local ____getCopiedEntries_result_4 = getCopiedEntries(nil, tstlClass, serializationType, traversalDescription)
260
+ local entries = ____getCopiedEntries_result_4.entries
261
+ local convertedNumberKeysToStrings = ____getCopiedEntries_result_4.convertedNumberKeysToStrings
262
+ if convertedNumberKeysToStrings then
263
+ newClass[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] = ""
194
264
  end
265
+ for ____, ____value in ipairs(entries) do
266
+ local key = ____value[1]
267
+ local value = ____value[2]
268
+ newClass[key] = value
269
+ end
270
+ return newClass
195
271
  end
196
- function validateValue(self, value, valueType, traversalDescription)
197
- if isSerializableIsaacAPIClass(nil, value) then
198
- return
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] = ""
199
287
  end
200
- if valueType == "function" or valueType == "nil" or valueType == "thread" or valueType == "userdata" then
201
- error(((("The deepCopy function detected that \"" .. traversalDescription) .. "\" has a value of type \"") .. valueType) .. "\", which is not supported.")
288
+ for ____, ____value in ipairs(entries) do
289
+ local key = ____value[1]
290
+ local value = ____value[2]
291
+ newTable[key] = value
202
292
  end
293
+ return newTable
203
294
  end
204
- function getNewValue(self, key, value, traversalDescription, serializationType)
205
- if isSerializableIsaacAPIClass(nil, value) then
206
- return copyIsaacAPIClass(nil, value, serializationType)
295
+ function getCopiedEntries(self, object, serializationType, traversalDescription)
296
+ local entries = {}
297
+ if __TS__InstanceOf(object, Map) or __TS__InstanceOf(object, Set) then
298
+ for ____, ____value in __TS__Iterator(object:entries()) do
299
+ local key = ____value[1]
300
+ local value = ____value[2]
301
+ __TS__ArrayPush(entries, {key, value})
302
+ end
303
+ else
304
+ for key, value in pairs(object) do
305
+ __TS__ArrayPush(entries, {key, value})
306
+ end
207
307
  end
208
- if isSerializedIsaacAPIClass(nil, value) and serializationType == SerializationType.DESERIALIZE then
209
- return deserializeIsaacAPIClass(nil, value)
308
+ local hasNumberKeys = __TS__ArraySome(
309
+ entries,
310
+ function(____, ____bindingPattern0)
311
+ local key
312
+ key = ____bindingPattern0[1]
313
+ return type(key) == "number"
314
+ end
315
+ )
316
+ local convertNumberKeysToStrings = serializationType == SerializationType.SERIALIZE and hasNumberKeys
317
+ local copiedEntries = {}
318
+ for ____, ____value in ipairs(entries) do
319
+ local key = ____value[1]
320
+ local value = ____value[2]
321
+ do
322
+ if isSerializationBrand(nil, key) then
323
+ goto __continue78
324
+ end
325
+ traversalDescription = getTraversalDescription(nil, key, traversalDescription)
326
+ local newValue = ____exports.deepCopy(nil, value, serializationType, traversalDescription)
327
+ local keyToUse = convertNumberKeysToStrings and tostring(key) or key
328
+ __TS__ArrayPush(copiedEntries, {keyToUse, newValue})
329
+ end
330
+ ::__continue78::
331
+ end
332
+ return {entries = copiedEntries, convertedNumberKeysToStrings = convertNumberKeysToStrings}
333
+ end
334
+ function checkMetatable(self, ____table, traversalDescription)
335
+ local metatable = getmetatable(____table)
336
+ if metatable == nil then
337
+ return
338
+ end
339
+ local tableDescription = traversalDescription == "" and "the table to copy" or ("\"" .. traversalDescription) .. "\""
340
+ error(("The deepCopy function detected that \"" .. tableDescription) .. "\" has a metatable. Copying tables with metatables is not supported, unless they are explicitly handled by the save data manager. (e.g. TypeScriptToLua Maps, TypeScriptToLua Sets, etc.)")
341
+ end
342
+ function deepCopyUserdata(self, value, serializationType, traversalDescription)
343
+ local classType = getIsaacAPIClassType(nil, value)
344
+ if classType == nil then
345
+ error("The deep copy function was not able to derive the Isaac API class type for: " .. traversalDescription)
210
346
  end
211
- if type(value) == "table" then
212
- local ____table = value
213
- traversalDescription = getTraversalDescription(nil, key, traversalDescription)
214
- return ____exports.deepCopy(nil, ____table, serializationType, traversalDescription)
347
+ if not COPYABLE_ISAAC_API_CLASS_TYPES_SET:has(classType) then
348
+ error((("The deep copy function does not support copying \"" .. traversalDescription) .. "\", since it is an Isaac API class of type: ") .. classType)
215
349
  end
216
- return value
350
+ return copyIsaacAPIClass(nil, value, serializationType)
217
351
  end
352
+ COPYABLE_ISAAC_API_CLASS_TYPES_SET = __TS__New(
353
+ Set,
354
+ getEnumValues(nil, CopyableIsaacAPIClassType)
355
+ )
218
356
  return ____exports
@@ -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. Use this
4
- * instead of the `EntityPlayer.CheckFamiliar` method so that the InitSeed of the spawned familiar
5
- * will be set properly. Note that when using this function, you need to manually account for Box of
6
- * Friends and Monster Manual (by looking at the number of collectible effects for the familiar).
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. For general purpose
12
- * usage, please use the `checkFamiliarFromCollectibles` helper function instead.
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 numTargetFamiliars The number of familiars that should exist. This function will add or
17
- * remove familiars until it matches the target count.
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, numTargetFamiliars: int, familiarVariant: int, familiarSubType?: int): 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. Use this instead of the `EntityPlayer.CheckFamiliar` method so that the InitSeed of
30
- * the spawned familiar will be set properly and Box of Friends is handled automatically.
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): 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
- local ____lualib = require("lualib_bundle")
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
- local ____array = require("functions.array")
7
- local copyArray = ____array.copyArray
8
- local ____entity = require("functions.entity")
9
- local removeEntities = ____entity.removeEntities
10
- local ____entitySpecific = require("functions.entitySpecific")
11
- local getFamiliars = ____entitySpecific.getFamiliars
12
- local spawnFamiliarWithSeed = ____entitySpecific.spawnFamiliarWithSeed
13
- local ____utils = require("functions.utils")
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 numTargetFamiliars = numCollectibles + numCollectibleEffects
57
- return ____exports.checkFamiliar(
21
+ local targetCount = numCollectibles + numCollectibleEffects
22
+ ____exports.checkFamiliar(
58
23
  nil,
59
24
  player,
60
25
  collectibleType,
61
- numTargetFamiliars,
26
+ targetCount,
62
27
  familiarVariant,
63
28
  familiarSubType
64
29
  )
@@ -27,7 +27,7 @@ export declare function logEntityID(this: void, entity: Entity): void;
27
27
  */
28
28
  export declare function logError(this: void, msg: string): void;
29
29
  /** Helper function for printing out every flag that is turned on. Useful when debugging. */
30
- export declare function logFlags(this: void, flags: int, flagEnum?: LuaTable, description?: string): void;
30
+ export declare function logFlags(this: void, flags: int, flagEnum?: LuaTable<AnyNotNil, unknown>, description?: string): void;
31
31
  /**
32
32
  * Helper function for printing out every game state flag that is turned on. Useful when debugging.
33
33
  */
@@ -1,12 +1,11 @@
1
1
  import { SerializationType } from "../enums/SerializationType";
2
- import { SerializableIsaacAPIClass } from "../types/private/SerializableIsaacAPIClass";
3
2
  import { SerializedIsaacAPIClass } from "../types/private/SerializedIsaacAPIClass";
4
- export declare function copyIsaacAPIClass(isaacAPIClass: SerializableIsaacAPIClass, serializationType: SerializationType): unknown;
3
+ export declare function copyIsaacAPIClass(isaacAPIClass: unknown, serializationType: SerializationType): unknown;
5
4
  /**
6
- * Deserialization is a special case, so we make a dedicated function for this. There is no need for
7
- * a "serializeIsaacAPIClass" function because the "copyIsaacAPIClass" function can handles all
8
- * serialization types.
5
+ * Deserialization is a special case, so we make a dedicated function for this.
6
+ *
7
+ * There is no need for a corresponding "serializeIsaacAPIClass" function because the
8
+ * "copyIsaacAPIClass" function can handles all serialization types.
9
9
  */
10
10
  export declare function deserializeIsaacAPIClass(serializedIsaacAPIClass: SerializedIsaacAPIClass): unknown;
11
- export declare function isSerializableIsaacAPIClass(object: unknown): object is SerializableIsaacAPIClass;
12
11
  export declare function isSerializedIsaacAPIClass(object: unknown): object is SerializedIsaacAPIClass;
@@ -1,13 +1,9 @@
1
1
  local ____lualib = require("lualib_bundle")
2
- local Set = ____lualib.Set
3
- local __TS__New = ____lualib.__TS__New
4
2
  local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
5
3
  local __TS__ObjectValues = ____lualib.__TS__ObjectValues
6
4
  local __TS__ArraySome = ____lualib.__TS__ArraySome
7
5
  local ____exports = {}
8
6
  local getSerializedTableType
9
- local ____SerializableIsaacAPIClassType = require("enums.private.SerializableIsaacAPIClassType")
10
- local SerializableIsaacAPIClassType = ____SerializableIsaacAPIClassType.SerializableIsaacAPIClassType
11
7
  local ____SerializationType = require("enums.SerializationType")
12
8
  local SerializationType = ____SerializationType.SerializationType
13
9
  local ____isaacAPIClassTypeToBrand = require("objects.isaacAPIClassTypeToBrand")
@@ -18,35 +14,29 @@ local ____serializedIsaacAPIClassTypeToIdentityFunction = require("objects.seria
18
14
  local SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION = ____serializedIsaacAPIClassTypeToIdentityFunction.SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION
19
15
  local ____isaacAPIClass = require("functions.isaacAPIClass")
20
16
  local getIsaacAPIClassType = ____isaacAPIClass.getIsaacAPIClassType
21
- local ____utils = require("functions.utils")
22
- local getEnumValues = ____utils.getEnumValues
23
17
  function getSerializedTableType(self, serializedIsaacAPIClass)
24
18
  for ____, ____value in ipairs(__TS__ObjectEntries(ISAAC_API_CLASS_TYPE_TO_BRAND)) do
25
- local serializableIsaacAPIClassType = ____value[1]
19
+ local copyableIsaacAPIClassType = ____value[1]
26
20
  local serializationBrand = ____value[2]
27
21
  if serializedIsaacAPIClass[serializationBrand] ~= nil then
28
- return serializableIsaacAPIClassType
22
+ return copyableIsaacAPIClassType
29
23
  end
30
24
  end
31
25
  return nil
32
26
  end
33
- local SERIALIZABLE_ISAAC_API_CLASS_TYPES_SET = __TS__New(
34
- Set,
35
- getEnumValues(nil, SerializableIsaacAPIClassType)
36
- )
37
27
  function ____exports.copyIsaacAPIClass(self, isaacAPIClass, serializationType)
38
28
  local objectType = type(isaacAPIClass)
39
29
  if objectType ~= "userdata" then
40
- error("Failed to serialize an Isaac API class since the provided object was of type: " .. objectType)
30
+ error("Failed to copy an Isaac API class since the provided object was of type: " .. objectType)
41
31
  end
42
32
  local isaacAPIClassType = getIsaacAPIClassType(nil, isaacAPIClass)
43
33
  if isaacAPIClassType == nil then
44
- error("Failed to serialize 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.")
45
35
  end
46
- local serializableIsaacAPIClassType = isaacAPIClassType
47
- local copyFunction = ISAAC_API_CLASS_TYPE_TO_COPY_FUNCTION[serializableIsaacAPIClassType]
36
+ local copyableIsaacAPIClassType = isaacAPIClassType
37
+ local copyFunction = ISAAC_API_CLASS_TYPE_TO_COPY_FUNCTION[copyableIsaacAPIClassType]
48
38
  if copyFunction == nil then
49
- error(("Failed to copy Isaac API class \"" .. serializableIsaacAPIClassType) .. "\" since there is not a defined copy function for this class type.")
39
+ error(("Failed to copy Isaac API class \"" .. copyableIsaacAPIClassType) .. "\" since there is not a defined copy function for this class type.")
50
40
  end
51
41
  return copyFunction(nil, isaacAPIClass, serializationType)
52
42
  end
@@ -55,23 +45,16 @@ function ____exports.deserializeIsaacAPIClass(self, serializedIsaacAPIClass)
55
45
  if objectType ~= "table" then
56
46
  error("Failed to deserialize an Isaac API class since the provided object was of type: " .. objectType)
57
47
  end
58
- local serializableIsaacAPIClassType = getSerializedTableType(nil, serializedIsaacAPIClass)
59
- if serializableIsaacAPIClassType == nil then
48
+ local copyableIsaacAPIClassType = getSerializedTableType(nil, serializedIsaacAPIClass)
49
+ if copyableIsaacAPIClassType == nil then
60
50
  error("Failed to deserialize an API class since a valid class type brand was not found.")
61
51
  end
62
- local copyFunction = ISAAC_API_CLASS_TYPE_TO_COPY_FUNCTION[serializableIsaacAPIClassType]
52
+ local copyFunction = ISAAC_API_CLASS_TYPE_TO_COPY_FUNCTION[copyableIsaacAPIClassType]
63
53
  if copyFunction == nil then
64
- error(("Failed to deserialize Isaac API class \"" .. serializableIsaacAPIClassType) .. "\" since there is not a defined copy function for this class type.")
54
+ error(("Failed to deserialize Isaac API class \"" .. copyableIsaacAPIClassType) .. "\" since there is not a defined copy function for this class type.")
65
55
  end
66
56
  return copyFunction(nil, serializedIsaacAPIClass, SerializationType.DESERIALIZE)
67
57
  end
68
- function ____exports.isSerializableIsaacAPIClass(self, object)
69
- local classType = getIsaacAPIClassType(nil, object)
70
- if classType == nil then
71
- return false
72
- end
73
- return SERIALIZABLE_ISAAC_API_CLASS_TYPES_SET:has(classType)
74
- end
75
58
  function ____exports.isSerializedIsaacAPIClass(self, object)
76
59
  local identityFunctions = __TS__ObjectValues(SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION)
77
60
  return __TS__ArraySome(
@@ -33,4 +33,4 @@ export declare function getStringsFromTable(table: LuaTable<string, unknown>, ob
33
33
  * This function is variadic, meaning that you can specify as many arguments as you want to check
34
34
  * for.
35
35
  */
36
- export declare function tableHasKeys(table: LuaTable, ...keys: string[]): boolean;
36
+ export declare function tableHasKeys(table: LuaTable<AnyNotNil, unknown>, ...keys: string[]): boolean;
@@ -1,11 +1,16 @@
1
1
  import { TSTLClass } from "../types/private/TSTLClass";
2
2
  /**
3
- * TypeScriptToLua classes are Lua tables that have a metatable with a certain amount of keys.
4
- *
5
- * For the purposes of this function, TSTL Maps, Sets, WeakMaps, and WeakSets do not count as TSTL
6
- * classes, because this function is intended to detect user-defined classes.
3
+ * Returns whether or not this is a class that is provided by the `isaacscript-common` library, such
4
+ * as a `DefaultMap`.
7
5
  */
8
- export declare function isTSTLClass(object: unknown): object is TSTLClass;
6
+ export declare function isIsaacScriptCommonClass(object: unknown): boolean;
7
+ /** TypeScriptToLua classes are Lua tables that have a metatable with a certain amount of keys. */
8
+ export declare function isUserDefinedTSTLClass(object: unknown): object is TSTLClass;
9
+ /**
10
+ * Returns whether or not this is a class that is provided as part of the TypeScriptToLua
11
+ * transpiler, such as a `Map` or a `Set`.
12
+ */
13
+ export declare function isVanillaTSTLClass(object: unknown): boolean;
9
14
  /**
10
15
  * Initializes a new TypeScriptToLua class in the situation where you do not know what kind of class
11
16
  * it is. This function requires that you provide an instantiated class of the same type, as it will
@@ -1,12 +1,17 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local Set = ____lualib.Set
3
3
  local __TS__New = ____lualib.__TS__New
4
- local Map = ____lualib.Map
5
4
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
5
+ local Map = ____lualib.Map
6
6
  local WeakMap = ____lualib.WeakMap
7
7
  local WeakSet = ____lualib.WeakSet
8
8
  local ____exports = {}
9
9
  local newTSTLClassFromMetatable
10
+ local ____DefaultMap = require("classes.DefaultMap")
11
+ local DefaultMap = ____DefaultMap.DefaultMap
12
+ function ____exports.isVanillaTSTLClass(self, object)
13
+ return __TS__InstanceOf(object, Map) or __TS__InstanceOf(object, Set) or __TS__InstanceOf(object, WeakMap) or __TS__InstanceOf(object, WeakSet)
14
+ end
10
15
  function newTSTLClassFromMetatable(self, metatable)
11
16
  local newClass = {}
12
17
  local newClassMetatable = setmetatable(newClass, metatable.constructor.prototype)
@@ -14,8 +19,11 @@ function newTSTLClassFromMetatable(self, metatable)
14
19
  return newClass
15
20
  end
16
21
  local TSTL_CLASS_METATABLE_KEYS = __TS__New(Set, {"____constructor", "__index", "constructor"})
17
- function ____exports.isTSTLClass(self, object)
18
- if __TS__InstanceOf(object, Map) or __TS__InstanceOf(object, Set) or __TS__InstanceOf(object, WeakMap) or __TS__InstanceOf(object, WeakSet) then
22
+ function ____exports.isIsaacScriptCommonClass(self, object)
23
+ return __TS__InstanceOf(object, DefaultMap)
24
+ end
25
+ function ____exports.isUserDefinedTSTLClass(self, object)
26
+ if ____exports.isVanillaTSTLClass(nil, object) or ____exports.isIsaacScriptCommonClass(nil, object) then
19
27
  return false
20
28
  end
21
29
  local objectType = type(object)
@@ -1,5 +1,4 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
- /// <reference types="typescript-to-lua/language-extensions" />
3
2
  /**
4
3
  * Helper function to get type safety on a switch statement.
5
4
  *
@@ -74,7 +73,7 @@ export declare function getEnumValues<T>(transpiledEnum: T): Array<T[keyof T]>;
74
73
  * Helper function to log what is happening in functions that recursively move through nested data
75
74
  * structures.
76
75
  */
77
- export declare function getTraversalDescription(key: AnyNotNil, traversalDescription: string): string;
76
+ export declare function getTraversalDescription(key: unknown, traversalDescription: string): string;
78
77
  /**
79
78
  * Converts a hex string like "#33aa33" to a KColor object.
80
79
  *
@@ -1,5 +1,5 @@
1
- import { SerializableIsaacAPIClassType } from "../enums/private/SerializableIsaacAPIClassType";
1
+ import { CopyableIsaacAPIClassType } from "../enums/private/CopyableIsaacAPIClassType";
2
2
  import { SerializationBrand } from "../enums/private/SerializationBrand";
3
3
  export declare const ISAAC_API_CLASS_TYPE_TO_BRAND: {
4
- readonly [key in SerializableIsaacAPIClassType]: SerializationBrand;
4
+ readonly [key in CopyableIsaacAPIClassType]: SerializationBrand;
5
5
  };
@@ -1,8 +1,8 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
- local ____SerializableIsaacAPIClassType = require("enums.private.SerializableIsaacAPIClassType")
4
- local SerializableIsaacAPIClassType = ____SerializableIsaacAPIClassType.SerializableIsaacAPIClassType
3
+ local ____CopyableIsaacAPIClassType = require("enums.private.CopyableIsaacAPIClassType")
4
+ local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
5
5
  local ____SerializationBrand = require("enums.private.SerializationBrand")
6
6
  local SerializationBrand = ____SerializationBrand.SerializationBrand
7
- ____exports.ISAAC_API_CLASS_TYPE_TO_BRAND = {[SerializableIsaacAPIClassType.COLOR] = SerializationBrand.COLOR, [SerializableIsaacAPIClassType.KCOLOR] = SerializationBrand.KCOLOR, [SerializableIsaacAPIClassType.RNG] = SerializationBrand.RNG, [SerializableIsaacAPIClassType.VECTOR] = SerializationBrand.VECTOR}
7
+ ____exports.ISAAC_API_CLASS_TYPE_TO_BRAND = {[CopyableIsaacAPIClassType.COLOR] = SerializationBrand.COLOR, [CopyableIsaacAPIClassType.KCOLOR] = SerializationBrand.KCOLOR, [CopyableIsaacAPIClassType.RNG] = SerializationBrand.RNG, [CopyableIsaacAPIClassType.VECTOR] = SerializationBrand.VECTOR}
8
8
  return ____exports
@@ -1,5 +1,5 @@
1
- import { SerializableIsaacAPIClassType } from "../enums/private/SerializableIsaacAPIClassType";
1
+ import { CopyableIsaacAPIClassType } from "../enums/private/CopyableIsaacAPIClassType";
2
2
  import { SerializationType } from "../enums/SerializationType";
3
3
  export declare const ISAAC_API_CLASS_TYPE_TO_COPY_FUNCTION: {
4
- readonly [key in SerializableIsaacAPIClassType]: (object: unknown, serializationType: SerializationType) => boolean;
4
+ readonly [key in CopyableIsaacAPIClassType]: (object: unknown, serializationType: SerializationType) => boolean;
5
5
  };
@@ -1,7 +1,7 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
- local ____SerializableIsaacAPIClassType = require("enums.private.SerializableIsaacAPIClassType")
4
- local SerializableIsaacAPIClassType = ____SerializableIsaacAPIClassType.SerializableIsaacAPIClassType
3
+ local ____CopyableIsaacAPIClassType = require("enums.private.CopyableIsaacAPIClassType")
4
+ local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
5
5
  local ____color = require("functions.color")
6
6
  local copyColor = ____color.copyColor
7
7
  local ____kColor = require("functions.kColor")
@@ -10,5 +10,5 @@ local ____rng = require("functions.rng")
10
10
  local copyRNG = ____rng.copyRNG
11
11
  local ____vector = require("functions.vector")
12
12
  local copyVector = ____vector.copyVector
13
- ____exports.ISAAC_API_CLASS_TYPE_TO_COPY_FUNCTION = {[SerializableIsaacAPIClassType.COLOR] = copyColor, [SerializableIsaacAPIClassType.KCOLOR] = copyKColor, [SerializableIsaacAPIClassType.RNG] = copyRNG, [SerializableIsaacAPIClassType.VECTOR] = copyVector}
13
+ ____exports.ISAAC_API_CLASS_TYPE_TO_COPY_FUNCTION = {[CopyableIsaacAPIClassType.COLOR] = copyColor, [CopyableIsaacAPIClassType.KCOLOR] = copyKColor, [CopyableIsaacAPIClassType.RNG] = copyRNG, [CopyableIsaacAPIClassType.VECTOR] = copyVector}
14
14
  return ____exports
@@ -1,4 +1,4 @@
1
- import { SerializableIsaacAPIClassType } from "../enums/private/SerializableIsaacAPIClassType";
1
+ import { CopyableIsaacAPIClassType } from "../enums/private/CopyableIsaacAPIClassType";
2
2
  export declare const SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION: {
3
- readonly [key in SerializableIsaacAPIClassType]: (object: unknown) => boolean;
3
+ readonly [key in CopyableIsaacAPIClassType]: (object: unknown) => boolean;
4
4
  };
@@ -1,7 +1,7 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
- local ____SerializableIsaacAPIClassType = require("enums.private.SerializableIsaacAPIClassType")
4
- local SerializableIsaacAPIClassType = ____SerializableIsaacAPIClassType.SerializableIsaacAPIClassType
3
+ local ____CopyableIsaacAPIClassType = require("enums.private.CopyableIsaacAPIClassType")
4
+ local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
5
5
  local ____color = require("functions.color")
6
6
  local isSerializedColor = ____color.isSerializedColor
7
7
  local ____kColor = require("functions.kColor")
@@ -10,5 +10,5 @@ local ____rng = require("functions.rng")
10
10
  local isSerializedRNG = ____rng.isSerializedRNG
11
11
  local ____vector = require("functions.vector")
12
12
  local isSerializedVector = ____vector.isSerializedVector
13
- ____exports.SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION = {[SerializableIsaacAPIClassType.COLOR] = isSerializedColor, [SerializableIsaacAPIClassType.KCOLOR] = isSerializedKColor, [SerializableIsaacAPIClassType.RNG] = isSerializedRNG, [SerializableIsaacAPIClassType.VECTOR] = isSerializedVector}
13
+ ____exports.SERIALIZED_ISAAC_API_CLASS_TYPE_TO_IDENTITY_FUNCTION = {[CopyableIsaacAPIClassType.COLOR] = isSerializedColor, [CopyableIsaacAPIClassType.KCOLOR] = isSerializedKColor, [CopyableIsaacAPIClassType.RNG] = isSerializedRNG, [CopyableIsaacAPIClassType.VECTOR] = isSerializedVector}
14
14
  return ____exports
@@ -1,4 +1,8 @@
1
1
  import { Primitive } from "../Primitive";
2
+ /**
3
+ * I don't know how to create a recursive type definition for only primitive values. For now, this
4
+ * is typed as "unknown", which provides no type safety.
5
+ */
2
6
  declare type Serializable = Primitive | unknown;
3
7
  /**
4
8
  * Each sub-object of save data has a string as a key, without arbitrary data as a value. However,
@@ -1,4 +1,4 @@
1
1
  /// <reference types="typescript-to-lua/language-extensions" />
2
- export declare type TSTLClass = LuaTable<string, unknown> & {
2
+ export declare type TSTLClass = LuaTable<AnyNotNil, unknown> & {
3
3
  __tstlClassBrand: unknown;
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.249",
3
+ "version": "1.2.252",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,8 +25,8 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "devDependencies": {
28
- "isaac-typescript-definitions": "^1.0.388",
29
- "isaacscript-lint": "^1.0.98",
28
+ "isaac-typescript-definitions": "^1.0.389",
29
+ "isaacscript-lint": "^1.0.99",
30
30
  "isaacscript-tsconfig": "^1.1.8",
31
31
  "typedoc": "^0.22.13",
32
32
  "typescript": "4.6.3",