isaacscript-common 3.15.0 → 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.
Files changed (41) hide show
  1. package/callbacks/postPlayerFatalDamage.lua +27 -1
  2. package/classes/DefaultMap.lua +6 -4
  3. package/enums/ModCallbackCustom.d.ts +1 -1
  4. package/features/deployJSONRoom.lua +62 -17
  5. package/features/saveDataManager/exports.lua +7 -6
  6. package/features/saveDataManager/load.lua +7 -5
  7. package/features/saveDataManager/main.lua +2 -2
  8. package/features/saveDataManager/merge.lua +12 -16
  9. package/features/saveDataManager/save.lua +2 -2
  10. package/features/saveDataManager/serializationBrand.lua +3 -1
  11. package/functions/ambush.lua +1 -1
  12. package/functions/array.d.ts +1 -0
  13. package/functions/array.lua +18 -12
  14. package/functions/color.lua +6 -7
  15. package/functions/deepCopy.lua +27 -24
  16. package/functions/deepCopyTests.lua +23 -27
  17. package/functions/entity.d.ts +4 -1
  18. package/functions/entity.lua +22 -25
  19. package/functions/enums.lua +3 -1
  20. package/functions/gridEntity.d.ts +3 -3
  21. package/functions/gridEntity.lua +7 -7
  22. package/functions/isaacAPIClass.lua +5 -3
  23. package/functions/jsonHelpers.d.ts +1 -1
  24. package/functions/jsonHelpers.lua +4 -4
  25. package/functions/kColor.lua +6 -7
  26. package/functions/log.d.ts +9 -2
  27. package/functions/log.lua +30 -21
  28. package/functions/rng.lua +10 -12
  29. package/functions/serialization.d.ts +1 -1
  30. package/functions/serialization.lua +9 -7
  31. package/functions/table.d.ts +14 -10
  32. package/functions/table.lua +54 -37
  33. package/functions/tstlClass.lua +6 -4
  34. package/functions/types.d.ts +10 -0
  35. package/functions/types.lua +25 -0
  36. package/functions/utils.d.ts +0 -2
  37. package/functions/utils.lua +0 -6
  38. package/functions/vector.lua +6 -7
  39. package/index.d.ts +1 -0
  40. package/index.lua +8 -0
  41. package/package.json +1 -1
@@ -2,8 +2,11 @@ local ____lualib = require("lualib_bundle")
2
2
  local Map = ____lualib.Map
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local ____exports = {}
5
- local hasSubscriptions, entityTakeDmgPlayer, v
5
+ local hasSubscriptions, entityTakeDmgPlayer, preUseItemBible, v
6
6
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
7
+ local BossID = ____isaac_2Dtypescript_2Ddefinitions.BossID
8
+ local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
9
+ local DamageFlagZero = ____isaac_2Dtypescript_2Ddefinitions.DamageFlagZero
7
10
  local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
8
11
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
9
12
  local ____cachedClasses = require("cachedClasses")
@@ -18,6 +21,8 @@ local isChildPlayer = ____playerIndex.isChildPlayer
18
21
  local ____revive = require("functions.revive")
19
22
  local isDamageToPlayerFatal = ____revive.isDamageToPlayerFatal
20
23
  local willPlayerRevive = ____revive.willPlayerRevive
24
+ local ____rooms = require("functions.rooms")
25
+ local inBossRoomOf = ____rooms.inBossRoomOf
21
26
  local ____postPlayerFatalDamage = require("callbacks.subscriptions.postPlayerFatalDamage")
22
27
  local postPlayerFatalDamageFire = ____postPlayerFatalDamage.postPlayerFatalDamageFire
23
28
  local postPlayerFatalDamageHasSubscriptions = ____postPlayerFatalDamage.postPlayerFatalDamageHasSubscriptions
@@ -63,11 +68,32 @@ function entityTakeDmgPlayer(self, tookDamage, damageAmount, damageFlags, damage
63
68
  end
64
69
  return nil
65
70
  end
71
+ function preUseItemBible(self, _collectibleType, _rng, player)
72
+ if not hasSubscriptions(nil) then
73
+ return nil
74
+ end
75
+ if not inBossRoomOf(nil, BossID.SATAN) then
76
+ return nil
77
+ end
78
+ local shouldSustainDeath = postPlayerFatalDamageFire(
79
+ nil,
80
+ player,
81
+ 0,
82
+ DamageFlagZero,
83
+ EntityRef(player),
84
+ 0
85
+ )
86
+ if shouldSustainDeath ~= nil then
87
+ return not shouldSustainDeath
88
+ end
89
+ return nil
90
+ end
66
91
  v = {run = {playersLastDamageGameFrame = __TS__New(Map)}}
67
92
  ---
68
93
  -- @internal
69
94
  function ____exports.postPlayerFatalDamageInit(self, mod)
70
95
  saveDataManager(nil, "postPlayerFatalDamage", v)
71
96
  mod:AddCallback(ModCallback.ENTITY_TAKE_DMG, entityTakeDmgPlayer, EntityType.PLAYER)
97
+ mod:AddCallback(ModCallback.PRE_USE_ITEM, preUseItemBible, CollectibleType.BIBLE)
72
98
  end
73
99
  return ____exports
@@ -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 argType = __TS__TypeOf(defaultValueOrFactoryFunction)
91
- local argIsPrimitive = argType == "boolean" or argType == "number" or argType == "string"
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 \"" .. argType) .. "\". 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.")
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 __continue25
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 __continue25
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
- ::__continue25::
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 __continue31
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
- ::__continue31::
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 = {level = {
417
- deployedRoomListIndexes = __TS__New(Set),
418
- roomToPersistentEntitiesMap = __TS__New(
419
- DefaultMap,
420
- function() return {} end
421
- ),
422
- roomToDecorationGridIndexesMap = __TS__New(
423
- DefaultMap,
424
- function() return {} end
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
- local keyType = type(key)
107
- if keyType ~= "string" then
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
- local keyType = type(key)
172
- if keyType ~= "string" then
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 iterateTableDeterministically = ____table.iterateTableDeterministically
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
- iterateTableDeterministically(
49
+ iterateTableInOrder(
47
50
  nil,
48
51
  newSaveData,
49
52
  function(____, key, value)
50
- if type(key) ~= "string" then
53
+ if not isString(nil, key) then
51
54
  return
52
55
  end
53
- local valueType = type(value)
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 iterateTableDeterministically = ____table.iterateTableDeterministically
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
- iterateTableDeterministically(
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 iterateTableDeterministically = ____table.iterateTableDeterministically
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
- local oldObjectType = type(oldObject)
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
- local newTableType = type(newTable)
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
- local oldTable = oldObject
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
- iterateTableDeterministically(
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
- iterateTableDeterministically(
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 valueType == "table" then
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
- iterateTableDeterministically(
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
- local valueType = type(value)
140
- if valueType == "table" then
137
+ if isTable(nil, value) then
141
138
  local oldValue = oldTable[key]
142
- local oldValueType = type(oldValue)
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 iterateTableDeterministically = ____table.iterateTableDeterministically
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
- iterateTableDeterministically(
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 type(key) ~= "string" then
14
+ if not isString(nil, key) then
13
15
  return false
14
16
  end
15
17
  return SERIALIZATION_BRAND_SET:has(key)
@@ -41,7 +41,7 @@ function ____exports.startAmbush(self)
41
41
  local coins = getCoins(nil)
42
42
  local coinsFromSack = __TS__ArrayFilter(
43
43
  coins,
44
- function(____, pickup) return GetPtrHash(pickup) == sackPtrHash end
44
+ function(____, pickup) return pickup.SpawnerEntity ~= nil and GetPtrHash(pickup.SpawnerEntity) == sackPtrHash end
45
45
  )
46
46
  removeEntities(nil, coinsFromSack)
47
47
  end
@@ -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.
@@ -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 type(object) ~= "table" then
286
+ if not isTable(nil, object) then
282
287
  return false
283
288
  end
284
- local ____table = object
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 numEntries = 0
290
- for key in pairs(____table) do
291
- numEntries = numEntries + 1
292
- if type(key) ~= "number" then
293
- return false
294
- end
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
- if numEntries == 0 then
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 <= numEntries do
302
- local element = ____table[i]
307
+ while i <= tableLength do
308
+ local element = object[i]
303
309
  if element == nil then
304
310
  return false
305
311
  end
@@ -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
- local colorType = type(color)
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
- local objectType = type(object)
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
- ____table,
126
+ object,
128
127
  table.unpack(KEYS)
129
- ) and ____table[SerializationBrand.COLOR] ~= nil
128
+ ) and object[SerializationBrand.COLOR] ~= nil
130
129
  end
131
130
  return ____exports