isaacscript-common 1.2.59 → 1.2.60

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.
@@ -1,13 +1,14 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
- local Map = ____lualib.Map
4
3
  local __TS__New = ____lualib.__TS__New
5
4
  local ____exports = {}
6
- local hasSubscriptions, postPEffectUpdateReordered, queueEmpty, queueNotEmpty, getPickingUpItemForPlayer, v
5
+ local hasSubscriptions, postPEffectUpdateReordered, queueEmpty, queueNotEmpty, v
7
6
  local ____exports = require("features.saveDataManager.exports")
8
7
  local saveDataManager = ____exports.saveDataManager
9
8
  local ____player = require("functions.player")
10
9
  local getPlayerIndex = ____player.getPlayerIndex
10
+ local ____DefaultMap = require("types.DefaultMap")
11
+ local DefaultMap = ____DefaultMap.DefaultMap
11
12
  local ____ModCallbacksCustom = require("types.ModCallbacksCustom")
12
13
  local ModCallbacksCustom = ____ModCallbacksCustom.ModCallbacksCustom
13
14
  local ____PickingUpItem = require("types.PickingUpItem")
@@ -26,7 +27,8 @@ function postPEffectUpdateReordered(self, player)
26
27
  if not hasSubscriptions(nil) then
27
28
  return
28
29
  end
29
- local pickingUpItem = getPickingUpItemForPlayer(nil, player)
30
+ local playerIndex = getPlayerIndex(nil, player)
31
+ local pickingUpItem = v.run.playerPickingUpItemMap:getAndSetDefault(playerIndex)
30
32
  if player:IsItemQueueEmpty() then
31
33
  queueEmpty(nil, player, pickingUpItem)
32
34
  else
@@ -51,16 +53,10 @@ function queueNotEmpty(self, player, pickingUpItem)
51
53
  preItemPickupFire(nil, player, pickingUpItem)
52
54
  end
53
55
  end
54
- function getPickingUpItemForPlayer(self, player)
55
- local playerIndex = getPlayerIndex(nil, player)
56
- local pickingUpItem = v.run.pickingUpItem:get(playerIndex)
57
- if pickingUpItem == nil then
58
- pickingUpItem = newPickingUpItem(nil)
59
- v.run.pickingUpItem:set(playerIndex, pickingUpItem)
60
- end
61
- return pickingUpItem
62
- end
63
- v = {run = {pickingUpItem = __TS__New(Map)}}
56
+ v = {run = {playerPickingUpItemMap = __TS__New(
57
+ DefaultMap,
58
+ function() return newPickingUpItem(nil) end
59
+ )}}
64
60
  function ____exports.itemPickupCallbacksInit(self, mod)
65
61
  saveDataManager(nil, "itemPickup", v, hasSubscriptions)
66
62
  mod:AddCallbackCustom(ModCallbacksCustom.MC_POST_PEFFECT_UPDATE_REORDERED, postPEffectUpdateReordered)
@@ -1,8 +1,7 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
- local Map = ____lualib.Map
4
- local __TS__New = ____lualib.__TS__New
5
3
  local Set = ____lualib.Set
4
+ local __TS__New = ____lualib.__TS__New
6
5
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
7
6
  local __TS__Iterator = ____lualib.__TS__Iterator
8
7
  local ____exports = {}
@@ -12,6 +11,8 @@ local saveDataManager = ____exports.saveDataManager
12
11
  local ____gridEntity = require("functions.gridEntity")
13
12
  local getCollidingEntitiesWithGridEntity = ____gridEntity.getCollidingEntitiesWithGridEntity
14
13
  local getGridEntities = ____gridEntity.getGridEntities
14
+ local ____DefaultMap = require("types.DefaultMap")
15
+ local DefaultMap = ____DefaultMap.DefaultMap
15
16
  local ____postGridEntityCollision = require("callbacks.subscriptions.postGridEntityCollision")
16
17
  local postGridEntityCollisionFire = ____postGridEntityCollision.postGridEntityCollisionFire
17
18
  local postGridEntityCollisionHasSubscriptions = ____postGridEntityCollision.postGridEntityCollisionHasSubscriptions
@@ -25,14 +26,10 @@ function postUpdate(self)
25
26
  for ____, gridEntity in ipairs(getGridEntities(nil)) do
26
27
  do
27
28
  if gridEntity.CollisionClass == GridCollisionClass.COLLISION_NONE then
28
- goto __continue6
29
+ goto __continue7
29
30
  end
30
31
  local gridEntityPtrHash = GetPtrHash(gridEntity)
31
- local oldCollidingEntities = v.room.collidingEntitiesMap:get(gridEntityPtrHash)
32
- if oldCollidingEntities == nil then
33
- oldCollidingEntities = __TS__New(Set)
34
- v.room.collidingEntitiesMap:set(gridEntityPtrHash, oldCollidingEntities)
35
- end
32
+ local oldCollidingEntities = v.room.collidingEntitiesMap:getAndSetDefault(gridEntityPtrHash)
36
33
  local collidingEntities = getCollidingEntitiesWithGridEntity(nil, gridEntity)
37
34
  for ____, entity in ipairs(collidingEntities) do
38
35
  local entityPtrHash = GetPtrHash(entity)
@@ -52,10 +49,13 @@ function postUpdate(self)
52
49
  end
53
50
  end
54
51
  end
55
- ::__continue6::
52
+ ::__continue7::
56
53
  end
57
54
  end
58
- v = {room = {collidingEntitiesMap = __TS__New(Map)}}
55
+ v = {room = {collidingEntitiesMap = __TS__New(
56
+ DefaultMap,
57
+ function() return __TS__New(Set) end
58
+ )}}
59
59
  function ____exports.postGridEntityCollisionInit(self, mod)
60
60
  saveDataManager(nil, "postGridEntityCollision", v, hasSubscriptions)
61
61
  mod:AddCallback(ModCallbacks.MC_POST_UPDATE, postUpdate)
@@ -11,6 +11,8 @@ local getPlayerIndex = ____player.getPlayerIndex
11
11
  local ____utils = require("functions.utils")
12
12
  local ensureAllCases = ____utils.ensureAllCases
13
13
  local getEnumValues = ____utils.getEnumValues
14
+ local ____DefaultMap = require("types.DefaultMap")
15
+ local DefaultMap = ____DefaultMap.DefaultMap
14
16
  local ____HealthType = require("types.HealthType")
15
17
  local HealthType = ____HealthType.HealthType
16
18
  local ____ModCallbacksCustom = require("types.ModCallbacksCustom")
@@ -26,13 +28,8 @@ function postPEffectUpdateReordered(self, player)
26
28
  return
27
29
  end
28
30
  local playerIndex = getPlayerIndex(nil, player, true)
29
- local playerHealthMap = v.run.playersHealthMap:get(playerIndex)
30
- if playerHealthMap == nil then
31
- playerHealthMap = __TS__New(Map)
32
- v.run.playersHealthMap:set(playerIndex, playerHealthMap)
33
- end
34
- local healthTypes = getEnumValues(nil, HealthType)
35
- for ____, healthType in ipairs(healthTypes) do
31
+ local playerHealthMap = v.run.playersHealthMap:getAndSetDefault(playerIndex)
32
+ for ____, healthType in ipairs(getEnumValues(nil, HealthType)) do
36
33
  local storedHealthValue = playerHealthMap:get(healthType)
37
34
  local currentHealthValue = getCurrentHealthValue(nil, player, healthType)
38
35
  playerHealthMap:set(healthType, currentHealthValue)
@@ -100,7 +97,10 @@ function getCurrentHealthValue(self, player, healthType)
100
97
  end
101
98
  until true
102
99
  end
103
- v = {run = {playersHealthMap = __TS__New(Map)}}
100
+ v = {run = {playersHealthMap = __TS__New(
101
+ DefaultMap,
102
+ function() return __TS__New(Map) end
103
+ )}}
104
104
  function ____exports.postPlayerChangeHealthCallbackInit(self, mod)
105
105
  saveDataManager(nil, "postPlayerChangeHealth", v, hasSubscriptions)
106
106
  mod:AddCallbackCustom(ModCallbacksCustom.MC_POST_PEFFECT_UPDATE_REORDERED, postPEffectUpdateReordered)
@@ -3,15 +3,16 @@ local ____lualib = require("lualib_bundle")
3
3
  local Set = ____lualib.Set
4
4
  local __TS__New = ____lualib.__TS__New
5
5
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
6
- local Map = ____lualib.Map
7
6
  local ____exports = {}
8
- local hasSubscriptions, postPEffectUpdateReordered, TRANSFORMATIONS, v
7
+ local hasSubscriptions, postPEffectUpdateReordered, VALID_TRANSFORMATIONS, v
9
8
  local ____exports = require("features.saveDataManager.exports")
10
9
  local saveDataManager = ____exports.saveDataManager
11
10
  local ____array = require("functions.array")
12
11
  local copyArray = ____array.copyArray
13
12
  local ____player = require("functions.player")
14
13
  local getPlayerIndex = ____player.getPlayerIndex
14
+ local ____DefaultMap = require("types.DefaultMap")
15
+ local DefaultMap = ____DefaultMap.DefaultMap
15
16
  local ____ModCallbacksCustom = require("types.ModCallbacksCustom")
16
17
  local ModCallbacksCustom = ____ModCallbacksCustom.ModCallbacksCustom
17
18
  local ____postTransformation = require("callbacks.subscriptions.postTransformation")
@@ -25,21 +26,12 @@ function postPEffectUpdateReordered(self, player)
25
26
  return
26
27
  end
27
28
  local playerIndex = getPlayerIndex(nil, player)
28
- local transformations = v.run.transformations:get(playerIndex)
29
- if transformations == nil then
30
- transformations = __TS__New(Map)
31
- v.run.transformations:set(playerIndex, transformations)
32
- end
33
- for ____, playerForm in ipairs(TRANSFORMATIONS) do
29
+ local playerTransformationsMap = v.run.playersTransformationsMap:getAndSetDefault(playerIndex)
30
+ for ____, playerForm in ipairs(VALID_TRANSFORMATIONS) do
34
31
  local hasForm = player:HasPlayerForm(playerForm)
35
- local storedForm = transformations:get(playerForm)
36
- if storedForm == nil then
37
- local defaultValue = false
38
- storedForm = defaultValue
39
- transformations:set(playerForm, defaultValue)
40
- end
32
+ local storedForm = playerTransformationsMap:getAndSetDefault(playerForm)
41
33
  if hasForm ~= storedForm then
42
- transformations:set(playerForm, hasForm)
34
+ playerTransformationsMap:set(playerForm, hasForm)
43
35
  postTransformationFire(nil, player, playerForm, hasForm)
44
36
  end
45
37
  end
@@ -47,20 +39,19 @@ end
47
39
  local UNUSED_TRANSFORMATIONS = __TS__New(Set, {PlayerForm.PLAYERFORM_FLIGHT})
48
40
  local tempTransformations = {}
49
41
  do
50
- local playerForm = 0
51
- while playerForm < PlayerForm.NUM_PLAYER_FORMS do
52
- do
53
- if UNUSED_TRANSFORMATIONS:has(playerForm) then
54
- goto __continue2
55
- end
56
- __TS__ArrayPush(tempTransformations, playerForm)
42
+ local i = 0
43
+ while i < PlayerForm.NUM_PLAYER_FORMS do
44
+ if not UNUSED_TRANSFORMATIONS:has(i) then
45
+ __TS__ArrayPush(tempTransformations, i)
57
46
  end
58
- ::__continue2::
59
- playerForm = playerForm + 1
47
+ i = i + 1
60
48
  end
61
49
  end
62
- TRANSFORMATIONS = copyArray(nil, tempTransformations)
63
- v = {run = {transformations = __TS__New(Map)}}
50
+ VALID_TRANSFORMATIONS = copyArray(nil, tempTransformations)
51
+ v = {run = {playersTransformationsMap = __TS__New(
52
+ DefaultMap,
53
+ function() return __TS__New(DefaultMap, false) end
54
+ )}}
64
55
  function ____exports.postTransformationCallbackInit(self, mod)
65
56
  saveDataManager(nil, "postTransformation", v, hasSubscriptions)
66
57
  mod:AddCallbackCustom(ModCallbacksCustom.MC_POST_PEFFECT_UPDATE_REORDERED, postPEffectUpdateReordered)
@@ -1,13 +1,14 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
- local Map = ____lualib.Map
4
3
  local __TS__New = ____lualib.__TS__New
5
4
  local ____exports = {}
6
- local hasSubscriptions, entityTakeDmgPlayer, postPEffectUpdateReordered, getTrinketMap, TRINKETS_THAT_CAN_BREAK, v
5
+ local hasSubscriptions, entityTakeDmgPlayer, postPEffectUpdateReordered, TRINKETS_THAT_CAN_BREAK, v
7
6
  local ____exports = require("features.saveDataManager.exports")
8
7
  local saveDataManager = ____exports.saveDataManager
9
8
  local ____player = require("functions.player")
10
9
  local getPlayerIndex = ____player.getPlayerIndex
10
+ local ____DefaultMap = require("types.DefaultMap")
11
+ local DefaultMap = ____DefaultMap.DefaultMap
11
12
  local ____ModCallbacksCustom = require("types.ModCallbacksCustom")
12
13
  local ModCallbacksCustom = ____ModCallbacksCustom.ModCallbacksCustom
13
14
  local ____postTrinketBreak = require("callbacks.subscriptions.postTrinketBreak")
@@ -24,45 +25,41 @@ function entityTakeDmgPlayer(self, tookDamage, _damageAmount, _damageFlags, _dam
24
25
  if player == nil then
25
26
  return
26
27
  end
27
- local trinketMap = getTrinketMap(nil, player)
28
+ local playerIndex = getPlayerIndex(nil, player)
29
+ local trinketMap = v.run.playersTrinketMap:getAndSetDefault(playerIndex)
28
30
  for ____, trinketType in ipairs(TRINKETS_THAT_CAN_BREAK) do
29
31
  do
30
32
  local numTrinketsHeld = player:GetTrinketMultiplier(trinketType)
31
- local oldNumTrinketsHeld = trinketMap:get(trinketType)
32
- if oldNumTrinketsHeld == nil or numTrinketsHeld >= oldNumTrinketsHeld then
33
- goto __continue7
33
+ local oldNumTrinketsHeld = trinketMap:getAndSetDefault(trinketType)
34
+ if numTrinketsHeld >= oldNumTrinketsHeld then
35
+ goto __continue8
34
36
  end
35
37
  trinketMap:set(trinketType, numTrinketsHeld)
36
38
  local numTrinketsOnGround = Isaac.CountEntities(nil, EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, trinketType)
37
39
  if numTrinketsOnGround > 0 then
38
- goto __continue7
40
+ goto __continue8
39
41
  end
40
42
  postTrinketBreakFire(nil, player, trinketType)
41
43
  end
42
- ::__continue7::
44
+ ::__continue8::
43
45
  end
44
46
  end
45
47
  function postPEffectUpdateReordered(self, player)
46
48
  if not hasSubscriptions(nil) then
47
49
  return
48
50
  end
49
- local trinketMap = getTrinketMap(nil, player)
51
+ local playerIndex = getPlayerIndex(nil, player)
52
+ local trinketMap = v.run.playersTrinketMap:getAndSetDefault(playerIndex)
50
53
  for ____, trinketType in ipairs(TRINKETS_THAT_CAN_BREAK) do
51
54
  local numTrinkets = player:GetTrinketMultiplier(trinketType)
52
55
  trinketMap:set(trinketType, numTrinkets)
53
56
  end
54
57
  end
55
- function getTrinketMap(self, player)
56
- local playerIndex = getPlayerIndex(nil, player)
57
- local playerTrinketMap = v.run.playerTrinketMap:get(playerIndex)
58
- if playerTrinketMap == nil then
59
- playerTrinketMap = __TS__New(Map)
60
- v.run.playerTrinketMap:set(playerIndex, playerTrinketMap)
61
- end
62
- return playerTrinketMap
63
- end
64
58
  TRINKETS_THAT_CAN_BREAK = {TrinketType.TRINKET_WISH_BONE, TrinketType.TRINKET_WALNUT}
65
- v = {run = {playerTrinketMap = __TS__New(Map)}}
59
+ v = {run = {playersTrinketMap = __TS__New(
60
+ DefaultMap,
61
+ function() return __TS__New(DefaultMap, 0) end
62
+ )}}
66
63
  function ____exports.postTrinketBreakCallbackInit(self, mod)
67
64
  saveDataManager(nil, "postTrinketBreak", v, hasSubscriptions)
68
65
  mod:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, entityTakeDmgPlayer, EntityType.ENTITY_PLAYER)
@@ -2,8 +2,8 @@
2
2
  local ____lualib = require("lualib_bundle")
3
3
  local Set = ____lualib.Set
4
4
  local __TS__New = ____lualib.__TS__New
5
- local Map = ____lualib.Map
6
5
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
6
+ local Map = ____lualib.Map
7
7
  local __TS__Iterator = ____lualib.__TS__Iterator
8
8
  local ____exports = {}
9
9
  local postNewRoom, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntityForJSONRoom, spawnNormalEntityForJSONRoom, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPC_TYPES_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, initialized, v
@@ -34,6 +34,8 @@ local setRoomCleared = ____rooms.setRoomCleared
34
34
  local setRoomUncleared = ____rooms.setRoomUncleared
35
35
  local ____spawnCollectible = require("functions.spawnCollectible")
36
36
  local spawnCollectible = ____spawnCollectible.spawnCollectible
37
+ local ____DefaultMap = require("types.DefaultMap")
38
+ local DefaultMap = ____DefaultMap.DefaultMap
37
39
  local ____exports = require("features.saveDataManager.exports")
38
40
  local saveDataManager = ____exports.saveDataManager
39
41
  function postNewRoom(self)
@@ -48,10 +50,7 @@ function setDecorationsInvisible(self)
48
50
  local game = Game()
49
51
  local room = game:GetRoom()
50
52
  local roomListIndex = getRoomListIndex(nil)
51
- local decorationGridIndexes = v.level.decorationGridIndexes:get(roomListIndex)
52
- if decorationGridIndexes == nil then
53
- return
54
- end
53
+ local decorationGridIndexes = v.level.roomToDecorationGridIndexesMap:getAndSetDefault(roomListIndex)
55
54
  for ____, gridIndex in ipairs(decorationGridIndexes) do
56
55
  local gridEntity = room:GetGridEntity(gridIndex)
57
56
  if gridEntity ~= nil then
@@ -63,10 +62,7 @@ function respawnPersistentEntities(self)
63
62
  local game = Game()
64
63
  local room = game:GetRoom()
65
64
  local roomListIndex = getRoomListIndex(nil)
66
- local persistentEntities = v.level.persistentEntities:get(roomListIndex)
67
- if persistentEntities == nil then
68
- return
69
- end
65
+ local persistentEntities = v.level.roomToPersistentEntitiesMap:getAndSetDefault(roomListIndex)
70
66
  for ____, persistentEntity in ipairs(persistentEntities) do
71
67
  local position = room:GetGridPosition(persistentEntity.gridIndex)
72
68
  Isaac.Spawn(
@@ -124,18 +120,14 @@ function fillRoomWithDecorations(self)
124
120
  local room = game:GetRoom()
125
121
  local gridSize = room:GetGridSize()
126
122
  local roomListIndex = getRoomListIndex(nil)
127
- local decorationGridIndexes = v.level.decorationGridIndexes:get(roomListIndex)
128
- if decorationGridIndexes == nil then
129
- decorationGridIndexes = {}
130
- v.level.decorationGridIndexes:set(roomListIndex, decorationGridIndexes)
131
- end
123
+ local decorationGridIndexes = v.level.roomToDecorationGridIndexesMap:getAndSetDefault(roomListIndex)
132
124
  do
133
125
  local gridIndex = 0
134
126
  while gridIndex < gridSize do
135
127
  do
136
128
  local existingGridEntity = room:GetGridEntity(gridIndex)
137
129
  if existingGridEntity ~= nil then
138
- goto __continue34
130
+ goto __continue33
139
131
  end
140
132
  local position = room:GetGridPosition(gridIndex)
141
133
  local decoration = Isaac.GridSpawn(GridEntityType.GRID_DECORATION, 0, position, true)
@@ -144,7 +136,7 @@ function fillRoomWithDecorations(self)
144
136
  end
145
137
  __TS__ArrayPush(decorationGridIndexes, gridIndex)
146
138
  end
147
- ::__continue34::
139
+ ::__continue33::
148
140
  gridIndex = gridIndex + 1
149
141
  end
150
142
  end
@@ -288,11 +280,7 @@ function storePersistentEntity(self, entity)
288
280
  local gridIndex = room:GetGridIndex(entity.Position)
289
281
  local roomListIndex = getRoomListIndex(nil)
290
282
  local persistentEntity = {gridIndex = gridIndex, type = entity.Type, variant = entity.Variant, subType = entity.SubType}
291
- local persistentEntities = v.level.persistentEntities:get(roomListIndex)
292
- if persistentEntities == nil then
293
- persistentEntities = {}
294
- v.level.persistentEntities:set(roomListIndex, persistentEntities)
295
- end
283
+ local persistentEntities = v.level.roomToPersistentEntitiesMap:getAndSetDefault(roomListIndex)
296
284
  __TS__ArrayPush(persistentEntities, persistentEntity)
297
285
  end
298
286
  function fixPitGraphics(self)
@@ -412,8 +400,14 @@ PERSISTENT_ENTITY_TYPES = __TS__New(Set, {EntityType.ENTITY_WALL_HUGGER})
412
400
  initialized = false
413
401
  v = {level = {
414
402
  deployedRoomListIndexes = __TS__New(Set),
415
- persistentEntities = __TS__New(Map),
416
- decorationGridIndexes = __TS__New(Map)
403
+ roomToPersistentEntitiesMap = __TS__New(
404
+ DefaultMap,
405
+ function() return {} end
406
+ ),
407
+ roomToDecorationGridIndexesMap = __TS__New(
408
+ DefaultMap,
409
+ function() return {} end
410
+ )
417
411
  }}
418
412
  function ____exports.deployJSONRoomInit(self, mod)
419
413
  initialized = true
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ ____exports.SAVE_DATA_MANAGER_DEBUG = false
4
+ return ____exports
@@ -3,12 +3,12 @@ local ____lualib = require("lualib_bundle")
3
3
  local __TS__StringTrim = ____lualib.__TS__StringTrim
4
4
  local ____exports = {}
5
5
  local readSaveDatFile, tryLoadModData, DEFAULT_MOD_DATA
6
- local ____debug = require("debug")
7
- local DEBUG = ____debug.DEBUG
8
6
  local ____json = require("functions.json")
9
7
  local jsonDecode = ____json.jsonDecode
10
8
  local ____log = require("functions.log")
11
9
  local log = ____log.log
10
+ local ____debug = require("features.saveDataManager.debug")
11
+ local SAVE_DATA_MANAGER_DEBUG = ____debug.SAVE_DATA_MANAGER_DEBUG
12
12
  local ____merge = require("features.saveDataManager.merge")
13
13
  local merge = ____merge.merge
14
14
  function readSaveDatFile(self, mod)
@@ -37,13 +37,12 @@ function ____exports.loadFromDisk(self, mod, oldSaveData)
37
37
  end
38
38
  local jsonString = readSaveDatFile(nil, mod)
39
39
  local newSaveData = jsonDecode(nil, jsonString)
40
- if DEBUG then
40
+ if SAVE_DATA_MANAGER_DEBUG then
41
41
  log("Converted data from the \"save#.dat\" to a Lua table.")
42
42
  end
43
43
  for key, value in pairs(newSaveData) do
44
44
  do
45
- local keyType = type(key)
46
- if keyType ~= "string" then
45
+ if type(key) ~= "string" then
47
46
  goto __continue5
48
47
  end
49
48
  local valueType = type(value)
@@ -54,8 +53,8 @@ function ____exports.loadFromDisk(self, mod, oldSaveData)
54
53
  if oldSaveDataForSubscriber == nil then
55
54
  goto __continue5
56
55
  end
57
- if DEBUG then
58
- log("Merging in stored data for feature: " .. tostring(key))
56
+ if SAVE_DATA_MANAGER_DEBUG then
57
+ log("Merging in stored data for feature: " .. key)
59
58
  end
60
59
  merge(nil, oldSaveDataForSubscriber, value, key)
61
60
  end
@@ -5,23 +5,23 @@ local __TS__InstanceOf = ____lualib.__TS__InstanceOf
5
5
  local Set = ____lualib.Set
6
6
  local ____exports = {}
7
7
  local mergeArray, mergeTSTLObject, mergeTable, mergeVector
8
- local ____constantsInternal = require("constantsInternal")
9
- local TSTL_OBJECT_WITH_NUMBER_KEYS_BRAND = ____constantsInternal.TSTL_OBJECT_WITH_NUMBER_KEYS_BRAND
10
- local ____debug = require("debug")
11
- local DEBUG = ____debug.DEBUG
12
8
  local ____array = require("functions.array")
13
9
  local isArray = ____array.isArray
14
10
  local ____deepCopy = require("functions.deepCopy")
15
11
  local addTraversalDescription = ____deepCopy.addTraversalDescription
16
12
  local deepCopy = ____deepCopy.deepCopy
17
13
  local deserializeVector = ____deepCopy.deserializeVector
18
- local isBrand = ____deepCopy.isBrand
19
14
  local isSerializedVector = ____deepCopy.isSerializedVector
20
15
  local SerializationType = ____deepCopy.SerializationType
21
16
  local ____log = require("functions.log")
22
17
  local log = ____log.log
23
18
  local ____table = require("functions.table")
24
19
  local clearTable = ____table.clearTable
20
+ local ____SerializationBrand = require("types.SerializationBrand")
21
+ local isSerializationBrand = ____SerializationBrand.isSerializationBrand
22
+ local SerializationBrand = ____SerializationBrand.SerializationBrand
23
+ local ____debug = require("features.saveDataManager.debug")
24
+ local SAVE_DATA_MANAGER_DEBUG = ____debug.SAVE_DATA_MANAGER_DEBUG
25
25
  function ____exports.merge(self, oldObject, newTable, traversalDescription)
26
26
  local oldObjectType = type(oldObject)
27
27
  if oldObjectType ~= "table" then
@@ -31,7 +31,7 @@ function ____exports.merge(self, oldObject, newTable, traversalDescription)
31
31
  if newTableType ~= "table" then
32
32
  error("The second argument given to the merge function is not a table.")
33
33
  end
34
- if DEBUG then
34
+ if SAVE_DATA_MANAGER_DEBUG then
35
35
  log("merge is operating on: " .. traversalDescription)
36
36
  end
37
37
  if mergeArray(nil, oldObject, newTable) then
@@ -56,10 +56,10 @@ function mergeArray(self, oldObject, newTable)
56
56
  end
57
57
  function mergeTSTLObject(self, oldObject, newTable, traversalDescription)
58
58
  oldObject:clear()
59
- local convertStringKeysToNumbers = newTable[TSTL_OBJECT_WITH_NUMBER_KEYS_BRAND] ~= nil
59
+ local convertStringKeysToNumbers = newTable[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] ~= nil
60
60
  for key, value in pairs(newTable) do
61
61
  do
62
- if isBrand(nil, key) then
62
+ if isSerializationBrand(nil, key) then
63
63
  goto __continue13
64
64
  end
65
65
  local keyToUse = key
@@ -89,7 +89,7 @@ end
89
89
  function mergeTable(self, oldTable, newTable, traversalDescription)
90
90
  for key, value in pairs(newTable) do
91
91
  do
92
- if isBrand(nil, key) then
92
+ if isSerializationBrand(nil, key) then
93
93
  goto __continue22
94
94
  end
95
95
  if mergeVector(nil, oldTable, key, value) then
@@ -104,7 +104,7 @@ function mergeTable(self, oldTable, newTable, traversalDescription)
104
104
  ____exports.merge(nil, oldValue, value, traversalDescription)
105
105
  end
106
106
  else
107
- if DEBUG then
107
+ if SAVE_DATA_MANAGER_DEBUG then
108
108
  log((("Merging key \"" .. tostring(key)) .. "\" with value: ") .. tostring(value))
109
109
  end
110
110
  oldTable[key] = value
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ local featuresInitialized = false
4
+ function ____exports.areFeaturesInitialized(self)
5
+ return featuresInitialized
6
+ end
7
+ function ____exports.setFeaturesInitialized(self)
8
+ featuresInitialized = true
9
+ end
10
+ return ____exports
@@ -15,16 +15,16 @@ export declare enum SerializationType {
15
15
  * - TSTL Maps
16
16
  * - TSTL Sets
17
17
  * - TSTL Classes
18
+ * - DefaultMaps
18
19
  * - Isaac Vectors
19
20
  *
20
21
  * @param oldObject The object to copy.
21
22
  * @param serializationType Has 3 possible values. Can leave TypeScriptToLua objects as-is, or can
22
- * serialize objects to Lua tables, or can deserialize Lua tables to objects. No serialization by
23
- * default.
23
+ * serialize objects to Lua tables, or can deserialize Lua tables to objects. Will perform no
24
+ * serialization by default.
24
25
  * @param traversalDescription Used to track the current key that we are operating on.
25
26
  */
26
27
  export declare function deepCopy(oldObject: LuaTable | Map<AnyNotNil, unknown> | Set<AnyNotNil>, serializationType?: SerializationType, traversalDescription?: string): LuaTable | Map<AnyNotNil, unknown> | Set<AnyNotNil>;
27
- export declare function isBrand(key: AnyNotNil): boolean;
28
28
  export declare function deserializeVector(vectorTable: LuaTable): Vector;
29
29
  export declare function addTraversalDescription(key: AnyNotNil, traversalDescription: string): string;
30
30
  /**
@@ -7,14 +7,13 @@ local __TS__InstanceOf = ____lualib.__TS__InstanceOf
7
7
  local __TS__Iterator = ____lualib.__TS__Iterator
8
8
  local ____exports = {}
9
9
  local isTSTLClass, copyClass, getNewClassFromMetatable, deepCopyValue, copyVector, checkMetatable, validateValue, TSTL_CLASS_KEYS
10
- local ____constantsInternal = require("constantsInternal")
11
- local TSTL_CLASS_BRAND = ____constantsInternal.TSTL_CLASS_BRAND
12
- local TSTL_MAP_BRAND = ____constantsInternal.TSTL_MAP_BRAND
13
- local TSTL_OBJECT_WITH_NUMBER_KEYS_BRAND = ____constantsInternal.TSTL_OBJECT_WITH_NUMBER_KEYS_BRAND
14
- local TSTL_SET_BRAND = ____constantsInternal.TSTL_SET_BRAND
15
- local VECTOR_BRAND = ____constantsInternal.VECTOR_BRAND
16
- local ____debug = require("debug")
17
- local DEBUG = ____debug.DEBUG
10
+ local ____debug = require("features.saveDataManager.debug")
11
+ local SAVE_DATA_MANAGER_DEBUG = ____debug.SAVE_DATA_MANAGER_DEBUG
12
+ local ____DefaultMap = require("types.DefaultMap")
13
+ local DefaultMap = ____DefaultMap.DefaultMap
14
+ local ____SerializationBrand = require("types.SerializationBrand")
15
+ local isSerializationBrand = ____SerializationBrand.isSerializationBrand
16
+ local SerializationBrand = ____SerializationBrand.SerializationBrand
18
17
  local ____log = require("functions.log")
19
18
  local log = ____log.log
20
19
  local ____vector = require("functions.vector")
@@ -30,7 +29,7 @@ function ____exports.deepCopy(self, oldObject, serializationType, traversalDescr
30
29
  if oldObjectType ~= "table" then
31
30
  error(("The deepCopy function was given a " .. oldObjectType) .. " instead of a table.")
32
31
  end
33
- if DEBUG then
32
+ if SAVE_DATA_MANAGER_DEBUG then
34
33
  local logString = "deepCopy is operating on: " .. traversalDescription
35
34
  if serializationType == ____exports.SerializationType.SERIALIZE then
36
35
  logString = logString .. " (serializing)"
@@ -41,17 +40,30 @@ function ____exports.deepCopy(self, oldObject, serializationType, traversalDescr
41
40
  end
42
41
  local oldTable = oldObject
43
42
  local isClass = isTSTLClass(nil, oldTable)
43
+ local hasTSTLDefaultMapBrand = false
44
44
  local hasTSTLMapBrand = false
45
45
  local hasTSTLSetBrand = false
46
46
  local hasTSTLClassBrand = false
47
47
  if not __TS__InstanceOf(oldObject, Map) and not __TS__InstanceOf(oldObject, Set) and not isClass then
48
48
  checkMetatable(nil, oldTable, traversalDescription)
49
- hasTSTLMapBrand = oldTable[TSTL_MAP_BRAND] ~= nil
50
- hasTSTLSetBrand = oldTable[TSTL_SET_BRAND] ~= nil
51
- hasTSTLClassBrand = oldTable[TSTL_CLASS_BRAND] ~= nil
49
+ hasTSTLDefaultMapBrand = oldTable[SerializationBrand.DEFAULT_MAP] ~= nil
50
+ hasTSTLMapBrand = oldTable[SerializationBrand.MAP] ~= nil
51
+ hasTSTLSetBrand = oldTable[SerializationBrand.SET] ~= nil
52
+ hasTSTLClassBrand = oldTable[SerializationBrand.CLASS] ~= nil
52
53
  end
53
54
  local newObject
54
- if serializationType == ____exports.SerializationType.NONE and __TS__InstanceOf(oldObject, Map) or serializationType == ____exports.SerializationType.DESERIALIZE and hasTSTLMapBrand then
55
+ if serializationType == ____exports.SerializationType.NONE and __TS__InstanceOf(oldObject, DefaultMap) then
56
+ local oldDefaultMap = oldObject
57
+ local constructorArg = oldDefaultMap:getConstructorArg()
58
+ newObject = __TS__New(DefaultMap, constructorArg)
59
+ elseif serializationType == ____exports.SerializationType.DESERIALIZE and hasTSTLDefaultMapBrand then
60
+ local defaultValue = oldTable[SerializationBrand.DEFAULT_MAP_VALUE]
61
+ if type(defaultValue) ~= "boolean" and type(defaultValue) ~= "number" and type(defaultValue) ~= "string" then
62
+ error("The deepCopy function failed to get a valid default value for a DefaultMap object when deserializing.")
63
+ else
64
+ newObject = __TS__New(DefaultMap, defaultValue)
65
+ end
66
+ elseif serializationType == ____exports.SerializationType.NONE and __TS__InstanceOf(oldObject, Map) or serializationType == ____exports.SerializationType.DESERIALIZE and hasTSTLMapBrand then
55
67
  newObject = __TS__New(Map)
56
68
  elseif serializationType == ____exports.SerializationType.NONE and __TS__InstanceOf(oldObject, Set) or serializationType == ____exports.SerializationType.DESERIALIZE and hasTSTLSetBrand then
57
69
  newObject = __TS__New(Set)
@@ -62,12 +74,19 @@ function ____exports.deepCopy(self, oldObject, serializationType, traversalDescr
62
74
  end
63
75
  if serializationType == ____exports.SerializationType.SERIALIZE then
64
76
  local newTable = newObject
65
- if __TS__InstanceOf(oldObject, Map) then
66
- newTable[TSTL_MAP_BRAND] = ""
77
+ if __TS__InstanceOf(oldObject, DefaultMap) then
78
+ newTable[SerializationBrand.DEFAULT_MAP] = ""
79
+ local oldDefaultMap = oldObject
80
+ local defaultValue = oldDefaultMap:getConstructorArg()
81
+ if type(defaultValue) == "boolean" or type(defaultValue) == "number" or type(defaultValue) == "string" then
82
+ newTable[SerializationBrand.DEFAULT_MAP_VALUE] = defaultValue
83
+ end
84
+ elseif __TS__InstanceOf(oldObject, Map) then
85
+ newTable[SerializationBrand.MAP] = ""
67
86
  elseif __TS__InstanceOf(oldObject, Set) then
68
- newTable[TSTL_SET_BRAND] = ""
87
+ newTable[SerializationBrand.SET] = ""
69
88
  elseif isClass then
70
- newTable[TSTL_CLASS_BRAND] = ""
89
+ newTable[SerializationBrand.CLASS] = ""
71
90
  end
72
91
  end
73
92
  if __TS__InstanceOf(oldObject, Map) then
@@ -75,8 +94,8 @@ function ____exports.deepCopy(self, oldObject, serializationType, traversalDescr
75
94
  local key = ____value[1]
76
95
  local value = ____value[2]
77
96
  do
78
- if ____exports.isBrand(nil, key) then
79
- goto __continue17
97
+ if isSerializationBrand(nil, key) then
98
+ goto __continue23
80
99
  end
81
100
  deepCopyValue(
82
101
  nil,
@@ -88,13 +107,13 @@ function ____exports.deepCopy(self, oldObject, serializationType, traversalDescr
88
107
  serializationType
89
108
  )
90
109
  end
91
- ::__continue17::
110
+ ::__continue23::
92
111
  end
93
112
  elseif __TS__InstanceOf(oldObject, Set) then
94
113
  for ____, key in __TS__Iterator(oldObject:values()) do
95
114
  do
96
- if ____exports.isBrand(nil, key) then
97
- goto __continue21
115
+ if isSerializationBrand(nil, key) then
116
+ goto __continue27
98
117
  end
99
118
  local value = ""
100
119
  deepCopyValue(
@@ -107,13 +126,13 @@ function ____exports.deepCopy(self, oldObject, serializationType, traversalDescr
107
126
  serializationType
108
127
  )
109
128
  end
110
- ::__continue21::
129
+ ::__continue27::
111
130
  end
112
131
  else
113
132
  for key, value in pairs(oldObject) do
114
133
  do
115
- if ____exports.isBrand(nil, key) then
116
- goto __continue25
134
+ if isSerializationBrand(nil, key) then
135
+ goto __continue31
117
136
  end
118
137
  deepCopyValue(
119
138
  nil,
@@ -125,7 +144,7 @@ function ____exports.deepCopy(self, oldObject, serializationType, traversalDescr
125
144
  serializationType
126
145
  )
127
146
  end
128
- ::__continue25::
147
+ ::__continue31::
129
148
  end
130
149
  end
131
150
  return newObject
@@ -141,6 +160,9 @@ function isTSTLClass(self, object)
141
160
  local numKeys = 0
142
161
  for key in pairs(metatable) do
143
162
  numKeys = numKeys + 1
163
+ if type(key) ~= "string" then
164
+ return false
165
+ end
144
166
  if not TSTL_CLASS_KEYS:has(key) then
145
167
  return false
146
168
  end
@@ -161,9 +183,6 @@ function getNewClassFromMetatable(self, metatable)
161
183
  newClass:____constructor()
162
184
  return newClass
163
185
  end
164
- function ____exports.isBrand(self, key)
165
- return key == TSTL_MAP_BRAND or key == TSTL_SET_BRAND or key == TSTL_CLASS_BRAND or key == TSTL_OBJECT_WITH_NUMBER_KEYS_BRAND or key == VECTOR_BRAND
166
- end
167
186
  function deepCopyValue(self, oldObject, newObject, key, value, traversalDescription, serializationType)
168
187
  local valueType = type(value)
169
188
  validateValue(nil, value, valueType, traversalDescription)
@@ -173,8 +192,8 @@ function deepCopyValue(self, oldObject, newObject, key, value, traversalDescript
173
192
  if serializationType == ____exports.SerializationType.SERIALIZE and isTSTLObject and keyType == "number" then
174
193
  convertNumberKeysToString = true
175
194
  local newTable = newObject
176
- newTable[TSTL_OBJECT_WITH_NUMBER_KEYS_BRAND] = ""
177
- if DEBUG then
195
+ newTable[SerializationBrand.OBJECT_WITH_NUMBER_KEYS] = ""
196
+ if SAVE_DATA_MANAGER_DEBUG then
178
197
  log("deepCopy is converting a TSTL map with number keys to strings.")
179
198
  end
180
199
  end
@@ -206,7 +225,7 @@ function copyVector(self, vector, serializationType)
206
225
  local vectorTable = {}
207
226
  vectorTable.X = vector.X
208
227
  vectorTable.Y = vector.Y
209
- vectorTable[VECTOR_BRAND] = ""
228
+ vectorTable[SerializationBrand.VECTOR] = ""
210
229
  return vectorTable
211
230
  end
212
231
  local newVector = Vector(vector.X, vector.Y)
@@ -254,7 +273,7 @@ function ____exports.isSerializedVector(self, object)
254
273
  return false
255
274
  end
256
275
  local ____table = object
257
- return ____table[VECTOR_BRAND] ~= nil and ____table.X ~= nil and ____table.Y ~= nil
276
+ return ____table[SerializationBrand.VECTOR] ~= nil and ____table.X ~= nil and ____table.Y ~= nil
258
277
  end
259
278
  ____exports.SerializationType = SerializationType or ({})
260
279
  ____exports.SerializationType.NONE = 0
@@ -5,11 +5,16 @@ local __TS__New = ____lualib.__TS__New
5
5
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
6
6
  local Set = ____lualib.Set
7
7
  local ____exports = {}
8
- local copiedObjectIsTable, copiedObjectHasKeyAndValueString, copiedTableHasKeyAndValueNumber, copiedTableDoesNotCoerceTypes, copiedObjectHasNoReferencesForPrimitivesForward, copiedObjectHasNoReferencesForPrimitivesBackward, copiedObjectHasNoReferencesForArray, copiedObjectHasChildObject, copiedMapIsMap, copiedMapHasValue, copiedSetIsSet, copiedSetHasValue, copiedMapHasChildMap
8
+ local copiedObjectIsTable, copiedObjectHasKeyAndValueString, copiedTableHasKeyAndValueNumber, copiedTableDoesNotCoerceTypes, copiedObjectHasNoReferencesForPrimitivesForward, copiedObjectHasNoReferencesForPrimitivesBackward, copiedObjectHasNoReferencesForArray, copiedObjectHasChildObject, copiedMapIsMap, copiedMapHasValue, copiedSetIsSet, copiedSetHasValue, copiedMapHasChildMap, copiedDefaultMapHasChildDefaultMap, copiedDefaultMapHasBrand
9
+ local ____DefaultMap = require("types.DefaultMap")
10
+ local DefaultMap = ____DefaultMap.DefaultMap
11
+ local ____SerializationBrand = require("types.SerializationBrand")
12
+ local SerializationBrand = ____SerializationBrand.SerializationBrand
9
13
  local ____array = require("functions.array")
10
14
  local arrayEquals = ____array.arrayEquals
11
15
  local ____deepCopy = require("functions.deepCopy")
12
16
  local deepCopy = ____deepCopy.deepCopy
17
+ local SerializationType = ____deepCopy.SerializationType
13
18
  local ____log = require("functions.log")
14
19
  local log = ____log.log
15
20
  function copiedObjectIsTable(self)
@@ -241,6 +246,59 @@ function copiedMapHasChildMap(self)
241
246
  error("The copied child Map did not have a value of: " .. tostring(childMapValue))
242
247
  end
243
248
  end
249
+ function copiedDefaultMapHasChildDefaultMap(self)
250
+ local parentMapKey = "abc"
251
+ local childMapKey1 = 123
252
+ local childMapKey2 = 456
253
+ local childMapDefaultValue = 1
254
+ local childMapCustomValue = 2
255
+ local oldParentMap = __TS__New(
256
+ DefaultMap,
257
+ function() return __TS__New(DefaultMap, childMapDefaultValue) end
258
+ )
259
+ local oldChildMap = oldParentMap:getAndSetDefault(parentMapKey)
260
+ oldChildMap:getAndSetDefault(childMapKey1)
261
+ oldChildMap:set(childMapKey2, childMapCustomValue)
262
+ local newTable = deepCopy(nil, oldParentMap)
263
+ local newParentMap = newTable
264
+ local newChildMap = newParentMap:get(parentMapKey)
265
+ if newChildMap == nil then
266
+ error("The copied DefaultMap did not have a child map at key: " .. parentMapKey)
267
+ end
268
+ local newChildMapType = type(newChildMap)
269
+ if newChildMapType ~= "table" then
270
+ error("The copied child DefaultMap had a type of: " .. newChildMapType)
271
+ end
272
+ if not __TS__InstanceOf(newChildMap, DefaultMap) then
273
+ error("The copied child DefaultMap was not a DefaultMap.")
274
+ end
275
+ local newChildMapValue1 = newChildMap:get(childMapKey1)
276
+ if newChildMapValue1 == nil then
277
+ error("The copied child DefaultMap did not have a key of: " .. tostring(childMapKey1))
278
+ end
279
+ if newChildMapValue1 ~= childMapDefaultValue then
280
+ error("The copied child Map did not have a default value of: " .. tostring(childMapDefaultValue))
281
+ end
282
+ local newChildMapValue2 = newChildMap:get(childMapKey2)
283
+ if newChildMapValue2 == nil then
284
+ error("The copied child DefaultMap did not have a key of: " .. tostring(childMapKey2))
285
+ end
286
+ if newChildMapValue2 ~= childMapCustomValue then
287
+ error("The copied child Map did not have a custom value of: " .. tostring(childMapCustomValue))
288
+ end
289
+ end
290
+ function copiedDefaultMapHasBrand(self)
291
+ local oldDefaultValue = "foo"
292
+ local oldDefaultMap = __TS__New(DefaultMap, oldDefaultValue)
293
+ local newTable = deepCopy(nil, oldDefaultMap, SerializationType.SERIALIZE)
294
+ if not (newTable[SerializationBrand.DEFAULT_MAP] ~= nil) then
295
+ error("The copied DefaultMap does not have the brand: " .. SerializationBrand.DEFAULT_MAP)
296
+ end
297
+ local serializedDefaultValue = newTable[SerializationBrand.DEFAULT_MAP]
298
+ if serializedDefaultValue ~= oldDefaultValue then
299
+ error("The copied DefaultMap does not have a serialized default value of: " .. oldDefaultValue)
300
+ end
301
+ end
244
302
  function ____exports.deepCopyTests(self)
245
303
  copiedObjectIsTable(nil)
246
304
  copiedObjectHasKeyAndValueString(nil)
@@ -255,6 +313,8 @@ function ____exports.deepCopyTests(self)
255
313
  copiedSetIsSet(nil)
256
314
  copiedSetHasValue(nil)
257
315
  copiedMapHasChildMap(nil)
316
+ copiedDefaultMapHasChildDefaultMap(nil)
317
+ copiedDefaultMapHasBrand(nil)
258
318
  log("All tests passed!")
259
319
  end
260
320
  return ____exports
@@ -38,7 +38,7 @@ export declare function logColor(this: void, color: Color): void;
38
38
  export declare function logEntity(this: void, entity: Entity): void;
39
39
  export declare function logKColor(this: void, kColor: KColor): void;
40
40
  export declare function logMap(this: void, map: Map<AnyNotNil, unknown>): void;
41
- export declare function logTable(this: void, table: unknown): void;
41
+ export declare function logTable(this: void, table: unknown, parentTables?: number): void;
42
42
  export declare function logTemporaryEffects(this: void, player: EntityPlayer): void;
43
43
  export declare function logSet(this: void, set: Set<AnyNotNil>): void;
44
44
  export declare function logVector(this: void, vector: Vector): void;
@@ -125,10 +125,24 @@ function ____exports.logMap(map)
125
125
  end
126
126
  ____exports.log("The size of the map was: " .. tostring(map.size))
127
127
  end
128
- function ____exports.logTable(____table)
129
- ____exports.log("Printing out a Lua table:")
128
+ function ____exports.logTable(____table, parentTables)
129
+ if parentTables == nil then
130
+ parentTables = 0
131
+ end
132
+ local numSpaces = (parentTables + 1) * 2
133
+ if parentTables == 0 then
134
+ ____exports.log("Printing out a Lua table:")
135
+ end
136
+ local indentation = string.rep(
137
+ " ",
138
+ math.floor(numSpaces)
139
+ )
130
140
  for key, value in pairs(____table) do
131
- ____exports.log(((" Key: " .. tostring(key)) .. ", Value: ") .. tostring(value))
141
+ ____exports.log((((indentation .. "Key: ") .. tostring(key)) .. ", Value: ") .. tostring(value))
142
+ local valueType = type(value)
143
+ if valueType == "table" then
144
+ ____exports.logTable(value, parentTables + 1)
145
+ end
132
146
  end
133
147
  end
134
148
  function ____exports.logTemporaryEffects(player)
@@ -145,7 +159,7 @@ function ____exports.logTemporaryEffects(player)
145
159
  do
146
160
  local effect = effectsList:Get(i)
147
161
  if effect == nil then
148
- goto __continue36
162
+ goto __continue38
149
163
  end
150
164
  if effect.Item:IsCollectible() then
151
165
  local collectibleName = getCollectibleName(nil, effect.Item.ID)
@@ -159,7 +173,7 @@ function ____exports.logTemporaryEffects(player)
159
173
  ____exports.log(((" " .. tostring(i + 1)) .. ") Unknown type of temporary effect: ") .. tostring(effect.Item.ID))
160
174
  end
161
175
  end
162
- ::__continue36::
176
+ ::__continue38::
163
177
  i = i + 1
164
178
  end
165
179
  end
@@ -2,8 +2,8 @@
2
2
  local ____exports = {}
3
3
  local ____preventCollectibleRotate = require("features.preventCollectibleRotate")
4
4
  local preventCollectibleRotate = ____preventCollectibleRotate.preventCollectibleRotate
5
- local ____initialized = require("initialized")
6
- local areFeaturesInitialized = ____initialized.areFeaturesInitialized
5
+ local ____featuresInitialized = require("featuresInitialized")
6
+ local areFeaturesInitialized = ____featuresInitialized.areFeaturesInitialized
7
7
  local ____collectibles = require("functions.collectibles")
8
8
  local isQuestCollectible = ____collectibles.isQuestCollectible
9
9
  local ____player = require("functions.player")
@@ -40,10 +40,16 @@ export declare const ensureAllCases: (obj: never) => never;
40
40
  * when you iterate over them, you will get both the names of the enums and the values of the enums,
41
41
  * in a random order. If all you need are the values of an enum, use this helper function.
42
42
  *
43
+ * This function will return the enum values in a sorted order, which may not necessarily be the
44
+ * same order as which they were declared in.
45
+ *
46
+ * This function will work properly for both number enums and string enums. (Reverse mappings are
47
+ * not created for string enums.)
48
+ *
43
49
  * For a more in depth explanation, see:
44
50
  * https://isaacscript.github.io/docs/gotchas#iterating-over-enums
45
51
  */
46
- export declare function getEnumValues(transpiledEnum: unknown): int[];
52
+ export declare function getEnumValues<T>(transpiledEnum: T): Array<T[keyof T]>;
47
53
  /**
48
54
  * Converts a hex string like "#33aa33" to a KColor object.
49
55
  *
@@ -1,15 +1,33 @@
1
1
  declare type FirstArg<K, V> = Iterable<[K, V]> | V | ((k: K) => V);
2
2
  declare type SecondArg<K, V> = V | ((k: K) => V);
3
3
  /**
4
- * An extended Map with a new method of `getAndSetDefault`.
4
+ * An extended Map with two new methods:
5
5
  *
6
- * When instantiating the object, you must specify either a default value or a function that returns
7
- * a default value.
6
+ * - `getAndSetDefault` - If the key exists, this will return the same thing as the `get` method.
7
+ * Otherwise, it will set a default value to the key, and then return the default value.
8
+ * - `getDefaultValue` - Returns the default value to be used for a new key. (If a factory function
9
+ * was provided during instantiation, this will execute the factory function.)
10
+ * - `getConstructorArg` - Helper method for cloning the map. Returns either the default value or
11
+ * the reference to the factory function.
12
+ *
13
+ * When instantiating a new DefaultMap, you must specify either a default value or a function that
14
+ * returns a default value.
8
15
  *
9
16
  * Example:
10
17
  * ```ts
11
- * const defaultMap1 = new DefaultMap<string, string>("foo");
12
- * const defaultMap2 = new DefaultMap<string, string>(["a", "b", "c"], "bar");
18
+ * // Initializes a new empty DefaultMap with a default value of "foo"
19
+ * const defaultMapWithPrimitive = new DefaultMap<string, string>("foo");
20
+ *
21
+ * // Initializes a new empty DefaultMap with a default value of a new Map
22
+ * const defaultMapWithFactory = new DefaultMap<string, Map<string, string>>(() => {
23
+ * return new Map<string, string>();
24
+ * })
25
+ *
26
+ * // Initializes a DefaultMap with some initial values and a default value of "bar"
27
+ * const defaultMapWithInitialValues = new DefaultMap<string, string>([
28
+ * ["a1", "a2"],
29
+ * ["b1", "b2"],
30
+ * ], "bar");
13
31
  * ```
14
32
  */
15
33
  export declare class DefaultMap<K, V> extends Map<K, V> {
@@ -21,10 +39,15 @@ export declare class DefaultMap<K, V> extends Map<K, V> {
21
39
  */
22
40
  constructor(iterableOrDefaultValueOrDefaultValueFactory: FirstArg<K, V>, defaultValueOrDefaultValueFactory?: SecondArg<K, V>);
23
41
  /**
24
- * Almost the same as `Map.prototype.get`. However, if the key does not exist in the map, then
25
- * this method will set the default value for the key and return the default value.
42
+ * If the key exists, this will return the same thing as the `get` method. Otherwise, it will set
43
+ * a default value to the key, and then return the default value.
44
+ */
45
+ getAndSetDefault(key: K): V;
46
+ /**
47
+ * Returns the default value to be used for a new key. (If a factory function was provided during
48
+ * instantiation, this will execute the factory function.)
26
49
  */
27
- getAndSetDefault(key: K): V | undefined;
28
50
  getDefaultValue(key: K): V;
51
+ getConstructorArg(): V | ((k: K) => V);
29
52
  }
30
53
  export {};
@@ -55,8 +55,9 @@ function DefaultMap.prototype.____constructor(self, iterableOrDefaultValueOrDefa
55
55
  self.defaultValueFactory = defaultValueFactory
56
56
  end
57
57
  function DefaultMap.prototype.getAndSetDefault(self, key)
58
- if self:has(key) then
59
- return self:get(key)
58
+ local value = self:get(key)
59
+ if value ~= nil then
60
+ return value
60
61
  end
61
62
  local defaultValue = self:getDefaultValue(key)
62
63
  self:set(key, defaultValue)
@@ -71,4 +72,13 @@ function DefaultMap.prototype.getDefaultValue(self, key)
71
72
  end
72
73
  return error("A DefaultMap was incorrectly instantiated.")
73
74
  end
75
+ function DefaultMap.prototype.getConstructorArg(self)
76
+ if self.defaultValue ~= nil then
77
+ return self.defaultValue
78
+ end
79
+ if self.defaultValueFactory ~= nil then
80
+ return self.defaultValueFactory
81
+ end
82
+ return error("A DefaultMap was incorrectly instantiated.")
83
+ end
74
84
  return ____exports
@@ -0,0 +1,15 @@
1
+ /// <reference types="typescript-to-lua/language-extensions" />
2
+ export declare enum SerializationBrand {
3
+ DEFAULT_MAP = "__TSTL_DEFAULT_MAP",
4
+ /**
5
+ * This is set to the value that represents the default value (instead of an empty string like the
6
+ * other brands are).
7
+ */
8
+ DEFAULT_MAP_VALUE = "__TSTL_DEFAULT_MAP_VALUE",
9
+ MAP = "__TSTL_MAP",
10
+ SET = "__TSTL_SET",
11
+ CLASS = "__TSTL_CLASS",
12
+ OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS",
13
+ VECTOR = "__VECTOR"
14
+ }
15
+ export declare function isSerializationBrand(key: AnyNotNil): boolean;
@@ -0,0 +1,24 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____lualib = require("lualib_bundle")
3
+ local Set = ____lualib.Set
4
+ local __TS__New = ____lualib.__TS__New
5
+ local ____exports = {}
6
+ local ____utils = require("functions.utils")
7
+ local getEnumValues = ____utils.getEnumValues
8
+ ____exports.SerializationBrand = SerializationBrand or ({})
9
+ ____exports.SerializationBrand.DEFAULT_MAP = "__TSTL_DEFAULT_MAP"
10
+ ____exports.SerializationBrand.DEFAULT_MAP_VALUE = "__TSTL_DEFAULT_MAP_VALUE"
11
+ ____exports.SerializationBrand.MAP = "__TSTL_MAP"
12
+ ____exports.SerializationBrand.SET = "__TSTL_SET"
13
+ ____exports.SerializationBrand.CLASS = "__TSTL_CLASS"
14
+ ____exports.SerializationBrand.OBJECT_WITH_NUMBER_KEYS = "__TSTL_OBJECT_WITH_NUMBER_KEYS"
15
+ ____exports.SerializationBrand.VECTOR = "__VECTOR"
16
+ local serializationBrands = getEnumValues(nil, ____exports.SerializationBrand)
17
+ local SERIALIZATION_BRAND_SET = __TS__New(Set, serializationBrands)
18
+ function ____exports.isSerializationBrand(self, key)
19
+ if type(key) ~= "string" then
20
+ return false
21
+ end
22
+ return SERIALIZATION_BRAND_SET:has(key)
23
+ end
24
+ return ____exports
@@ -87,9 +87,9 @@ local ____main = require("features.saveDataManager.main")
87
87
  local saveDataManagerInit = ____main.saveDataManagerInit
88
88
  local ____sirenHelpers = require("features.sirenHelpers")
89
89
  local sirenHelpersInit = ____sirenHelpers.sirenHelpersInit
90
- local ____initialized = require("initialized")
91
- local areFeaturesInitialized = ____initialized.areFeaturesInitialized
92
- local setFeaturesInitialized = ____initialized.setFeaturesInitialized
90
+ local ____featuresInitialized = require("featuresInitialized")
91
+ local areFeaturesInitialized = ____featuresInitialized.areFeaturesInitialized
92
+ local setFeaturesInitialized = ____featuresInitialized.setFeaturesInitialized
93
93
  local ____patchErrorFunctions = require("patchErrorFunctions")
94
94
  local patchErrorFunction = ____patchErrorFunctions.patchErrorFunction
95
95
  local ____ModUpgraded = require("types.ModUpgraded")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.59",
3
+ "version": "1.2.60",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",