isaacscript-common 1.2.219 → 1.2.222
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/enums/private/SerializableIsaacAPIClassType.d.ts +7 -0
- package/dist/enums/private/SerializableIsaacAPIClassType.lua +8 -0
- package/dist/enums/private/SerializationBrand.d.ts +1 -0
- package/dist/enums/private/SerializationBrand.lua +1 -0
- package/dist/features/extraConsoleCommands/commands.lua +3 -2
- package/dist/features/saveDataManager/merge.d.ts +1 -0
- package/dist/features/saveDataManager/merge.lua +7 -19
- package/dist/functions/collectibles.d.ts +6 -2
- package/dist/functions/collectibles.lua +41 -2
- package/dist/functions/color.d.ts +9 -3
- package/dist/functions/color.lua +26 -15
- package/dist/functions/deepCopy.d.ts +1 -0
- package/dist/functions/deepCopy.lua +35 -34
- package/dist/functions/isaacAPIClass.d.ts +25 -0
- package/dist/functions/isaacAPIClass.lua +52 -0
- package/dist/functions/kColor.d.ts +30 -0
- package/dist/functions/kColor.lua +90 -0
- package/dist/functions/log.lua +3 -3
- package/dist/functions/rng.d.ts +6 -3
- package/dist/functions/rng.lua +7 -3
- package/dist/functions/roomData.d.ts +7 -0
- package/dist/functions/roomData.lua +10 -0
- package/dist/functions/rooms.d.ts +4 -0
- package/dist/functions/rooms.lua +32 -6
- package/dist/functions/serialization.d.ts +5 -0
- package/dist/functions/serialization.lua +115 -0
- package/dist/functions/sprite.d.ts +10 -0
- package/dist/functions/sprite.lua +32 -0
- package/dist/functions/table.d.ts +4 -4
- package/dist/functions/vector.d.ts +6 -3
- package/dist/functions/vector.lua +7 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.lua +24 -8
- package/dist/types/private/IsaacAPIClass.d.ts +4 -0
- package/dist/types/private/IsaacAPIClass.lua +3 -0
- package/dist/types/private/SerializableIsaacAPIClass.d.ts +4 -0
- package/dist/types/private/SerializableIsaacAPIClass.lua +3 -0
- package/dist/types/private/SerializedIsaacAPIClass.d.ts +4 -0
- package/dist/types/private/SerializedIsaacAPIClass.lua +3 -0
- package/package.json +2 -2
|
@@ -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
|
|
@@ -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)
|
|
@@ -40,6 +40,7 @@ local ____playerIndex = require("functions.playerIndex")
|
|
|
40
40
|
local getPlayers = ____playerIndex.getPlayers
|
|
41
41
|
local ____roomData = require("functions.roomData")
|
|
42
42
|
local getRoomData = ____roomData.getRoomData
|
|
43
|
+
local getRoomDescriptor = ____roomData.getRoomDescriptor
|
|
43
44
|
local ____rooms = require("functions.rooms")
|
|
44
45
|
local changeRoom = ____rooms.changeRoom
|
|
45
46
|
local getRoomGridIndexesForType = ____rooms.getRoomGridIndexesForType
|
|
@@ -129,8 +130,8 @@ function devilAngel(self, useDevil)
|
|
|
129
130
|
local roomType = devilAngelRoomData.Type
|
|
130
131
|
local conflictingType = useDevil and RoomType.ROOM_ANGEL or RoomType.ROOM_DEVIL
|
|
131
132
|
if roomType == conflictingType then
|
|
132
|
-
local
|
|
133
|
-
|
|
133
|
+
local roomDescriptor = getRoomDescriptor(nil, GridRooms.ROOM_DEVIL_IDX)
|
|
134
|
+
roomDescriptor.Data = nil
|
|
134
135
|
end
|
|
135
136
|
end
|
|
136
137
|
if useDevil then
|
|
@@ -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
|
|
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
|
|
19
|
-
local
|
|
20
|
-
local
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
oldTable[key] =
|
|
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.
|
|
@@ -15,8 +17,8 @@ export declare function getCollectibleDescription(collectibleType: CollectibleTy
|
|
|
15
17
|
*/
|
|
16
18
|
export declare function getCollectibleDevilHeartPrice(collectibleType: CollectibleType | int, player: EntityPlayer): PickupPrice;
|
|
17
19
|
/**
|
|
18
|
-
* Helper function to get the path to a collectible's sprite. Returns
|
|
19
|
-
*
|
|
20
|
+
* Helper function to get the path to a collectible's sprite. Returns the path to the question mark
|
|
21
|
+
* sprite (i.e. from Curse of the Blind) if the provided collectible type was not valid.
|
|
20
22
|
*/
|
|
21
23
|
export declare function getCollectibleGfxFilename(collectibleType: CollectibleType | int): string;
|
|
22
24
|
/**
|
|
@@ -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
|
|
@@ -85,7 +114,7 @@ end
|
|
|
85
114
|
function ____exports.getCollectibleGfxFilename(self, collectibleType)
|
|
86
115
|
local itemConfigItem = itemConfig:GetCollectible(collectibleType)
|
|
87
116
|
if itemConfigItem == nil then
|
|
88
|
-
return
|
|
117
|
+
return BLIND_ITEM_PNG_PATH
|
|
89
118
|
end
|
|
90
119
|
return itemConfigItem.GfxFileName
|
|
91
120
|
end
|
|
@@ -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,
|
|
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 {};
|
package/dist/functions/color.lua
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
34
|
-
local
|
|
35
|
-
if
|
|
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
|
-
|
|
52
|
-
if
|
|
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
|
-
|
|
64
|
-
if
|
|
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.
|
|
101
|
-
|
|
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
|
|
@@ -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,
|
|
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
|
|
19
|
-
local
|
|
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
|
|
23
|
-
local
|
|
24
|
-
local
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
|
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
|
|
249
|
-
|
|
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 {};
|