isaacscript-common 12.5.0 → 12.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1665,6 +1665,12 @@ export declare class DefaultMap<Key, Value, Args extends unknown[] = []> extends
1665
1665
  getConstructorArg(): Value | FactoryFunction<Value, Args>;
1666
1666
  }
1667
1667
 
1668
+ /**
1669
+ * Helper function to get the value from a `DefaultMap` that corresponds to an entity, assuming that
1670
+ * the map uses `PtrHash` as an index.
1671
+ */
1672
+ export declare function defaultMapGetHash<V, A extends unknown[]>(map: DefaultMap<PtrHash, V, A>, entity: Entity, ...extraArgs: A): V;
1673
+
1668
1674
  /**
1669
1675
  * Helper function to make using default maps with an index of `PlayerIndex` easier. Use this
1670
1676
  * instead of the `DefaultMap.getAndSetDefault` method if you have a default map of this type.
@@ -1685,6 +1691,15 @@ export declare class DefaultMap<Key, Value, Args extends unknown[] = []> extends
1685
1691
  */
1686
1692
  export declare function defaultMapGetPlayer<V, A extends unknown[]>(map: DefaultMap<PlayerIndex, V, A>, player: EntityPlayer, ...extraArgs: A): V;
1687
1693
 
1694
+ /**
1695
+ * Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
1696
+ * the map uses `PtrHash` as an index.
1697
+ *
1698
+ * Since `Map` and `DefaultMap` set values in the same way, this function is simply an alias for the
1699
+ * `mapSetHash` helper function.
1700
+ */
1701
+ export declare function defaultMapSetHash<V>(map: Map<PtrHash, V>, entity: Entity, value: V): void;
1702
+
1688
1703
  /**
1689
1704
  * Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
1690
1705
  * `Map.set` method if you have a map of this type.
@@ -3603,8 +3618,11 @@ export declare function getLastTrinketType(): TrinketType;
3603
3618
  * array.
3604
3619
  *
3605
3620
  * This is useful in the `POST_ENTITY_REMOVE` callback; see the `isLeavingRoom` function.
3621
+ *
3622
+ * Note that this function can return undefined in the case where it is called on the first room of
3623
+ * the run.
3606
3624
  */
3607
- export declare function getLatestRoomDescription(): RoomDescription;
3625
+ export declare function getLatestRoomDescription(): RoomDescription | undefined;
3608
3626
 
3609
3627
  /**
3610
3628
  * Helper function to get the closest value from a map based on partial search text. For the
@@ -6175,7 +6193,7 @@ export declare function isLaser(variable: unknown): variable is EntityLaser;
6175
6193
  * in the room history array for the current room.)
6176
6194
  *
6177
6195
  * This function is intended to be used in the `POST_ENTITY_REMOVE` callback to detect when an
6178
- * entity is pseudo-persistent entity such as a pickup is despawning.
6196
+ * entity is despawning.
6179
6197
  */
6180
6198
  export declare function isLeavingRoom(): boolean;
6181
6199
 
@@ -6993,6 +7011,12 @@ export declare function mapGetPlayer<V>(map: Map<PlayerIndex, V>, player: Entity
6993
7011
  */
6994
7012
  export declare function mapHasPlayer<V>(map: Map<PlayerIndex, V>, player: EntityPlayer): boolean;
6995
7013
 
7014
+ /**
7015
+ * Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
7016
+ * the map uses `PtrHash` as an index.
7017
+ */
7018
+ export declare function mapSetHash<V>(map: Map<PtrHash, V>, entity: Entity, value: V): void;
7019
+
6996
7020
  /**
6997
7021
  * Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
6998
7022
  * `Map.set` method if you have a map of this type.
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 12.5.0
3
+ isaacscript-common 12.5.2
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -9323,7 +9323,7 @@ ____exports.ClottyVariant.GRILLED_CLOTTY = 3
9323
9323
  ____exports.ClottyVariant[____exports.ClottyVariant.GRILLED_CLOTTY] = "GRILLED_CLOTTY"
9324
9324
  --- For `EntityType.MULLIGAN` (16).
9325
9325
  ____exports.MulliganVariant = {}
9326
- ____exports.MulliganVariant.MULLIGAN = 16
9326
+ ____exports.MulliganVariant.MULLIGAN = 0
9327
9327
  ____exports.MulliganVariant[____exports.MulliganVariant.MULLIGAN] = "MULLIGAN"
9328
9328
  ____exports.MulliganVariant.MULLIGOON = 1
9329
9329
  ____exports.MulliganVariant[____exports.MulliganVariant.MULLIGOON] = "MULLIGOON"
@@ -12533,6 +12533,8 @@ local ____exports = {}
12533
12533
  --
12534
12534
  -- The `gridspawn` console command accepts `GridEntityXMLType` instead of `GridEntityType`.
12535
12535
  ____exports.GridEntityXMLType = {}
12536
+ ____exports.GridEntityXMLType.DECORATION = 0
12537
+ ____exports.GridEntityXMLType[____exports.GridEntityXMLType.DECORATION] = "DECORATION"
12536
12538
  ____exports.GridEntityXMLType.ROCK = 1000
12537
12539
  ____exports.GridEntityXMLType[____exports.GridEntityXMLType.ROCK] = "ROCK"
12538
12540
  ____exports.GridEntityXMLType.ROCK_BOMB = 1001
@@ -41252,7 +41254,7 @@ local __TS__New = ____lualib.__TS__New
41252
41254
  local Map = ____lualib.Map
41253
41255
  local __TS__Iterator = ____lualib.__TS__Iterator
41254
41256
  local ____exports = {}
41255
- 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
41257
+ local preUseItemWeNeedToGoDeeper, postNewRoomReordered, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntityForJSONRoom, spawnNormalEntityForJSONRoom, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPC_TYPES_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, GRID_ENTITY_XML_TYPE_SET, v
41256
41258
  local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.src.index")
41257
41259
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
41258
41260
  local EffectVariant = ____isaac_2Dtypescript_2Ddefinitions.EffectVariant
@@ -41261,6 +41263,7 @@ local EntityFlag = ____isaac_2Dtypescript_2Ddefinitions.EntityFlag
41261
41263
  local EntityGridCollisionClass = ____isaac_2Dtypescript_2Ddefinitions.EntityGridCollisionClass
41262
41264
  local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
41263
41265
  local GridEntityType = ____isaac_2Dtypescript_2Ddefinitions.GridEntityType
41266
+ local GridEntityXMLType = ____isaac_2Dtypescript_2Ddefinitions.GridEntityXMLType
41264
41267
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
41265
41268
  local PickupVariant = ____isaac_2Dtypescript_2Ddefinitions.PickupVariant
41266
41269
  local PitfallVariant = ____isaac_2Dtypescript_2Ddefinitions.PitfallVariant
@@ -41284,6 +41287,8 @@ local ____entitiesSpecific = require("src.functions.entitiesSpecific")
41284
41287
  local getNPCs = ____entitiesSpecific.getNPCs
41285
41288
  local removeAllBombs = ____entitiesSpecific.removeAllBombs
41286
41289
  local removeAllPickups = ____entitiesSpecific.removeAllPickups
41290
+ local ____enums = require("src.functions.enums")
41291
+ local getEnumValues = ____enums.getEnumValues
41287
41292
  local ____gridEntities = require("src.functions.gridEntities")
41288
41293
  local convertXMLGridEntityType = ____gridEntities.convertXMLGridEntityType
41289
41294
  local getAllGridIndexes = ____gridEntities.getAllGridIndexes
@@ -41481,7 +41486,8 @@ function spawnAllEntities(self, jsonRoom, rng, verbose)
41481
41486
  if subType == nil then
41482
41487
  error("Failed to convert the entity sub-type to a number: " .. tostring(subType))
41483
41488
  end
41484
- if entityTypeNumber >= 1000 then
41489
+ local isGridEntity = GRID_ENTITY_XML_TYPE_SET:has(entityTypeNumber)
41490
+ if isGridEntity then
41485
41491
  local gridEntityXMLType = entityTypeNumber
41486
41492
  if verbose then
41487
41493
  log(
@@ -41705,6 +41711,8 @@ end
41705
41711
  FEATURE_NAME = "deployJSONRoom"
41706
41712
  NPC_TYPES_TO_NOT_REMOVE = __TS__New(Set, {EntityType.DARK_ESAU})
41707
41713
  PERSISTENT_ENTITY_TYPES = __TS__New(Set, {EntityType.WALL_HUGGER})
41714
+ local gridEntityXMLTypes = getEnumValues(nil, GridEntityXMLType)
41715
+ GRID_ENTITY_XML_TYPE_SET = __TS__New(Set, gridEntityXMLTypes)
41708
41716
  v = {
41709
41717
  level = {
41710
41718
  deployedRoomListIndexes = __TS__New(Set),
@@ -42027,16 +42035,15 @@ function ____exports.getPreviousRoomDescription(self)
42027
42035
  error("Failed to find a room description for any rooms thus far on this run.")
42028
42036
  end
42029
42037
  function ____exports.getLatestRoomDescription(self)
42030
- local latestRoomDescription = getLastElement(nil, v.run.roomHistory)
42031
- if latestRoomDescription == nil then
42032
- error("Failed to get the latest room description since the room history array was empty.")
42033
- end
42034
- return latestRoomDescription
42038
+ return getLastElement(nil, v.run.roomHistory)
42035
42039
  end
42036
42040
  function ____exports.isLeavingRoom(self)
42037
42041
  local roomListIndex = getRoomListIndex(nil)
42038
42042
  local roomVisitedCount = getRoomVisitedCount(nil)
42039
42043
  local latestRoomDescription = ____exports.getLatestRoomDescription(nil)
42044
+ if latestRoomDescription == nil then
42045
+ return false
42046
+ end
42040
42047
  return roomListIndex ~= latestRoomDescription.roomListIndex or roomVisitedCount ~= latestRoomDescription.roomVisitedCount
42041
42048
  end
42042
42049
  return ____exports
@@ -42081,6 +42088,9 @@ function checkDespawningFromPlayerLeavingRoom(self, entity)
42081
42088
  end
42082
42089
  function trackDespawningPickupPosition(self, entity, index)
42083
42090
  local previousRoomDescription = getLatestRoomDescription(nil)
42091
+ if previousRoomDescription == nil then
42092
+ return
42093
+ end
42084
42094
  local previousRoomListIndex = previousRoomDescription.roomListIndex
42085
42095
  local persistentEntityDescription = {
42086
42096
  entityType = entity.Type,
@@ -42098,7 +42108,7 @@ function postNewRoomReordered(self)
42098
42108
  local description = ____value[2]
42099
42109
  do
42100
42110
  if roomListIndex ~= description.roomListIndex then
42101
- goto __continue9
42111
+ goto __continue10
42102
42112
  end
42103
42113
  v.level.persistentEntities:delete(index)
42104
42114
  spawnAndTrack(
@@ -42111,7 +42121,7 @@ function postNewRoomReordered(self)
42111
42121
  true
42112
42122
  )
42113
42123
  end
42114
- ::__continue9::
42124
+ ::__continue10::
42115
42125
  end
42116
42126
  end
42117
42127
  function spawnAndTrack(self, entityType, variant, subType, position, index, respawning)
@@ -42172,14 +42182,14 @@ function ____exports.removePersistentEntity(self, persistentEntityIndex, removeE
42172
42182
  do
42173
42183
  local index, entityPtr = table.unpack(tuple)
42174
42184
  if index ~= persistentEntityIndex then
42175
- goto __continue16
42185
+ goto __continue17
42176
42186
  end
42177
42187
  v.room.spawnedPersistentEntities:delete(ptrHash)
42178
42188
  if removeEntity and entityPtr.Ref ~= nil then
42179
42189
  entityPtr.Ref:Remove()
42180
42190
  end
42181
42191
  end
42182
- ::__continue16::
42192
+ ::__continue17::
42183
42193
  end
42184
42194
  end
42185
42195
  return ____exports
@@ -42253,6 +42263,9 @@ function checkDespawningFromPlayerLeavingRoom(self, entity)
42253
42263
  end
42254
42264
  function trackDespawningPickupMetadata(self, entity, pickupIndex)
42255
42265
  local previousRoomDescription = getLatestRoomDescription(nil)
42266
+ if previousRoomDescription == nil then
42267
+ return
42268
+ end
42256
42269
  local previousRoomListIndex = previousRoomDescription.roomListIndex
42257
42270
  local pickupDescriptions = v.level.pickupData:getAndSetDefault(previousRoomListIndex)
42258
42271
  local pickupDescription = {position = entity.Position, initSeed = entity.InitSeed}
@@ -42263,16 +42276,16 @@ function trackDespawningPickupMetadata(self, entity, pickupIndex)
42263
42276
  local room = game:GetRoom()
42264
42277
  local roomType = room:GetType()
42265
42278
  repeat
42266
- local ____switch13 = roomType
42267
- local ____cond13 = ____switch13 == RoomType.TREASURE
42268
- if ____cond13 then
42279
+ local ____switch14 = roomType
42280
+ local ____cond14 = ____switch14 == RoomType.TREASURE
42281
+ if ____cond14 then
42269
42282
  do
42270
42283
  v.run.pickupDataTreasureRooms:set(pickupIndex, pickupDescription)
42271
42284
  break
42272
42285
  end
42273
42286
  end
42274
- ____cond13 = ____cond13 or ____switch13 == RoomType.BOSS
42275
- if ____cond13 then
42287
+ ____cond14 = ____cond14 or ____switch14 == RoomType.BOSS
42288
+ if ____cond14 then
42276
42289
  do
42277
42290
  v.run.pickupDataBossRooms:set(pickupIndex, pickupDescription)
42278
42291
  break
@@ -42324,15 +42337,15 @@ function getPostAscentPickupIndex(self, pickup)
42324
42337
  local room = game:GetRoom()
42325
42338
  local roomType = room:GetType()
42326
42339
  repeat
42327
- local ____switch29 = roomType
42328
- local ____cond29 = ____switch29 == RoomType.TREASURE
42329
- if ____cond29 then
42340
+ local ____switch30 = roomType
42341
+ local ____cond30 = ____switch30 == RoomType.TREASURE
42342
+ if ____cond30 then
42330
42343
  do
42331
42344
  return getStoredPickupIndex(nil, pickup, v.run.pickupDataTreasureRooms)
42332
42345
  end
42333
42346
  end
42334
- ____cond29 = ____cond29 or ____switch29 == RoomType.BOSS
42335
- if ____cond29 then
42347
+ ____cond30 = ____cond30 or ____switch30 == RoomType.BOSS
42348
+ if ____cond30 then
42336
42349
  do
42337
42350
  return getStoredPickupIndex(nil, pickup, v.run.pickupDataBossRooms)
42338
42351
  end
@@ -42788,6 +42801,10 @@ local ____array = require("src.functions.array")
42788
42801
  local sumArray = ____array.sumArray
42789
42802
  local ____string = require("src.functions.string")
42790
42803
  local getPartialMatch = ____string.getPartialMatch
42804
+ function ____exports.mapSetHash(self, map, entity, value)
42805
+ local hash = GetPtrHash(entity)
42806
+ map:set(hash, value)
42807
+ end
42791
42808
  function ____exports.copyMap(self, oldMap)
42792
42809
  local newMap = __TS__New(Map)
42793
42810
  for ____, ____value in __TS__Iterator(oldMap:entries()) do
@@ -42797,6 +42814,13 @@ function ____exports.copyMap(self, oldMap)
42797
42814
  end
42798
42815
  return newMap
42799
42816
  end
42817
+ function ____exports.defaultMapGetHash(self, map, entity, ...)
42818
+ local ptrHash = GetPtrHash(entity)
42819
+ return map:getAndSetDefault(ptrHash, ...)
42820
+ end
42821
+ function ____exports.defaultMapSetHash(self, map, entity, value)
42822
+ ____exports.mapSetHash(nil, map, entity, value)
42823
+ end
42800
42824
  function ____exports.getMapPartialMatch(self, searchText, map)
42801
42825
  local keys = {__TS__Spread(map:keys())}
42802
42826
  local matchingKey = getPartialMatch(nil, searchText, keys)
@@ -1 +1 @@
1
- {"version":3,"file":"deployJSONRoom.d.ts","sourceRoot":"","sources":["../../../src/features/deployJSONRoom.ts"],"names":[],"mappings":";;AAuDA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAuKvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,EACvC,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,IAAI,CAuBN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,QAAQ,EAAE,EAC3C,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,IAAI,CAaN;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,mBAAmB,EAAE,OAAO,GAAG,IAAI,CAwB5D"}
1
+ {"version":3,"file":"deployJSONRoom.d.ts","sourceRoot":"","sources":["../../../src/features/deployJSONRoom.ts"],"names":[],"mappings":";;AAwDA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AA4KvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,EACvC,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,IAAI,CAuBN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,QAAQ,EAAE,EAC3C,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,IAAI,CAaN;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,mBAAmB,EAAE,OAAO,GAAG,IAAI,CAwB5D"}
@@ -4,7 +4,7 @@ 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 preUseItemWeNeedToGoDeeper, 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, GRID_ENTITY_XML_TYPE_SET, v
8
8
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
9
9
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
10
10
  local EffectVariant = ____isaac_2Dtypescript_2Ddefinitions.EffectVariant
@@ -13,6 +13,7 @@ local EntityFlag = ____isaac_2Dtypescript_2Ddefinitions.EntityFlag
13
13
  local EntityGridCollisionClass = ____isaac_2Dtypescript_2Ddefinitions.EntityGridCollisionClass
14
14
  local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
15
15
  local GridEntityType = ____isaac_2Dtypescript_2Ddefinitions.GridEntityType
16
+ local GridEntityXMLType = ____isaac_2Dtypescript_2Ddefinitions.GridEntityXMLType
16
17
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
17
18
  local PickupVariant = ____isaac_2Dtypescript_2Ddefinitions.PickupVariant
18
19
  local PitfallVariant = ____isaac_2Dtypescript_2Ddefinitions.PitfallVariant
@@ -36,6 +37,8 @@ local ____entitiesSpecific = require("src.functions.entitiesSpecific")
36
37
  local getNPCs = ____entitiesSpecific.getNPCs
37
38
  local removeAllBombs = ____entitiesSpecific.removeAllBombs
38
39
  local removeAllPickups = ____entitiesSpecific.removeAllPickups
40
+ local ____enums = require("src.functions.enums")
41
+ local getEnumValues = ____enums.getEnumValues
39
42
  local ____gridEntities = require("src.functions.gridEntities")
40
43
  local convertXMLGridEntityType = ____gridEntities.convertXMLGridEntityType
41
44
  local getAllGridIndexes = ____gridEntities.getAllGridIndexes
@@ -241,7 +244,8 @@ function spawnAllEntities(self, jsonRoom, rng, verbose)
241
244
  if subType == nil then
242
245
  error("Failed to convert the entity sub-type to a number: " .. tostring(subType))
243
246
  end
244
- if entityTypeNumber >= 1000 then
247
+ local isGridEntity = GRID_ENTITY_XML_TYPE_SET:has(entityTypeNumber)
248
+ if isGridEntity then
245
249
  local gridEntityXMLType = entityTypeNumber
246
250
  if verbose then
247
251
  log(
@@ -465,6 +469,8 @@ end
465
469
  FEATURE_NAME = "deployJSONRoom"
466
470
  NPC_TYPES_TO_NOT_REMOVE = __TS__New(Set, {EntityType.DARK_ESAU})
467
471
  PERSISTENT_ENTITY_TYPES = __TS__New(Set, {EntityType.WALL_HUGGER})
472
+ local gridEntityXMLTypes = getEnumValues(nil, GridEntityXMLType)
473
+ GRID_ENTITY_XML_TYPE_SET = __TS__New(Set, gridEntityXMLTypes)
468
474
  v = {
469
475
  level = {
470
476
  deployedRoomListIndexes = __TS__New(Set),
@@ -1 +1 @@
1
- {"version":3,"file":"persistentEntities.d.ts","sourceRoot":"","sources":["../../../src/features/persistentEntities.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAEX,MAAM,8BAA8B,CAAC;AAgHtC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,GAAG,EACZ,QAAQ,EAAE,MAAM,GACf,CAAC,MAAM,EAAE,GAAG,CAAC,CAcf;AAwBD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,qBAAqB,EAAE,GAAG,EAC1B,YAAY,UAAO,GAClB,IAAI,CAiBN"}
1
+ {"version":3,"file":"persistentEntities.d.ts","sourceRoot":"","sources":["../../../src/features/persistentEntities.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAEX,MAAM,8BAA8B,CAAC;AAoHtC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,GAAG,EACZ,QAAQ,EAAE,MAAM,GACf,CAAC,MAAM,EAAE,GAAG,CAAC,CAcf;AAwBD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,qBAAqB,EAAE,GAAG,EAC1B,YAAY,UAAO,GAClB,IAAI,CAiBN"}
@@ -37,6 +37,9 @@ function checkDespawningFromPlayerLeavingRoom(self, entity)
37
37
  end
38
38
  function trackDespawningPickupPosition(self, entity, index)
39
39
  local previousRoomDescription = getLatestRoomDescription(nil)
40
+ if previousRoomDescription == nil then
41
+ return
42
+ end
40
43
  local previousRoomListIndex = previousRoomDescription.roomListIndex
41
44
  local persistentEntityDescription = {
42
45
  entityType = entity.Type,
@@ -54,7 +57,7 @@ function postNewRoomReordered(self)
54
57
  local description = ____value[2]
55
58
  do
56
59
  if roomListIndex ~= description.roomListIndex then
57
- goto __continue9
60
+ goto __continue10
58
61
  end
59
62
  v.level.persistentEntities:delete(index)
60
63
  spawnAndTrack(
@@ -67,7 +70,7 @@ function postNewRoomReordered(self)
67
70
  true
68
71
  )
69
72
  end
70
- ::__continue9::
73
+ ::__continue10::
71
74
  end
72
75
  end
73
76
  function spawnAndTrack(self, entityType, variant, subType, position, index, respawning)
@@ -152,14 +155,14 @@ function ____exports.removePersistentEntity(self, persistentEntityIndex, removeE
152
155
  do
153
156
  local index, entityPtr = table.unpack(tuple)
154
157
  if index ~= persistentEntityIndex then
155
- goto __continue16
158
+ goto __continue17
156
159
  end
157
160
  v.room.spawnedPersistentEntities:delete(ptrHash)
158
161
  if removeEntity and entityPtr.Ref ~= nil then
159
162
  entityPtr.Ref:Remove()
160
163
  end
161
164
  end
162
- ::__continue16::
165
+ ::__continue17::
163
166
  end
164
167
  end
165
168
  return ____exports
@@ -1 +1 @@
1
- {"version":3,"file":"pickupIndex.d.ts","sourceRoot":"","sources":["../../../src/features/pickupIndex.ts"],"names":[],"mappings":";AAeA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAkNnD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW,CAahE"}
1
+ {"version":3,"file":"pickupIndex.d.ts","sourceRoot":"","sources":["../../../src/features/pickupIndex.ts"],"names":[],"mappings":";AAeA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAsNnD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW,CAahE"}
@@ -62,6 +62,9 @@ function checkDespawningFromPlayerLeavingRoom(self, entity)
62
62
  end
63
63
  function trackDespawningPickupMetadata(self, entity, pickupIndex)
64
64
  local previousRoomDescription = getLatestRoomDescription(nil)
65
+ if previousRoomDescription == nil then
66
+ return
67
+ end
65
68
  local previousRoomListIndex = previousRoomDescription.roomListIndex
66
69
  local pickupDescriptions = v.level.pickupData:getAndSetDefault(previousRoomListIndex)
67
70
  local pickupDescription = {position = entity.Position, initSeed = entity.InitSeed}
@@ -72,16 +75,16 @@ function trackDespawningPickupMetadata(self, entity, pickupIndex)
72
75
  local room = game:GetRoom()
73
76
  local roomType = room:GetType()
74
77
  repeat
75
- local ____switch13 = roomType
76
- local ____cond13 = ____switch13 == RoomType.TREASURE
77
- if ____cond13 then
78
+ local ____switch14 = roomType
79
+ local ____cond14 = ____switch14 == RoomType.TREASURE
80
+ if ____cond14 then
78
81
  do
79
82
  v.run.pickupDataTreasureRooms:set(pickupIndex, pickupDescription)
80
83
  break
81
84
  end
82
85
  end
83
- ____cond13 = ____cond13 or ____switch13 == RoomType.BOSS
84
- if ____cond13 then
86
+ ____cond14 = ____cond14 or ____switch14 == RoomType.BOSS
87
+ if ____cond14 then
85
88
  do
86
89
  v.run.pickupDataBossRooms:set(pickupIndex, pickupDescription)
87
90
  break
@@ -133,15 +136,15 @@ function getPostAscentPickupIndex(self, pickup)
133
136
  local room = game:GetRoom()
134
137
  local roomType = room:GetType()
135
138
  repeat
136
- local ____switch29 = roomType
137
- local ____cond29 = ____switch29 == RoomType.TREASURE
138
- if ____cond29 then
139
+ local ____switch30 = roomType
140
+ local ____cond30 = ____switch30 == RoomType.TREASURE
141
+ if ____cond30 then
139
142
  do
140
143
  return getStoredPickupIndex(nil, pickup, v.run.pickupDataTreasureRooms)
141
144
  end
142
145
  end
143
- ____cond29 = ____cond29 or ____switch29 == RoomType.BOSS
144
- if ____cond29 then
146
+ ____cond30 = ____cond30 or ____switch30 == RoomType.BOSS
147
+ if ____cond30 then
145
148
  do
146
149
  return getStoredPickupIndex(nil, pickup, v.run.pickupDataBossRooms)
147
150
  end
@@ -16,8 +16,11 @@ export declare function getPreviousRoomDescription(): RoomDescription;
16
16
  * array.
17
17
  *
18
18
  * This is useful in the `POST_ENTITY_REMOVE` callback; see the `isLeavingRoom` function.
19
+ *
20
+ * Note that this function can return undefined in the case where it is called on the first room of
21
+ * the run.
19
22
  */
20
- export declare function getLatestRoomDescription(): RoomDescription;
23
+ export declare function getLatestRoomDescription(): RoomDescription | undefined;
21
24
  /**
22
25
  * Helper function to detect if the game is in the state where the room index has changed to a new
23
26
  * room, but the entities from the previous room are currently in the process of despawning. (At
@@ -25,7 +28,7 @@ export declare function getLatestRoomDescription(): RoomDescription;
25
28
  * in the room history array for the current room.)
26
29
  *
27
30
  * This function is intended to be used in the `POST_ENTITY_REMOVE` callback to detect when an
28
- * entity is pseudo-persistent entity such as a pickup is despawning.
31
+ * entity is despawning.
29
32
  */
30
33
  export declare function isLeavingRoom(): boolean;
31
34
  //# sourceMappingURL=roomHistory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"roomHistory.d.ts","sourceRoot":"","sources":["../../../src/features/roomHistory.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAmDhE;;;GAGG;AACH,wBAAgB,cAAc,IAAI,SAAS,eAAe,EAAE,CAG3D;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,IAAI,eAAe,CAe5D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,IAAI,eAAe,CAS1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,OAAO,CASvC"}
1
+ {"version":3,"file":"roomHistory.d.ts","sourceRoot":"","sources":["../../../src/features/roomHistory.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAmDhE;;;GAGG;AACH,wBAAgB,cAAc,IAAI,SAAS,eAAe,EAAE,CAG3D;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,IAAI,eAAe,CAe5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,IAAI,eAAe,GAAG,SAAS,CAEtE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAevC"}
@@ -79,12 +79,11 @@ end
79
79
  -- array.
80
80
  --
81
81
  -- This is useful in the `POST_ENTITY_REMOVE` callback; see the `isLeavingRoom` function.
82
+ --
83
+ -- Note that this function can return undefined in the case where it is called on the first room of
84
+ -- the run.
82
85
  function ____exports.getLatestRoomDescription(self)
83
- local latestRoomDescription = getLastElement(nil, v.run.roomHistory)
84
- if latestRoomDescription == nil then
85
- error("Failed to get the latest room description since the room history array was empty.")
86
- end
87
- return latestRoomDescription
86
+ return getLastElement(nil, v.run.roomHistory)
88
87
  end
89
88
  --- Helper function to detect if the game is in the state where the room index has changed to a new
90
89
  -- room, but the entities from the previous room are currently in the process of despawning. (At
@@ -92,11 +91,14 @@ end
92
91
  -- in the room history array for the current room.)
93
92
  --
94
93
  -- This function is intended to be used in the `POST_ENTITY_REMOVE` callback to detect when an
95
- -- entity is pseudo-persistent entity such as a pickup is despawning.
94
+ -- entity is despawning.
96
95
  function ____exports.isLeavingRoom(self)
97
96
  local roomListIndex = getRoomListIndex(nil)
98
97
  local roomVisitedCount = getRoomVisitedCount(nil)
99
98
  local latestRoomDescription = ____exports.getLatestRoomDescription(nil)
99
+ if latestRoomDescription == nil then
100
+ return false
101
+ end
100
102
  return roomListIndex ~= latestRoomDescription.roomListIndex or roomVisitedCount ~= latestRoomDescription.roomVisitedCount
101
103
  end
102
104
  return ____exports
@@ -1,5 +1,21 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
3
+ import { DefaultMap } from "../classes/DefaultMap";
1
4
  /** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
2
5
  export declare function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V>;
6
+ /**
7
+ * Helper function to get the value from a `DefaultMap` that corresponds to an entity, assuming that
8
+ * the map uses `PtrHash` as an index.
9
+ */
10
+ export declare function defaultMapGetHash<V, A extends unknown[]>(map: DefaultMap<PtrHash, V, A>, entity: Entity, ...extraArgs: A): V;
11
+ /**
12
+ * Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
13
+ * the map uses `PtrHash` as an index.
14
+ *
15
+ * Since `Map` and `DefaultMap` set values in the same way, this function is simply an alias for the
16
+ * `mapSetHash` helper function.
17
+ */
18
+ export declare function defaultMapSetHash<V>(map: Map<PtrHash, V>, entity: Entity, value: V): void;
3
19
  /**
4
20
  * Helper function to get the closest value from a map based on partial search text. For the
5
21
  * purposes of this function, both search text and map keys are converted to lowercase before
@@ -20,6 +36,11 @@ export declare function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V>;
20
36
  * ```
21
37
  */
22
38
  export declare function getMapPartialMatch<T>(searchText: string, map: ReadonlyMap<string, T>): [string, T] | undefined;
39
+ /**
40
+ * Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
41
+ * the map uses `PtrHash` as an index.
42
+ */
43
+ export declare function mapSetHash<V>(map: Map<PtrHash, V>, entity: Entity, value: V): void;
23
44
  /** Helper function to sum every value in a map together. */
24
45
  export declare function sumMap(map: Map<unknown, number> | ReadonlyMap<unknown, number>): number;
25
46
  //# sourceMappingURL=map.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/functions/map.ts"],"names":[],"mappings":"AAGA,mGAAmG;AACnG,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAO1D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAC1B,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAgBzB;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,CACpB,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,GACvD,MAAM,CAGR"}
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/functions/map.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAInD,mGAAmG;AACnG,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAO1D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EACtD,GAAG,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,MAAM,EAAE,MAAM,EACd,GAAG,SAAS,EAAE,CAAC,GACd,CAAC,CAGH;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,GACP,IAAI,CAEN;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAC1B,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAgBzB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,GACP,IAAI,CAGN;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,CACpB,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,GACvD,MAAM,CAGR"}
@@ -8,6 +8,12 @@ local ____array = require("src.functions.array")
8
8
  local sumArray = ____array.sumArray
9
9
  local ____string = require("src.functions.string")
10
10
  local getPartialMatch = ____string.getPartialMatch
11
+ --- Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
12
+ -- the map uses `PtrHash` as an index.
13
+ function ____exports.mapSetHash(self, map, entity, value)
14
+ local hash = GetPtrHash(entity)
15
+ map:set(hash, value)
16
+ end
11
17
  --- Helper function to copy a map. (You can also use a Map constructor to accomplish this task.)
12
18
  function ____exports.copyMap(self, oldMap)
13
19
  local newMap = __TS__New(Map)
@@ -18,6 +24,20 @@ function ____exports.copyMap(self, oldMap)
18
24
  end
19
25
  return newMap
20
26
  end
27
+ --- Helper function to get the value from a `DefaultMap` that corresponds to an entity, assuming that
28
+ -- the map uses `PtrHash` as an index.
29
+ function ____exports.defaultMapGetHash(self, map, entity, ...)
30
+ local ptrHash = GetPtrHash(entity)
31
+ return map:getAndSetDefault(ptrHash, ...)
32
+ end
33
+ --- Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
34
+ -- the map uses `PtrHash` as an index.
35
+ --
36
+ -- Since `Map` and `DefaultMap` set values in the same way, this function is simply an alias for the
37
+ -- `mapSetHash` helper function.
38
+ function ____exports.defaultMapSetHash(self, map, entity, value)
39
+ ____exports.mapSetHash(nil, map, entity, value)
40
+ end
21
41
  --- Helper function to get the closest value from a map based on partial search text. For the
22
42
  -- purposes of this function, both search text and map keys are converted to lowercase before
23
43
  -- attempting to find a match.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "12.5.0",
3
+ "version": "12.5.2",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -22,6 +22,6 @@
22
22
  "main": "dist/src/index",
23
23
  "types": "dist/src/index.d.ts",
24
24
  "dependencies": {
25
- "isaac-typescript-definitions": "^7.2.5"
25
+ "isaac-typescript-definitions": "^7.2.6"
26
26
  }
27
27
  }
@@ -36,6 +36,7 @@ import {
36
36
  removeAllBombs,
37
37
  removeAllPickups,
38
38
  } from "../functions/entitiesSpecific";
39
+ import { getEnumValues } from "../functions/enums";
39
40
  import {
40
41
  convertXMLGridEntityType,
41
42
  getAllGridIndexes,
@@ -74,6 +75,11 @@ const PERSISTENT_ENTITY_TYPES: ReadonlySet<EntityType> = new Set([
74
75
  EntityType.WALL_HUGGER,
75
76
  ]);
76
77
 
78
+ const gridEntityXMLTypes = getEnumValues(GridEntityXMLType);
79
+ const GRID_ENTITY_XML_TYPE_SET: ReadonlySet<number> = new Set(
80
+ gridEntityXMLTypes,
81
+ );
82
+
77
83
  const v = {
78
84
  level: {
79
85
  deployedRoomListIndexes: new Set<int>(),
@@ -492,8 +498,8 @@ function spawnAllEntities(
492
498
  error(`Failed to convert the entity sub-type to a number: ${subType}`);
493
499
  }
494
500
 
495
- // Note that XML entity type 1000 is a rock, not an effect.
496
- if (entityTypeNumber >= 1000) {
501
+ const isGridEntity = GRID_ENTITY_XML_TYPE_SET.has(entityTypeNumber);
502
+ if (isGridEntity) {
497
503
  const gridEntityXMLType = entityTypeNumber as GridEntityXMLType;
498
504
  if (verbose) {
499
505
  log(
@@ -82,6 +82,10 @@ function trackDespawningPickupPosition(entity: Entity, index: int) {
82
82
  // (The "latest" room description is really the previous room, because the `POST_NEW_ROOM`
83
83
  // callback was not fired yet.)
84
84
  const previousRoomDescription = getLatestRoomDescription();
85
+ if (previousRoomDescription === undefined) {
86
+ return;
87
+ }
88
+
85
89
  const previousRoomListIndex = previousRoomDescription.roomListIndex;
86
90
  const persistentEntityDescription: PersistentEntityDescription = {
87
91
  entityType: entity.Type,
@@ -114,6 +114,10 @@ function trackDespawningPickupMetadata(
114
114
  // The "latest" room description is really the previous room, because the `POST_NEW_ROOM` callback
115
115
  // was not fired yet.
116
116
  const previousRoomDescription = getLatestRoomDescription();
117
+ if (previousRoomDescription === undefined) {
118
+ return;
119
+ }
120
+
117
121
  const previousRoomListIndex = previousRoomDescription.roomListIndex;
118
122
  const pickupDescriptions = v.level.pickupData.getAndSetDefault(
119
123
  previousRoomListIndex,
@@ -100,16 +100,12 @@ export function getPreviousRoomDescription(): RoomDescription {
100
100
  * array.
101
101
  *
102
102
  * This is useful in the `POST_ENTITY_REMOVE` callback; see the `isLeavingRoom` function.
103
+ *
104
+ * Note that this function can return undefined in the case where it is called on the first room of
105
+ * the run.
103
106
  */
104
- export function getLatestRoomDescription(): RoomDescription {
105
- const latestRoomDescription = getLastElement(v.run.roomHistory);
106
- if (latestRoomDescription === undefined) {
107
- error(
108
- "Failed to get the latest room description since the room history array was empty.",
109
- );
110
- }
111
-
112
- return latestRoomDescription;
107
+ export function getLatestRoomDescription(): RoomDescription | undefined {
108
+ return getLastElement(v.run.roomHistory);
113
109
  }
114
110
 
115
111
  /**
@@ -119,13 +115,19 @@ export function getLatestRoomDescription(): RoomDescription {
119
115
  * in the room history array for the current room.)
120
116
  *
121
117
  * This function is intended to be used in the `POST_ENTITY_REMOVE` callback to detect when an
122
- * entity is pseudo-persistent entity such as a pickup is despawning.
118
+ * entity is despawning.
123
119
  */
124
120
  export function isLeavingRoom(): boolean {
125
121
  const roomListIndex = getRoomListIndex();
126
122
  const roomVisitedCount = getRoomVisitedCount();
127
123
  const latestRoomDescription = getLatestRoomDescription();
128
124
 
125
+ // Sometimes, this function can be called in situations where entities from the previous run are
126
+ // being despawned. If this is the case, then the room history will currently be empty.
127
+ if (latestRoomDescription === undefined) {
128
+ return false;
129
+ }
130
+
129
131
  return (
130
132
  roomListIndex !== latestRoomDescription.roomListIndex ||
131
133
  roomVisitedCount !== latestRoomDescription.roomVisitedCount
@@ -1,3 +1,4 @@
1
+ import { DefaultMap } from "../classes/DefaultMap";
1
2
  import { sumArray } from "./array";
2
3
  import { getPartialMatch } from "./string";
3
4
 
@@ -11,6 +12,34 @@ export function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V> {
11
12
  return newMap;
12
13
  }
13
14
 
15
+ /**
16
+ * Helper function to get the value from a `DefaultMap` that corresponds to an entity, assuming that
17
+ * the map uses `PtrHash` as an index.
18
+ */
19
+ export function defaultMapGetHash<V, A extends unknown[]>(
20
+ map: DefaultMap<PtrHash, V, A>,
21
+ entity: Entity,
22
+ ...extraArgs: A
23
+ ): V {
24
+ const ptrHash = GetPtrHash(entity);
25
+ return map.getAndSetDefault(ptrHash, ...extraArgs);
26
+ }
27
+
28
+ /**
29
+ * Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
30
+ * the map uses `PtrHash` as an index.
31
+ *
32
+ * Since `Map` and `DefaultMap` set values in the same way, this function is simply an alias for the
33
+ * `mapSetHash` helper function.
34
+ */
35
+ export function defaultMapSetHash<V>(
36
+ map: Map<PtrHash, V>,
37
+ entity: Entity,
38
+ value: V,
39
+ ): void {
40
+ mapSetHash(map, entity, value);
41
+ }
42
+
14
43
  /**
15
44
  * Helper function to get the closest value from a map based on partial search text. For the
16
45
  * purposes of this function, both search text and map keys are converted to lowercase before
@@ -51,6 +80,19 @@ export function getMapPartialMatch<T>(
51
80
  return [matchingKey, value];
52
81
  }
53
82
 
83
+ /**
84
+ * Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
85
+ * the map uses `PtrHash` as an index.
86
+ */
87
+ export function mapSetHash<V>(
88
+ map: Map<PtrHash, V>,
89
+ entity: Entity,
90
+ value: V,
91
+ ): void {
92
+ const hash = GetPtrHash(entity);
93
+ map.set(hash, value);
94
+ }
95
+
54
96
  /** Helper function to sum every value in a map together. */
55
97
  export function sumMap(
56
98
  map: Map<unknown, number> | ReadonlyMap<unknown, number>,