isaacscript-common 3.15.2 → 3.15.3
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/callbacks/postPlayerFatalDamage.lua +3 -3
- package/classes/DefaultMap.lua +6 -4
- package/enums/ModCallbackCustom.d.ts +1 -1
- package/features/deployJSONRoom.lua +62 -17
- package/features/saveDataManager/exports.lua +7 -6
- package/features/saveDataManager/load.lua +7 -5
- package/features/saveDataManager/main.lua +2 -2
- package/features/saveDataManager/merge.lua +12 -16
- package/features/saveDataManager/save.lua +2 -2
- package/features/saveDataManager/serializationBrand.lua +3 -1
- package/functions/array.d.ts +1 -0
- package/functions/array.lua +18 -12
- package/functions/color.lua +6 -7
- package/functions/deepCopy.lua +27 -24
- package/functions/deepCopyTests.lua +23 -27
- package/functions/entity.d.ts +4 -1
- package/functions/entity.lua +22 -25
- package/functions/enums.lua +3 -1
- package/functions/gridEntity.d.ts +3 -3
- package/functions/gridEntity.lua +7 -7
- package/functions/isaacAPIClass.lua +5 -3
- package/functions/jsonHelpers.d.ts +1 -1
- package/functions/jsonHelpers.lua +4 -4
- package/functions/kColor.lua +6 -7
- package/functions/log.d.ts +9 -2
- package/functions/log.lua +30 -21
- package/functions/rng.lua +10 -12
- package/functions/serialization.d.ts +1 -1
- package/functions/serialization.lua +9 -7
- package/functions/table.d.ts +14 -10
- package/functions/table.lua +54 -37
- package/functions/tstlClass.lua +6 -4
- package/functions/types.d.ts +10 -0
- package/functions/types.lua +25 -0
- package/functions/utils.d.ts +0 -2
- package/functions/utils.lua +0 -6
- package/functions/vector.lua +6 -7
- package/index.d.ts +1 -0
- package/index.lua +8 -0
- package/package.json +1 -1
|
@@ -70,10 +70,10 @@ function entityTakeDmgPlayer(self, tookDamage, damageAmount, damageFlags, damage
|
|
|
70
70
|
end
|
|
71
71
|
function preUseItemBible(self, _collectibleType, _rng, player)
|
|
72
72
|
if not hasSubscriptions(nil) then
|
|
73
|
-
return
|
|
73
|
+
return nil
|
|
74
74
|
end
|
|
75
75
|
if not inBossRoomOf(nil, BossID.SATAN) then
|
|
76
|
-
return
|
|
76
|
+
return nil
|
|
77
77
|
end
|
|
78
78
|
local shouldSustainDeath = postPlayerFatalDamageFire(
|
|
79
79
|
nil,
|
|
@@ -86,7 +86,7 @@ function preUseItemBible(self, _collectibleType, _rng, player)
|
|
|
86
86
|
if shouldSustainDeath ~= nil then
|
|
87
87
|
return not shouldSustainDeath
|
|
88
88
|
end
|
|
89
|
-
return
|
|
89
|
+
return nil
|
|
90
90
|
end
|
|
91
91
|
v = {run = {playersLastDamageGameFrame = __TS__New(Map)}}
|
|
92
92
|
---
|
package/classes/DefaultMap.lua
CHANGED
|
@@ -4,6 +4,9 @@ local Map = ____lualib.Map
|
|
|
4
4
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
5
5
|
local __TS__TypeOf = ____lualib.__TS__TypeOf
|
|
6
6
|
local ____exports = {}
|
|
7
|
+
local ____types = require("functions.types")
|
|
8
|
+
local isFunction = ____types.isFunction
|
|
9
|
+
local isPrimitive = ____types.isPrimitive
|
|
7
10
|
--- `DefaultMap` is a data structure that makes working with default values easier.
|
|
8
11
|
--
|
|
9
12
|
-- It is a common pattern to look up a value in a `Map`, and then, if the value does not exist, set
|
|
@@ -87,11 +90,10 @@ local DefaultMap = ____exports.DefaultMap
|
|
|
87
90
|
DefaultMap.name = "DefaultMap"
|
|
88
91
|
__TS__ClassExtends(DefaultMap, Map)
|
|
89
92
|
function DefaultMap.prototype.____constructor(self, defaultValueOrFactoryFunction, initializerArray)
|
|
90
|
-
local
|
|
91
|
-
local
|
|
92
|
-
local argIsFunction = argType == "function"
|
|
93
|
+
local argIsPrimitive = isPrimitive(nil, defaultValueOrFactoryFunction)
|
|
94
|
+
local argIsFunction = isFunction(nil, defaultValueOrFactoryFunction)
|
|
93
95
|
if not argIsPrimitive and not argIsFunction then
|
|
94
|
-
error(("Failed to instantiate a DefaultMap since the provided default value was of type \"" ..
|
|
96
|
+
error(("Failed to instantiate a DefaultMap since the provided default value was of type \"" .. __TS__TypeOf(defaultValueOrFactoryFunction)) .. "\". This error usually means that you are trying to use an array (or some other non-primitive data structure that is passed by reference) as the default value. Instead, return the data structure in a factory function, like \"() => []\". See the DefaultMap documentation for more details.")
|
|
95
97
|
end
|
|
96
98
|
Map.prototype.____constructor(self, initializerArray)
|
|
97
99
|
if argIsFunction then
|
|
@@ -734,7 +734,7 @@ export declare enum ModCallbackCustom {
|
|
|
734
734
|
* prevent the fatal damage.
|
|
735
735
|
*
|
|
736
736
|
* Note that this function does properly take into account Guppy's Collar, Broken Ankh, Spirit
|
|
737
|
-
* Shackles, and Mysterious Paper.
|
|
737
|
+
* Shackles, and Mysterious Paper. It also takes into account using The Bible on Satan.
|
|
738
738
|
*
|
|
739
739
|
* - When registering the callback, takes an optional second argument that will make the callback
|
|
740
740
|
* only fire if the player matches the `PlayerVariant` provided.
|
|
@@ -4,14 +4,16 @@ local __TS__New = ____lualib.__TS__New
|
|
|
4
4
|
local Map = ____lualib.Map
|
|
5
5
|
local __TS__Iterator = ____lualib.__TS__Iterator
|
|
6
6
|
local ____exports = {}
|
|
7
|
-
local postNewRoomReordered, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntityForJSONRoom, spawnNormalEntityForJSONRoom, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPC_TYPES_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, v
|
|
7
|
+
local preUseItemWeNeedToGoDeeper, postNewRoomReordered, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntityForJSONRoom, spawnNormalEntityForJSONRoom, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPC_TYPES_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, v
|
|
8
8
|
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
|
|
9
|
+
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
|
|
9
10
|
local EffectVariant = ____isaac_2Dtypescript_2Ddefinitions.EffectVariant
|
|
10
11
|
local EntityCollisionClass = ____isaac_2Dtypescript_2Ddefinitions.EntityCollisionClass
|
|
11
12
|
local EntityFlag = ____isaac_2Dtypescript_2Ddefinitions.EntityFlag
|
|
12
13
|
local EntityGridCollisionClass = ____isaac_2Dtypescript_2Ddefinitions.EntityGridCollisionClass
|
|
13
14
|
local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
|
|
14
15
|
local GridEntityType = ____isaac_2Dtypescript_2Ddefinitions.GridEntityType
|
|
16
|
+
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
|
|
15
17
|
local PickupVariant = ____isaac_2Dtypescript_2Ddefinitions.PickupVariant
|
|
16
18
|
local PitfallVariant = ____isaac_2Dtypescript_2Ddefinitions.PitfallVariant
|
|
17
19
|
local RoomType = ____isaac_2Dtypescript_2Ddefinitions.RoomType
|
|
@@ -23,6 +25,8 @@ local ____ModCallbackCustom = require("enums.ModCallbackCustom")
|
|
|
23
25
|
local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
|
|
24
26
|
local ____featuresInitialized = require("featuresInitialized")
|
|
25
27
|
local errorIfFeaturesNotInitialized = ____featuresInitialized.errorIfFeaturesNotInitialized
|
|
28
|
+
local ____array = require("functions.array")
|
|
29
|
+
local emptyArray = ____array.emptyArray
|
|
26
30
|
local ____entity = require("functions.entity")
|
|
27
31
|
local removeAllMatchingEntities = ____entity.removeAllMatchingEntities
|
|
28
32
|
local spawn = ____entity.spawn
|
|
@@ -35,6 +39,7 @@ local ____gridEntity = require("functions.gridEntity")
|
|
|
35
39
|
local convertXMLGridEntityType = ____gridEntity.convertXMLGridEntityType
|
|
36
40
|
local getGridEntities = ____gridEntity.getGridEntities
|
|
37
41
|
local removeAllGridExcept = ____gridEntity.removeAllGridExcept
|
|
42
|
+
local removeGrid = ____gridEntity.removeGrid
|
|
38
43
|
local setGridEntityInvisible = ____gridEntity.setGridEntityInvisible
|
|
39
44
|
local spawnGridWithVariant = ____gridEntity.spawnGridWithVariant
|
|
40
45
|
local ____jsonRoom = require("functions.jsonRoom")
|
|
@@ -56,8 +61,44 @@ local ____spawnCollectible = require("functions.spawnCollectible")
|
|
|
56
61
|
local spawnCollectible = ____spawnCollectible.spawnCollectible
|
|
57
62
|
local ____utils = require("functions.utils")
|
|
58
63
|
local erange = ____utils.erange
|
|
64
|
+
local ____runInNFrames = require("features.runInNFrames")
|
|
65
|
+
local runNextGameFrame = ____runInNFrames.runNextGameFrame
|
|
59
66
|
local ____exports = require("features.saveDataManager.exports")
|
|
60
67
|
local saveDataManager = ____exports.saveDataManager
|
|
68
|
+
function preUseItemWeNeedToGoDeeper(self, _collectibleType, _rng, player)
|
|
69
|
+
if v.room.manuallyUsingShovel then
|
|
70
|
+
return nil
|
|
71
|
+
end
|
|
72
|
+
local roomListIndex = getRoomListIndex(nil)
|
|
73
|
+
if not v.level.deployedRoomListIndexes:has(roomListIndex) then
|
|
74
|
+
return nil
|
|
75
|
+
end
|
|
76
|
+
local decorations = getGridEntities(nil, GridEntityType.DECORATION)
|
|
77
|
+
for ____, decoration in ipairs(decorations) do
|
|
78
|
+
removeGrid(nil, decoration, false)
|
|
79
|
+
end
|
|
80
|
+
local playerPtr = EntityPtr(player)
|
|
81
|
+
runNextGameFrame(
|
|
82
|
+
nil,
|
|
83
|
+
function()
|
|
84
|
+
local futureEntity = playerPtr.Ref
|
|
85
|
+
if futureEntity == nil then
|
|
86
|
+
return
|
|
87
|
+
end
|
|
88
|
+
local futurePlayer = futureEntity:ToPlayer()
|
|
89
|
+
if futurePlayer == nil then
|
|
90
|
+
return
|
|
91
|
+
end
|
|
92
|
+
v.room.manuallyUsingShovel = true
|
|
93
|
+
futurePlayer:UseActiveItem(CollectibleType.WE_NEED_TO_GO_DEEPER)
|
|
94
|
+
v.room.manuallyUsingShovel = false
|
|
95
|
+
local decorationGridIndexes = v.level.roomToDecorationGridIndexesMap:getAndSetDefault(roomListIndex)
|
|
96
|
+
emptyArray(nil, decorationGridIndexes)
|
|
97
|
+
fillRoomWithDecorations(nil)
|
|
98
|
+
end
|
|
99
|
+
)
|
|
100
|
+
return true
|
|
101
|
+
end
|
|
61
102
|
function postNewRoomReordered(self)
|
|
62
103
|
local roomListIndex = getRoomListIndex(nil)
|
|
63
104
|
if not v.level.deployedRoomListIndexes:has(roomListIndex) then
|
|
@@ -124,10 +165,10 @@ function removeSpecificNPCs(self)
|
|
|
124
165
|
for ____, npc in ipairs(getNPCs(nil)) do
|
|
125
166
|
do
|
|
126
167
|
if NPC_TYPES_TO_NOT_REMOVE:has(npc.Type) then
|
|
127
|
-
goto
|
|
168
|
+
goto __continue33
|
|
128
169
|
end
|
|
129
170
|
if npc:HasEntityFlags(EntityFlag.CHARM) or npc:HasEntityFlags(EntityFlag.FRIENDLY) or npc:HasEntityFlags(EntityFlag.PERSISTENT) then
|
|
130
|
-
goto
|
|
171
|
+
goto __continue33
|
|
131
172
|
end
|
|
132
173
|
npc:ClearEntityFlags(EntityFlag.APPEAR)
|
|
133
174
|
npc:Remove()
|
|
@@ -136,7 +177,7 @@ function removeSpecificNPCs(self)
|
|
|
136
177
|
room:SetGridPath(gridIndex, 0)
|
|
137
178
|
end
|
|
138
179
|
end
|
|
139
|
-
::
|
|
180
|
+
::__continue33::
|
|
140
181
|
end
|
|
141
182
|
end
|
|
142
183
|
function fillRoomWithDecorations(self)
|
|
@@ -148,7 +189,7 @@ function fillRoomWithDecorations(self)
|
|
|
148
189
|
do
|
|
149
190
|
local existingGridEntity = room:GetGridEntity(gridIndex)
|
|
150
191
|
if existingGridEntity ~= nil then
|
|
151
|
-
goto
|
|
192
|
+
goto __continue39
|
|
152
193
|
end
|
|
153
194
|
local position = room:GetGridPosition(gridIndex)
|
|
154
195
|
local decoration = Isaac.GridSpawn(GridEntityType.DECORATION, 0, position)
|
|
@@ -157,7 +198,7 @@ function fillRoomWithDecorations(self)
|
|
|
157
198
|
end
|
|
158
199
|
decorationGridIndexes[#decorationGridIndexes + 1] = gridIndex
|
|
159
200
|
end
|
|
160
|
-
::
|
|
201
|
+
::__continue39::
|
|
161
202
|
end
|
|
162
203
|
end
|
|
163
204
|
function spawnAllEntities(self, jsonRoom, rng, verbose)
|
|
@@ -413,21 +454,25 @@ end
|
|
|
413
454
|
FEATURE_NAME = "JSON room deployer"
|
|
414
455
|
NPC_TYPES_TO_NOT_REMOVE = __TS__New(Set, {EntityType.DARK_ESAU})
|
|
415
456
|
PERSISTENT_ENTITY_TYPES = __TS__New(Set, {EntityType.WALL_HUGGER})
|
|
416
|
-
v = {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
457
|
+
v = {
|
|
458
|
+
level = {
|
|
459
|
+
deployedRoomListIndexes = __TS__New(Set),
|
|
460
|
+
roomToPersistentEntitiesMap = __TS__New(
|
|
461
|
+
DefaultMap,
|
|
462
|
+
function() return {} end
|
|
463
|
+
),
|
|
464
|
+
roomToDecorationGridIndexesMap = __TS__New(
|
|
465
|
+
DefaultMap,
|
|
466
|
+
function() return {} end
|
|
467
|
+
)
|
|
468
|
+
},
|
|
469
|
+
room = {manuallyUsingShovel = false}
|
|
470
|
+
}
|
|
427
471
|
---
|
|
428
472
|
-- @internal
|
|
429
473
|
function ____exports.deployJSONRoomInit(self, mod)
|
|
430
474
|
saveDataManager(nil, "deployJSONRoom", v)
|
|
475
|
+
mod:AddCallback(ModCallback.PRE_USE_ITEM, preUseItemWeNeedToGoDeeper, CollectibleType.WE_NEED_TO_GO_DEEPER)
|
|
431
476
|
mod:AddCallbackCustom(ModCallbackCustom.POST_NEW_ROOM_REORDERED, postNewRoomReordered)
|
|
432
477
|
end
|
|
433
478
|
--- Helper function to deconstruct a vanilla room and set up a custom room in its place.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local Map = ____lualib.Map
|
|
3
|
+
local __TS__TypeOf = ____lualib.__TS__TypeOf
|
|
3
4
|
local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
|
|
4
5
|
local ____exports = {}
|
|
5
6
|
local ____SerializationType = require("enums.SerializationType")
|
|
@@ -8,6 +9,8 @@ local ____featuresInitialized = require("featuresInitialized")
|
|
|
8
9
|
local errorIfFeaturesNotInitialized = ____featuresInitialized.errorIfFeaturesNotInitialized
|
|
9
10
|
local ____deepCopy = require("functions.deepCopy")
|
|
10
11
|
local deepCopy = ____deepCopy.deepCopy
|
|
12
|
+
local ____types = require("functions.types")
|
|
13
|
+
local isString = ____types.isString
|
|
11
14
|
local ____constants = require("features.saveDataManager.constants")
|
|
12
15
|
local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
|
|
13
16
|
local ____main = require("features.saveDataManager.main")
|
|
@@ -103,9 +106,8 @@ local saveDataMap = ____maps.saveDataMap
|
|
|
103
106
|
-- not clutter the the "save#.dat" file with unnecessary keys.
|
|
104
107
|
function ____exports.saveDataManager(self, key, v, conditionalFunc)
|
|
105
108
|
errorIfFeaturesNotInitialized(nil, SAVE_DATA_MANAGER_FEATURE_NAME)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
error((("The " .. SAVE_DATA_MANAGER_FEATURE_NAME) .. " requires that keys are strings. You tried to use a key of type: ") .. keyType)
|
|
109
|
+
if not isString(nil, key) then
|
|
110
|
+
error((("The " .. SAVE_DATA_MANAGER_FEATURE_NAME) .. " requires that keys are strings. You tried to use a key of type: ") .. __TS__TypeOf(key))
|
|
109
111
|
end
|
|
110
112
|
if saveDataMap[key] ~= nil then
|
|
111
113
|
error((("The " .. SAVE_DATA_MANAGER_FEATURE_NAME) .. " is already managing save data for a key of: ") .. key)
|
|
@@ -168,9 +170,8 @@ end
|
|
|
168
170
|
-- ```
|
|
169
171
|
function ____exports.saveDataManagerReset(self, key, childObjectKey)
|
|
170
172
|
errorIfFeaturesNotInitialized(nil, SAVE_DATA_MANAGER_FEATURE_NAME)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
error((("The " .. SAVE_DATA_MANAGER_FEATURE_NAME) .. " requires that keys are strings. You tried to use a key of type: ") .. keyType)
|
|
173
|
+
if not isString(nil, key) then
|
|
174
|
+
error((("The " .. SAVE_DATA_MANAGER_FEATURE_NAME) .. " requires that keys are strings. You tried to use a key of type: ") .. __TS__TypeOf(key))
|
|
174
175
|
end
|
|
175
176
|
local saveData = saveDataMap[key]
|
|
176
177
|
if saveData == nil then
|
|
@@ -8,7 +8,10 @@ local ____log = require("functions.log")
|
|
|
8
8
|
local log = ____log.log
|
|
9
9
|
local logError = ____log.logError
|
|
10
10
|
local ____table = require("functions.table")
|
|
11
|
-
local
|
|
11
|
+
local iterateTableInOrder = ____table.iterateTableInOrder
|
|
12
|
+
local ____types = require("functions.types")
|
|
13
|
+
local isString = ____types.isString
|
|
14
|
+
local isTable = ____types.isTable
|
|
12
15
|
local ____constants = require("features.saveDataManager.constants")
|
|
13
16
|
local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
|
|
14
17
|
local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
|
|
@@ -43,15 +46,14 @@ function ____exports.loadFromDisk(self, mod, oldSaveData)
|
|
|
43
46
|
if SAVE_DATA_MANAGER_DEBUG then
|
|
44
47
|
log("Converted data from the \"save#.dat\" to a Lua table.")
|
|
45
48
|
end
|
|
46
|
-
|
|
49
|
+
iterateTableInOrder(
|
|
47
50
|
nil,
|
|
48
51
|
newSaveData,
|
|
49
52
|
function(____, key, value)
|
|
50
|
-
if
|
|
53
|
+
if not isString(nil, key) then
|
|
51
54
|
return
|
|
52
55
|
end
|
|
53
|
-
|
|
54
|
-
if valueType ~= "table" then
|
|
56
|
+
if not isTable(nil, value) then
|
|
55
57
|
return
|
|
56
58
|
end
|
|
57
59
|
local oldSaveDataForSubscriber = oldSaveData[key]
|
|
@@ -19,7 +19,7 @@ local ____log = require("functions.log")
|
|
|
19
19
|
local logError = ____log.logError
|
|
20
20
|
local ____table = require("functions.table")
|
|
21
21
|
local clearTable = ____table.clearTable
|
|
22
|
-
local
|
|
22
|
+
local iterateTableInOrder = ____table.iterateTableInOrder
|
|
23
23
|
local ____constants = require("features.saveDataManager.constants")
|
|
24
24
|
local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
|
|
25
25
|
local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
|
|
@@ -66,7 +66,7 @@ function restoreDefaultsAll(self)
|
|
|
66
66
|
restoreDefaults(nil, SaveDataKey.ROOM)
|
|
67
67
|
end
|
|
68
68
|
function restoreDefaults(self, saveDataKey)
|
|
69
|
-
|
|
69
|
+
iterateTableInOrder(
|
|
70
70
|
nil,
|
|
71
71
|
saveDataMap,
|
|
72
72
|
function(____, subscriberName, saveData)
|
|
@@ -18,10 +18,12 @@ local deserializeIsaacAPIClass = ____serialization.deserializeIsaacAPIClass
|
|
|
18
18
|
local isSerializedIsaacAPIClass = ____serialization.isSerializedIsaacAPIClass
|
|
19
19
|
local ____table = require("functions.table")
|
|
20
20
|
local clearTable = ____table.clearTable
|
|
21
|
-
local
|
|
21
|
+
local iterateTableInOrder = ____table.iterateTableInOrder
|
|
22
22
|
local ____tstlClass = require("functions.tstlClass")
|
|
23
23
|
local isTSTLMap = ____tstlClass.isTSTLMap
|
|
24
24
|
local isTSTLSet = ____tstlClass.isTSTLSet
|
|
25
|
+
local ____types = require("functions.types")
|
|
26
|
+
local isTable = ____types.isTable
|
|
25
27
|
local ____utils = require("functions.utils")
|
|
26
28
|
local getTraversalDescription = ____utils.getTraversalDescription
|
|
27
29
|
local ____constants = require("features.saveDataManager.constants")
|
|
@@ -52,17 +54,14 @@ function ____exports.merge(self, oldObject, newTable, traversalDescription)
|
|
|
52
54
|
if SAVE_DATA_MANAGER_DEBUG then
|
|
53
55
|
log("merge is traversing: " .. traversalDescription)
|
|
54
56
|
end
|
|
55
|
-
|
|
56
|
-
if oldObjectType ~= "table" then
|
|
57
|
+
if not isTable(nil, oldObject) then
|
|
57
58
|
error("The first argument given to the merge function is not a table.")
|
|
58
59
|
end
|
|
59
|
-
|
|
60
|
-
if newTableType ~= "table" then
|
|
60
|
+
if not isTable(nil, newTable) then
|
|
61
61
|
error("The second argument given to the merge function is not a table.")
|
|
62
62
|
end
|
|
63
63
|
if isArray(nil, oldObject) and isArray(nil, newTable) then
|
|
64
|
-
|
|
65
|
-
mergeArray(nil, oldTable, newTable)
|
|
64
|
+
mergeArray(nil, oldObject, newTable)
|
|
66
65
|
return
|
|
67
66
|
end
|
|
68
67
|
if isTSTLMap(nil, oldObject) or isTSTLSet(nil, oldObject) then
|
|
@@ -73,7 +72,7 @@ function ____exports.merge(self, oldObject, newTable, traversalDescription)
|
|
|
73
72
|
end
|
|
74
73
|
function mergeArray(self, oldArray, newArray)
|
|
75
74
|
clearTable(nil, oldArray)
|
|
76
|
-
|
|
75
|
+
iterateTableInOrder(
|
|
77
76
|
nil,
|
|
78
77
|
newArray,
|
|
79
78
|
function(____, key, value)
|
|
@@ -85,7 +84,7 @@ end
|
|
|
85
84
|
function mergeTSTLObject(self, oldObject, newTable, traversalDescription)
|
|
86
85
|
oldObject:clear()
|
|
87
86
|
local convertStringKeysToNumbers = newTable[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] ~= nil
|
|
88
|
-
|
|
87
|
+
iterateTableInOrder(
|
|
89
88
|
nil,
|
|
90
89
|
newTable,
|
|
91
90
|
function(____, key, value)
|
|
@@ -101,9 +100,8 @@ function mergeTSTLObject(self, oldObject, newTable, traversalDescription)
|
|
|
101
100
|
keyToUse = numberKey
|
|
102
101
|
end
|
|
103
102
|
if isTSTLMap(nil, oldObject) then
|
|
104
|
-
local valueType = type(value)
|
|
105
103
|
local valueCopy
|
|
106
|
-
if
|
|
104
|
+
if isTable(nil, value) then
|
|
107
105
|
valueCopy = deepCopy(nil, value, SerializationType.DESERIALIZE, traversalDescription)
|
|
108
106
|
else
|
|
109
107
|
valueCopy = value
|
|
@@ -117,7 +115,7 @@ function mergeTSTLObject(self, oldObject, newTable, traversalDescription)
|
|
|
117
115
|
)
|
|
118
116
|
end
|
|
119
117
|
function mergeTable(self, oldTable, newTable, traversalDescription)
|
|
120
|
-
|
|
118
|
+
iterateTableInOrder(
|
|
121
119
|
nil,
|
|
122
120
|
newTable,
|
|
123
121
|
function(____, key, value)
|
|
@@ -136,11 +134,9 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
|
|
|
136
134
|
oldTable[key] = deserializedObject
|
|
137
135
|
return
|
|
138
136
|
end
|
|
139
|
-
|
|
140
|
-
if valueType == "table" then
|
|
137
|
+
if isTable(nil, value) then
|
|
141
138
|
local oldValue = oldTable[key]
|
|
142
|
-
|
|
143
|
-
if oldValueType ~= "table" then
|
|
139
|
+
if not isTable(nil, oldValue) then
|
|
144
140
|
oldValue = {}
|
|
145
141
|
oldTable[key] = oldValue
|
|
146
142
|
end
|
|
@@ -12,13 +12,13 @@ local jsonEncode = ____jsonHelpers.jsonEncode
|
|
|
12
12
|
local ____log = require("functions.log")
|
|
13
13
|
local log = ____log.log
|
|
14
14
|
local ____table = require("functions.table")
|
|
15
|
-
local
|
|
15
|
+
local iterateTableInOrder = ____table.iterateTableInOrder
|
|
16
16
|
local ____constants = require("features.saveDataManager.constants")
|
|
17
17
|
local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
|
|
18
18
|
local SAVE_DATA_MANAGER_FEATURE_NAME = ____constants.SAVE_DATA_MANAGER_FEATURE_NAME
|
|
19
19
|
function getAllSaveDataToWriteToDisk(self, saveDataMap, saveDataConditionalFuncMap)
|
|
20
20
|
local allSaveData = {}
|
|
21
|
-
|
|
21
|
+
iterateTableInOrder(
|
|
22
22
|
nil,
|
|
23
23
|
saveDataMap,
|
|
24
24
|
function(____, subscriberName, saveData)
|
|
@@ -6,10 +6,12 @@ local ____SerializationBrand = require("enums.private.SerializationBrand")
|
|
|
6
6
|
local SerializationBrand = ____SerializationBrand.SerializationBrand
|
|
7
7
|
local ____enums = require("functions.enums")
|
|
8
8
|
local getEnumValues = ____enums.getEnumValues
|
|
9
|
+
local ____types = require("functions.types")
|
|
10
|
+
local isString = ____types.isString
|
|
9
11
|
local SERIALIZATION_BRANDS = getEnumValues(nil, SerializationBrand)
|
|
10
12
|
local SERIALIZATION_BRAND_SET = __TS__New(Set, SERIALIZATION_BRANDS)
|
|
11
13
|
function ____exports.isSerializationBrand(self, key)
|
|
12
|
-
if
|
|
14
|
+
if not isString(nil, key) then
|
|
13
15
|
return false
|
|
14
16
|
end
|
|
15
17
|
return SERIALIZATION_BRAND_SET:has(key)
|
package/functions/array.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export declare function combineArrays<T>(...arrays: Array<T[] | readonly T[]>):
|
|
|
54
54
|
* entire array will be copied.
|
|
55
55
|
*/
|
|
56
56
|
export declare function copyArray<T>(oldArray: T[] | readonly T[], numElements?: int): T[];
|
|
57
|
+
/** Helper function to remove all of the elements in an array in-place. */
|
|
57
58
|
export declare function emptyArray<T>(array: T[]): void;
|
|
58
59
|
/**
|
|
59
60
|
* Helper function to get an array containing the indexes of an array.
|
package/functions/array.lua
CHANGED
|
@@ -8,6 +8,7 @@ local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
|
|
|
8
8
|
local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
|
|
9
9
|
local __TS__ArraySort = ____lualib.__TS__ArraySort
|
|
10
10
|
local __TS__ArrayMap = ____lualib.__TS__ArrayMap
|
|
11
|
+
local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
|
|
11
12
|
local __TS__ArraySome = ____lualib.__TS__ArraySome
|
|
12
13
|
local __TS__ArrayReduce = ____lualib.__TS__ArrayReduce
|
|
13
14
|
local ____exports = {}
|
|
@@ -17,6 +18,9 @@ local ____rng = require("functions.rng")
|
|
|
17
18
|
local getRandomSeed = ____rng.getRandomSeed
|
|
18
19
|
local isRNG = ____rng.isRNG
|
|
19
20
|
local newRNG = ____rng.newRNG
|
|
21
|
+
local ____types = require("functions.types")
|
|
22
|
+
local isNumber = ____types.isNumber
|
|
23
|
+
local isTable = ____types.isTable
|
|
20
24
|
local ____utils = require("functions.utils")
|
|
21
25
|
local erange = ____utils.erange
|
|
22
26
|
local ____repeat = ____utils["repeat"]
|
|
@@ -193,6 +197,7 @@ function ____exports.copyArray(self, oldArray, numElements)
|
|
|
193
197
|
end
|
|
194
198
|
return newArray
|
|
195
199
|
end
|
|
200
|
+
--- Helper function to remove all of the elements in an array in-place.
|
|
196
201
|
function ____exports.emptyArray(self, array)
|
|
197
202
|
__TS__ArraySplice(array, 0, #array)
|
|
198
203
|
end
|
|
@@ -278,28 +283,29 @@ end
|
|
|
278
283
|
-- - the table contains all numerical indexes that are contiguous, starting at 1
|
|
279
284
|
-- - the table has no keys (i.e. an "empty" table)
|
|
280
285
|
function ____exports.isArray(self, object)
|
|
281
|
-
if
|
|
286
|
+
if not isTable(nil, object) then
|
|
282
287
|
return false
|
|
283
288
|
end
|
|
284
|
-
local
|
|
285
|
-
local metatable = getmetatable(____table)
|
|
289
|
+
local metatable = getmetatable(object)
|
|
286
290
|
if metatable ~= nil then
|
|
287
291
|
return false
|
|
288
292
|
end
|
|
289
|
-
local
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
293
|
+
local keys = __TS__ObjectKeys(object)
|
|
294
|
+
local hasAllNumberKeys = __TS__ArrayEvery(
|
|
295
|
+
keys,
|
|
296
|
+
function(____, key) return isNumber(nil, key) end
|
|
297
|
+
)
|
|
298
|
+
if not hasAllNumberKeys then
|
|
299
|
+
return false
|
|
295
300
|
end
|
|
296
|
-
|
|
301
|
+
local tableLength = #object
|
|
302
|
+
if tableLength == 0 then
|
|
297
303
|
return true
|
|
298
304
|
end
|
|
299
305
|
do
|
|
300
306
|
local i = 1
|
|
301
|
-
while i <=
|
|
302
|
-
local element =
|
|
307
|
+
while i <= tableLength do
|
|
308
|
+
local element = object[i]
|
|
303
309
|
if element == nil then
|
|
304
310
|
return false
|
|
305
311
|
end
|
package/functions/color.lua
CHANGED
|
@@ -11,6 +11,8 @@ local ____table = require("functions.table")
|
|
|
11
11
|
local copyValuesToTable = ____table.copyValuesToTable
|
|
12
12
|
local getNumbersFromTable = ____table.getNumbersFromTable
|
|
13
13
|
local tableHasKeys = ____table.tableHasKeys
|
|
14
|
+
local ____types = require("functions.types")
|
|
15
|
+
local isTable = ____types.isTable
|
|
14
16
|
local ____utils = require("functions.utils")
|
|
15
17
|
local ensureAllCases = ____utils.ensureAllCases
|
|
16
18
|
--- Helper function to check if something is an instantiated Color object.
|
|
@@ -73,8 +75,7 @@ function ____exports.copyColor(self, color, serializationType)
|
|
|
73
75
|
____cond4 = ____cond4 or ____switch4 == SerializationType.DESERIALIZE
|
|
74
76
|
if ____cond4 then
|
|
75
77
|
do
|
|
76
|
-
|
|
77
|
-
if ____exports.isColor(nil, color) or colorType ~= "table" then
|
|
78
|
+
if not isTable(nil, color) then
|
|
78
79
|
error(("Failed to deserialize a " .. OBJECT_NAME) .. " object since the provided object was not a Lua table.")
|
|
79
80
|
end
|
|
80
81
|
local r, g, b, a, ro, go, bo = table.unpack(getNumbersFromTable(
|
|
@@ -117,15 +118,13 @@ end
|
|
|
117
118
|
--- Used to determine is the given table is a serialized `Color` object created by the save data
|
|
118
119
|
-- manager and/or the `deepCopy` function.
|
|
119
120
|
function ____exports.isSerializedColor(self, object)
|
|
120
|
-
|
|
121
|
-
if objectType ~= "table" then
|
|
121
|
+
if not isTable(nil, object) then
|
|
122
122
|
return false
|
|
123
123
|
end
|
|
124
|
-
local ____table = object
|
|
125
124
|
return tableHasKeys(
|
|
126
125
|
nil,
|
|
127
|
-
|
|
126
|
+
object,
|
|
128
127
|
table.unpack(KEYS)
|
|
129
|
-
) and
|
|
128
|
+
) and object[SerializationBrand.COLOR] ~= nil
|
|
130
129
|
end
|
|
131
130
|
return ____exports
|
package/functions/deepCopy.lua
CHANGED
|
@@ -39,6 +39,9 @@ local isTSTLMap = ____tstlClass.isTSTLMap
|
|
|
39
39
|
local isTSTLSet = ____tstlClass.isTSTLSet
|
|
40
40
|
local isUserDefinedTSTLClass = ____tstlClass.isUserDefinedTSTLClass
|
|
41
41
|
local newTSTLClass = ____tstlClass.newTSTLClass
|
|
42
|
+
local ____types = require("functions.types")
|
|
43
|
+
local isNumber = ____types.isNumber
|
|
44
|
+
local isPrimitive = ____types.isPrimitive
|
|
42
45
|
local ____utils = require("functions.utils")
|
|
43
46
|
local ensureAllCases = ____utils.ensureAllCases
|
|
44
47
|
local getTraversalDescription = ____utils.getTraversalDescription
|
|
@@ -106,8 +109,8 @@ function ____exports.deepCopy(self, value, serializationType, traversalDescripti
|
|
|
106
109
|
____cond6 = ____cond6 or ____switch6 == "table"
|
|
107
110
|
if ____cond6 then
|
|
108
111
|
do
|
|
109
|
-
local
|
|
110
|
-
return deepCopyTable(nil,
|
|
112
|
+
local luaTable = value
|
|
113
|
+
return deepCopyTable(nil, luaTable, serializationType, traversalDescription)
|
|
111
114
|
end
|
|
112
115
|
end
|
|
113
116
|
____cond6 = ____cond6 or ____switch6 == "userdata"
|
|
@@ -123,34 +126,34 @@ function ____exports.deepCopy(self, value, serializationType, traversalDescripti
|
|
|
123
126
|
end
|
|
124
127
|
until true
|
|
125
128
|
end
|
|
126
|
-
function deepCopyTable(self,
|
|
127
|
-
if isDefaultMap(nil,
|
|
128
|
-
return deepCopyDefaultMap(nil,
|
|
129
|
+
function deepCopyTable(self, luaTable, serializationType, traversalDescription)
|
|
130
|
+
if isDefaultMap(nil, luaTable) or luaTable[SerializationBrand.DEFAULT_MAP] ~= nil then
|
|
131
|
+
return deepCopyDefaultMap(nil, luaTable, serializationType, traversalDescription)
|
|
129
132
|
end
|
|
130
|
-
if isTSTLMap(nil,
|
|
131
|
-
return deepCopyMap(nil,
|
|
133
|
+
if isTSTLMap(nil, luaTable) or luaTable[SerializationBrand.MAP] ~= nil then
|
|
134
|
+
return deepCopyMap(nil, luaTable, serializationType, traversalDescription)
|
|
132
135
|
end
|
|
133
|
-
if isTSTLSet(nil,
|
|
134
|
-
return deepCopySet(nil,
|
|
136
|
+
if isTSTLSet(nil, luaTable) or luaTable[SerializationBrand.SET] ~= nil then
|
|
137
|
+
return deepCopySet(nil, luaTable, serializationType, traversalDescription)
|
|
135
138
|
end
|
|
136
|
-
local className = getTSTLClassName(nil,
|
|
139
|
+
local className = getTSTLClassName(nil, luaTable)
|
|
137
140
|
if className == "WeakMap" then
|
|
138
141
|
error("The deep copy function does not support copying the \"WeakMap\" class for: " .. traversalDescription)
|
|
139
142
|
end
|
|
140
143
|
if className == "WeakSet" then
|
|
141
144
|
error("The deep copy function does not support copying the \"WeakSet\" class for: " .. traversalDescription)
|
|
142
145
|
end
|
|
143
|
-
if isUserDefinedTSTLClass(nil,
|
|
144
|
-
return deepCopyTSTLClass(nil,
|
|
146
|
+
if isUserDefinedTSTLClass(nil, luaTable) then
|
|
147
|
+
return deepCopyTSTLClass(nil, luaTable, serializationType, traversalDescription)
|
|
145
148
|
end
|
|
146
|
-
checkMetatable(nil,
|
|
147
|
-
if isSerializedIsaacAPIClass(nil,
|
|
148
|
-
return deserializeIsaacAPIClass(nil,
|
|
149
|
+
checkMetatable(nil, luaTable, traversalDescription)
|
|
150
|
+
if isSerializedIsaacAPIClass(nil, luaTable) and serializationType == SerializationType.DESERIALIZE then
|
|
151
|
+
return deserializeIsaacAPIClass(nil, luaTable)
|
|
149
152
|
end
|
|
150
|
-
if isArray(nil,
|
|
151
|
-
return deepCopyArray(nil,
|
|
153
|
+
if isArray(nil, luaTable) then
|
|
154
|
+
return deepCopyArray(nil, luaTable, serializationType, traversalDescription)
|
|
152
155
|
end
|
|
153
|
-
return deepCopyNormalLuaTable(nil,
|
|
156
|
+
return deepCopyNormalLuaTable(nil, luaTable, serializationType, traversalDescription)
|
|
154
157
|
end
|
|
155
158
|
function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescription)
|
|
156
159
|
local ____isDefaultMap_result_0
|
|
@@ -173,7 +176,7 @@ function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescri
|
|
|
173
176
|
____cond23 = ____cond23 or ____switch23 == SerializationType.SERIALIZE
|
|
174
177
|
if ____cond23 then
|
|
175
178
|
do
|
|
176
|
-
if
|
|
179
|
+
if not isPrimitive(nil, constructorArg) then
|
|
177
180
|
return deepCopyMap(nil, defaultMap, serializationType, traversalDescription)
|
|
178
181
|
end
|
|
179
182
|
newDefaultMap = {}
|
|
@@ -308,9 +311,9 @@ function deepCopyArray(self, array, serializationType, traversalDescription)
|
|
|
308
311
|
end
|
|
309
312
|
return newArray
|
|
310
313
|
end
|
|
311
|
-
function deepCopyNormalLuaTable(self,
|
|
314
|
+
function deepCopyNormalLuaTable(self, luaTable, serializationType, traversalDescription)
|
|
312
315
|
local newTable = {}
|
|
313
|
-
local ____getCopiedEntries_result_5 = getCopiedEntries(nil,
|
|
316
|
+
local ____getCopiedEntries_result_5 = getCopiedEntries(nil, luaTable, serializationType, traversalDescription)
|
|
314
317
|
local entries = ____getCopiedEntries_result_5.entries
|
|
315
318
|
local convertedNumberKeysToStrings = ____getCopiedEntries_result_5.convertedNumberKeysToStrings
|
|
316
319
|
if convertedNumberKeysToStrings then
|
|
@@ -345,7 +348,7 @@ function getCopiedEntries(self, object, serializationType, traversalDescription)
|
|
|
345
348
|
function(____, ____bindingPattern0)
|
|
346
349
|
local key
|
|
347
350
|
key = ____bindingPattern0[1]
|
|
348
|
-
return
|
|
351
|
+
return isNumber(nil, key)
|
|
349
352
|
end
|
|
350
353
|
)
|
|
351
354
|
local convertNumberKeysToStrings = serializationType == SerializationType.SERIALIZE and hasNumberKeys
|
|
@@ -366,8 +369,8 @@ function getCopiedEntries(self, object, serializationType, traversalDescription)
|
|
|
366
369
|
end
|
|
367
370
|
return {entries = copiedEntries, convertedNumberKeysToStrings = convertNumberKeysToStrings}
|
|
368
371
|
end
|
|
369
|
-
function checkMetatable(self,
|
|
370
|
-
local metatable = getmetatable(
|
|
372
|
+
function checkMetatable(self, luaTable, traversalDescription)
|
|
373
|
+
local metatable = getmetatable(luaTable)
|
|
371
374
|
if metatable == nil then
|
|
372
375
|
return
|
|
373
376
|
end
|