isaacscript-common 12.5.0 → 12.5.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.
package/dist/index.d.ts CHANGED
@@ -3603,8 +3603,11 @@ export declare function getLastTrinketType(): TrinketType;
3603
3603
  * array.
3604
3604
  *
3605
3605
  * This is useful in the `POST_ENTITY_REMOVE` callback; see the `isLeavingRoom` function.
3606
+ *
3607
+ * Note that this function can return undefined in the case where it is called on the first room of
3608
+ * the run.
3606
3609
  */
3607
- export declare function getLatestRoomDescription(): RoomDescription;
3610
+ export declare function getLatestRoomDescription(): RoomDescription | undefined;
3608
3611
 
3609
3612
  /**
3610
3613
  * Helper function to get the closest value from a map based on partial search text. For the
@@ -6175,7 +6178,7 @@ export declare function isLaser(variable: unknown): variable is EntityLaser;
6175
6178
  * in the room history array for the current room.)
6176
6179
  *
6177
6180
  * 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.
6181
+ * entity is despawning.
6179
6182
  */
6180
6183
  export declare function isLeavingRoom(): boolean;
6181
6184
 
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 12.5.0
3
+ isaacscript-common 12.5.1
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -42027,16 +42027,15 @@ function ____exports.getPreviousRoomDescription(self)
42027
42027
  error("Failed to find a room description for any rooms thus far on this run.")
42028
42028
  end
42029
42029
  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
42030
+ return getLastElement(nil, v.run.roomHistory)
42035
42031
  end
42036
42032
  function ____exports.isLeavingRoom(self)
42037
42033
  local roomListIndex = getRoomListIndex(nil)
42038
42034
  local roomVisitedCount = getRoomVisitedCount(nil)
42039
42035
  local latestRoomDescription = ____exports.getLatestRoomDescription(nil)
42036
+ if latestRoomDescription == nil then
42037
+ return false
42038
+ end
42040
42039
  return roomListIndex ~= latestRoomDescription.roomListIndex or roomVisitedCount ~= latestRoomDescription.roomVisitedCount
42041
42040
  end
42042
42041
  return ____exports
@@ -42081,6 +42080,9 @@ function checkDespawningFromPlayerLeavingRoom(self, entity)
42081
42080
  end
42082
42081
  function trackDespawningPickupPosition(self, entity, index)
42083
42082
  local previousRoomDescription = getLatestRoomDescription(nil)
42083
+ if previousRoomDescription == nil then
42084
+ return
42085
+ end
42084
42086
  local previousRoomListIndex = previousRoomDescription.roomListIndex
42085
42087
  local persistentEntityDescription = {
42086
42088
  entityType = entity.Type,
@@ -42098,7 +42100,7 @@ function postNewRoomReordered(self)
42098
42100
  local description = ____value[2]
42099
42101
  do
42100
42102
  if roomListIndex ~= description.roomListIndex then
42101
- goto __continue9
42103
+ goto __continue10
42102
42104
  end
42103
42105
  v.level.persistentEntities:delete(index)
42104
42106
  spawnAndTrack(
@@ -42111,7 +42113,7 @@ function postNewRoomReordered(self)
42111
42113
  true
42112
42114
  )
42113
42115
  end
42114
- ::__continue9::
42116
+ ::__continue10::
42115
42117
  end
42116
42118
  end
42117
42119
  function spawnAndTrack(self, entityType, variant, subType, position, index, respawning)
@@ -42172,14 +42174,14 @@ function ____exports.removePersistentEntity(self, persistentEntityIndex, removeE
42172
42174
  do
42173
42175
  local index, entityPtr = table.unpack(tuple)
42174
42176
  if index ~= persistentEntityIndex then
42175
- goto __continue16
42177
+ goto __continue17
42176
42178
  end
42177
42179
  v.room.spawnedPersistentEntities:delete(ptrHash)
42178
42180
  if removeEntity and entityPtr.Ref ~= nil then
42179
42181
  entityPtr.Ref:Remove()
42180
42182
  end
42181
42183
  end
42182
- ::__continue16::
42184
+ ::__continue17::
42183
42185
  end
42184
42186
  end
42185
42187
  return ____exports
@@ -42253,6 +42255,9 @@ function checkDespawningFromPlayerLeavingRoom(self, entity)
42253
42255
  end
42254
42256
  function trackDespawningPickupMetadata(self, entity, pickupIndex)
42255
42257
  local previousRoomDescription = getLatestRoomDescription(nil)
42258
+ if previousRoomDescription == nil then
42259
+ return
42260
+ end
42256
42261
  local previousRoomListIndex = previousRoomDescription.roomListIndex
42257
42262
  local pickupDescriptions = v.level.pickupData:getAndSetDefault(previousRoomListIndex)
42258
42263
  local pickupDescription = {position = entity.Position, initSeed = entity.InitSeed}
@@ -42263,16 +42268,16 @@ function trackDespawningPickupMetadata(self, entity, pickupIndex)
42263
42268
  local room = game:GetRoom()
42264
42269
  local roomType = room:GetType()
42265
42270
  repeat
42266
- local ____switch13 = roomType
42267
- local ____cond13 = ____switch13 == RoomType.TREASURE
42268
- if ____cond13 then
42271
+ local ____switch14 = roomType
42272
+ local ____cond14 = ____switch14 == RoomType.TREASURE
42273
+ if ____cond14 then
42269
42274
  do
42270
42275
  v.run.pickupDataTreasureRooms:set(pickupIndex, pickupDescription)
42271
42276
  break
42272
42277
  end
42273
42278
  end
42274
- ____cond13 = ____cond13 or ____switch13 == RoomType.BOSS
42275
- if ____cond13 then
42279
+ ____cond14 = ____cond14 or ____switch14 == RoomType.BOSS
42280
+ if ____cond14 then
42276
42281
  do
42277
42282
  v.run.pickupDataBossRooms:set(pickupIndex, pickupDescription)
42278
42283
  break
@@ -42324,15 +42329,15 @@ function getPostAscentPickupIndex(self, pickup)
42324
42329
  local room = game:GetRoom()
42325
42330
  local roomType = room:GetType()
42326
42331
  repeat
42327
- local ____switch29 = roomType
42328
- local ____cond29 = ____switch29 == RoomType.TREASURE
42329
- if ____cond29 then
42332
+ local ____switch30 = roomType
42333
+ local ____cond30 = ____switch30 == RoomType.TREASURE
42334
+ if ____cond30 then
42330
42335
  do
42331
42336
  return getStoredPickupIndex(nil, pickup, v.run.pickupDataTreasureRooms)
42332
42337
  end
42333
42338
  end
42334
- ____cond29 = ____cond29 or ____switch29 == RoomType.BOSS
42335
- if ____cond29 then
42339
+ ____cond30 = ____cond30 or ____switch30 == RoomType.BOSS
42340
+ if ____cond30 then
42336
42341
  do
42337
42342
  return getStoredPickupIndex(nil, pickup, v.run.pickupDataBossRooms)
42338
42343
  end
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "12.5.0",
3
+ "version": "12.5.1",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -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