isaacscript-common 6.6.5 → 6.8.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 (234) hide show
  1. package/dist/callbacks/customRevive.lua +4 -4
  2. package/dist/callbacks/postCursedTeleport.lua +2 -2
  3. package/dist/callbacks/postCustomDoorEnter.lua +5 -5
  4. package/dist/callbacks/postDiceRoomActivated.lua +2 -2
  5. package/dist/callbacks/postFlip.lua +3 -3
  6. package/dist/callbacks/postGridEntity.lua +3 -3
  7. package/dist/callbacks/postGridEntityCollision.lua +3 -3
  8. package/dist/callbacks/postGridEntityRender.lua +2 -2
  9. package/dist/callbacks/postNewRoomEarly.lua +5 -5
  10. package/dist/callbacks/postPickupCollect.lua +2 -2
  11. package/dist/callbacks/postPitRender.lua +2 -2
  12. package/dist/callbacks/postPitUpdate.lua +2 -2
  13. package/dist/callbacks/postPlayerCollectible.lua +2 -2
  14. package/dist/callbacks/postPoopRender.lua +2 -2
  15. package/dist/callbacks/postPoopUpdate.lua +2 -2
  16. package/dist/callbacks/postPressurePlateRender.lua +2 -2
  17. package/dist/callbacks/postPressurePlateUpdate.lua +2 -2
  18. package/dist/callbacks/postPurchase.lua +2 -2
  19. package/dist/callbacks/postRockRender.lua +2 -2
  20. package/dist/callbacks/postRockUpdate.lua +2 -2
  21. package/dist/callbacks/postSlotInitUpdate.lua +2 -2
  22. package/dist/callbacks/postSlotRender.lua +2 -2
  23. package/dist/callbacks/postSpikesRender.lua +2 -2
  24. package/dist/callbacks/postSpikesUpdate.lua +2 -2
  25. package/dist/callbacks/postTNTRender.lua +2 -2
  26. package/dist/callbacks/postTNTUpdate.lua +2 -2
  27. package/dist/callbacks/preBerserkDeath.lua +2 -2
  28. package/dist/callbacks/preNewLevel.lua +2 -2
  29. package/dist/callbacks/subscriptions/postDoorRender.d.ts +2 -3
  30. package/dist/callbacks/subscriptions/postDoorRender.d.ts.map +1 -1
  31. package/dist/callbacks/subscriptions/postDoorRender.lua +3 -3
  32. package/dist/callbacks/subscriptions/postDoorUpdate.d.ts +2 -3
  33. package/dist/callbacks/subscriptions/postDoorUpdate.d.ts.map +1 -1
  34. package/dist/callbacks/subscriptions/postDoorUpdate.lua +3 -3
  35. package/dist/callbacks/subscriptions/postPitRender.d.ts +2 -3
  36. package/dist/callbacks/subscriptions/postPitRender.d.ts.map +1 -1
  37. package/dist/callbacks/subscriptions/postPitRender.lua +3 -3
  38. package/dist/callbacks/subscriptions/postPitUpdate.d.ts +2 -3
  39. package/dist/callbacks/subscriptions/postPitUpdate.d.ts.map +1 -1
  40. package/dist/callbacks/subscriptions/postPitUpdate.lua +3 -3
  41. package/dist/callbacks/subscriptions/postPoopRender.d.ts +2 -3
  42. package/dist/callbacks/subscriptions/postPoopRender.d.ts.map +1 -1
  43. package/dist/callbacks/subscriptions/postPoopRender.lua +3 -3
  44. package/dist/callbacks/subscriptions/postPoopUpdate.d.ts +2 -3
  45. package/dist/callbacks/subscriptions/postPoopUpdate.d.ts.map +1 -1
  46. package/dist/callbacks/subscriptions/postPoopUpdate.lua +3 -3
  47. package/dist/callbacks/subscriptions/postPressurePlateRender.d.ts +2 -3
  48. package/dist/callbacks/subscriptions/postPressurePlateRender.d.ts.map +1 -1
  49. package/dist/callbacks/subscriptions/postPressurePlateRender.lua +3 -3
  50. package/dist/callbacks/subscriptions/postPressurePlateUpdate.d.ts +2 -3
  51. package/dist/callbacks/subscriptions/postPressurePlateUpdate.d.ts.map +1 -1
  52. package/dist/callbacks/subscriptions/postPressurePlateUpdate.lua +3 -3
  53. package/dist/features/characterStats.lua +2 -2
  54. package/dist/features/collectibleItemPoolType.lua +2 -2
  55. package/dist/features/customGridEntity.d.ts.map +1 -1
  56. package/dist/features/customGridEntity.lua +5 -5
  57. package/dist/features/customStage/backdrop.lua +2 -2
  58. package/dist/features/customStage/{gridEntities.d.ts → customStageGridEntities.d.ts} +1 -1
  59. package/dist/features/customStage/customStageGridEntities.d.ts.map +1 -0
  60. package/dist/features/customStage/{gridEntities.lua → customStageGridEntities.lua} +8 -8
  61. package/dist/features/customStage/{util.d.ts → customStageUtils.d.ts} +1 -1
  62. package/dist/features/customStage/customStageUtils.d.ts.map +1 -0
  63. package/dist/features/customStage/{util.lua → customStageUtils.lua} +0 -0
  64. package/dist/features/customStage/exports.lua +4 -4
  65. package/dist/features/customStage/init.lua +6 -6
  66. package/dist/features/customStage/shadows.lua +2 -2
  67. package/dist/features/customStage/versusScreen.lua +4 -4
  68. package/dist/features/debugDisplay/v.lua +4 -4
  69. package/dist/features/deployJSONRoom.lua +20 -20
  70. package/dist/features/extraConsoleCommands/commandsSubroutines.lua +7 -7
  71. package/dist/features/extraConsoleCommands/listCommands.d.ts.map +1 -1
  72. package/dist/features/extraConsoleCommands/listCommands.lua +14 -14
  73. package/dist/features/pause.lua +2 -2
  74. package/dist/features/persistentEntities.lua +2 -2
  75. package/dist/features/preventCollectibleRotation.lua +2 -2
  76. package/dist/features/saveDataManager/exports.d.ts.map +1 -1
  77. package/dist/features/sirenHelpers.lua +2 -2
  78. package/dist/functions/ambush.lua +5 -5
  79. package/dist/functions/{boss.d.ts → bosses.d.ts} +22 -4
  80. package/dist/functions/bosses.d.ts.map +1 -0
  81. package/dist/functions/{boss.lua → bosses.lua} +38 -13
  82. package/dist/functions/collectibleTag.lua +2 -2
  83. package/dist/functions/collectibles.lua +5 -5
  84. package/dist/functions/{entity.d.ts → entities.d.ts} +21 -19
  85. package/dist/functions/entities.d.ts.map +1 -0
  86. package/dist/functions/{entity.lua → entities.lua} +25 -20
  87. package/dist/functions/{entitySpecific.d.ts → entitiesSpecific.d.ts} +145 -68
  88. package/dist/functions/entitiesSpecific.d.ts.map +1 -0
  89. package/dist/functions/{entitySpecific.lua → entitiesSpecific.lua} +203 -65
  90. package/dist/functions/familiars.lua +2 -2
  91. package/dist/functions/{gridEntity.d.ts → gridEntities.d.ts} +48 -17
  92. package/dist/functions/gridEntities.d.ts.map +1 -0
  93. package/dist/functions/{gridEntity.lua → gridEntities.lua} +140 -90
  94. package/dist/functions/gridEntitiesSpecific.d.ts +141 -0
  95. package/dist/functions/gridEntitiesSpecific.d.ts.map +1 -0
  96. package/dist/functions/gridEntitiesSpecific.lua +366 -0
  97. package/dist/functions/log.d.ts +14 -6
  98. package/dist/functions/log.d.ts.map +1 -1
  99. package/dist/functions/log.lua +201 -163
  100. package/dist/functions/{npc.d.ts → npcs.d.ts} +24 -2
  101. package/dist/functions/npcs.d.ts.map +1 -0
  102. package/dist/functions/{npc.lua → npcs.lua} +44 -9
  103. package/dist/functions/pickups.d.ts +4 -119
  104. package/dist/functions/pickups.d.ts.map +1 -1
  105. package/dist/functions/pickups.lua +10 -439
  106. package/dist/functions/pickupsSpecific.d.ts +229 -0
  107. package/dist/functions/pickupsSpecific.d.ts.map +1 -0
  108. package/dist/functions/pickupsSpecific.lua +560 -0
  109. package/dist/functions/playerHealth.lua +6 -6
  110. package/dist/functions/{player.d.ts → players.d.ts} +1 -1
  111. package/dist/functions/players.d.ts.map +1 -0
  112. package/dist/functions/{player.lua → players.lua} +0 -0
  113. package/dist/functions/pocketItems.lua +2 -2
  114. package/dist/functions/positionVelocity.lua +6 -6
  115. package/dist/functions/pressurePlate.d.ts +10 -0
  116. package/dist/functions/pressurePlate.d.ts.map +1 -0
  117. package/dist/functions/pressurePlate.lua +29 -0
  118. package/dist/functions/revive.lua +7 -7
  119. package/dist/functions/rooms.lua +2 -2
  120. package/dist/functions/saveFile.lua +3 -3
  121. package/dist/functions/spawnCollectible.lua +4 -4
  122. package/dist/functions/{sprite.d.ts → sprites.d.ts} +1 -1
  123. package/dist/functions/sprites.d.ts.map +1 -0
  124. package/dist/functions/{sprite.lua → sprites.lua} +0 -0
  125. package/dist/functions/transformations.lua +2 -2
  126. package/dist/functions/trinketGive.lua +2 -2
  127. package/dist/functions/trinkets.lua +6 -6
  128. package/dist/functions/utils.d.ts +7 -0
  129. package/dist/functions/utils.d.ts.map +1 -1
  130. package/dist/functions/utils.lua +35 -22
  131. package/dist/index.d.ts +10 -8
  132. package/dist/index.d.ts.map +1 -1
  133. package/dist/index.lua +26 -10
  134. package/dist/types/AnyGridEntity.d.ts +10 -0
  135. package/dist/types/AnyGridEntity.d.ts.map +1 -0
  136. package/dist/types/AnyGridEntity.lua +2 -0
  137. package/package.json +2 -2
  138. package/src/callbacks/customRevive.ts +2 -2
  139. package/src/callbacks/postCursedTeleport.ts +1 -1
  140. package/src/callbacks/postCustomDoorEnter.ts +2 -2
  141. package/src/callbacks/postDiceRoomActivated.ts +1 -1
  142. package/src/callbacks/postFlip.ts +1 -1
  143. package/src/callbacks/postGridEntity.ts +1 -1
  144. package/src/callbacks/postGridEntityCollision.ts +1 -1
  145. package/src/callbacks/postGridEntityRender.ts +1 -1
  146. package/src/callbacks/postNewRoomEarly.ts +9 -3
  147. package/src/callbacks/postPickupCollect.ts +1 -1
  148. package/src/callbacks/postPitRender.ts +1 -1
  149. package/src/callbacks/postPitUpdate.ts +1 -1
  150. package/src/callbacks/postPlayerCollectible.ts +1 -1
  151. package/src/callbacks/postPoopRender.ts +1 -1
  152. package/src/callbacks/postPoopUpdate.ts +1 -1
  153. package/src/callbacks/postPressurePlateRender.ts +1 -1
  154. package/src/callbacks/postPressurePlateUpdate.ts +1 -1
  155. package/src/callbacks/postPurchase.ts +1 -1
  156. package/src/callbacks/postRockRender.ts +1 -1
  157. package/src/callbacks/postRockUpdate.ts +1 -1
  158. package/src/callbacks/postSlotInitUpdate.ts +1 -1
  159. package/src/callbacks/postSlotRender.ts +1 -1
  160. package/src/callbacks/postSpikesRender.ts +1 -1
  161. package/src/callbacks/postSpikesUpdate.ts +1 -1
  162. package/src/callbacks/postTNTRender.ts +1 -1
  163. package/src/callbacks/postTNTUpdate.ts +1 -1
  164. package/src/callbacks/preBerserkDeath.ts +1 -1
  165. package/src/callbacks/preNewLevel.ts +1 -1
  166. package/src/callbacks/subscriptions/postDoorRender.ts +7 -5
  167. package/src/callbacks/subscriptions/postDoorUpdate.ts +7 -5
  168. package/src/callbacks/subscriptions/postPitRender.ts +6 -7
  169. package/src/callbacks/subscriptions/postPitUpdate.ts +6 -7
  170. package/src/callbacks/subscriptions/postPoopRender.ts +7 -5
  171. package/src/callbacks/subscriptions/postPoopUpdate.ts +7 -5
  172. package/src/callbacks/subscriptions/postPressurePlateRender.ts +7 -5
  173. package/src/callbacks/subscriptions/postPressurePlateUpdate.ts +7 -5
  174. package/src/features/characterStats.ts +1 -1
  175. package/src/features/collectibleItemPoolType.ts +1 -1
  176. package/src/features/customGridEntity.ts +6 -3
  177. package/src/features/customStage/backdrop.ts +1 -1
  178. package/src/features/customStage/{gridEntities.ts → customStageGridEntities.ts} +3 -3
  179. package/src/features/customStage/{util.ts → customStageUtils.ts} +0 -0
  180. package/src/features/customStage/exports.ts +2 -2
  181. package/src/features/customStage/init.ts +1 -1
  182. package/src/features/customStage/shadows.ts +1 -1
  183. package/src/features/customStage/versusScreen.ts +2 -2
  184. package/src/features/debugDisplay/v.ts +2 -2
  185. package/src/features/deployJSONRoom.ts +11 -7
  186. package/src/features/extraConsoleCommands/commandsSubroutines.ts +5 -5
  187. package/src/features/extraConsoleCommands/listCommands.ts +10 -6
  188. package/src/features/pause.ts +1 -1
  189. package/src/features/persistentEntities.ts +1 -1
  190. package/src/features/preventCollectibleRotation.ts +1 -1
  191. package/src/features/saveDataManager/exports.ts +7 -4
  192. package/src/features/sirenHelpers.ts +1 -1
  193. package/src/functions/ambush.ts +2 -2
  194. package/src/functions/{boss.ts → bosses.ts} +29 -21
  195. package/src/functions/collectibleTag.ts +1 -1
  196. package/src/functions/collectibles.ts +2 -2
  197. package/src/functions/{entity.ts → entities.ts} +23 -21
  198. package/src/functions/{entitySpecific.ts → entitiesSpecific.ts} +170 -99
  199. package/src/functions/familiars.ts +1 -1
  200. package/src/functions/{gridEntity.ts → gridEntities.ts} +110 -34
  201. package/src/functions/gridEntitiesSpecific.ts +490 -0
  202. package/src/functions/log.ts +227 -181
  203. package/src/functions/{npc.ts → npcs.ts} +42 -11
  204. package/src/functions/pickups.ts +8 -475
  205. package/src/functions/pickupsSpecific.ts +613 -0
  206. package/src/functions/playerHealth.ts +1 -1
  207. package/src/functions/{player.ts → players.ts} +0 -0
  208. package/src/functions/pocketItems.ts +1 -1
  209. package/src/functions/positionVelocity.ts +3 -3
  210. package/src/functions/pressurePlate.ts +29 -0
  211. package/src/functions/revive.ts +2 -2
  212. package/src/functions/rooms.ts +1 -1
  213. package/src/functions/saveFile.ts +1 -1
  214. package/src/functions/spawnCollectible.ts +2 -2
  215. package/src/functions/{sprite.ts → sprites.ts} +0 -0
  216. package/src/functions/transformations.ts +1 -1
  217. package/src/functions/trinketGive.ts +1 -1
  218. package/src/functions/trinkets.ts +3 -3
  219. package/src/functions/utils.ts +32 -13
  220. package/src/index.ts +10 -8
  221. package/src/types/AnyGridEntity.ts +9 -0
  222. package/dist/features/customStage/gridEntities.d.ts.map +0 -1
  223. package/dist/features/customStage/util.d.ts.map +0 -1
  224. package/dist/functions/boss.d.ts.map +0 -1
  225. package/dist/functions/entity.d.ts.map +0 -1
  226. package/dist/functions/entitySpecific.d.ts.map +0 -1
  227. package/dist/functions/gridEntity.d.ts.map +0 -1
  228. package/dist/functions/gridEntitySpecific.d.ts +0 -29
  229. package/dist/functions/gridEntitySpecific.d.ts.map +0 -1
  230. package/dist/functions/gridEntitySpecific.lua +0 -114
  231. package/dist/functions/npc.d.ts.map +0 -1
  232. package/dist/functions/player.d.ts.map +0 -1
  233. package/dist/functions/sprite.d.ts.map +0 -1
  234. package/src/functions/gridEntitySpecific.ts +0 -143
@@ -1,4 +1,5 @@
1
1
  import {
2
+ CrawlSpaceVariant,
2
3
  GridCollisionClass,
3
4
  GridEntityType,
4
5
  GridEntityXMLType,
@@ -16,10 +17,12 @@ import {
16
17
  ROOM_SHAPE_TO_TOP_LEFT_WALL_GRID_INDEX_MAP,
17
18
  } from "../maps/roomShapeToTopLeftWallGridIndexMap";
18
19
  import { BACKDROP_TYPE_TO_ROCK_ALT_TYPE } from "../objects/backdropTypeToRockAltType";
20
+ import { AnyGridEntity } from "../types/AnyGridEntity";
19
21
  import { isCircleIntersectingRectangle } from "./math";
20
22
  import { getRandomSeed } from "./rng";
21
23
  import { roomUpdateSafe } from "./rooms";
22
- import { clearSprite } from "./sprite";
24
+ import { clearSprite } from "./sprites";
25
+ import { isNumber } from "./types";
23
26
  import { erange } from "./utils";
24
27
  import { isVector } from "./vector";
25
28
 
@@ -127,6 +130,22 @@ export function getCollidingEntitiesWithGridEntity(
127
130
  );
128
131
  }
129
132
 
133
+ /**
134
+ * Helper function to get all of the crawl spaces in the room.
135
+ *
136
+ * @param crawlSpaceVariant Optional. If specified, will only get the crawl spaces that match the
137
+ * variant. Default is -1, which matches every variant.
138
+ */
139
+ export function getCrawlSpaces(
140
+ crawlSpaceVariant: CrawlSpaceVariant = -1,
141
+ ): GridEntity[] {
142
+ if ((crawlSpaceVariant as int) === -1) {
143
+ return getGridEntities(GridEntityType.CRAWL_SPACE);
144
+ }
145
+
146
+ return getMatchingGridEntities(GridEntityType.CRAWL_SPACE, crawlSpaceVariant);
147
+ }
148
+
130
149
  /**
131
150
  * Helper function to get every grid entity in the current room.
132
151
  *
@@ -245,6 +264,8 @@ export function getGridEntityIDFromConstituents(
245
264
  /**
246
265
  * Helper function to get all of the grid entities in the room that specifically match the type and
247
266
  * variant provided.
267
+ *
268
+ * If you want to match every variant, use the `getGridEntities` function instead.
248
269
  */
249
270
  export function getMatchingGridEntities(
250
271
  gridEntityType: GridEntityType,
@@ -329,6 +350,25 @@ export function getTopLeftWallGridIndex(): int {
329
350
  : topLeftWallGridIndex;
330
351
  }
331
352
 
353
+ /**
354
+ * Helper function to get all of the grid entities of type `GridEntityType.TRAPDOOR` in the room.
355
+ * Specify a specific trapdoor variant to select only trapdoors of that variant.
356
+ */
357
+ export function getTrapdoors(trapdoorVariant?: TrapdoorVariant): GridEntity[] {
358
+ if (trapdoorVariant === undefined) {
359
+ return getGridEntities(GridEntityType.TRAPDOOR);
360
+ }
361
+
362
+ return getMatchingGridEntities(GridEntityType.TRAPDOOR, trapdoorVariant);
363
+ }
364
+
365
+ /**
366
+ * Helper function to see if the provided gridEntity is in its respective broken state. See the
367
+ * `GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP` constant for more details.
368
+ *
369
+ * Note that in the case of `GridEntityType.LOCK` (11), the state will turn to being broken before
370
+ * the actual collision for the entity is removed.
371
+ */
332
372
  export function isGridEntityBreakableByExplosion(
333
373
  gridEntity: GridEntity,
334
374
  ): boolean {
@@ -345,11 +385,9 @@ export function isGridEntityBreakableByExplosion(
345
385
  }
346
386
 
347
387
  /**
348
- * Helper function to see if the provided gridEntity is in its respective broken state. See the
349
- * `GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP` constant for more details.
350
- *
351
- * Note that in the case of `GridEntityType.LOCK` (11), the state will turn to being broken before
352
- * the actual collision for the entity is removed.
388
+ * Helper function to detect whether a given Void Portal is one that randomly spawns after a boss is
389
+ * defeated or is one that naturally spawns in the room after Hush. (This is determined by looking
390
+ * at the VarData of the entity.)
353
391
  */
354
392
  export function isGridEntityBroken(gridEntity: GridEntity): boolean {
355
393
  const gridEntityType = gridEntity.GetType();
@@ -358,9 +396,8 @@ export function isGridEntityBroken(gridEntity: GridEntity): boolean {
358
396
  }
359
397
 
360
398
  /**
361
- * Helper function to detect whether a given Void Portal is one that randomly spawns after a boss is
362
- * defeated or is one that naturally spawns in the room after Hush. (This is determined by looking
363
- * at the VarData of the entity.)
399
+ * Helper function to determine if all of the pressure plates in the current room are pushed.
400
+ * Returns true if there are no pressure plates in the room.
364
401
  */
365
402
  export function isPostBossVoidPortal(gridEntity: GridEntity): boolean {
366
403
  // - The VarData of Void Portals that are spawned after bosses will be equal to 1.
@@ -385,7 +422,7 @@ export function isPostBossVoidPortal(gridEntity: GridEntity): boolean {
385
422
  * );
386
423
  * ```
387
424
  *
388
- * @returns True if one or more grid entities were removed, false otherwise.
425
+ * @returns The grid entities that were removed.
389
426
  */
390
427
  export function removeAllGridExcept(
391
428
  ...gridEntityTypes: GridEntityType[]
@@ -396,7 +433,7 @@ export function removeAllGridExcept(
396
433
  for (const gridEntity of gridEntities) {
397
434
  const gridEntityType = gridEntity.GetType();
398
435
  if (!gridEntityTypeExceptions.has(gridEntityType)) {
399
- removeGrid(gridEntity, false);
436
+ removeGridEntity(gridEntity, false);
400
437
  removedGridEntities.push(gridEntity);
401
438
  }
402
439
  }
@@ -436,7 +473,7 @@ export function removeAllMatchingGridEntities(
436
473
  }
437
474
 
438
475
  for (const gridEntity of gridEntities) {
439
- removeGrid(gridEntity, false);
476
+ removeGridEntity(gridEntity, false);
440
477
  }
441
478
 
442
479
  roomUpdateSafe();
@@ -444,24 +481,63 @@ export function removeAllMatchingGridEntities(
444
481
  }
445
482
 
446
483
  /**
447
- * Helper function to remove a grid entity simply by providing the grid entity object. By default,
448
- * this will also update the room.
484
+ * Helper function to remove all of the grid entities in the supplied array.
485
+ *
486
+ * @param gridEntities The array of grid entities to remove.
487
+ * @param updateRoom Whether or not to update the room after the grid entities are removed. This is
488
+ * generally a good idea because if the room is not updated, you will be unable to
489
+ * spawn another grid entity on the same tile until a frame has passed. However,
490
+ * doing this is expensive, since it involves a call to `Isaac.GetRoomEntities`,
491
+ * so set this to false if you need to invoke this function multiple times.
492
+ * @param cap Optional. If specified, will only remove the given amount of entities.
493
+ * @returns An array of the entities that were removed.
494
+ */
495
+ export function removeGridEntities<T extends AnyGridEntity>(
496
+ gridEntities: T[],
497
+ updateRoom: boolean,
498
+ cap?: int,
499
+ ): T[] {
500
+ if (gridEntities.length === 0) {
501
+ return [];
502
+ }
503
+
504
+ const gridEntitiesRemoved: T[] = [];
505
+ for (const gridEntity of gridEntities) {
506
+ removeGridEntity(gridEntity, false);
507
+
508
+ gridEntitiesRemoved.push(gridEntity);
509
+ if (cap !== undefined && gridEntitiesRemoved.length >= cap) {
510
+ break;
511
+ }
512
+ }
513
+
514
+ if (updateRoom) {
515
+ roomUpdateSafe();
516
+ }
517
+
518
+ return gridEntitiesRemoved;
519
+ }
520
+
521
+ /**
522
+ * Helper function to remove a grid entity by providing the grid entity object or the grid index
523
+ * inside of the room.
449
524
  *
450
525
  * @param gridEntityOrGridIndex The grid entity or grid index to remove.
451
- * @param updateRoom Optional. Whether or not to update the room after the grid entity is removed.
452
- * Default is true. This is generally a good idea because if the room is not
453
- * updated, you will be unable to spawn another grid entity on the same tile until
454
- * a frame has passed. However, doing this is expensive, since it involves a call
455
- * to `Isaac.GetRoomEntities`, so set it to false if you need to invoke this
456
- * function multiple times.
526
+ * @param updateRoom Whether or not to update the room after the grid entity is removed. This is
527
+ * generally a good idea because if the room is not updated, you will be unable to
528
+ * spawn another grid entity on the same tile until a frame has passed. However,
529
+ * doing this is expensive, since it involves a call to `Isaac.GetRoomEntities`,
530
+ * so set this to false if you need to invoke this function multiple times.
457
531
  */
458
- export function removeGrid(
459
- gridEntityOrGridIndex: GridEntity,
460
- updateRoom = true,
532
+ export function removeGridEntity(
533
+ gridEntityOrGridIndex: GridEntity | int,
534
+ updateRoom: boolean,
461
535
  ): void {
462
536
  const room = game.GetRoom();
463
537
 
464
- const gridIndex = gridEntityOrGridIndex.GetGridIndex();
538
+ const gridIndex = isNumber(gridEntityOrGridIndex)
539
+ ? gridEntityOrGridIndex
540
+ : gridEntityOrGridIndex.GetGridIndex();
465
541
  room.RemoveGridEntity(gridIndex, 0, false);
466
542
 
467
543
  if (updateRoom) {
@@ -492,22 +568,22 @@ export function spawnGiantPoop(topLeftGridIndex: int): void {
492
568
  const bottomLeftGridIndex = topLeftGridIndex + gridWidth;
493
569
  const bottomRightGridIndex = bottomLeftGridIndex + 1;
494
570
 
495
- spawnGridWithVariant(
571
+ spawnGridEntityWithVariant(
496
572
  GridEntityType.POOP,
497
573
  PoopGridEntityVariant.GIGA_TOP_LEFT,
498
574
  topLeftGridIndex,
499
575
  );
500
- spawnGridWithVariant(
576
+ spawnGridEntityWithVariant(
501
577
  GridEntityType.POOP,
502
578
  PoopGridEntityVariant.GIGA_TOP_RIGHT,
503
579
  topRightGridIndex,
504
580
  );
505
- spawnGridWithVariant(
581
+ spawnGridEntityWithVariant(
506
582
  GridEntityType.POOP,
507
583
  PoopGridEntityVariant.GIGA_BOTTOM_LEFT,
508
584
  bottomLeftGridIndex,
509
585
  );
510
- spawnGridWithVariant(
586
+ spawnGridEntityWithVariant(
511
587
  GridEntityType.POOP,
512
588
  PoopGridEntityVariant.GIGA_BOTTOM_RIGHT,
513
589
  bottomRightGridIndex,
@@ -518,18 +594,18 @@ export function spawnGiantPoop(topLeftGridIndex: int): void {
518
594
  * Helper function to spawn a grid entity.
519
595
  *
520
596
  * This function assumes you want to give the grid entity a variant of 0. If you want to specify a
521
- * variant, use the `spawnGridWithVariant` helper function instead.
597
+ * variant, use the `spawnGridEntityWithVariant` helper function instead.
522
598
  *
523
599
  * Use this instead of the `Isaac.GridSpawn` method since it:
524
600
  * - handles giving pits collision
525
601
  * - removes existing grid entities on the same tile, if any
526
602
  * - allows you to specify either the grid index or the position
527
603
  */
528
- export function spawnGrid(
604
+ export function spawnGridEntity(
529
605
  gridEntityType: GridEntityType,
530
606
  gridIndexOrPosition: int | Vector,
531
607
  ): GridEntity | undefined {
532
- return spawnGridWithVariant(gridEntityType, 0, gridIndexOrPosition);
608
+ return spawnGridEntityWithVariant(gridEntityType, 0, gridIndexOrPosition);
533
609
  }
534
610
 
535
611
  /**
@@ -540,7 +616,7 @@ export function spawnGrid(
540
616
  * - removes existing grid entities on the same tile, if any
541
617
  * - allows you to specify the grid index or the position
542
618
  */
543
- export function spawnGridWithVariant(
619
+ export function spawnGridEntityWithVariant(
544
620
  gridEntityType: GridEntityType,
545
621
  variant: int,
546
622
  gridIndexOrPosition: int | Vector,
@@ -551,7 +627,7 @@ export function spawnGridWithVariant(
551
627
  ? room.GetGridEntityFromPos(gridIndexOrPosition)
552
628
  : room.GetGridEntity(gridIndexOrPosition);
553
629
  if (existingGridEntity !== undefined) {
554
- removeGrid(existingGridEntity);
630
+ removeGridEntity(existingGridEntity, true);
555
631
  }
556
632
 
557
633
  const position = isVector(gridIndexOrPosition)
@@ -634,7 +710,7 @@ export function spawnRockAltReward(
634
710
  * with the appropriate variant, as the game does not give it the correct sprite automatically.
635
711
  */
636
712
  export function spawnVoidPortal(gridIndex: int): GridEntity | undefined {
637
- const voidPortal = spawnGridWithVariant(
713
+ const voidPortal = spawnGridEntityWithVariant(
638
714
  GridEntityType.TRAPDOOR,
639
715
  TrapdoorVariant.VOID_PORTAL,
640
716
  gridIndex,