isaacscript-common 6.11.2 → 6.12.0

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 (142) hide show
  1. package/dist/callbacks/postGridEntityCustomRender.d.ts +2 -0
  2. package/dist/callbacks/postGridEntityCustomRender.d.ts.map +1 -0
  3. package/dist/callbacks/postGridEntityCustomRender.lua +36 -0
  4. package/dist/callbacks/postGridEntityCustomUpdate.d.ts +2 -0
  5. package/dist/callbacks/postGridEntityCustomUpdate.d.ts.map +1 -0
  6. package/dist/callbacks/postGridEntityCustomUpdate.lua +36 -0
  7. package/dist/callbacks/postNewRoomEarly.lua +2 -2
  8. package/dist/callbacks/postPickupInitFirst.lua +1 -20
  9. package/dist/callbacks/reorderedCallbacks.d.ts +5 -5
  10. package/dist/callbacks/reorderedCallbacks.d.ts.map +1 -1
  11. package/dist/callbacks/reorderedCallbacks.lua +5 -5
  12. package/dist/callbacks/subscriptions/postGridEntityCustomRender.d.ts +6 -0
  13. package/dist/callbacks/subscriptions/postGridEntityCustomRender.d.ts.map +1 -0
  14. package/dist/callbacks/subscriptions/postGridEntityCustomRender.lua +29 -0
  15. package/dist/callbacks/subscriptions/postGridEntityCustomUpdate.d.ts +6 -0
  16. package/dist/callbacks/subscriptions/postGridEntityCustomUpdate.d.ts.map +1 -0
  17. package/dist/callbacks/subscriptions/postGridEntityCustomUpdate.lua +29 -0
  18. package/dist/constants.d.ts +1 -5
  19. package/dist/constants.d.ts.map +1 -1
  20. package/dist/constants.lua +0 -7
  21. package/dist/constantsFirstLast.d.ts +5 -1
  22. package/dist/constantsFirstLast.d.ts.map +1 -1
  23. package/dist/constantsFirstLast.lua +6 -0
  24. package/dist/enums/ModCallbackCustom.d.ts +89 -66
  25. package/dist/enums/ModCallbackCustom.d.ts.map +1 -1
  26. package/dist/enums/ModCallbackCustom.lua +62 -58
  27. package/dist/features/customGridEntity.d.ts +9 -0
  28. package/dist/features/customGridEntity.d.ts.map +1 -1
  29. package/dist/features/customGridEntity.lua +20 -0
  30. package/dist/features/customTrapdoor/customTrapdoorConstants.d.ts +2 -2
  31. package/dist/features/customTrapdoor/customTrapdoorConstants.d.ts.map +1 -1
  32. package/dist/features/customTrapdoor/customTrapdoorConstants.lua +2 -2
  33. package/dist/features/customTrapdoor/init.d.ts.map +1 -1
  34. package/dist/features/customTrapdoor/init.lua +4 -3
  35. package/dist/features/customTrapdoor/touched.d.ts.map +1 -1
  36. package/dist/features/customTrapdoor/touched.lua +51 -33
  37. package/dist/features/deployJSONRoom.d.ts +2 -2
  38. package/dist/features/deployJSONRoom.lua +2 -2
  39. package/dist/features/extraConsoleCommands/listCommands.d.ts.map +1 -1
  40. package/dist/features/extraConsoleCommands/listCommands.lua +4 -4
  41. package/dist/features/pause.d.ts +1 -1
  42. package/dist/features/pause.d.ts.map +1 -1
  43. package/dist/features/pause.lua +87 -8
  44. package/dist/features/persistentEntities.d.ts.map +1 -1
  45. package/dist/features/persistentEntities.lua +7 -7
  46. package/dist/features/pickupIndex.d.ts +19 -0
  47. package/dist/features/pickupIndex.d.ts.map +1 -0
  48. package/dist/features/pickupIndex.lua +197 -0
  49. package/dist/features/roomHistory.d.ts +24 -0
  50. package/dist/features/roomHistory.d.ts.map +1 -0
  51. package/dist/features/roomHistory.lua +89 -0
  52. package/dist/functions/collectibles.d.ts +26 -13
  53. package/dist/functions/collectibles.d.ts.map +1 -1
  54. package/dist/functions/collectibles.lua +26 -13
  55. package/dist/functions/entities.d.ts +3 -3
  56. package/dist/functions/entities.d.ts.map +1 -1
  57. package/dist/functions/entities.lua +8 -3
  58. package/dist/functions/gridEntities.d.ts +2 -2
  59. package/dist/functions/gridEntities.lua +2 -2
  60. package/dist/functions/isaacAPIClass.d.ts +64 -0
  61. package/dist/functions/isaacAPIClass.d.ts.map +1 -1
  62. package/dist/functions/isaacAPIClass.lua +84 -1
  63. package/dist/functions/pickupVariants.d.ts +2 -2
  64. package/dist/functions/pickupVariants.d.ts.map +1 -1
  65. package/dist/functions/pickupVariants.lua +2 -2
  66. package/dist/functions/playerCenter.lua +2 -2
  67. package/dist/functions/playerIndex.d.ts +0 -3
  68. package/dist/functions/playerIndex.d.ts.map +1 -1
  69. package/dist/functions/playerIndex.lua +4 -23
  70. package/dist/functions/roomData.d.ts +3 -2
  71. package/dist/functions/roomData.d.ts.map +1 -1
  72. package/dist/functions/roomData.lua +3 -2
  73. package/dist/functions/rooms.d.ts +6 -6
  74. package/dist/functions/rooms.lua +6 -6
  75. package/dist/functions/stage.d.ts +1 -0
  76. package/dist/functions/stage.d.ts.map +1 -1
  77. package/dist/functions/stage.lua +4 -0
  78. package/dist/index.d.ts +3 -0
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.lua +23 -0
  81. package/dist/initCustomCallbacks.d.ts.map +1 -1
  82. package/dist/initCustomCallbacks.lua +6 -0
  83. package/dist/initFeatures.d.ts.map +1 -1
  84. package/dist/initFeatures.lua +6 -0
  85. package/dist/interfaces/AddCallbackParameterCustom.d.ts +4 -0
  86. package/dist/interfaces/AddCallbackParameterCustom.d.ts.map +1 -1
  87. package/dist/interfaces/RoomDescription.d.ts +14 -0
  88. package/dist/interfaces/RoomDescription.d.ts.map +1 -0
  89. package/dist/interfaces/RoomDescription.lua +2 -0
  90. package/dist/objects/callbackRegisterFunctions.d.ts.map +1 -1
  91. package/dist/objects/callbackRegisterFunctions.lua +6 -0
  92. package/dist/types/CollectibleIndex.d.ts +1 -1
  93. package/dist/types/PickupIndex.d.ts +17 -0
  94. package/dist/types/PickupIndex.d.ts.map +1 -0
  95. package/dist/types/PickupIndex.lua +2 -0
  96. package/dist/types/PlayerIndex.d.ts +1 -1
  97. package/dist/upgradeMod.d.ts.map +1 -1
  98. package/package.json +1 -1
  99. package/src/callbacks/postGridEntityCustomRender.ts +44 -0
  100. package/src/callbacks/postGridEntityCustomUpdate.ts +44 -0
  101. package/src/callbacks/postNewRoomEarly.ts +2 -2
  102. package/src/callbacks/postPickupInitFirst.ts +1 -32
  103. package/src/callbacks/postPlayerReorderedCallbacks.ts +3 -3
  104. package/src/callbacks/reorderedCallbacks.ts +9 -8
  105. package/src/callbacks/subscriptions/postGridEntityCustomRender.ts +41 -0
  106. package/src/callbacks/subscriptions/postGridEntityCustomUpdate.ts +41 -0
  107. package/src/constants.ts +1 -9
  108. package/src/constantsFirstLast.ts +16 -0
  109. package/src/enums/ModCallbackCustom.ts +33 -8
  110. package/src/features/customGridEntity.ts +25 -0
  111. package/src/features/customTrapdoor/customTrapdoorConstants.ts +2 -2
  112. package/src/features/customTrapdoor/init.ts +7 -5
  113. package/src/features/customTrapdoor/touched.ts +59 -39
  114. package/src/features/deployJSONRoom.ts +4 -4
  115. package/src/features/extraConsoleCommands/listCommands.ts +5 -7
  116. package/src/features/pause.ts +97 -7
  117. package/src/features/persistentEntities.ts +9 -8
  118. package/src/features/pickupIndex.ts +257 -0
  119. package/src/features/playerInventory.ts +2 -2
  120. package/src/features/roomHistory.ts +113 -0
  121. package/src/features/saveDataManager/main.ts +2 -2
  122. package/src/features/taintedLazarusPlayers.ts +5 -5
  123. package/src/functions/collectibles.ts +26 -13
  124. package/src/functions/entities.ts +6 -3
  125. package/src/functions/gridEntities.ts +2 -2
  126. package/src/functions/isaacAPIClass.ts +106 -1
  127. package/src/functions/pickupVariants.ts +2 -2
  128. package/src/functions/playerCenter.ts +2 -2
  129. package/src/functions/playerIndex.ts +8 -21
  130. package/src/functions/roomData.ts +3 -2
  131. package/src/functions/rooms.ts +6 -6
  132. package/src/functions/stage.ts +10 -1
  133. package/src/index.ts +3 -0
  134. package/src/initCustomCallbacks.ts +4 -0
  135. package/src/initFeatures.ts +4 -0
  136. package/src/interfaces/AddCallbackParameterCustom.ts +4 -0
  137. package/src/interfaces/RoomDescription.ts +19 -0
  138. package/src/objects/callbackRegisterFunctions.ts +6 -0
  139. package/src/types/CollectibleIndex.ts +1 -1
  140. package/src/types/PickupIndex.ts +15 -0
  141. package/src/types/PlayerIndex.ts +1 -1
  142. package/src/upgradeMod.ts +2 -1
@@ -0,0 +1,257 @@
1
+ import {
2
+ EntityType,
3
+ ModCallback,
4
+ RoomType,
5
+ } from "isaac-typescript-definitions";
6
+ import { game } from "../cachedClasses";
7
+ import { DefaultMap } from "../classes/DefaultMap";
8
+ import { ModUpgraded } from "../classes/ModUpgraded";
9
+ import { ModCallbackCustom } from "../enums/ModCallbackCustom";
10
+ import { errorIfFeaturesNotInitialized } from "../featuresInitialized";
11
+ import { getEntityID } from "../functions/entities";
12
+ import { getPickups } from "../functions/entitiesSpecific";
13
+ import { getRoomListIndex } from "../functions/roomData";
14
+ import { onAscent } from "../functions/stage";
15
+ import { vectorEquals } from "../functions/vector";
16
+ import { PickupIndex } from "../types/PickupIndex";
17
+ import { getLatestRoomDescription } from "./roomHistory";
18
+ import { saveDataManager } from "./saveDataManager/exports";
19
+
20
+ interface PickupDescription {
21
+ position: Vector;
22
+ initSeed: Seed;
23
+ }
24
+
25
+ const FEATURE_NAME = "pickupIndex";
26
+
27
+ const v = {
28
+ run: {
29
+ pickupCounter: 0 as PickupIndex,
30
+ currentRoomListIndex: 0,
31
+
32
+ pickupDataTreasureRooms: new Map<PickupIndex, PickupDescription>(),
33
+ pickupDataBossRooms: new Map<PickupIndex, PickupDescription>(),
34
+ },
35
+
36
+ level: {
37
+ /** Indexed by room list index. */
38
+ pickupData: new DefaultMap<int, Map<PickupIndex, PickupDescription>>(
39
+ () => new Map(),
40
+ ),
41
+ },
42
+
43
+ room: {
44
+ pickupIndexes: new Map<PtrHash, PickupIndex>(),
45
+ },
46
+ };
47
+
48
+ export function pickupIndexInit(mod: ModUpgraded): void {
49
+ saveDataManager(FEATURE_NAME, v);
50
+
51
+ mod.AddCallback(ModCallback.POST_PICKUP_INIT, postPickupInit); // 34
52
+ mod.AddCallback(
53
+ ModCallback.POST_ENTITY_REMOVE,
54
+ postEntityRemovePickup,
55
+ EntityType.PICKUP,
56
+ ); // 67
57
+ mod.AddCallbackCustom(
58
+ ModCallbackCustom.POST_NEW_ROOM_REORDERED,
59
+ postNewRoomReordered,
60
+ );
61
+ }
62
+
63
+ // ModCallback.POST_PICKUP_INIT (34)
64
+ function postPickupInit(pickup: EntityPickup) {
65
+ const ptrHash = GetPtrHash(pickup);
66
+
67
+ // In certain situations, pickups can be morphed, and this should not incur a new pickup counter.
68
+ // (For example, the collectible rotation with Tainted Isaac.)
69
+ if (v.room.pickupIndexes.has(ptrHash)) {
70
+ return;
71
+ }
72
+
73
+ // If we are re-entering a room that previously had a pickup, then we don't need to make a new
74
+ // index, because we will re-use the existing one.
75
+ const room = game.GetRoom();
76
+ const isFirstVisit = room.IsFirstVisit();
77
+ const roomFrameCount = room.GetFrameCount();
78
+ if (!isFirstVisit && roomFrameCount <= 0) {
79
+ return;
80
+ }
81
+
82
+ v.run.pickupCounter++;
83
+ v.room.pickupIndexes.set(ptrHash, v.run.pickupCounter);
84
+
85
+ // Additionally, keep track of which room we are storing the pointer hashes for.
86
+ v.run.currentRoomListIndex = getRoomListIndex();
87
+ }
88
+
89
+ // ModCallback.POST_ENTITY_REMOVE (67)
90
+ // EntityType.PICKUP (5)
91
+ function postEntityRemovePickup(entity: Entity) {
92
+ checkDespawningFromPlayerLeavingRoom(entity);
93
+ }
94
+
95
+ function checkDespawningFromPlayerLeavingRoom(entity: Entity) {
96
+ const ptrHash = GetPtrHash(entity);
97
+ const pickupIndex = v.room.pickupIndexes.get(ptrHash);
98
+ if (pickupIndex === undefined) {
99
+ return;
100
+ }
101
+
102
+ const roomListIndex = getRoomListIndex();
103
+ if (roomListIndex === v.run.currentRoomListIndex) {
104
+ // This is a pickup that is despawning in the current room. For example, it could be a heart
105
+ // pickup that the player picked up. Thus, we do not need to keep track of it's metadata.
106
+ return;
107
+ }
108
+
109
+ trackDespawningPickupMetadata(entity, pickupIndex);
110
+ }
111
+
112
+ /**
113
+ * This is a pickup that is despawning because the player is in the process of leaving the room.
114
+ * Keep track of the metadata for later. We need to use the previous room list index because even
115
+ * though the `POST_NEW_ROOM` callback was not fired yet, we have already traveled to the next room.
116
+ */
117
+ function trackDespawningPickupMetadata(
118
+ entity: Entity,
119
+ pickupIndex: PickupIndex,
120
+ ) {
121
+ const previousRoomDescription = getLatestRoomDescription();
122
+ const previousRoomListIndex = previousRoomDescription.roomListIndex;
123
+ const pickupDescriptions = v.level.pickupData.getAndSetDefault(
124
+ previousRoomListIndex,
125
+ );
126
+
127
+ const pickupDescription: PickupDescription = {
128
+ position: entity.Position,
129
+ initSeed: entity.InitSeed,
130
+ };
131
+ pickupDescriptions.set(pickupIndex, pickupDescription);
132
+
133
+ // If the despawning pickup was in a Treasure Room or Boss Room, then it is possible that the
134
+ // pickup could re-appear during The Ascent. If this is the case, we store the metadata on a
135
+ // separate map to reference later.
136
+ if (onAscent()) {
137
+ return;
138
+ }
139
+
140
+ const room = game.GetRoom();
141
+ const roomType = room.GetType();
142
+
143
+ switch (roomType) {
144
+ case RoomType.TREASURE: {
145
+ v.run.pickupDataTreasureRooms.set(pickupIndex, pickupDescription);
146
+ break;
147
+ }
148
+
149
+ case RoomType.BOSS: {
150
+ v.run.pickupDataBossRooms.set(pickupIndex, pickupDescription);
151
+ break;
152
+ }
153
+
154
+ default: {
155
+ break;
156
+ }
157
+ }
158
+ }
159
+
160
+ // ModCallbackCustom.POST_NEW_ROOM_REORDERED
161
+ function postNewRoomReordered() {
162
+ const room = game.GetRoom();
163
+ const isFirstVisit = room.IsFirstVisit();
164
+
165
+ if (isFirstVisit) {
166
+ return;
167
+ }
168
+
169
+ const roomListIndex = getRoomListIndex();
170
+ const pickupDescriptions = v.level.pickupData.getAndSetDefault(roomListIndex);
171
+
172
+ for (const pickup of getPickups()) {
173
+ let pickupIndex = getStoredPickupIndex(pickup, pickupDescriptions);
174
+ if (pickupIndex === undefined) {
175
+ pickupIndex = getPostAscentPickupIndex(pickup);
176
+ }
177
+
178
+ if (pickupIndex === undefined) {
179
+ const entityID = getEntityID(pickup);
180
+ error(
181
+ `Failed to find a pickup index corresponding to existing pickup: ${entityID}`,
182
+ );
183
+ }
184
+
185
+ const ptrHash = GetPtrHash(pickup);
186
+ v.room.pickupIndexes.set(ptrHash, pickupIndex);
187
+ }
188
+ }
189
+
190
+ function getStoredPickupIndex(
191
+ pickup: Entity,
192
+ pickupDescriptions: Map<PickupIndex, PickupDescription>,
193
+ ): PickupIndex | undefined {
194
+ for (const [pickupIndex, pickupDescription] of pickupDescriptions.entries()) {
195
+ if (
196
+ vectorEquals(pickupDescription.position, pickup.Position) &&
197
+ pickupDescription.initSeed === pickup.InitSeed
198
+ ) {
199
+ return pickupIndex;
200
+ }
201
+ }
202
+
203
+ return undefined;
204
+ }
205
+
206
+ function getPostAscentPickupIndex(pickup: EntityPickup) {
207
+ // If we have not found the pickup index yet, we might be re-entering a post-Ascent Treasure Room
208
+ // or Boss Room.
209
+ if (!onAscent()) {
210
+ return undefined;
211
+ }
212
+
213
+ const room = game.GetRoom();
214
+ const roomType = room.GetType();
215
+
216
+ switch (roomType) {
217
+ case RoomType.TREASURE: {
218
+ return getStoredPickupIndex(pickup, v.run.pickupDataTreasureRooms);
219
+ }
220
+
221
+ case RoomType.BOSS: {
222
+ return getStoredPickupIndex(pickup, v.run.pickupDataBossRooms);
223
+ }
224
+
225
+ default: {
226
+ return undefined;
227
+ }
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Mods often have to track variables relating to a pickups. Finding an index for these kinds of
233
+ * data structures is difficult, since pickups are respawned every time a player re-enters a room,
234
+ * so the `PtrHash` will change.
235
+ *
236
+ * Use this function to get a unique index for a pickup to use in these data structures.
237
+ *
238
+ * Specifically, `PickupIndex` is a number that represents the spawn order of the pickup on the
239
+ * current run. For example, the first pickup spawned will have an index of 1, the second one will
240
+ * have an index of 2, and so on.
241
+ *
242
+ * Tracking pickups requires stateful tracking, so using pickup indexes requires an upgraded mod.
243
+ */
244
+ export function getPickupIndex(pickup: EntityPickup): PickupIndex {
245
+ errorIfFeaturesNotInitialized(FEATURE_NAME);
246
+
247
+ const ptrHash = GetPtrHash(pickup);
248
+ const pickupIndex = v.room.pickupIndexes.get(ptrHash);
249
+ if (pickupIndex === undefined) {
250
+ const entityID = getEntityID(pickup);
251
+ error(
252
+ `Failed to get a pickup index for entity ${entityID} with hash: ${ptrHash}`,
253
+ );
254
+ }
255
+
256
+ return pickupIndex;
257
+ }
@@ -76,8 +76,8 @@ function useItemD4(
76
76
 
77
77
  // ModCallback.POST_GAME_STARTED (15)
78
78
  function postGameStarted() {
79
- // We don't use the PostPlayerInit callback because some items are not given to the player at that
80
- // point.
79
+ // We don't use the `POST_PLAYER_INIT` callback because some items are not given to the player at
80
+ // that point.
81
81
  for (const player of getAllPlayers()) {
82
82
  const playerIndex = getPlayerIndex(player);
83
83
  if (!v.run.playersInventory.has(playerIndex)) {
@@ -0,0 +1,113 @@
1
+ import { game } from "../cachedClasses";
2
+ import { ModUpgraded } from "../classes/ModUpgraded";
3
+ import { ModCallbackCustom } from "../enums/ModCallbackCustom";
4
+ import { errorIfFeaturesNotInitialized } from "../featuresInitialized";
5
+ import { getLastElement } from "../functions/array";
6
+ import {
7
+ getRoomGridIndex,
8
+ getRoomListIndex,
9
+ getRoomName,
10
+ getRoomStageID,
11
+ getRoomSubType,
12
+ getRoomVariant,
13
+ } from "../functions/roomData";
14
+ import { RoomDescription } from "../interfaces/RoomDescription";
15
+ import { saveDataManager } from "./saveDataManager/exports";
16
+
17
+ const FEATURE_NAME = "roomHistory";
18
+
19
+ const v = {
20
+ run: {
21
+ roomHistory: [] as RoomDescription[],
22
+ },
23
+ };
24
+
25
+ /** @internal */
26
+ export function roomHistoryInit(mod: ModUpgraded): void {
27
+ saveDataManager(FEATURE_NAME, v);
28
+
29
+ mod.AddCallbackCustom(
30
+ ModCallbackCustom.POST_NEW_ROOM_EARLY,
31
+ postNewRoomEarly,
32
+ );
33
+ }
34
+
35
+ // ModCallbackCustom.POST_NEW_ROOM_EARLY
36
+ function postNewRoomEarly() {
37
+ const level = game.GetLevel();
38
+ const stage = level.GetStage();
39
+ const stageType = level.GetStageType();
40
+ const room = game.GetRoom();
41
+ const roomType = room.GetType();
42
+ const stageID = getRoomStageID();
43
+ const roomVariant = getRoomVariant();
44
+ const roomSubType = getRoomSubType();
45
+ const roomName = getRoomName();
46
+ const roomGridIndex = getRoomGridIndex();
47
+ const roomListIndex = getRoomListIndex();
48
+
49
+ const roomDescription: RoomDescription = {
50
+ stage,
51
+ stageType,
52
+ stageID,
53
+ roomType,
54
+ roomVariant,
55
+ roomSubType,
56
+ roomName,
57
+ roomGridIndex,
58
+ roomListIndex,
59
+ };
60
+ v.run.roomHistory.push(roomDescription);
61
+ }
62
+
63
+ /**
64
+ * Helper function to get information about all of the rooms that a player has visited thus far on
65
+ * this run.
66
+ */
67
+ export function getRoomHistory(): readonly RoomDescription[] {
68
+ errorIfFeaturesNotInitialized(FEATURE_NAME);
69
+ return v.run.roomHistory;
70
+ }
71
+
72
+ /**
73
+ * Helper function to get information about the room that was previously visited.
74
+ *
75
+ * In the special case of only one room having been visited thus far (i.e. the starting room of the
76
+ * run), the starting room will be returned.
77
+ */
78
+ export function getPreviousRoomDescription(): RoomDescription {
79
+ const previousRoomDescription =
80
+ v.run.roomHistory[v.run.roomHistory.length - 2];
81
+ if (previousRoomDescription !== undefined) {
82
+ return previousRoomDescription;
83
+ }
84
+
85
+ const startingRoomDescription = v.run.roomHistory[0];
86
+ if (startingRoomDescription !== undefined) {
87
+ return startingRoomDescription;
88
+ }
89
+
90
+ error(
91
+ "Failed to find a room description for any rooms thus far on this run.",
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Helper function to get information about the most recent room that is stored in the room history
97
+ * array.
98
+ *
99
+ * This is useful in the `POST_ENTITY_REMOVE` callback, since if an entity is despawning due to a
100
+ * player having left the room, the current room will have changed already, but the `POST_NEW_ROOM`
101
+ * callback will not have fired yet, and there will not be an entry in the room history array for
102
+ * the current room.
103
+ */
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;
113
+ }
@@ -65,8 +65,8 @@ function postPlayerInit() {
65
65
  restoreDefaultsAll();
66
66
  }
67
67
 
68
- // On continued runs, the PostNewLevel callback will not fire, so we do not have to worry about
69
- // saved data based on level getting overwritten.
68
+ // On continued runs, the `POST_NEW_LEVEL` callback will not fire, so we do not have to worry
69
+ // about saved data based on level getting overwritten.
70
70
  }
71
71
 
72
72
  // ModCallback.PRE_GAME_EXIT (17)
@@ -58,11 +58,11 @@ function postPlayerInit(player: EntityPlayer) {
58
58
  /**
59
59
  * Indexes are the `PtrHash`, values are the `EntityPtr` of the *other* Lazarus.
60
60
  *
61
- * When starting a run, the PostPlayerInit callback will fire first for Dead Tainted Lazarus, then
62
- * for Tainted Lazarus. When continuing a run, the PostPlayerInit callback will fire first for the
63
- * character that is currently active. Thus, since the order of the characters is not certain, we
64
- * insert each of their pointers into a queue, and then only populate the map when we have one
65
- * Tainted Lazarus and one Dead Tainted Lazarus.
61
+ * When starting a run, the `POST_PLAYER_INIT` callback will fire first for Dead Tainted Lazarus,
62
+ * then for Tainted Lazarus. When continuing a run, the `POST_PLAYER_INIT` callback will fire first
63
+ * for the character that is currently active. Thus, since the order of the characters is not
64
+ * certain, we insert each of their pointers into a queue, and then only populate the map when we
65
+ * have one Tainted Lazarus and one Dead Tainted Lazarus.
66
66
  */
67
67
  function checkDequeue() {
68
68
  if (
@@ -176,38 +176,51 @@ export function getCollectibleGfxFilename(
176
176
  }
177
177
 
178
178
  /**
179
- * Mods often have to track variables relating to a collectible. Finding an index for these kinds of
180
- * data structures is difficult, since collectibles are respawned every time a player re-enters a
181
- * room, so the `PtrHash` will change. Instead, we use a 4-tuple of the room list index, the grid
182
- * index of the collectible in the room, the collectible's SubType, and the collectible's InitSeed.
179
+ * Mods may have to keep track of data relating to a collectible. Finding an index for these kinds
180
+ * of data structures is difficult, since collectibles are respawned every time a player re-enters a
181
+ * room (like all other pickups), so the `PtrHash` will change.
182
+ *
183
+ * Use this function to get a unique index for a collectible to use in these data structures.
184
+ *
185
+ * If your mod is upgraded, then you should use the `getPickupIndex` function instead, as it is more
186
+ * general purpose and less prone to error (but relies on stateful tracking of pickups as the run
187
+ * progresses).
188
+ *
189
+ * Collectibles are a special case of pickups: they cannot be pushed around. (They actually can be
190
+ * pushed, but usually will stay on the same grid index.) Thus, it is possible to generate a
191
+ * somewhat reliable non-stateful index for collectibles. We use a 4-tuple of the room list index,
192
+ * the grid index of the collectible in the room, the collectible's `SubType`, and the collectible's
193
+ * `InitSeed`.
183
194
  *
184
195
  * Collectibles that are shifted by Tainted Isaac's mechanic will have unique collectible indexes
185
- * because the SubType is different. (The collectible entities share the same InitSeed.)
196
+ * because the `SubType` is different. (The collectible entities share the same `InitSeed` and
197
+ * `PtrHash`.)
186
198
  *
187
199
  * Collectibles that are rolled (with e.g. a D6) will have unique collectible indexes because the
188
- * SubType and InitSeed are different. If you want to track collectibles independently of any
200
+ * `SubType` and `InitSeed` are different. If you want to track collectibles independently of any
189
201
  * rerolls, then you can use the `PtrHash` as an index instead. (The `PtrHash` will not persist
190
202
  * between rooms, however.)
191
203
  *
192
204
  * Note that:
193
205
  * - The grid index is a necessary part of the collectible index because Diplopia and Crooked Penny
194
- * can cause two or more collectibles with the same SubType and InitSeed to exist in the same
206
+ * can cause two or more collectibles with the same `SubType` and `InitSeed` to exist in the same
195
207
  * room.
196
208
  * - This index will fail in the case where the player uses Diplopia or a successful Crooked Penny
197
209
  * seven or more times in the same room, since that will cause two or more collectibles with the
198
- * same grid index, SubType, and InitSeed to exist.
199
- * - The SubType is a necessary part of the collectible index because Tainted Isaac will
200
- * continuously cause collectibles to morph into new sub-types with the same InitSeed.
210
+ * same grid index, `SubType`, and `InitSeed` to exist. (More than seven is required in non-1x1
211
+ * rooms.)
212
+ * - The `SubType` is a necessary part of the collectible index because Tainted Isaac will
213
+ * continuously cause collectibles to morph into new sub-types with the same `InitSeed`.
201
214
  * - Using a collectible's position as part of the index is problematic, since players can push a
202
215
  * pedestal. (Even using the grid index does not solve this problem, since it is possible in
203
216
  * certain cases for collectibles to be spawned at a position that is not aligned with the grid,
204
217
  * and the pedestal pushed to an adjacent tile, but this case should be extremely rare.)
205
218
  * - Mega Chests spawn two collectibles on the exact same position. However, both of them will have
206
- * different InitSeeds, so this is not a problem for this indexing scheme.
219
+ * a different `InitSeed`, so this is not a problem for this indexing scheme.
207
220
  * - The indexing scheme used is different for collectibles that are inside of a Treasure Room or
208
221
  * Boss Room, in order to handle the case of the player seeing the same collectible again in a
209
- * post-Ascent Treasure Room or Boss Room. A 5-tuple of stage, stage type, grid index, SubType,
210
- * and InitSeed is used in this case. (Using the room list index or the room grid index is not
222
+ * post-Ascent Treasure Room or Boss Room. A 5-tuple of stage, stage type, grid index, `SubType`,
223
+ * and `InitSeed` is used in this case. (Using the room list index or the room grid index is not
211
224
  * suitable for this purpose, since both of these values can change in the post-Ascent rooms.)
212
225
  * Even though Treasure Rooms and Boss Rooms are grouped together in this scheme, there probably
213
226
  * will not be collectibles with the same grid index, SubType, and InitSeed.
@@ -7,6 +7,7 @@ import { getIsaacAPIClassName } from "./isaacAPIClass";
7
7
  import { getRandom } from "./random";
8
8
  import { isRNG, newRNG } from "./rng";
9
9
  import { isPrimitive } from "./types";
10
+ import { isVector, vectorToString } from "./vector";
10
11
 
11
12
  /**
12
13
  * Helper function to count the number of entities in room. Use this over the vanilla
@@ -130,10 +131,10 @@ export function getEntities(
130
131
 
131
132
  /**
132
133
  * Helper function to get all the fields on an entity. For example, this is useful for comparing it
133
- * to another entity later.
134
+ * to another entity later. (One option is to use the `logTableDifferences` function for this.)
134
135
  *
135
- * This function will only get fields that are equal to booleans, numbers, or strings, as comparing
136
- * other types is non-trivial.
136
+ * This function will only get fields that are equal to booleans, numbers, or strings, or Vectors,
137
+ * as comparing other types is non-trivial.
137
138
  */
138
139
  export function getEntityFields(
139
140
  entity: Entity,
@@ -187,6 +188,8 @@ function setPrimitiveEntityFields(
187
188
  const value = entity[indexKey];
188
189
  if (isPrimitive(value)) {
189
190
  entityFields.set(indexKey, value);
191
+ } else if (isVector(value)) {
192
+ entityFields.set(indexKey, vectorToString(value));
190
193
  }
191
194
  }
192
195
  }
@@ -95,8 +95,8 @@ export function getAllGridIndexes(): int[] {
95
95
  * Gets the entities that have a hitbox that overlaps with any part of the square that the grid
96
96
  * entity is on.
97
97
  *
98
- * Note that this function will not work properly in the PostNewRoom callback, since entities do not
99
- * have collision yet in that callback.
98
+ * Note that this function will not work properly in the `POST_NEW_ROOM` callback, since entities do
99
+ * not have collision yet in that callback.
100
100
  */
101
101
  export function getCollidingEntitiesWithGridEntity(
102
102
  gridEntity: GridEntity,
@@ -1,4 +1,5 @@
1
1
  import { IsaacAPIClass } from "../types/private/IsaacAPIClass";
2
+ import { trimPrefix } from "./string";
2
3
  import { isString, isUserdata } from "./types";
3
4
 
4
5
  /**
@@ -9,6 +10,10 @@ import { isString, isUserdata } from "./types";
9
10
  *
10
11
  * Returns undefined if the object is not of type `userdata` or if the "__type" metatable key does
11
12
  * not exist.
13
+ *
14
+ * In some cases, Isaac classes can be a read-only. If this is the case, the "__type" field will be
15
+ * prepended with "const ". This function will always strip this prefix, if it exists. For example,
16
+ * the class name returned for "const Vector" will be "Vector".
12
17
  */
13
18
  export function getIsaacAPIClassName(object: unknown): string | undefined {
14
19
  if (!isUserdata(object)) {
@@ -27,7 +32,40 @@ export function getIsaacAPIClassName(object: unknown): string | undefined {
27
32
  return undefined;
28
33
  }
29
34
 
30
- return classType;
35
+ return trimPrefix(classType, "const ");
36
+ }
37
+
38
+ /** Helper function to detect if a variable is of type `EntityBomb`. */
39
+ export function isBomb(variable: unknown): variable is EntityBomb {
40
+ return getIsaacAPIClassName(variable) === "EntityBomb";
41
+ }
42
+
43
+ /** Helper function to detect if a variable is of type `GridEntityDoor`. */
44
+ export function isDoor(variable: unknown): variable is GridEntityDoor {
45
+ return getIsaacAPIClassName(variable) === "GridEntityDoor";
46
+ }
47
+
48
+ /** Helper function to detect if a variable is of type `EntityEffect`. */
49
+ export function isEffect(variable: unknown): variable is EntityEffect {
50
+ return getIsaacAPIClassName(variable) === "EntityEffect";
51
+ }
52
+
53
+ /**
54
+ * Helper function to detect if a variable is of type `Entity`. This will return false for child
55
+ * classes such as `EntityPlayer` or `EntityTear`.
56
+ */
57
+ export function isEntity(variable: unknown): variable is Entity {
58
+ return getIsaacAPIClassName(variable) === "Entity";
59
+ }
60
+
61
+ /** Helper function to detect if a variable is of type `EntityEffect`. */
62
+ export function isFamiliar(variable: unknown): variable is EntityFamiliar {
63
+ return getIsaacAPIClassName(variable) === "EntityEffect";
64
+ }
65
+
66
+ /** Helper function to detect if a variable is of type `GridEntity`. */
67
+ export function isGridEntity(variable: unknown): variable is GridEntity {
68
+ return getIsaacAPIClassName(variable) === "GridEntity";
31
69
  }
32
70
 
33
71
  /**
@@ -51,6 +89,73 @@ export function isIsaacAPIClassOfType(
51
89
  );
52
90
  }
53
91
 
92
+ /** Helper function to detect if a variable is of type `EntityKnife`. */
93
+ export function isKnife(variable: unknown): variable is EntityKnife {
94
+ return getIsaacAPIClassName(variable) === "EntityKnife";
95
+ }
96
+
97
+ /** Helper function to detect if a variable is of type `EntityLaser`. */
98
+ export function isLaser(variable: unknown): variable is EntityLaser {
99
+ return getIsaacAPIClassName(variable) === "EntityLaser";
100
+ }
101
+
102
+ /** Helper function to detect if a variable is of type `EntityNPC`. */
103
+ export function isNPC(variable: unknown): variable is EntityNPC {
104
+ return getIsaacAPIClassName(variable) === "EntityNPC";
105
+ }
106
+
107
+ /** Helper function to detect if a variable is of type `EntityPickup`. */
108
+ export function isPickup(variable: unknown): variable is EntityPickup {
109
+ return getIsaacAPIClassName(variable) === "EntityPickup";
110
+ }
111
+
112
+ /** Helper function to detect if a variable is of type `GridEntityPit`. */
113
+ export function isPit(variable: unknown): variable is GridEntityPit {
114
+ return getIsaacAPIClassName(variable) === "GridEntityPit";
115
+ }
116
+
117
+ /** Helper function to detect if a variable is of type `EntityPlayer`. */
118
+ export function isPlayer(variable: unknown): variable is EntityPlayer {
119
+ return getIsaacAPIClassName(variable) === "EntityPlayer";
120
+ }
121
+
122
+ /** Helper function to detect if a variable is of type `GridEntityPoop`. */
123
+ export function isPoop(variable: unknown): variable is GridEntityPoop {
124
+ return getIsaacAPIClassName(variable) === "GridEntityPoop";
125
+ }
126
+
127
+ /** Helper function to detect if a variable is of type `GridEntityPressurePlate`. */
128
+ export function isPressurePlate(
129
+ variable: unknown,
130
+ ): variable is GridEntityPressurePlate {
131
+ return getIsaacAPIClassName(variable) === "GridEntityPressurePlate";
132
+ }
133
+
134
+ /** Helper function to detect if a variable is of type `EntityProjectile`. */
135
+ export function isProjectile(variable: unknown): variable is EntityProjectile {
136
+ return getIsaacAPIClassName(variable) === "EntityProjectile";
137
+ }
138
+
139
+ /** Helper function to detect if a variable is of type `GridEntityRock`. */
140
+ export function isRock(variable: unknown): variable is GridEntityRock {
141
+ return getIsaacAPIClassName(variable) === "GridEntityRock";
142
+ }
143
+
144
+ /** Helper function to detect if a variable is of type `GridEntitySpikes`. */
145
+ export function isSpikes(variable: unknown): variable is GridEntitySpikes {
146
+ return getIsaacAPIClassName(variable) === "GridEntitySpikes";
147
+ }
148
+
149
+ /** Helper function to detect if a variable is of type `GridEntityTNT`. */
150
+ export function isTNT(variable: unknown): variable is GridEntityTNT {
151
+ return getIsaacAPIClassName(variable) === "GridEntityTNT";
152
+ }
153
+
154
+ /** Helper function to detect if a variable is of type `EntityTear`. */
155
+ export function isTear(variable: unknown): variable is EntityTear {
156
+ return getIsaacAPIClassName(variable) === "EntityTear";
157
+ }
158
+
54
159
  /**
55
160
  * Helper function to check if an instantiated Isaac API class is equal to another one of the same
56
161
  * type. You must provide the list of keys to check for.
@@ -18,12 +18,12 @@ export function isKey(pickup: EntityPickup): pickup is EntityPickupKey {
18
18
  }
19
19
 
20
20
  /** For `PickupVariant.BOMB` (40) */
21
- export function isBomb(pickup: EntityPickup): pickup is EntityPickupBomb {
21
+ export function isBombPickup(pickup: EntityPickup): pickup is EntityPickupBomb {
22
22
  return pickup.Variant === PickupVariant.BOMB;
23
23
  }
24
24
 
25
25
  /** For `PickupVariant.POOP` (42) */
26
- export function isPoop(pickup: EntityPickup): pickup is EntityPickupPoop {
26
+ export function isPoopPickup(pickup: EntityPickup): pickup is EntityPickupPoop {
27
27
  return pickup.Variant === PickupVariant.POOP;
28
28
  }
29
29