isaacscript-common 1.2.219 → 1.2.220

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 (35) hide show
  1. package/dist/enums/private/SerializableIsaacAPIClassType.d.ts +7 -0
  2. package/dist/enums/private/SerializableIsaacAPIClassType.lua +8 -0
  3. package/dist/enums/private/SerializationBrand.d.ts +1 -0
  4. package/dist/enums/private/SerializationBrand.lua +1 -0
  5. package/dist/features/saveDataManager/merge.d.ts +1 -0
  6. package/dist/features/saveDataManager/merge.lua +7 -19
  7. package/dist/functions/collectibles.d.ts +4 -0
  8. package/dist/functions/collectibles.lua +40 -1
  9. package/dist/functions/color.d.ts +9 -3
  10. package/dist/functions/color.lua +26 -15
  11. package/dist/functions/deepCopy.d.ts +1 -0
  12. package/dist/functions/deepCopy.lua +35 -34
  13. package/dist/functions/isaacAPIClass.d.ts +25 -0
  14. package/dist/functions/isaacAPIClass.lua +52 -0
  15. package/dist/functions/kColor.d.ts +30 -0
  16. package/dist/functions/kColor.lua +90 -0
  17. package/dist/functions/log.lua +3 -3
  18. package/dist/functions/rng.d.ts +6 -3
  19. package/dist/functions/rng.lua +7 -3
  20. package/dist/functions/serialization.d.ts +5 -0
  21. package/dist/functions/serialization.lua +115 -0
  22. package/dist/functions/sprite.d.ts +10 -0
  23. package/dist/functions/sprite.lua +32 -0
  24. package/dist/functions/table.d.ts +4 -4
  25. package/dist/functions/vector.d.ts +6 -3
  26. package/dist/functions/vector.lua +7 -3
  27. package/dist/index.d.ts +3 -1
  28. package/dist/index.lua +24 -8
  29. package/dist/types/private/IsaacAPIClass.d.ts +4 -0
  30. package/dist/types/private/IsaacAPIClass.lua +3 -0
  31. package/dist/types/private/SerializableIsaacAPIClass.d.ts +4 -0
  32. package/dist/types/private/SerializableIsaacAPIClass.lua +3 -0
  33. package/dist/types/private/SerializedIsaacAPIClass.d.ts +4 -0
  34. package/dist/types/private/SerializedIsaacAPIClass.lua +3 -0
  35. package/package.json +2 -2
@@ -0,0 +1,7 @@
1
+ /** This must match the enumeration in the JSDoc comments for `deepCopy` and `merge`. */
2
+ export declare enum SerializableIsaacAPIClassType {
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.SerializableIsaacAPIClassType = SerializableIsaacAPIClassType or ({})
4
+ ____exports.SerializableIsaacAPIClassType.COLOR = "Color"
5
+ ____exports.SerializableIsaacAPIClassType.KCOLOR = "KColor"
6
+ ____exports.SerializableIsaacAPIClassType.RNG = "RNG"
7
+ ____exports.SerializableIsaacAPIClassType.VECTOR = "Vector"
8
+ return ____exports
@@ -11,6 +11,7 @@ export declare enum SerializationBrand {
11
11
  CLASS = "__TSTL_CLASS",
12
12
  OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS",
13
13
  COLOR = "__COLOR",
14
+ KCOLOR = "__KCOLOR",
14
15
  RNG = "__RNG",
15
16
  VECTOR = "__VECTOR"
16
17
  }
@@ -12,6 +12,7 @@ ____exports.SerializationBrand.SET = "__TSTL_SET"
12
12
  ____exports.SerializationBrand.CLASS = "__TSTL_CLASS"
13
13
  ____exports.SerializationBrand.OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS"
14
14
  ____exports.SerializationBrand.COLOR = "__COLOR"
15
+ ____exports.SerializationBrand.KCOLOR = "__KCOLOR"
15
16
  ____exports.SerializationBrand.RNG = "__RNG"
16
17
  ____exports.SerializationBrand.VECTOR = "__VECTOR"
17
18
  local SERIALIZATION_BRANDS = getEnumValues(nil, ____exports.SerializationBrand)
@@ -11,6 +11,7 @@
11
11
  * - TSTL classes
12
12
  * - `DefaultMap`
13
13
  * - Isaac `Color` objects
14
+ * - Isaac `KColor` objects
14
15
  * - Isaac `RNG` objects
15
16
  * - Isaac `Vector` objects
16
17
  *
@@ -3,7 +3,7 @@ local Map = ____lualib.Map
3
3
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
4
4
  local Set = ____lualib.Set
5
5
  local ____exports = {}
6
- local mergeArray, mergeTSTLObject, mergeTable, tryDeserializeIsaacClass
6
+ local mergeArray, mergeTSTLObject, mergeTable
7
7
  local ____SerializationBrand = require("enums.private.SerializationBrand")
8
8
  local isSerializationBrand = ____SerializationBrand.isSerializationBrand
9
9
  local SerializationBrand = ____SerializationBrand.SerializationBrand
@@ -15,16 +15,13 @@ local ____deepCopy = require("functions.deepCopy")
15
15
  local deepCopy = ____deepCopy.deepCopy
16
16
  local ____log = require("functions.log")
17
17
  local log = ____log.log
18
- local ____rng = require("functions.rng")
19
- local copyRNG = ____rng.copyRNG
20
- local isSerializedRNG = ____rng.isSerializedRNG
18
+ local ____serialization = require("functions.serialization")
19
+ local copySerializableIsaacAPIClass = ____serialization.copySerializableIsaacAPIClass
20
+ local isSerializedIsaacAPIClass = ____serialization.isSerializedIsaacAPIClass
21
21
  local ____table = require("functions.table")
22
22
  local clearTable = ____table.clearTable
23
23
  local ____utils = require("functions.utils")
24
24
  local getTraversalDescription = ____utils.getTraversalDescription
25
- local ____vector = require("functions.vector")
26
- local copyVector = ____vector.copyVector
27
- local isSerializedVector = ____vector.isSerializedVector
28
25
  local ____constants = require("features.saveDataManager.constants")
29
26
  local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
30
27
  function ____exports.merge(self, oldObject, newTable, traversalDescription)
@@ -103,9 +100,9 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
103
100
  if isSerializationBrand(nil, key) then
104
101
  goto __continue23
105
102
  end
106
- local deserializedIsaacClass = tryDeserializeIsaacClass(nil, value)
107
- if deserializedIsaacClass ~= nil then
108
- oldTable[key] = deserializedIsaacClass
103
+ if isSerializedIsaacAPIClass(nil, value) then
104
+ local deserializedObject = copySerializableIsaacAPIClass(nil, value, SerializationType.DESERIALIZE)
105
+ oldTable[key] = deserializedObject
109
106
  goto __continue23
110
107
  end
111
108
  local valueType = type(value)
@@ -128,13 +125,4 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
128
125
  ::__continue23::
129
126
  end
130
127
  end
131
- function tryDeserializeIsaacClass(self, value)
132
- if isSerializedVector(nil, value) then
133
- return copyVector(nil, value, SerializationType.DESERIALIZE)
134
- end
135
- if isSerializedRNG(nil, value) then
136
- return copyRNG(nil, value, SerializationType.DESERIALIZE)
137
- end
138
- return nil
139
- end
140
128
  return ____exports
@@ -4,6 +4,8 @@ import { CollectibleIndex } from "../types/CollectibleIndex";
4
4
  export declare function clearCollectibleSprite(collectible: EntityPickup): void;
5
5
  export declare function collectibleHasCacheFlag(collectibleType: CollectibleType | int, cacheFlag: CacheFlag): boolean;
6
6
  export declare function collectibleHasTag(collectibleType: CollectibleType | int, tag: ItemConfigTag): boolean;
7
+ /** Helper function to check if two collectible sprites have the same sprite sheet loaded. */
8
+ export declare function collectibleSpriteEquals(sprite1: Sprite, sprite2: Sprite): boolean;
7
9
  /**
8
10
  * Helper function to get the in-game description for a collectible. Returns "Unknown" if the
9
11
  * provided collectible type was not valid.
@@ -99,6 +101,8 @@ export declare function getCollectibles(matchingSubType?: number): EntityPickup[
99
101
  export declare function getMaxCollectibleType(): int;
100
102
  /** Returns true if the item type in the item config is equal to `ItemType.ITEM_ACTIVE`. */
101
103
  export declare function isActiveCollectible(collectibleType: CollectibleType | int): boolean;
104
+ /** Returns true if the collectible has a red question mark sprite. */
105
+ export declare function isBlindCollectible(collectible: EntityPickup): boolean;
102
106
  /**
103
107
  * Returns whether or not the given collectible is a "glitched" item. All items are replaced by
104
108
  * glitched items once a player has TMTRAINER. However, glitched items can also "naturally" appear
@@ -1,6 +1,6 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
- local COLLECTIBLE_SPRITE_LAYER, COLLECTIBLE_SHADOW_LAYER
3
+ local initQuestionMarkSprite, COLLECTIBLE_SPRITE_LAYER, COLLECTIBLE_SHADOW_LAYER
4
4
  local ____cachedClasses = require("cachedClasses")
5
5
  local game = ____cachedClasses.game
6
6
  local itemConfig = ____cachedClasses.itemConfig
@@ -23,6 +23,14 @@ local ____roomData = require("functions.roomData")
23
23
  local getRoomListIndex = ____roomData.getRoomListIndex
24
24
  local ____sprite = require("functions.sprite")
25
25
  local clearSprite = ____sprite.clearSprite
26
+ local spriteEquals = ____sprite.spriteEquals
27
+ function initQuestionMarkSprite(self)
28
+ local sprite = Sprite()
29
+ sprite:Load("gfx/005.100_collectible.anm2", false)
30
+ sprite:ReplaceSpritesheet(1, "gfx/items/collectibles/questionmark.png")
31
+ sprite:LoadGraphics()
32
+ return sprite
33
+ end
26
34
  function ____exports.setCollectibleSprite(self, collectible, pngPath)
27
35
  if collectible.Variant ~= 100 then
28
36
  error("You cannot set a collectible sprite for pickups of variant: " .. tostring(collectible.Variant))
@@ -38,6 +46,7 @@ end
38
46
  COLLECTIBLE_SPRITE_LAYER = 1
39
47
  COLLECTIBLE_SHADOW_LAYER = 4
40
48
  local GLITCHED_ITEM_THRESHOLD = 4000000000
49
+ local questionMarkSprite = initQuestionMarkSprite(nil)
41
50
  function ____exports.clearCollectibleSprite(self, collectible)
42
51
  ____exports.setCollectibleSprite(nil, collectible, nil)
43
52
  end
@@ -55,6 +64,26 @@ function ____exports.collectibleHasTag(self, collectibleType, tag)
55
64
  end
56
65
  return itemConfigItem:HasTags(tag)
57
66
  end
67
+ function ____exports.collectibleSpriteEquals(self, sprite1, sprite2)
68
+ local xStart = -1
69
+ local xFinish = 1
70
+ local xIncrement = 1
71
+ local yStart = -40
72
+ local yFinish = 10
73
+ local yIncrement = 3
74
+ return spriteEquals(
75
+ nil,
76
+ sprite1,
77
+ sprite2,
78
+ COLLECTIBLE_SPRITE_LAYER,
79
+ xStart,
80
+ xFinish,
81
+ xIncrement,
82
+ yStart,
83
+ yFinish,
84
+ yIncrement
85
+ )
86
+ end
58
87
  function ____exports.getCollectibleDescription(self, collectibleType)
59
88
  local collectibleDescription = COLLECTIBLE_DESCRIPTION_MAP:get(collectibleType)
60
89
  if collectibleDescription ~= nil then
@@ -164,6 +193,16 @@ function ____exports.isActiveCollectible(self, collectibleType)
164
193
  local itemType = ____exports.getCollectibleItemType(nil, collectibleType)
165
194
  return itemType == ItemType.ITEM_ACTIVE
166
195
  end
196
+ function ____exports.isBlindCollectible(self, collectible)
197
+ if collectible.Variant ~= 100 then
198
+ error("You cannot get check for question mark sprites for pickups of variant: " .. tostring(collectible.Variant))
199
+ end
200
+ local sprite = collectible:GetSprite()
201
+ local animation = sprite:GetAnimation()
202
+ local frame = sprite:GetFrame()
203
+ questionMarkSprite:SetFrame(animation, frame)
204
+ return ____exports.collectibleSpriteEquals(nil, sprite, questionMarkSprite)
205
+ end
167
206
  function ____exports.isGlitchedCollectible(self, pickup)
168
207
  return pickup.Variant == 100 and pickup.SubType > GLITCHED_ITEM_THRESHOLD
169
208
  end
@@ -1,12 +1,15 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /// <reference types="typescript-to-lua/language-extensions" />
3
3
  import { SerializationType } from "../enums/SerializationType";
4
- declare type SerializedColor = LuaTable<string, string | number>;
4
+ declare type SerializedColor = LuaTable<string, unknown> & {
5
+ __serializedColorBrand: unknown;
6
+ };
5
7
  interface CopyColorReturn {
6
8
  [SerializationType.NONE]: Color;
7
9
  [SerializationType.SERIALIZE]: SerializedColor;
8
10
  [SerializationType.DESERIALIZE]: Color;
9
11
  }
12
+ export declare function colorEquals(color1: Color, color2: Color): boolean;
10
13
  /**
11
14
  * Helper function to copy a `Color` object.
12
15
  *
@@ -16,9 +19,12 @@ interface CopyColorReturn {
16
19
  */
17
20
  export declare function copyColor<C extends Color | SerializedColor, S extends SerializationType>(color: C, serializationType: S): CopyColorReturn[S];
18
21
  export declare function copyColor<C extends Color | SerializedColor>(color: C): CopyColorReturn[SerializationType.NONE];
19
- export declare function copyKColor(kColor: KColor): KColor;
20
22
  export declare function getDefaultColor(): Color;
21
- export declare function getDefaultKColor(): KColor;
22
23
  /** Helper function to check if something is an instantiated Color object. */
23
24
  export declare function isColor(object: unknown): object is Color;
25
+ /**
26
+ * Used to determine is the given table is a serialized `Color` object created by the save data
27
+ * manager and/or the `deepCopy` function.
28
+ */
29
+ export declare function isSerializedColor(object: unknown): object is SerializedColor;
24
30
  export {};
@@ -5,15 +5,17 @@ local ____SerializationBrand = require("enums.private.SerializationBrand")
5
5
  local SerializationBrand = ____SerializationBrand.SerializationBrand
6
6
  local ____SerializationType = require("enums.SerializationType")
7
7
  local SerializationType = ____SerializationType.SerializationType
8
+ local ____isaacAPIClass = require("functions.isaacAPIClass")
9
+ local isaacAPIClassEquals = ____isaacAPIClass.isaacAPIClassEquals
10
+ local isIsaacAPIClassOfType = ____isaacAPIClass.isIsaacAPIClassOfType
8
11
  local ____table = require("functions.table")
9
12
  local copyValuesToTable = ____table.copyValuesToTable
10
13
  local getNumbersFromTable = ____table.getNumbersFromTable
11
- local ____userdata = require("functions.userdata")
12
- local isUserdataObject = ____userdata.isUserdataObject
14
+ local tableHasKeys = ____table.tableHasKeys
13
15
  local ____utils = require("functions.utils")
14
16
  local ensureAllCases = ____utils.ensureAllCases
15
17
  function ____exports.isColor(self, object)
16
- return isUserdataObject(nil, object, OBJECT_NAME)
18
+ return isIsaacAPIClassOfType(nil, object, OBJECT_NAME)
17
19
  end
18
20
  local KEYS = {
19
21
  "R",
@@ -25,14 +27,17 @@ local KEYS = {
25
27
  "BO"
26
28
  }
27
29
  OBJECT_NAME = "Color"
30
+ function ____exports.colorEquals(self, color1, color2)
31
+ return isaacAPIClassEquals(nil, color1, color2, KEYS)
32
+ end
28
33
  function ____exports.copyColor(self, color, serializationType)
29
34
  if serializationType == nil then
30
35
  serializationType = SerializationType.NONE
31
36
  end
32
37
  repeat
33
- local ____switch3 = serializationType
34
- local ____cond3 = ____switch3 == SerializationType.NONE
35
- if ____cond3 then
38
+ local ____switch4 = serializationType
39
+ local ____cond4 = ____switch4 == SerializationType.NONE
40
+ if ____cond4 then
36
41
  do
37
42
  if not ____exports.isColor(nil, color) then
38
43
  error(((("Failed to copy a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
@@ -48,8 +53,8 @@ function ____exports.copyColor(self, color, serializationType)
48
53
  )
49
54
  end
50
55
  end
51
- ____cond3 = ____cond3 or ____switch3 == SerializationType.SERIALIZE
52
- if ____cond3 then
56
+ ____cond4 = ____cond4 or ____switch4 == SerializationType.SERIALIZE
57
+ if ____cond4 then
53
58
  do
54
59
  if not ____exports.isColor(nil, color) then
55
60
  error(((("Failed to serialize a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
@@ -60,8 +65,8 @@ function ____exports.copyColor(self, color, serializationType)
60
65
  return colorTable
61
66
  end
62
67
  end
63
- ____cond3 = ____cond3 or ____switch3 == SerializationType.DESERIALIZE
64
- if ____cond3 then
68
+ ____cond4 = ____cond4 or ____switch4 == SerializationType.DESERIALIZE
69
+ if ____cond4 then
65
70
  do
66
71
  local colorType = type(color)
67
72
  if ____exports.isColor(nil, color) or colorType ~= "table" then
@@ -91,13 +96,19 @@ function ____exports.copyColor(self, color, serializationType)
91
96
  end
92
97
  until true
93
98
  end
94
- function ____exports.copyKColor(self, kColor)
95
- return KColor(kColor.Red, kColor.Green, kColor.Blue, kColor.Alpha)
96
- end
97
99
  function ____exports.getDefaultColor(self)
98
100
  return Color(1, 1, 1)
99
101
  end
100
- function ____exports.getDefaultKColor(self)
101
- return KColor(1, 1, 1, 1)
102
+ function ____exports.isSerializedColor(self, object)
103
+ local objectType = type(object)
104
+ if objectType ~= "table" then
105
+ return false
106
+ end
107
+ local ____table = object
108
+ return tableHasKeys(
109
+ nil,
110
+ ____table,
111
+ table.unpack(KEYS)
112
+ ) and ____table[SerializationBrand.COLOR] ~= nil
102
113
  end
103
114
  return ____exports
@@ -12,6 +12,7 @@ import { SerializationType } from "../enums/SerializationType";
12
12
  * - TSTL classes
13
13
  * - `DefaultMap`
14
14
  * - Isaac `Color` objects
15
+ * - Isaac `KColor` objects
15
16
  * - Isaac `RNG` objects
16
17
  * - Isaac `Vector` objects
17
18
  *
@@ -5,7 +5,7 @@ local Map = ____lualib.Map
5
5
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
6
6
  local __TS__Iterator = ____lualib.__TS__Iterator
7
7
  local ____exports = {}
8
- local isTSTLClass, copyClass, getNewClassFromMetatable, deepCopyValue, checkMetatable, validateValue, isCopyableIsaacAPIClass, TSTL_CLASS_KEYS
8
+ local isTSTLClass, checkMetatable, copyClass, getNewClassFromMetatable, deepCopyValue, validateValue, getNewValue, TSTL_CLASS_KEYS
9
9
  local ____DefaultMap = require("classes.DefaultMap")
10
10
  local DefaultMap = ____DefaultMap.DefaultMap
11
11
  local ____SerializationBrand = require("enums.private.SerializationBrand")
@@ -15,20 +15,15 @@ local ____SerializationType = require("enums.SerializationType")
15
15
  local SerializationType = ____SerializationType.SerializationType
16
16
  local ____constants = require("features.saveDataManager.constants")
17
17
  local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
18
- local ____color = require("functions.color")
19
- local isColor = ____color.isColor
18
+ local ____isaacAPIClass = require("functions.isaacAPIClass")
19
+ local isSerializableIsaacAPIClass = ____isaacAPIClass.isSerializableIsaacAPIClass
20
20
  local ____log = require("functions.log")
21
21
  local log = ____log.log
22
- local ____rng = require("functions.rng")
23
- local copyRNG = ____rng.copyRNG
24
- local isRNG = ____rng.isRNG
25
- local isSerializedRNG = ____rng.isSerializedRNG
22
+ local ____serialization = require("functions.serialization")
23
+ local copySerializableIsaacAPIClass = ____serialization.copySerializableIsaacAPIClass
24
+ local isSerializedIsaacAPIClass = ____serialization.isSerializedIsaacAPIClass
26
25
  local ____utils = require("functions.utils")
27
26
  local getTraversalDescription = ____utils.getTraversalDescription
28
- local ____vector = require("functions.vector")
29
- local copyVector = ____vector.copyVector
30
- local isSerializedVector = ____vector.isSerializedVector
31
- local isVector = ____vector.isVector
32
27
  function ____exports.deepCopy(self, oldObject, serializationType, traversalDescription)
33
28
  if serializationType == nil then
34
29
  serializationType = SerializationType.NONE
@@ -180,6 +175,14 @@ function isTSTLClass(self, object)
180
175
  end
181
176
  return numKeys == TSTL_CLASS_KEYS.size
182
177
  end
178
+ function checkMetatable(self, ____table, traversalDescription)
179
+ local metatable = getmetatable(____table)
180
+ if metatable == nil then
181
+ return
182
+ end
183
+ local tableDescription = traversalDescription == "" and "the table to copy" or ("\"" .. traversalDescription) .. "\""
184
+ 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.)")
185
+ end
183
186
  function copyClass(self, oldClass)
184
187
  local metatable = getmetatable(oldClass)
185
188
  local newClass = getNewClassFromMetatable(nil, metatable)
@@ -208,18 +211,13 @@ function deepCopyValue(self, oldObject, newObject, key, value, traversalDescript
208
211
  log("deepCopy is converting a TSTL map with number keys to strings.")
209
212
  end
210
213
  end
211
- local newValue
212
- if isRNG(nil, value) or isSerializedRNG(nil, value) and serializationType == SerializationType.DESERIALIZE then
213
- newValue = copyRNG(nil, value, serializationType)
214
- elseif isVector(nil, value) or isSerializedVector(nil, value) and serializationType == SerializationType.DESERIALIZE then
215
- newValue = copyVector(nil, value, serializationType)
216
- elseif valueType == "table" then
217
- local ____table = value
218
- traversalDescription = getTraversalDescription(nil, key, traversalDescription)
219
- newValue = ____exports.deepCopy(nil, ____table, serializationType, traversalDescription)
220
- else
221
- newValue = value
222
- end
214
+ local newValue = getNewValue(
215
+ nil,
216
+ key,
217
+ value,
218
+ traversalDescription,
219
+ serializationType
220
+ )
223
221
  if __TS__InstanceOf(newObject, Map) then
224
222
  newObject:set(key, newValue)
225
223
  elseif __TS__InstanceOf(newObject, Set) then
@@ -229,24 +227,27 @@ function deepCopyValue(self, oldObject, newObject, key, value, traversalDescript
229
227
  newObject[keyToUse] = newValue
230
228
  end
231
229
  end
232
- function checkMetatable(self, ____table, traversalDescription)
233
- local metatable = getmetatable(____table)
234
- if metatable == nil then
235
- return
236
- end
237
- local tableDescription = traversalDescription == "" and "the table to copy" or ("\"" .. traversalDescription) .. "\""
238
- 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.)")
239
- end
240
230
  function validateValue(self, value, valueType, traversalDescription)
241
- if isCopyableIsaacAPIClass(nil, value) then
231
+ if isSerializableIsaacAPIClass(nil, value) then
242
232
  return
243
233
  end
244
234
  if valueType == "function" or valueType == "nil" or valueType == "thread" or valueType == "userdata" then
245
235
  error(((("The deepCopy function detected that \"" .. traversalDescription) .. "\" has a value of type \"") .. valueType) .. "\", which is not supported.")
246
236
  end
247
237
  end
248
- function isCopyableIsaacAPIClass(self, value)
249
- return isColor(nil, value) or isRNG(nil, value) or isVector(nil, value)
238
+ function getNewValue(self, key, value, traversalDescription, serializationType)
239
+ if isSerializableIsaacAPIClass(nil, value) then
240
+ return copySerializableIsaacAPIClass(nil, value, serializationType)
241
+ end
242
+ if isSerializedIsaacAPIClass(nil, value) and serializationType == SerializationType.DESERIALIZE then
243
+ return copySerializableIsaacAPIClass(nil, value, serializationType)
244
+ end
245
+ if type(value) == "table" then
246
+ local ____table = value
247
+ traversalDescription = getTraversalDescription(nil, key, traversalDescription)
248
+ return ____exports.deepCopy(nil, ____table, serializationType, traversalDescription)
249
+ end
250
+ return value
250
251
  end
251
252
  TSTL_CLASS_KEYS = __TS__New(Set, {"____constructor", "__index", "constructor"})
252
253
  return ____exports
@@ -0,0 +1,25 @@
1
+ import { IsaacAPIClass } from "../types/private/IsaacAPIClass";
2
+ import { SerializableIsaacAPIClass } from "../types/private/SerializableIsaacAPIClass";
3
+ /**
4
+ * Helper function to get the type of a class from the Isaac API. This is contained within the
5
+ * "__type" metatable key. In this context, the type of the class is equivalent to the name.
6
+ *
7
+ * For example, a `Vector` class is has a type of "Vector".
8
+ *
9
+ * Returns undefined if the object is not of type `userdata` or if the "__type" metatable key does
10
+ * not exist.
11
+ */
12
+ export declare function getIsaacAPIClassType(object: unknown): string | undefined;
13
+ /**
14
+ * Helper function to check if something is an instantiated class from the Isaac API. (All classes
15
+ * from the Isaac API have a type of "userdata" in Lua with a metatable key of "__type" equal to the
16
+ * name of the class.)
17
+ */
18
+ export declare function isIsaacAPIClass(object: unknown): object is IsaacAPIClass;
19
+ export declare function isIsaacAPIClassOfType(object: unknown, classType: string): boolean;
20
+ export declare function isSerializableIsaacAPIClass(object: unknown): object is SerializableIsaacAPIClass;
21
+ /**
22
+ * Helper function to check if an instantiated Isaac API class is equal to another one of the same
23
+ * type. You must provide the list of keys to check for.
24
+ */
25
+ export declare function isaacAPIClassEquals(object1: unknown, object2: unknown, keys: string[]): boolean;
@@ -0,0 +1,52 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Set = ____lualib.Set
3
+ local __TS__New = ____lualib.__TS__New
4
+ local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
5
+ local ____exports = {}
6
+ local ____SerializableIsaacAPIClassType = require("enums.private.SerializableIsaacAPIClassType")
7
+ local SerializableIsaacAPIClassType = ____SerializableIsaacAPIClassType.SerializableIsaacAPIClassType
8
+ local ____utils = require("functions.utils")
9
+ local getEnumValues = ____utils.getEnumValues
10
+ local SERIALIZABLE_ISAAC_API_CLASS_TYPES_SET = __TS__New(
11
+ Set,
12
+ getEnumValues(nil, SerializableIsaacAPIClassType)
13
+ )
14
+ function ____exports.getIsaacAPIClassType(self, object)
15
+ local objectType = type(object)
16
+ if objectType ~= "userdata" then
17
+ return nil
18
+ end
19
+ local metatable = getmetatable(object)
20
+ if metatable == nil then
21
+ return nil
22
+ end
23
+ local classType = metatable.__type
24
+ if type(classType) ~= "string" then
25
+ return nil
26
+ end
27
+ return classType
28
+ end
29
+ function ____exports.isIsaacAPIClass(self, object)
30
+ local isaacAPIClassType = ____exports.getIsaacAPIClassType(nil, object)
31
+ return isaacAPIClassType ~= nil
32
+ end
33
+ function ____exports.isIsaacAPIClassOfType(self, object, classType)
34
+ local isaacAPIClassType = ____exports.getIsaacAPIClassType(nil, object)
35
+ return isaacAPIClassType == classType or isaacAPIClassType == "const " .. classType
36
+ end
37
+ function ____exports.isSerializableIsaacAPIClass(self, object)
38
+ local classType = ____exports.getIsaacAPIClassType(nil, object)
39
+ if classType == nil then
40
+ return false
41
+ end
42
+ return SERIALIZABLE_ISAAC_API_CLASS_TYPES_SET:has(classType)
43
+ end
44
+ function ____exports.isaacAPIClassEquals(self, object1, object2, keys)
45
+ local table1 = object1
46
+ local table2 = object2
47
+ return __TS__ArrayEvery(
48
+ keys,
49
+ function(____, key) return table1[key] == table2[key] end
50
+ )
51
+ end
52
+ return ____exports
@@ -0,0 +1,30 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="typescript-to-lua/language-extensions" />
3
+ import { SerializationType } from "../enums/SerializationType";
4
+ declare type SerializedKColor = LuaTable<string, unknown> & {
5
+ __serializedKColorBrand: unknown;
6
+ };
7
+ interface CopyKColorReturn {
8
+ [SerializationType.NONE]: KColor;
9
+ [SerializationType.SERIALIZE]: SerializedKColor;
10
+ [SerializationType.DESERIALIZE]: KColor;
11
+ }
12
+ /**
13
+ * Helper function to copy a `KColor` object.
14
+ *
15
+ * @param kColor The KColor object to copy. In the case of deserialization, this will actually be a
16
+ * Lua table instead of an instantiated KColor class.
17
+ * @param serializationType Default is `SerializationType.NONE`.
18
+ */
19
+ export declare function copyKColor<K extends KColor | SerializedKColor, S extends SerializationType>(kColor: K, serializationType: S): CopyKColorReturn[S];
20
+ export declare function copyKColor<K extends KColor | SerializedKColor>(kColor: K): CopyKColorReturn[SerializationType.NONE];
21
+ export declare function getDefaultKColor(): KColor;
22
+ /** Helper function to check if something is an instantiated KColor object. */
23
+ export declare function isKColor(object: unknown): object is KColor;
24
+ /**
25
+ * Used to determine is the given table is a serialized `KColor` object created by the save data
26
+ * manager and/or the `deepCopy` function.
27
+ */
28
+ export declare function isSerializedKColor(object: unknown): object is SerializedKColor;
29
+ export declare function kColorEquals(kColor1: KColor, kColor2: KColor): boolean;
30
+ export {};
@@ -0,0 +1,90 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ local OBJECT_NAME
4
+ local ____SerializationBrand = require("enums.private.SerializationBrand")
5
+ local SerializationBrand = ____SerializationBrand.SerializationBrand
6
+ local ____SerializationType = require("enums.SerializationType")
7
+ local SerializationType = ____SerializationType.SerializationType
8
+ local ____isaacAPIClass = require("functions.isaacAPIClass")
9
+ local isaacAPIClassEquals = ____isaacAPIClass.isaacAPIClassEquals
10
+ local isIsaacAPIClassOfType = ____isaacAPIClass.isIsaacAPIClassOfType
11
+ local ____table = require("functions.table")
12
+ local copyValuesToTable = ____table.copyValuesToTable
13
+ local getNumbersFromTable = ____table.getNumbersFromTable
14
+ local tableHasKeys = ____table.tableHasKeys
15
+ local ____utils = require("functions.utils")
16
+ local ensureAllCases = ____utils.ensureAllCases
17
+ function ____exports.isKColor(self, object)
18
+ return isIsaacAPIClassOfType(nil, object, OBJECT_NAME)
19
+ end
20
+ local KEYS = {"Red", "Green", "Blue", "Alpha"}
21
+ OBJECT_NAME = "KColor"
22
+ function ____exports.copyKColor(self, kColor, serializationType)
23
+ if serializationType == nil then
24
+ serializationType = SerializationType.NONE
25
+ end
26
+ repeat
27
+ local ____switch3 = serializationType
28
+ local ____cond3 = ____switch3 == SerializationType.NONE
29
+ if ____cond3 then
30
+ do
31
+ if not ____exports.isKColor(nil, kColor) then
32
+ error(((("Failed to copy a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
33
+ end
34
+ return KColor(kColor.Red, kColor.Green, kColor.Blue, kColor.Alpha)
35
+ end
36
+ end
37
+ ____cond3 = ____cond3 or ____switch3 == SerializationType.SERIALIZE
38
+ if ____cond3 then
39
+ do
40
+ if not ____exports.isKColor(nil, kColor) then
41
+ error(((("Failed to serialize a " .. OBJECT_NAME) .. " object since the provided object was not a userdata ") .. OBJECT_NAME) .. " class.")
42
+ end
43
+ local kColorTable = {}
44
+ copyValuesToTable(nil, kColor, KEYS, kColorTable)
45
+ kColorTable[SerializationBrand.KCOLOR] = ""
46
+ return kColorTable
47
+ end
48
+ end
49
+ ____cond3 = ____cond3 or ____switch3 == SerializationType.DESERIALIZE
50
+ if ____cond3 then
51
+ do
52
+ local kColorType = type(kColor)
53
+ if ____exports.isKColor(nil, kColor) or kColorType ~= "table" then
54
+ error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
55
+ end
56
+ local r, g, b, a = table.unpack(getNumbersFromTable(
57
+ nil,
58
+ kColor,
59
+ OBJECT_NAME,
60
+ table.unpack(KEYS)
61
+ ))
62
+ return KColor(r, g, b, a)
63
+ end
64
+ end
65
+ do
66
+ do
67
+ return ensureAllCases(nil, serializationType)
68
+ end
69
+ end
70
+ until true
71
+ end
72
+ function ____exports.getDefaultKColor(self)
73
+ return KColor(1, 1, 1, 1)
74
+ end
75
+ function ____exports.isSerializedKColor(self, object)
76
+ local objectType = type(object)
77
+ if objectType ~= "table" then
78
+ return false
79
+ end
80
+ local ____table = object
81
+ return tableHasKeys(
82
+ nil,
83
+ ____table,
84
+ table.unpack(KEYS)
85
+ ) and ____table[SerializationBrand.KCOLOR] ~= nil
86
+ end
87
+ function ____exports.kColorEquals(self, kColor1, kColor2)
88
+ return isaacAPIClassEquals(nil, kColor1, kColor2, KEYS)
89
+ end
90
+ return ____exports
@@ -20,6 +20,8 @@ local ____flag = require("functions.flag")
20
20
  local hasFlag = ____flag.hasFlag
21
21
  local ____gridEntity = require("functions.gridEntity")
22
22
  local getGridEntities = ____gridEntity.getGridEntities
23
+ local ____isaacAPIClass = require("functions.isaacAPIClass")
24
+ local getIsaacAPIClassType = ____isaacAPIClass.getIsaacAPIClassType
23
25
  local ____math = require("functions.math")
24
26
  local range = ____math.range
25
27
  local ____player = require("functions.player")
@@ -35,8 +37,6 @@ local ____set = require("functions.set")
35
37
  local getSortedSetValues = ____set.getSortedSetValues
36
38
  local ____trinkets = require("functions.trinkets")
37
39
  local getTrinketName = ____trinkets.getTrinketName
38
- local ____userdata = require("functions.userdata")
39
- local getUserdataType = ____userdata.getUserdataType
40
40
  local ____utils = require("functions.utils")
41
41
  local printConsole = ____utils.printConsole
42
42
  function ____exports.getDebugPrependString(self, msg, numParentFunctions)
@@ -434,7 +434,7 @@ function ____exports.logUserdata(userdata)
434
434
  ____exports.log("Userdata: [no metatable]")
435
435
  return
436
436
  end
437
- local classType = getUserdataType(nil, userdata)
437
+ local classType = getIsaacAPIClassType(nil, userdata)
438
438
  if classType == nil then
439
439
  ____exports.log("Userdata: [no class type]")
440
440
  else
@@ -1,7 +1,9 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /// <reference types="typescript-to-lua/language-extensions" />
3
3
  import { SerializationType } from "../enums/SerializationType";
4
- declare type SerializedRNG = LuaTable<string, string | number>;
4
+ declare type SerializedRNG = LuaTable<string, unknown> & {
5
+ __serializedRNGBrand: unknown;
6
+ };
5
7
  interface CopyRNGReturn {
6
8
  [SerializationType.NONE]: RNG;
7
9
  [SerializationType.SERIALIZE]: SerializedRNG;
@@ -25,8 +27,8 @@ export declare function getRandomSeed(): Seed;
25
27
  /** Helper function to check if something is an instantiated RNG object. */
26
28
  export declare function isRNG(object: unknown): object is RNG;
27
29
  /**
28
- * Used to determine is the given table is a serialized Vector created by the save data manager
29
- * and/or the `deepCopy` function.
30
+ * Used to determine is the given table is a serialized `RNG` object created by the save data
31
+ * manager and/or the `deepCopy` function.
30
32
  */
31
33
  export declare function isSerializedRNG(object: unknown): object is SerializedRNG;
32
34
  /**
@@ -35,6 +37,7 @@ export declare function isSerializedRNG(object: unknown): object is SerializedRN
35
37
  * @param seed The seed to initialize it with. Default is `getRandomSeed()`.
36
38
  */
37
39
  export declare function newRNG(seed?: Seed): RNG;
40
+ export declare function rngEquals(rng1: RNG, rng2: RNG): boolean;
38
41
  /**
39
42
  * Helper function to iterate over the provided object and set the seed for all of the values that
40
43
  * are RNG objects equal to a particular seed.
@@ -8,11 +8,12 @@ local ____SerializationBrand = require("enums.private.SerializationBrand")
8
8
  local SerializationBrand = ____SerializationBrand.SerializationBrand
9
9
  local ____SerializationType = require("enums.SerializationType")
10
10
  local SerializationType = ____SerializationType.SerializationType
11
+ local ____isaacAPIClass = require("functions.isaacAPIClass")
12
+ local isaacAPIClassEquals = ____isaacAPIClass.isaacAPIClassEquals
13
+ local isIsaacAPIClassOfType = ____isaacAPIClass.isIsaacAPIClassOfType
11
14
  local ____table = require("functions.table")
12
15
  local getNumbersFromTable = ____table.getNumbersFromTable
13
16
  local tableHasKeys = ____table.tableHasKeys
14
- local ____userdata = require("functions.userdata")
15
- local isUserdataObject = ____userdata.isUserdataObject
16
17
  local ____utils = require("functions.utils")
17
18
  local ensureAllCases = ____utils.ensureAllCases
18
19
  function ____exports.getRandomSeed(self)
@@ -21,7 +22,7 @@ function ____exports.getRandomSeed(self)
21
22
  return safeRandomNumber
22
23
  end
23
24
  function ____exports.isRNG(self, object)
24
- return isUserdataObject(nil, object, OBJECT_NAME)
25
+ return isIsaacAPIClassOfType(nil, object, OBJECT_NAME)
25
26
  end
26
27
  function ____exports.newRNG(self, seed)
27
28
  if seed == nil then
@@ -105,6 +106,9 @@ function ____exports.isSerializedRNG(self, object)
105
106
  table.unpack(KEYS)
106
107
  ) and ____table[SerializationBrand.RNG] ~= nil
107
108
  end
109
+ function ____exports.rngEquals(self, rng1, rng2)
110
+ return isaacAPIClassEquals(nil, rng1, rng2, KEYS)
111
+ end
108
112
  function ____exports.setAllRNGToSeed(self, object, seed)
109
113
  local objectType = type(object)
110
114
  if objectType ~= "table" then
@@ -0,0 +1,5 @@
1
+ import { SerializationType } from "../enums/SerializationType";
2
+ import { SerializableIsaacAPIClass } from "../types/private/SerializableIsaacAPIClass";
3
+ import { SerializedIsaacAPIClass } from "../types/private/SerializedIsaacAPIClass";
4
+ export declare function copySerializableIsaacAPIClass(isaacAPIClassOrSerializedTable: SerializableIsaacAPIClass | SerializedIsaacAPIClass, serializationType: SerializationType): unknown;
5
+ export declare function isSerializedIsaacAPIClass(object: unknown): object is SerializedIsaacAPIClass;
@@ -0,0 +1,115 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ local ____SerializableIsaacAPIClassType = require("enums.private.SerializableIsaacAPIClassType")
4
+ local SerializableIsaacAPIClassType = ____SerializableIsaacAPIClassType.SerializableIsaacAPIClassType
5
+ local ____color = require("functions.color")
6
+ local copyColor = ____color.copyColor
7
+ local isSerializedColor = ____color.isSerializedColor
8
+ local ____isaacAPIClass = require("functions.isaacAPIClass")
9
+ local getIsaacAPIClassType = ____isaacAPIClass.getIsaacAPIClassType
10
+ local ____kColor = require("functions.kColor")
11
+ local copyKColor = ____kColor.copyKColor
12
+ local isSerializedKColor = ____kColor.isSerializedKColor
13
+ local ____rng = require("functions.rng")
14
+ local copyRNG = ____rng.copyRNG
15
+ local isSerializedRNG = ____rng.isSerializedRNG
16
+ local ____utils = require("functions.utils")
17
+ local ensureAllCases = ____utils.ensureAllCases
18
+ local getEnumValues = ____utils.getEnumValues
19
+ local ____vector = require("functions.vector")
20
+ local copyVector = ____vector.copyVector
21
+ local isSerializedVector = ____vector.isSerializedVector
22
+ function ____exports.copySerializableIsaacAPIClass(self, isaacAPIClassOrSerializedTable, serializationType)
23
+ local isaacAPIClassType = getIsaacAPIClassType(nil, isaacAPIClassOrSerializedTable)
24
+ repeat
25
+ local ____switch3 = isaacAPIClassType
26
+ local ____cond3 = ____switch3 == SerializableIsaacAPIClassType.COLOR
27
+ if ____cond3 then
28
+ do
29
+ local color = isaacAPIClassOrSerializedTable
30
+ return copyColor(nil, color, serializationType)
31
+ end
32
+ end
33
+ ____cond3 = ____cond3 or ____switch3 == SerializableIsaacAPIClassType.KCOLOR
34
+ if ____cond3 then
35
+ do
36
+ local kColor = isaacAPIClassOrSerializedTable
37
+ return copyKColor(nil, kColor, serializationType)
38
+ end
39
+ end
40
+ ____cond3 = ____cond3 or ____switch3 == SerializableIsaacAPIClassType.RNG
41
+ if ____cond3 then
42
+ do
43
+ local rng = isaacAPIClassOrSerializedTable
44
+ return copyRNG(nil, rng)
45
+ end
46
+ end
47
+ ____cond3 = ____cond3 or ____switch3 == SerializableIsaacAPIClassType.VECTOR
48
+ if ____cond3 then
49
+ do
50
+ local vector = isaacAPIClassOrSerializedTable
51
+ return copyVector(nil, vector)
52
+ end
53
+ end
54
+ do
55
+ do
56
+ return ensureAllCases(nil, isaacAPIClassType)
57
+ end
58
+ end
59
+ until true
60
+ end
61
+ function ____exports.isSerializedIsaacAPIClass(self, object)
62
+ local objectType = type(object)
63
+ if objectType ~= "table" then
64
+ return false
65
+ end
66
+ local serializableIsaacAPIClassTypes = getEnumValues(nil, SerializableIsaacAPIClassType)
67
+ for ____, serializableIsaacAPIClassType in ipairs(serializableIsaacAPIClassTypes) do
68
+ repeat
69
+ local ____switch12 = serializableIsaacAPIClassType
70
+ local ____cond12 = ____switch12 == SerializableIsaacAPIClassType.COLOR
71
+ if ____cond12 then
72
+ do
73
+ if isSerializedColor(nil, object) then
74
+ return true
75
+ end
76
+ break
77
+ end
78
+ end
79
+ ____cond12 = ____cond12 or ____switch12 == SerializableIsaacAPIClassType.KCOLOR
80
+ if ____cond12 then
81
+ do
82
+ if isSerializedKColor(nil, object) then
83
+ return true
84
+ end
85
+ break
86
+ end
87
+ end
88
+ ____cond12 = ____cond12 or ____switch12 == SerializableIsaacAPIClassType.RNG
89
+ if ____cond12 then
90
+ do
91
+ if isSerializedRNG(nil, object) then
92
+ return true
93
+ end
94
+ break
95
+ end
96
+ end
97
+ ____cond12 = ____cond12 or ____switch12 == SerializableIsaacAPIClassType.VECTOR
98
+ if ____cond12 then
99
+ do
100
+ if isSerializedVector(nil, object) then
101
+ return true
102
+ end
103
+ break
104
+ end
105
+ end
106
+ do
107
+ do
108
+ ensureAllCases(nil, serializableIsaacAPIClassType)
109
+ end
110
+ end
111
+ until true
112
+ end
113
+ return false
114
+ end
115
+ return ____exports
@@ -24,3 +24,13 @@ export declare function clearSprite(sprite: Sprite, ...layerIDs: int[]): void;
24
24
  * as player animations.
25
25
  */
26
26
  export declare function getFinalFrameOfAnimation(sprite: Sprite, animation?: string): int;
27
+ /**
28
+ * Helper function to check if two sprite layers have the same sprite sheet by using the
29
+ * `Sprite.GetTexel` method.
30
+ *
31
+ * Since checking every single texel in the entire sprite is very expensive, this function requires
32
+ * that you provide a range of specific texels to check.
33
+ */
34
+ export declare function spriteEquals(sprite1: Sprite, sprite2: Sprite, layerID: int, xStart: int, xFinish: int, xIncrement: int, yStart: int, yFinish: int, yIncrement: int): boolean;
35
+ /** Helper function to check if two texels on a sprite are equivalent to each other. */
36
+ export declare function texelEquals(sprite1: Sprite, sprite2: Sprite, position: Vector, layerID: int): boolean;
@@ -2,8 +2,15 @@
2
2
  local ____exports = {}
3
3
  local ____constants = require("constants")
4
4
  local EMPTY_PNG_PATH = ____constants.EMPTY_PNG_PATH
5
+ local ____kColor = require("functions.kColor")
6
+ local kColorEquals = ____kColor.kColorEquals
5
7
  local ____math = require("functions.math")
6
8
  local range = ____math.range
9
+ function ____exports.texelEquals(self, sprite1, sprite2, position, layerID)
10
+ local kColor1 = sprite1:GetTexel(position, Vector.Zero, 1, layerID)
11
+ local kColor2 = sprite2:GetTexel(position, Vector.Zero, 1, layerID)
12
+ return kColorEquals(nil, kColor1, kColor2)
13
+ end
7
14
  function ____exports.clearSprite(self, sprite, ...)
8
15
  local layerIDs = {...}
9
16
  if #layerIDs == 0 then
@@ -29,4 +36,29 @@ function ____exports.getFinalFrameOfAnimation(self, sprite, animation)
29
36
  sprite:SetFrame(currentFrame)
30
37
  return finalFrame
31
38
  end
39
+ function ____exports.spriteEquals(self, sprite1, sprite2, layerID, xStart, xFinish, xIncrement, yStart, yFinish, yIncrement)
40
+ do
41
+ local x = xStart
42
+ while x <= xFinish do
43
+ do
44
+ local y = yStart
45
+ while y <= yFinish do
46
+ local position = Vector(x, y)
47
+ if not ____exports.texelEquals(
48
+ nil,
49
+ sprite1,
50
+ sprite2,
51
+ position,
52
+ layerID
53
+ ) then
54
+ return false
55
+ end
56
+ y = y + yIncrement
57
+ end
58
+ end
59
+ x = x + xIncrement
60
+ end
61
+ end
62
+ return true
63
+ end
32
64
  return ____exports
@@ -5,28 +5,28 @@
5
5
  */
6
6
  export declare function clearTable(table: LuaTable): void;
7
7
  /** Helper function to copy specific values from a object to a table. */
8
- export declare function copyValuesToTable(object: unknown, keys: string[], table: LuaTable<string, string | number>): void;
8
+ export declare function copyValuesToTable(object: unknown, keys: string[], table: LuaTable<string, unknown>): void;
9
9
  /**
10
10
  * Helper function to safely get boolean values from a Lua table. Will throw an error if the
11
11
  * specific value does not exist on the table.
12
12
  *
13
13
  * This function is variadic, meaning that you can specify N arguments to get N values.
14
14
  */
15
- export declare function getBooleansFromTable(table: LuaTable<string, string | number>, objectName: string, ...keys: string[]): boolean[];
15
+ export declare function getBooleansFromTable(table: LuaTable<string, unknown>, objectName: string, ...keys: string[]): boolean[];
16
16
  /**
17
17
  * Helper function to safely get number values from a Lua table. Will throw an error if the specific
18
18
  * value does not exist on the table or if it cannot be converted to a number.
19
19
  *
20
20
  * This function is variadic, meaning that you can specify N arguments to get N values.
21
21
  */
22
- export declare function getNumbersFromTable(table: LuaTable<string, string | number>, objectName: string, ...keys: string[]): number[];
22
+ export declare function getNumbersFromTable(table: LuaTable<string, unknown>, objectName: string, ...keys: string[]): number[];
23
23
  /**
24
24
  * Helper function to safely get string values from a Lua table. Will throw an error if the specific
25
25
  * value does not exist on the table.
26
26
  *
27
27
  * This function is variadic, meaning that you can specify N arguments to get N values.
28
28
  */
29
- export declare function getStringsFromTable(table: LuaTable<string, string | number>, objectName: string, ...keys: string[]): string[];
29
+ export declare function getStringsFromTable(table: LuaTable<string, unknown>, objectName: string, ...keys: string[]): string[];
30
30
  /**
31
31
  * Helper function to check if a Lua table has all of the provided keys.
32
32
  *
@@ -1,7 +1,9 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /// <reference types="typescript-to-lua/language-extensions" />
3
3
  import { SerializationType } from "../enums/SerializationType";
4
- declare type SerializedVector = LuaTable<string, string | number>;
4
+ declare type SerializedVector = LuaTable<string, unknown> & {
5
+ __serializedVectorBrand: unknown;
6
+ };
5
7
  interface CopyVectorReturn {
6
8
  [SerializationType.NONE]: Vector;
7
9
  [SerializationType.SERIALIZE]: SerializedVector;
@@ -28,12 +30,13 @@ export declare function getOneVector(): Vector;
28
30
  */
29
31
  export declare function getZeroVector(): Vector;
30
32
  /**
31
- * Used to determine is the given table is a serialized Vector created by the save data manager
32
- * and/or the `deepCopy` function.
33
+ * Used to determine is the given table is a serialized `Vector` object created by the save data
34
+ * manager and/or the `deepCopy` function.
33
35
  */
34
36
  export declare function isSerializedVector(object: unknown): object is SerializedVector;
35
37
  /** Helper function to check if something is an instantiated Vector object. */
36
38
  export declare function isVector(object: unknown): object is Vector;
39
+ export declare function vectorEquals(vector1: Vector, vector2: Vector): boolean;
37
40
  /** Helper function for finding out which way a vector is pointing. */
38
41
  export declare function vectorToDirection(vector: Vector): Direction;
39
42
  export {};
@@ -7,16 +7,17 @@ local ____SerializationType = require("enums.SerializationType")
7
7
  local SerializationType = ____SerializationType.SerializationType
8
8
  local ____directionToVector = require("objects.directionToVector")
9
9
  local DIRECTION_TO_VECTOR = ____directionToVector.DIRECTION_TO_VECTOR
10
+ local ____isaacAPIClass = require("functions.isaacAPIClass")
11
+ local isaacAPIClassEquals = ____isaacAPIClass.isaacAPIClassEquals
12
+ local isIsaacAPIClassOfType = ____isaacAPIClass.isIsaacAPIClassOfType
10
13
  local ____table = require("functions.table")
11
14
  local copyValuesToTable = ____table.copyValuesToTable
12
15
  local getNumbersFromTable = ____table.getNumbersFromTable
13
16
  local tableHasKeys = ____table.tableHasKeys
14
- local ____userdata = require("functions.userdata")
15
- local isUserdataObject = ____userdata.isUserdataObject
16
17
  local ____utils = require("functions.utils")
17
18
  local ensureAllCases = ____utils.ensureAllCases
18
19
  function ____exports.isVector(self, object)
19
- return isUserdataObject(nil, object, OBJECT_NAME)
20
+ return isIsaacAPIClassOfType(nil, object, OBJECT_NAME)
20
21
  end
21
22
  local KEYS = {"X", "Y"}
22
23
  OBJECT_NAME = "Vector"
@@ -91,6 +92,9 @@ function ____exports.isSerializedVector(self, object)
91
92
  table.unpack(KEYS)
92
93
  ) and ____table[SerializationBrand.VECTOR] ~= nil
93
94
  end
95
+ function ____exports.vectorEquals(self, vector1, vector2)
96
+ return isaacAPIClassEquals(nil, vector1, vector2, KEYS)
97
+ end
94
98
  function ____exports.vectorToDirection(self, vector)
95
99
  local degrees = vector:GetAngleDegrees()
96
100
  if degrees > -45 and degrees < 45 then
package/dist/index.d.ts CHANGED
@@ -51,8 +51,10 @@ export * from "./functions/flying";
51
51
  export * from "./functions/globals";
52
52
  export * from "./functions/gridEntity";
53
53
  export * from "./functions/input";
54
+ export * from "./functions/isaacAPIClass";
54
55
  export * from "./functions/jsonHelpers";
55
56
  export * from "./functions/jsonRoom";
57
+ export * from "./functions/kColor";
56
58
  export * from "./functions/language";
57
59
  export * from "./functions/log";
58
60
  export * from "./functions/map";
@@ -74,6 +76,7 @@ export * from "./functions/roomData";
74
76
  export * from "./functions/rooms";
75
77
  export * from "./functions/run";
76
78
  export * from "./functions/seeds";
79
+ export * from "./functions/serialization";
77
80
  export * from "./functions/set";
78
81
  export * from "./functions/sound";
79
82
  export * from "./functions/spawnCollectible";
@@ -88,7 +91,6 @@ export * from "./functions/trinketGive";
88
91
  export * from "./functions/trinkets";
89
92
  export * from "./functions/trinketSet";
90
93
  export * from "./functions/ui";
91
- export * from "./functions/userdata";
92
94
  export * from "./functions/utils";
93
95
  export * from "./functions/vector";
94
96
  export * from "./maps/cardMap";
package/dist/index.lua CHANGED
@@ -411,6 +411,14 @@ do
411
411
  end
412
412
  end
413
413
  end
414
+ do
415
+ local ____export = require("functions.isaacAPIClass")
416
+ for ____exportKey, ____exportValue in pairs(____export) do
417
+ if ____exportKey ~= "default" then
418
+ ____exports[____exportKey] = ____exportValue
419
+ end
420
+ end
421
+ end
414
422
  do
415
423
  local ____export = require("functions.jsonHelpers")
416
424
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -427,6 +435,14 @@ do
427
435
  end
428
436
  end
429
437
  end
438
+ do
439
+ local ____export = require("functions.kColor")
440
+ for ____exportKey, ____exportValue in pairs(____export) do
441
+ if ____exportKey ~= "default" then
442
+ ____exports[____exportKey] = ____exportValue
443
+ end
444
+ end
445
+ end
430
446
  do
431
447
  local ____export = require("functions.language")
432
448
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -592,6 +608,14 @@ do
592
608
  end
593
609
  end
594
610
  end
611
+ do
612
+ local ____export = require("functions.serialization")
613
+ for ____exportKey, ____exportValue in pairs(____export) do
614
+ if ____exportKey ~= "default" then
615
+ ____exports[____exportKey] = ____exportValue
616
+ end
617
+ end
618
+ end
595
619
  do
596
620
  local ____export = require("functions.set")
597
621
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -704,14 +728,6 @@ do
704
728
  end
705
729
  end
706
730
  end
707
- do
708
- local ____export = require("functions.userdata")
709
- for ____exportKey, ____exportValue in pairs(____export) do
710
- if ____exportKey ~= "default" then
711
- ____exports[____exportKey] = ____exportValue
712
- end
713
- end
714
- end
715
731
  do
716
732
  local ____export = require("functions.utils")
717
733
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -0,0 +1,4 @@
1
+ /// <reference types="typescript-to-lua/language-extensions" />
2
+ export declare type IsaacAPIClass = LuaTable<string, unknown> & {
3
+ __isaacAPIClassBrand: unknown;
4
+ };
@@ -0,0 +1,3 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ return ____exports
@@ -0,0 +1,4 @@
1
+ import { IsaacAPIClass } from "./IsaacAPIClass";
2
+ export declare type SerializableIsaacAPIClass = IsaacAPIClass & {
3
+ __serializableIsaacAPIClassBrand: unknown;
4
+ };
@@ -0,0 +1,3 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ return ____exports
@@ -0,0 +1,4 @@
1
+ /// <reference types="typescript-to-lua/language-extensions" />
2
+ export declare type SerializedIsaacAPIClass = LuaTable<string, unknown> & {
3
+ __serializedIsaacAPIClassBrand: unknown;
4
+ };
@@ -0,0 +1,3 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.219",
3
+ "version": "1.2.220",
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.379",
28
+ "isaac-typescript-definitions": "^1.0.380",
29
29
  "isaacscript-lint": "^1.0.95",
30
30
  "isaacscript-tsconfig": "^1.1.8",
31
31
  "typedoc": "^0.22.13",