isaacscript-common 3.2.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/cachedClasses.d.ts +2 -1
  2. package/callbacks/customRevive.lua +3 -3
  3. package/callbacks/postGridEntity.lua +5 -3
  4. package/callbacks/postHolyMantleRemoved.lua +2 -2
  5. package/callbacks/postPlayerCollectible.d.ts +1 -0
  6. package/callbacks/postPlayerCollectible.lua +95 -0
  7. package/callbacks/postRoomClearChanged.lua +5 -3
  8. package/callbacks/postSlotInitUpdate.lua +5 -3
  9. package/callbacks/subscriptions/postPlayerCollectibleAdded.d.ts +6 -0
  10. package/callbacks/subscriptions/postPlayerCollectibleAdded.lua +34 -0
  11. package/callbacks/subscriptions/postPlayerCollectibleRemoved.d.ts +6 -0
  12. package/callbacks/subscriptions/postPlayerCollectibleRemoved.lua +34 -0
  13. package/constants.d.ts +8 -0
  14. package/constants.lua +5 -0
  15. package/constantsFirstLast.d.ts +3 -0
  16. package/enums/ModCallbackCustom.d.ts +427 -177
  17. package/enums/ModCallbackCustom.lua +36 -32
  18. package/features/deployJSONRoom.lua +5 -4
  19. package/features/extraConsoleCommands/listCommands.lua +1 -0
  20. package/features/persistentEntities.d.ts +28 -0
  21. package/features/persistentEntities.lua +150 -0
  22. package/features/playerInventory.d.ts +1 -10
  23. package/features/playerInventory.lua +23 -60
  24. package/functions/array.d.ts +3 -3
  25. package/functions/array.lua +3 -3
  26. package/functions/collectibleSet.d.ts +3 -3
  27. package/functions/collectibleSet.lua +3 -5
  28. package/functions/color.d.ts +2 -16
  29. package/functions/color.lua +0 -9
  30. package/functions/entity.d.ts +10 -0
  31. package/functions/entity.lua +29 -0
  32. package/functions/log.lua +2 -2
  33. package/functions/pills.d.ts +10 -0
  34. package/functions/pills.lua +16 -0
  35. package/functions/roomData.d.ts +5 -5
  36. package/functions/roomData.lua +7 -7
  37. package/functions/rooms.d.ts +1 -4
  38. package/functions/rooms.lua +19 -25
  39. package/functions/saveFile.lua +0 -1
  40. package/index.d.ts +2 -1
  41. package/index.lua +7 -2
  42. package/initCustomCallbacks.lua +3 -0
  43. package/initFeatures.lua +3 -0
  44. package/interfaces/AddCallbackParameterCustom.d.ts +4 -0
  45. package/maps/PHDPillConversions.d.ts +2 -0
  46. package/maps/PHDPillConversions.lua +25 -0
  47. package/maps/falsePHDPillConversions.d.ts +2 -0
  48. package/maps/falsePHDPillConversions.lua +39 -0
  49. package/objects/callbackRegisterFunctions.lua +6 -0
  50. package/package.json +2 -2
@@ -94,68 +94,72 @@ ____exports.ModCallbackCustom.POST_PLAYER_CHANGE_HEALTH = 42
94
94
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PLAYER_CHANGE_HEALTH] = "POST_PLAYER_CHANGE_HEALTH"
95
95
  ____exports.ModCallbackCustom.POST_PLAYER_CHANGE_TYPE = 43
96
96
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PLAYER_CHANGE_TYPE] = "POST_PLAYER_CHANGE_TYPE"
97
- ____exports.ModCallbackCustom.POST_PLAYER_FATAL_DAMAGE = 44
97
+ ____exports.ModCallbackCustom.POST_PLAYER_COLLECTIBLE_ADDED = 44
98
+ ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PLAYER_COLLECTIBLE_ADDED] = "POST_PLAYER_COLLECTIBLE_ADDED"
99
+ ____exports.ModCallbackCustom.POST_PLAYER_COLLECTIBLE_REMOVED = 45
100
+ ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PLAYER_COLLECTIBLE_REMOVED] = "POST_PLAYER_COLLECTIBLE_REMOVED"
101
+ ____exports.ModCallbackCustom.POST_PLAYER_FATAL_DAMAGE = 46
98
102
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PLAYER_FATAL_DAMAGE] = "POST_PLAYER_FATAL_DAMAGE"
99
- ____exports.ModCallbackCustom.POST_PLAYER_INIT_LATE = 45
103
+ ____exports.ModCallbackCustom.POST_PLAYER_INIT_LATE = 47
100
104
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PLAYER_INIT_LATE] = "POST_PLAYER_INIT_LATE"
101
- ____exports.ModCallbackCustom.POST_PLAYER_INIT_REORDERED = 46
105
+ ____exports.ModCallbackCustom.POST_PLAYER_INIT_REORDERED = 48
102
106
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PLAYER_INIT_REORDERED] = "POST_PLAYER_INIT_REORDERED"
103
- ____exports.ModCallbackCustom.POST_PLAYER_RENDER_REORDERED = 47
107
+ ____exports.ModCallbackCustom.POST_PLAYER_RENDER_REORDERED = 49
104
108
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PLAYER_RENDER_REORDERED] = "POST_PLAYER_RENDER_REORDERED"
105
- ____exports.ModCallbackCustom.POST_PLAYER_UPDATE_REORDERED = 48
109
+ ____exports.ModCallbackCustom.POST_PLAYER_UPDATE_REORDERED = 50
106
110
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PLAYER_UPDATE_REORDERED] = "POST_PLAYER_UPDATE_REORDERED"
107
- ____exports.ModCallbackCustom.POST_POOP_RENDER = 49
111
+ ____exports.ModCallbackCustom.POST_POOP_RENDER = 51
108
112
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_POOP_RENDER] = "POST_POOP_RENDER"
109
- ____exports.ModCallbackCustom.POST_POOP_UPDATE = 50
113
+ ____exports.ModCallbackCustom.POST_POOP_UPDATE = 52
110
114
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_POOP_UPDATE] = "POST_POOP_UPDATE"
111
- ____exports.ModCallbackCustom.POST_PRESSURE_PLATE_RENDER = 51
115
+ ____exports.ModCallbackCustom.POST_PRESSURE_PLATE_RENDER = 53
112
116
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PRESSURE_PLATE_RENDER] = "POST_PRESSURE_PLATE_RENDER"
113
- ____exports.ModCallbackCustom.POST_PRESSURE_PLATE_UPDATE = 52
117
+ ____exports.ModCallbackCustom.POST_PRESSURE_PLATE_UPDATE = 54
114
118
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PRESSURE_PLATE_UPDATE] = "POST_PRESSURE_PLATE_UPDATE"
115
- ____exports.ModCallbackCustom.POST_PROJECTILE_INIT_LATE = 53
119
+ ____exports.ModCallbackCustom.POST_PROJECTILE_INIT_LATE = 55
116
120
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PROJECTILE_INIT_LATE] = "POST_PROJECTILE_INIT_LATE"
117
- ____exports.ModCallbackCustom.POST_PURCHASE = 54
121
+ ____exports.ModCallbackCustom.POST_PURCHASE = 56
118
122
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_PURCHASE] = "POST_PURCHASE"
119
- ____exports.ModCallbackCustom.POST_ROCK_RENDER = 55
123
+ ____exports.ModCallbackCustom.POST_ROCK_RENDER = 57
120
124
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_ROCK_RENDER] = "POST_ROCK_RENDER"
121
- ____exports.ModCallbackCustom.POST_ROCK_UPDATE = 56
125
+ ____exports.ModCallbackCustom.POST_ROCK_UPDATE = 58
122
126
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_ROCK_UPDATE] = "POST_ROCK_UPDATE"
123
- ____exports.ModCallbackCustom.POST_ROOM_CLEAR_CHANGED = 57
127
+ ____exports.ModCallbackCustom.POST_ROOM_CLEAR_CHANGED = 59
124
128
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_ROOM_CLEAR_CHANGED] = "POST_ROOM_CLEAR_CHANGED"
125
- ____exports.ModCallbackCustom.POST_SACRIFICE = 58
129
+ ____exports.ModCallbackCustom.POST_SACRIFICE = 60
126
130
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_SACRIFICE] = "POST_SACRIFICE"
127
- ____exports.ModCallbackCustom.POST_SLOT_ANIMATION_CHANGED = 59
131
+ ____exports.ModCallbackCustom.POST_SLOT_ANIMATION_CHANGED = 61
128
132
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_SLOT_ANIMATION_CHANGED] = "POST_SLOT_ANIMATION_CHANGED"
129
- ____exports.ModCallbackCustom.POST_SLOT_DESTROYED = 60
133
+ ____exports.ModCallbackCustom.POST_SLOT_DESTROYED = 62
130
134
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_SLOT_DESTROYED] = "POST_SLOT_DESTROYED"
131
- ____exports.ModCallbackCustom.POST_SLOT_INIT = 61
135
+ ____exports.ModCallbackCustom.POST_SLOT_INIT = 63
132
136
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_SLOT_INIT] = "POST_SLOT_INIT"
133
- ____exports.ModCallbackCustom.POST_SLOT_RENDER = 62
137
+ ____exports.ModCallbackCustom.POST_SLOT_RENDER = 64
134
138
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_SLOT_RENDER] = "POST_SLOT_RENDER"
135
- ____exports.ModCallbackCustom.POST_SLOT_UPDATE = 63
139
+ ____exports.ModCallbackCustom.POST_SLOT_UPDATE = 65
136
140
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_SLOT_UPDATE] = "POST_SLOT_UPDATE"
137
- ____exports.ModCallbackCustom.POST_SPIKES_RENDER = 64
141
+ ____exports.ModCallbackCustom.POST_SPIKES_RENDER = 66
138
142
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_SPIKES_RENDER] = "POST_SPIKES_RENDER"
139
- ____exports.ModCallbackCustom.POST_SPIKES_UPDATE = 65
143
+ ____exports.ModCallbackCustom.POST_SPIKES_UPDATE = 67
140
144
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_SPIKES_UPDATE] = "POST_SPIKES_UPDATE"
141
- ____exports.ModCallbackCustom.POST_TEAR_INIT_LATE = 66
145
+ ____exports.ModCallbackCustom.POST_TEAR_INIT_LATE = 68
142
146
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_TEAR_INIT_LATE] = "POST_TEAR_INIT_LATE"
143
- ____exports.ModCallbackCustom.POST_TEAR_INIT_VERY_LATE = 67
147
+ ____exports.ModCallbackCustom.POST_TEAR_INIT_VERY_LATE = 69
144
148
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_TEAR_INIT_VERY_LATE] = "POST_TEAR_INIT_VERY_LATE"
145
- ____exports.ModCallbackCustom.POST_TNT_RENDER = 68
149
+ ____exports.ModCallbackCustom.POST_TNT_RENDER = 70
146
150
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_TNT_RENDER] = "POST_TNT_RENDER"
147
- ____exports.ModCallbackCustom.POST_TNT_UPDATE = 69
151
+ ____exports.ModCallbackCustom.POST_TNT_UPDATE = 71
148
152
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_TNT_UPDATE] = "POST_TNT_UPDATE"
149
- ____exports.ModCallbackCustom.POST_TRANSFORMATION = 70
153
+ ____exports.ModCallbackCustom.POST_TRANSFORMATION = 72
150
154
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_TRANSFORMATION] = "POST_TRANSFORMATION"
151
- ____exports.ModCallbackCustom.POST_TRINKET_BREAK = 71
155
+ ____exports.ModCallbackCustom.POST_TRINKET_BREAK = 73
152
156
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.POST_TRINKET_BREAK] = "POST_TRINKET_BREAK"
153
- ____exports.ModCallbackCustom.PRE_BERSERK_DEATH = 72
157
+ ____exports.ModCallbackCustom.PRE_BERSERK_DEATH = 74
154
158
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.PRE_BERSERK_DEATH] = "PRE_BERSERK_DEATH"
155
- ____exports.ModCallbackCustom.PRE_CUSTOM_REVIVE = 73
159
+ ____exports.ModCallbackCustom.PRE_CUSTOM_REVIVE = 75
156
160
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.PRE_CUSTOM_REVIVE] = "PRE_CUSTOM_REVIVE"
157
- ____exports.ModCallbackCustom.PRE_ITEM_PICKUP = 74
161
+ ____exports.ModCallbackCustom.PRE_ITEM_PICKUP = 76
158
162
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.PRE_ITEM_PICKUP] = "PRE_ITEM_PICKUP"
159
- ____exports.ModCallbackCustom.PRE_NEW_LEVEL = 75
163
+ ____exports.ModCallbackCustom.PRE_NEW_LEVEL = 77
160
164
  ____exports.ModCallbackCustom[____exports.ModCallbackCustom.PRE_NEW_LEVEL] = "PRE_NEW_LEVEL"
161
165
  return ____exports
@@ -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 postNewRoom, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntityForJSONRoom, spawnNormalEntityForJSONRoom, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPC_TYPES_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, v
7
+ local postNewRoomReordered, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntityForJSONRoom, spawnNormalEntityForJSONRoom, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPC_TYPES_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, v
8
8
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
9
9
  local EffectVariant = ____isaac_2Dtypescript_2Ddefinitions.EffectVariant
10
10
  local EntityCollisionClass = ____isaac_2Dtypescript_2Ddefinitions.EntityCollisionClass
@@ -12,7 +12,6 @@ local EntityFlag = ____isaac_2Dtypescript_2Ddefinitions.EntityFlag
12
12
  local EntityGridCollisionClass = ____isaac_2Dtypescript_2Ddefinitions.EntityGridCollisionClass
13
13
  local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
14
14
  local GridEntityType = ____isaac_2Dtypescript_2Ddefinitions.GridEntityType
15
- local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
16
15
  local PickupVariant = ____isaac_2Dtypescript_2Ddefinitions.PickupVariant
17
16
  local PitfallVariant = ____isaac_2Dtypescript_2Ddefinitions.PitfallVariant
18
17
  local RoomType = ____isaac_2Dtypescript_2Ddefinitions.RoomType
@@ -20,6 +19,8 @@ local ____cachedClasses = require("cachedClasses")
20
19
  local game = ____cachedClasses.game
21
20
  local ____DefaultMap = require("classes.DefaultMap")
22
21
  local DefaultMap = ____DefaultMap.DefaultMap
22
+ local ____ModCallbackCustom = require("enums.ModCallbackCustom")
23
+ local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
23
24
  local ____featuresInitialized = require("featuresInitialized")
24
25
  local errorIfFeaturesNotInitialized = ____featuresInitialized.errorIfFeaturesNotInitialized
25
26
  local ____entity = require("functions.entity")
@@ -57,7 +58,7 @@ local ____utils = require("functions.utils")
57
58
  local erange = ____utils.erange
58
59
  local ____exports = require("features.saveDataManager.exports")
59
60
  local saveDataManager = ____exports.saveDataManager
60
- function postNewRoom(self)
61
+ function postNewRoomReordered(self)
61
62
  local roomListIndex = getRoomListIndex(nil)
62
63
  if not v.level.deployedRoomListIndexes:has(roomListIndex) then
63
64
  return
@@ -427,7 +428,7 @@ v = {level = {
427
428
  -- @internal
428
429
  function ____exports.deployJSONRoomInit(self, mod)
429
430
  saveDataManager(nil, "deployJSONRoom", v)
430
- mod:AddCallback(ModCallback.POST_NEW_ROOM, postNewRoom)
431
+ mod:AddCallbackCustom(ModCallbackCustom.POST_NEW_ROOM_REORDERED, postNewRoomReordered)
431
432
  end
432
433
  --- Helper function to deconstruct a vanilla room and set up a custom room in its place.
433
434
  -- Specifically, this will clear the current room of all entities and grid entities, and then spawn
@@ -810,6 +810,7 @@ end
810
810
  --- Logs information about the room to the "log.txt" file.
811
811
  function ____exports.roomCommand(self)
812
812
  logRoom()
813
+ printConsole(nil, "Logged room information to the \"log.txt\" file.")
813
814
  end
814
815
  --- Gives a rotten heart. Provide a number to give a custom amount of hearts. (You can use negative
815
816
  -- numbers to remove hearts.)
@@ -0,0 +1,28 @@
1
+ import { EntityType } from "isaac-typescript-definitions";
2
+ /**
3
+ * Helper function to spawn an entity that will have persistence similar to a pickup.
4
+ *
5
+ * By default, as soon as you leave a room, any spawned entities will be despawned and will not
6
+ * return if the player revisits the room. This means that if you want to have an entity like a
7
+ * pickup, you have to manually respawn it when the player re-enters the room. Use this helper
8
+ * function to avoid having to do any tracking on your own.
9
+ *
10
+ * Conventionally, the word "persistent" refers to `EntityFlag.FLAG_PERSISTENT`, which is used on
11
+ * e.g. familiars to make them appear in every room. On the other hand, pickups are also persistent,
12
+ * but they are not present in every room, only one specific room. This function spawns entities
13
+ * like pickups, not familiars.
14
+ *
15
+ * @returns A tuple containing the entity and the persistent entity index. You can use the index
16
+ * with the `removePersistentEntity` function.
17
+ */
18
+ export declare function spawnPersistentEntity(entityType: EntityType, variant: int, subType: int, position: Vector): [Entity, int];
19
+ /**
20
+ * Helper function to stop an entity spawned with the `spawnPersistentEntity` helper function from
21
+ * respawning.
22
+ *
23
+ * @param persistentEntityIndex The index that was returned by the `spawnPersistentEntity` function.
24
+ * @param removeEntity Optional. True by default. Set to false if you want to stop an entity from
25
+ * being persistent but you don't want to actually remove the currently-spawned
26
+ * entity from the room.
27
+ */
28
+ export declare function removePersistentEntity(persistentEntityIndex: int, removeEntity?: boolean): void;
@@ -0,0 +1,150 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Map = ____lualib.Map
3
+ local __TS__New = ____lualib.__TS__New
4
+ local __TS__Iterator = ____lualib.__TS__Iterator
5
+ local ____exports = {}
6
+ local postEntityRemove, postNewRoomReordered, spawnAndTrack, v
7
+ local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
8
+ local EntityFlag = ____isaac_2Dtypescript_2Ddefinitions.EntityFlag
9
+ local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
10
+ local ____cachedClasses = require("cachedClasses")
11
+ local game = ____cachedClasses.game
12
+ local ____ModCallbackCustom = require("enums.ModCallbackCustom")
13
+ local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
14
+ local ____entity = require("functions.entity")
15
+ local spawn = ____entity.spawn
16
+ local ____roomData = require("functions.roomData")
17
+ local getRoomListIndex = ____roomData.getRoomListIndex
18
+ local ____exports = require("features.saveDataManager.exports")
19
+ local saveDataManager = ____exports.saveDataManager
20
+ function postEntityRemove(self, entity)
21
+ local ptrHash = GetPtrHash(entity)
22
+ local tuple = v.room.spawnedPersistentEntities:get(ptrHash)
23
+ if tuple == nil then
24
+ return
25
+ end
26
+ local index = tuple[1]
27
+ local level = game:GetLevel()
28
+ local previousRoomGridIndex = level:GetPreviousRoomIndex()
29
+ local previousRoomListIndex = getRoomListIndex(nil, previousRoomGridIndex)
30
+ v.level.persistentEntities:set(index, {
31
+ entityType = entity.Type,
32
+ variant = entity.Variant,
33
+ subType = entity.SubType,
34
+ roomListIndex = previousRoomListIndex,
35
+ position = entity.Position
36
+ })
37
+ end
38
+ function postNewRoomReordered(self)
39
+ local roomListIndex = getRoomListIndex(nil)
40
+ for ____, ____value in __TS__Iterator(v.level.persistentEntities:entries()) do
41
+ local index = ____value[1]
42
+ local description = ____value[2]
43
+ do
44
+ if roomListIndex ~= description.roomListIndex then
45
+ goto __continue6
46
+ end
47
+ v.level.persistentEntities:delete(index)
48
+ spawnAndTrack(
49
+ nil,
50
+ description.entityType,
51
+ description.variant,
52
+ description.subType,
53
+ description.position,
54
+ index,
55
+ true
56
+ )
57
+ end
58
+ ::__continue6::
59
+ end
60
+ end
61
+ function spawnAndTrack(self, entityType, variant, subType, position, index, respawning)
62
+ if respawning == nil then
63
+ respawning = false
64
+ end
65
+ local entity = spawn(
66
+ nil,
67
+ entityType,
68
+ variant,
69
+ subType,
70
+ position
71
+ )
72
+ if respawning then
73
+ entity:ClearEntityFlags(EntityFlag.APPEAR)
74
+ end
75
+ local ptrHash = GetPtrHash(entity)
76
+ local tuple = {
77
+ index,
78
+ EntityPtr(entity)
79
+ }
80
+ v.room.spawnedPersistentEntities:set(ptrHash, tuple)
81
+ return entity
82
+ end
83
+ --- Iterates upward as new persistent entities are created.
84
+ local persistentEntityIndexCounter = 0
85
+ v = {
86
+ level = {persistentEntities = __TS__New(Map)},
87
+ room = {spawnedPersistentEntities = __TS__New(Map)}
88
+ }
89
+ ---
90
+ -- @internal
91
+ function ____exports.persistentEntitiesInit(self, mod)
92
+ saveDataManager(nil, "persistentEntities", v)
93
+ mod:AddCallback(ModCallback.POST_ENTITY_REMOVE, postEntityRemove)
94
+ mod:AddCallbackCustom(ModCallbackCustom.POST_NEW_ROOM_REORDERED, postNewRoomReordered)
95
+ end
96
+ --- Helper function to spawn an entity that will have persistence similar to a pickup.
97
+ --
98
+ -- By default, as soon as you leave a room, any spawned entities will be despawned and will not
99
+ -- return if the player revisits the room. This means that if you want to have an entity like a
100
+ -- pickup, you have to manually respawn it when the player re-enters the room. Use this helper
101
+ -- function to avoid having to do any tracking on your own.
102
+ --
103
+ -- Conventionally, the word "persistent" refers to `EntityFlag.FLAG_PERSISTENT`, which is used on
104
+ -- e.g. familiars to make them appear in every room. On the other hand, pickups are also persistent,
105
+ -- but they are not present in every room, only one specific room. This function spawns entities
106
+ -- like pickups, not familiars.
107
+ --
108
+ -- @returns A tuple containing the entity and the persistent entity index. You can use the index
109
+ -- with the `removePersistentEntity` function.
110
+ function ____exports.spawnPersistentEntity(self, entityType, variant, subType, position)
111
+ persistentEntityIndexCounter = persistentEntityIndexCounter + 1
112
+ local entity = spawnAndTrack(
113
+ nil,
114
+ entityType,
115
+ variant,
116
+ subType,
117
+ position,
118
+ persistentEntityIndexCounter
119
+ )
120
+ return {entity, persistentEntityIndexCounter}
121
+ end
122
+ --- Helper function to stop an entity spawned with the `spawnPersistentEntity` helper function from
123
+ -- respawning.
124
+ --
125
+ -- @param persistentEntityIndex The index that was returned by the `spawnPersistentEntity` function.
126
+ -- @param removeEntity Optional. True by default. Set to false if you want to stop an entity from
127
+ -- being persistent but you don't want to actually remove the currently-spawned
128
+ -- entity from the room.
129
+ function ____exports.removePersistentEntity(self, persistentEntityIndex, removeEntity)
130
+ if removeEntity == nil then
131
+ removeEntity = true
132
+ end
133
+ v.level.persistentEntities:delete(persistentEntityIndex)
134
+ for ____, ____value in __TS__Iterator(v.room.spawnedPersistentEntities:entries()) do
135
+ local ptrHash = ____value[1]
136
+ local tuple = ____value[2]
137
+ do
138
+ local index, entityPtr = table.unpack(tuple)
139
+ if index ~= persistentEntityIndex then
140
+ goto __continue13
141
+ end
142
+ v.room.spawnedPersistentEntities:delete(ptrHash)
143
+ if removeEntity and entityPtr.Ref ~= nil then
144
+ entityPtr.Ref:Remove()
145
+ end
146
+ end
147
+ ::__continue13::
148
+ end
149
+ end
150
+ return ____exports
@@ -1,4 +1,4 @@
1
- import { ActiveSlot, CollectibleType } from "isaac-typescript-definitions";
1
+ import { CollectibleType } from "isaac-typescript-definitions";
2
2
  /**
3
3
  * Helper function to get all of the collectibles that the player has gotten so far on this run, in
4
4
  * order.
@@ -12,12 +12,3 @@ import { ActiveSlot, CollectibleType } from "isaac-typescript-definitions";
12
12
  * order of the lowest `CollectibleType` to the highest.
13
13
  */
14
14
  export declare function getPlayerInventory(player: EntityPlayer, includeActiveCollectibles?: boolean): CollectibleType[];
15
- /**
16
- * Helper function to add a collectible to a player. Use this instead of the
17
- * `EntityPlayer.AddCollectible` method if you want the collectible that is added to be
18
- * automatically tracked by the player inventory tracker feature.
19
- *
20
- * You only need to use this function if you are using the inventory feature from the standard
21
- * library.
22
- */
23
- export declare function addCollectible(player: EntityPlayer, collectibleType: CollectibleType, charge?: int, firstTimePickingUp?: boolean, activeSlot?: ActiveSlot, varData?: int): void;
@@ -1,10 +1,9 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__New = ____lualib.__TS__New
3
- local Set = ____lualib.Set
4
3
  local __TS__Iterator = ____lualib.__TS__Iterator
5
4
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
6
5
  local ____exports = {}
7
- local newPlayerInventory, useItemD4, postGameStarted, postItemPickup, addCollectibleToInventory, v
6
+ local newPlayerInventory, resetInventory, useItemD4, postGameStarted, postCollectibleAdded, postCollectibleRemoved, v
8
7
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
9
8
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
10
9
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
@@ -21,13 +20,14 @@ local ____collectibles = require("functions.collectibles")
21
20
  local isActiveCollectible = ____collectibles.isActiveCollectible
22
21
  local ____collectibleSet = require("functions.collectibleSet")
23
22
  local getCollectibleSet = ____collectibleSet.getCollectibleSet
23
+ local ____playerDataStructures = require("functions.playerDataStructures")
24
+ local defaultMapGetPlayer = ____playerDataStructures.defaultMapGetPlayer
25
+ local mapSetPlayer = ____playerDataStructures.mapSetPlayer
24
26
  local ____playerIndex = require("functions.playerIndex")
25
27
  local getAllPlayers = ____playerIndex.getAllPlayers
26
28
  local getPlayerIndex = ____playerIndex.getPlayerIndex
27
29
  local ____utils = require("functions.utils")
28
30
  local ____repeat = ____utils["repeat"]
29
- local ____PickingUpItem = require("types.PickingUpItem")
30
- local pickingUpItemIsCollectible = ____PickingUpItem.pickingUpItemIsCollectible
31
31
  local ____exports = require("features.saveDataManager.exports")
32
32
  local saveDataManager = ____exports.saveDataManager
33
33
  function newPlayerInventory(self, player)
@@ -45,62 +45,42 @@ function newPlayerInventory(self, player)
45
45
  end
46
46
  return inventory
47
47
  end
48
- function useItemD4(self, _collectibleType, _rng, player)
49
- local playerIndex = getPlayerIndex(nil, player)
48
+ function resetInventory(self, player)
50
49
  local inventory = newPlayerInventory(nil, player)
51
- v.run.playersInventory:set(playerIndex, inventory)
50
+ mapSetPlayer(nil, v.run.playersInventory, player, inventory)
51
+ end
52
+ function useItemD4(self, _collectibleType, _rng, player)
53
+ resetInventory(nil, player)
52
54
  end
53
55
  function postGameStarted(self)
54
56
  for ____, player in ipairs(getAllPlayers(nil)) do
55
57
  local playerIndex = getPlayerIndex(nil, player)
56
58
  if not v.run.playersInventory:has(playerIndex) then
57
- local inventory = newPlayerInventory(nil, player)
58
- v.run.playersInventory:set(playerIndex, inventory)
59
+ resetInventory(nil, player)
59
60
  end
60
61
  end
61
62
  end
62
- function postItemPickup(self, player, pickingUpItem)
63
- if not pickingUpItemIsCollectible(nil, pickingUpItem) then
64
- return
65
- end
66
- addCollectibleToInventory(nil, player, pickingUpItem.subType)
67
- end
68
- function addCollectibleToInventory(self, player, collectibleType)
69
- local playerIndex = getPlayerIndex(nil, player)
70
- local inventory = v.run.playersInventory:getAndSetDefault(playerIndex, player)
63
+ function postCollectibleAdded(self, player, collectibleType)
64
+ local inventory = defaultMapGetPlayer(nil, v.run.playersInventory, player, player)
71
65
  inventory[#inventory + 1] = collectibleType
72
- if not isActiveCollectible(nil, collectibleType) then
73
- return
74
- end
75
- local activeCollectibleTypes = v.run.playersActiveCollectibleTypes:getAndSetDefault(playerIndex)
76
- activeCollectibleTypes[#activeCollectibleTypes + 1] = collectibleType
77
- local droppedActiveCollectibleTypes = __TS__ArrayFilter(
78
- activeCollectibleTypes,
79
- function(____, activeCollectibleType) return not player:HasCollectible(activeCollectibleType) end
80
- )
81
- for ____, activeCollectibleType in ipairs(droppedActiveCollectibleTypes) do
82
- arrayRemoveInPlace(nil, inventory, activeCollectibleType)
83
- arrayRemoveInPlace(nil, activeCollectibleTypes, activeCollectibleType)
84
- end
66
+ end
67
+ function postCollectibleRemoved(self, player, collectibleType)
68
+ local inventory = defaultMapGetPlayer(nil, v.run.playersInventory, player, player)
69
+ arrayRemoveInPlace(nil, inventory, collectibleType)
85
70
  end
86
71
  local FEATURE_NAME = "player inventory tracker"
87
- v = {run = {
88
- playersInventory = __TS__New(
89
- DefaultMap,
90
- function(____, player) return newPlayerInventory(nil, player) end
91
- ),
92
- playersActiveCollectibleTypes = __TS__New(
93
- DefaultMap,
94
- function() return {} end
95
- )
96
- }}
72
+ v = {run = {playersInventory = __TS__New(
73
+ DefaultMap,
74
+ function(____, player) return newPlayerInventory(nil, player) end
75
+ )}}
97
76
  ---
98
77
  -- @internal
99
78
  function ____exports.playerInventoryInit(self, mod)
100
79
  saveDataManager(nil, "playerInventory", v)
101
80
  mod:AddCallback(ModCallback.POST_USE_ITEM, useItemD4, CollectibleType.D4)
102
81
  mod:AddCallback(ModCallback.POST_GAME_STARTED, postGameStarted)
103
- mod:AddCallbackCustom(ModCallbackCustom.POST_ITEM_PICKUP, postItemPickup)
82
+ mod:AddCallbackCustom(ModCallbackCustom.POST_PLAYER_COLLECTIBLE_ADDED, postCollectibleAdded)
83
+ mod:AddCallbackCustom(ModCallbackCustom.POST_PLAYER_COLLECTIBLE_REMOVED, postCollectibleRemoved)
104
84
  end
105
85
  --- Helper function to get all of the collectibles that the player has gotten so far on this run, in
106
86
  -- order.
@@ -117,8 +97,7 @@ function ____exports.getPlayerInventory(self, player, includeActiveCollectibles)
117
97
  includeActiveCollectibles = true
118
98
  end
119
99
  errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
120
- local playerIndex = getPlayerIndex(nil, player)
121
- local inventory = v.run.playersInventory:getAndSetDefault(playerIndex, player)
100
+ local inventory = defaultMapGetPlayer(nil, v.run.playersInventory, player, player)
122
101
  local copiedInventory = copyArray(nil, inventory)
123
102
  if includeActiveCollectibles then
124
103
  return copiedInventory
@@ -128,20 +107,4 @@ function ____exports.getPlayerInventory(self, player, includeActiveCollectibles)
128
107
  function(____, collectibleType) return not isActiveCollectible(nil, collectibleType) end
129
108
  )
130
109
  end
131
- --- Helper function to add a collectible to a player. Use this instead of the
132
- -- `EntityPlayer.AddCollectible` method if you want the collectible that is added to be
133
- -- automatically tracked by the player inventory tracker feature.
134
- --
135
- -- You only need to use this function if you are using the inventory feature from the standard
136
- -- library.
137
- function ____exports.addCollectible(self, player, collectibleType, charge, firstTimePickingUp, activeSlot, varData)
138
- player:AddCollectible(
139
- collectibleType,
140
- charge,
141
- firstTimePickingUp,
142
- activeSlot,
143
- varData
144
- )
145
- addCollectibleToInventory(nil, player, collectibleType)
146
- end
147
110
  return ____exports
@@ -16,7 +16,7 @@ export declare function arrayEquals<T>(array1: T[] | readonly T[], array2: T[] |
16
16
  export declare function arrayRemove<T>(originalArray: T[] | readonly T[], ...elementsToRemove: T[]): T[];
17
17
  /**
18
18
  * Removes the specified element(s) from the array. If the specified element(s) are not found in the
19
- * array, this function will do nothing. Returns whether or not one or more elements were removed.
19
+ * array, this function will do nothing. Returns true if one or more elements were removed.
20
20
  *
21
21
  * This function is variadic, meaning that you can specify N arguments to remove N elements.
22
22
  */
@@ -31,8 +31,8 @@ export declare function arrayRemoveInPlace<T>(array: T[], ...elementsToRemove: T
31
31
  export declare function arrayRemoveIndex<T>(originalArray: T[] | readonly T[], ...indexesToRemove: int[]): T[];
32
32
  /**
33
33
  * Removes the elements at the specified indexes from the array. If the specified indexes are not
34
- * found in the array, this function will do nothing. Returns whether or not one or more elements
35
- * were removed.
34
+ * found in the array, this function will do nothing. Returns true if one or more elements were
35
+ * removed.
36
36
  *
37
37
  * This function is variadic, meaning that you can specify N arguments to remove N elements.
38
38
  */
@@ -87,7 +87,7 @@ function ____exports.arrayRemove(self, originalArray, ...)
87
87
  return array
88
88
  end
89
89
  --- Removes the specified element(s) from the array. If the specified element(s) are not found in the
90
- -- array, this function will do nothing. Returns whether or not one or more elements were removed.
90
+ -- array, this function will do nothing. Returns true if one or more elements were removed.
91
91
  --
92
92
  -- This function is variadic, meaning that you can specify N arguments to remove N elements.
93
93
  function ____exports.arrayRemoveInPlace(self, array, ...)
@@ -122,8 +122,8 @@ function ____exports.arrayRemoveIndex(self, originalArray, ...)
122
122
  return array
123
123
  end
124
124
  --- Removes the elements at the specified indexes from the array. If the specified indexes are not
125
- -- found in the array, this function will do nothing. Returns whether or not one or more elements
126
- -- were removed.
125
+ -- found in the array, this function will do nothing. Returns true if one or more elements were
126
+ -- removed.
127
127
  --
128
128
  -- This function is variadic, meaning that you can specify N arguments to remove N elements.
129
129
  function ____exports.arrayRemoveIndexInPlace(self, array, ...)
@@ -2,8 +2,8 @@ import { CollectibleType } from "isaac-typescript-definitions";
2
2
  /**
3
3
  * Returns a set containing every valid collectible type in the game, including modded collectibles.
4
4
  */
5
- export declare function getCollectibleSet(): Set<CollectibleType>;
5
+ export declare function getCollectibleSet(): ReadonlySet<CollectibleType>;
6
6
  /** Returns a set containing every modded collectible type in the game. */
7
- export declare function getModdedCollectibleSet(): Set<CollectibleType>;
7
+ export declare function getModdedCollectibleSet(): ReadonlySet<CollectibleType>;
8
8
  /** Returns a set containing every valid vanilla collectible type in the game. */
9
- export declare function getVanillaCollectibleSet(): Set<CollectibleType>;
9
+ export declare function getVanillaCollectibleSet(): ReadonlySet<CollectibleType>;
@@ -8,8 +8,6 @@ local ____constantsFirstLast = require("constantsFirstLast")
8
8
  local LAST_VANILLA_COLLECTIBLE_TYPE = ____constantsFirstLast.LAST_VANILLA_COLLECTIBLE_TYPE
9
9
  local ____collectibles = require("functions.collectibles")
10
10
  local getCollectibleTypeRange = ____collectibles.getCollectibleTypeRange
11
- local ____set = require("functions.set")
12
- local copySet = ____set.copySet
13
11
  local ALL_COLLECTIBLES_SET = __TS__New(Set)
14
12
  local VANILLA_COLLECTIBLES_SET = __TS__New(Set)
15
13
  local MODDED_COLLECTIBLES_SET = __TS__New(Set)
@@ -35,20 +33,20 @@ function ____exports.getCollectibleSet(self)
35
33
  if ALL_COLLECTIBLES_SET.size == 0 then
36
34
  initCollectibleSets(nil)
37
35
  end
38
- return copySet(nil, ALL_COLLECTIBLES_SET)
36
+ return ALL_COLLECTIBLES_SET
39
37
  end
40
38
  --- Returns a set containing every modded collectible type in the game.
41
39
  function ____exports.getModdedCollectibleSet(self)
42
40
  if ALL_COLLECTIBLES_SET.size == 0 then
43
41
  initCollectibleSets(nil)
44
42
  end
45
- return copySet(nil, MODDED_COLLECTIBLES_SET)
43
+ return MODDED_COLLECTIBLES_SET
46
44
  end
47
45
  --- Returns a set containing every valid vanilla collectible type in the game.
48
46
  function ____exports.getVanillaCollectibleSet(self)
49
47
  if ALL_COLLECTIBLES_SET.size == 0 then
50
48
  initCollectibleSets(nil)
51
49
  end
52
- return copySet(nil, VANILLA_COLLECTIBLES_SET)
50
+ return VANILLA_COLLECTIBLES_SET
53
51
  end
54
52
  return ____exports
@@ -9,9 +9,6 @@ interface CopyColorReturn {
9
9
  [SerializationType.SERIALIZE]: SerializedColor;
10
10
  [SerializationType.DESERIALIZE]: Color;
11
11
  }
12
- /**
13
- * @category color
14
- */
15
12
  export declare function colorEquals(color1: Color, color2: Color): boolean;
16
13
  /**
17
14
  * Helper function to copy a `Color` object.
@@ -19,27 +16,16 @@ export declare function colorEquals(color1: Color, color2: Color): boolean;
19
16
  * @param color The Color object to copy. In the case of deserialization, this will actually be a
20
17
  * Lua table instead of an instantiated Color class.
21
18
  * @param serializationType Default is `SerializationType.NONE`.
22
- * @category color
23
19
  */
24
20
  export declare function copyColor<C extends Color | SerializedColor, S extends SerializationType>(color: C, serializationType: S): CopyColorReturn[S];
25
21
  export declare function copyColor<C extends Color | SerializedColor>(color: C): CopyColorReturn[SerializationType.NONE];
26
- /**
27
- * Returns `Color(1, 1, 1)`.
28
- *
29
- * @category color
30
- */
22
+ /** Returns `Color(1, 1, 1)`. */
31
23
  export declare function getDefaultColor(): Color;
32
- /**
33
- * Helper function to check if something is an instantiated Color object.
34
- *
35
- * @category color
36
- */
24
+ /** Helper function to check if something is an instantiated Color object. */
37
25
  export declare function isColor(object: unknown): object is Color;
38
26
  /**
39
27
  * Used to determine is the given table is a serialized `Color` object created by the save data
40
28
  * manager and/or the `deepCopy` function.
41
- *
42
- * @category color
43
29
  */
44
30
  export declare function isSerializedColor(object: unknown): object is SerializedColor;
45
31
  export {};