isaacscript-common 9.3.0 → 9.5.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 (41) hide show
  1. package/dist/callbacks/subscriptions/postGridEntityCollision.d.ts +4 -2
  2. package/dist/callbacks/subscriptions/postGridEntityCollision.d.ts.map +1 -1
  3. package/dist/callbacks/subscriptions/postGridEntityCollision.lua +8 -0
  4. package/dist/callbacks/subscriptions/postGridEntityCustomCollision.d.ts +4 -2
  5. package/dist/callbacks/subscriptions/postGridEntityCustomCollision.d.ts.map +1 -1
  6. package/dist/callbacks/subscriptions/postGridEntityCustomCollision.lua +8 -0
  7. package/dist/enums/ModCallbackCustom.d.ts +52 -26
  8. package/dist/enums/ModCallbackCustom.d.ts.map +1 -1
  9. package/dist/features/customStage/customStageGridEntities.d.ts +4 -4
  10. package/dist/features/customStage/customStageGridEntities.d.ts.map +1 -1
  11. package/dist/features/customStage/customStageGridEntities.lua +4 -4
  12. package/dist/functions/effects.d.ts +1 -1
  13. package/dist/functions/effects.d.ts.map +1 -1
  14. package/dist/functions/effects.lua +1 -1
  15. package/dist/functions/entities.d.ts +4 -0
  16. package/dist/functions/entities.d.ts.map +1 -1
  17. package/dist/functions/entities.lua +4 -0
  18. package/dist/functions/entityTypes.d.ts +1 -1
  19. package/dist/functions/entityTypes.d.ts.map +1 -1
  20. package/dist/functions/entityTypes.lua +1 -1
  21. package/dist/functions/gridEntitiesSpecific.d.ts +24 -0
  22. package/dist/functions/gridEntitiesSpecific.d.ts.map +1 -1
  23. package/dist/functions/gridEntitiesSpecific.lua +41 -0
  24. package/dist/functions/pickupVariants.d.ts +11 -11
  25. package/dist/functions/pickupVariants.d.ts.map +1 -1
  26. package/dist/functions/pickupVariants.lua +11 -11
  27. package/dist/functions/pickups.d.ts +2 -0
  28. package/dist/functions/pickups.d.ts.map +1 -1
  29. package/dist/functions/pickups.lua +2 -0
  30. package/dist/index.d.ts +105 -41
  31. package/package.json +2 -2
  32. package/src/callbacks/subscriptions/postGridEntityCollision.ts +21 -1
  33. package/src/callbacks/subscriptions/postGridEntityCustomCollision.ts +25 -2
  34. package/src/enums/ModCallbackCustom.ts +52 -26
  35. package/src/features/customStage/customStageGridEntities.ts +4 -4
  36. package/src/functions/effects.ts +1 -1
  37. package/src/functions/entities.ts +4 -0
  38. package/src/functions/entityTypes.ts +1 -1
  39. package/src/functions/gridEntitiesSpecific.ts +54 -0
  40. package/src/functions/pickupVariants.ts +11 -11
  41. package/src/functions/pickups.ts +2 -0
@@ -356,8 +356,10 @@ export enum ModCallbackCustom {
356
356
  * For grid entities created with `spawnCustomGridEntity`, use the
357
357
  * `POST_GRID_ENTITY_CUSTOM_BROKEN` callback instead.
358
358
  *
359
- * When registering the callback, takes an optional second argument that will make the callback
360
- * only fire if it matches the `GridEntityType` provided.
359
+ * - When registering the callback, takes an optional second argument that will make the callback
360
+ * only fire if it matches the `GridEntityType` provided.
361
+ * - When registering the callback, takes an optional third argument that will make the callback
362
+ * only fire if it matches the variant provided.
361
363
  *
362
364
  * ```ts
363
365
  * function postGridEntityBroken(gridEntity: GridEntity): void {}
@@ -373,8 +375,14 @@ export enum ModCallbackCustom {
373
375
  * For grid entities created with `spawnCustomGridEntity`, use the
374
376
  * `POST_GRID_ENTITY_CUSTOM_COLLISION` callback instead.
375
377
  *
376
- * When registering the callback, takes an optional second argument that will make the callback
377
- * only fire if it matches the `GridEntityType` provided.
378
+ * - When registering the callback, takes an optional second argument that will make the callback
379
+ * only fire if it matches the `GridEntityType` provided.
380
+ * - When registering the callback, takes an optional third argument that will make the callback
381
+ * only fire if it matches the variant provided (for the grid entity).
382
+ * - When registering the callback, takes an optional fourth argument that will make the callback
383
+ * only fire if the colliding entity matches the `EntityType` provided.
384
+ * - When registering the callback, takes an optional fifth argument that will make the callback
385
+ * only fire if the colliding entity matches the variant provided.
378
386
  *
379
387
  * ```ts
380
388
  * function postGridEntityCollision(
@@ -390,7 +398,8 @@ export enum ModCallbackCustom {
390
398
  * with the `spawnCustomGridEntity` helper function.
391
399
  *
392
400
  * When registering the callback, takes an optional second argument that will make the callback
393
- * only fire if it matches the `GridEntityType` provided.
401
+ * only fire if it matches the `GridEntityType` provided. (Custom grid entities do not have
402
+ * variants, so there is no need for an optional third argument to filter by variant.)
394
403
  *
395
404
  * ```ts
396
405
  * function postGridEntityCustomBroken(
@@ -405,8 +414,13 @@ export enum ModCallbackCustom {
405
414
  * The same as the `POST_GRID_ENTITY_COLLISION` callback, but only fires for grid entities created
406
415
  * with the `spawnCustomGridEntity` helper function.
407
416
  *
408
- * When registering the callback, takes an optional second argument that will make the callback
409
- * only fire if it matches the `GridEntityType` provided.
417
+ * - When registering the callback, takes an optional second argument that will make the callback
418
+ * only fire if it matches the `GridEntityType` provided. (Custom grid entities do not have
419
+ * variants, so there is no need for an optional third argument to filter by variant.)
420
+ * - When registering the callback, takes an optional third argument that will make the callback
421
+ * only fire if the the colliding entity matches the `EntityType` provided.
422
+ * - When registering the callback, takes an optional fourth argument that will make the callback
423
+ * only fire if the the colliding entity matches the variant provided.
410
424
  *
411
425
  * ```ts
412
426
  * function postGridEntityCustomCollision(
@@ -423,7 +437,8 @@ export enum ModCallbackCustom {
423
437
  * the `spawnCustomGridEntity` helper function.
424
438
  *
425
439
  * When registering the callback, takes an optional second argument that will make the callback
426
- * only fire if it matches the `GridEntityType` provided.
440
+ * only fire if it matches the `GridEntityType` provided. (Custom grid entities do not have
441
+ * variants, so there is no need for an optional third argument to filter by variant.)
427
442
  *
428
443
  * ```ts
429
444
  * function postGridEntityCustomInit(
@@ -439,7 +454,8 @@ export enum ModCallbackCustom {
439
454
  * with the `spawnCustomGridEntity` helper function.
440
455
  *
441
456
  * When registering the callback, takes an optional second argument that will make the callback
442
- * only fire if it matches the `GridEntityType` provided.
457
+ * only fire if it matches the `GridEntityType` provided. (Custom grid entities do not have
458
+ * variants, so there is no need for an optional third argument to filter by variant.)
443
459
  *
444
460
  * ```ts
445
461
  * function postGridEntityCustomRemove(
@@ -455,7 +471,8 @@ export enum ModCallbackCustom {
455
471
  * with the `spawnCustomGridEntity` helper function.
456
472
  *
457
473
  * When registering the callback, takes an optional second argument that will make the callback
458
- * only fire if it matches the `GridEntityType` provided.
474
+ * only fire if it matches the `GridEntityType` provided. (Custom grid entities do not have
475
+ * variants, so there is no need for an optional third argument to filter by variant.)
459
476
  *
460
477
  * ```ts
461
478
  * function postGridEntityCustomRender(
@@ -471,7 +488,8 @@ export enum ModCallbackCustom {
471
488
  * created with the `spawnCustomGridEntity` helper function.
472
489
  *
473
490
  * When registering the callback, takes an optional second argument that will make the callback
474
- * only fire if it matches the `GridEntityType` provided.
491
+ * only fire if it matches the `GridEntityType` provided. (Custom grid entities do not have
492
+ * variants, so there is no need for an optional third argument to filter by variant.)
475
493
  *
476
494
  * ```ts
477
495
  * function postGridEntityCustomStateChanged(
@@ -489,7 +507,8 @@ export enum ModCallbackCustom {
489
507
  * with the `spawnCustomGridEntity` helper function.
490
508
  *
491
509
  * When registering the callback, takes an optional second argument that will make the callback
492
- * only fire if it matches the `GridEntityType` provided.
510
+ * only fire if it matches the `GridEntityType` provided. (Custom grid entities do not have
511
+ * variants, so there is no need for an optional third argument to filter by variant.)
493
512
  *
494
513
  * ```ts
495
514
  * function postGridEntityCustomUpdate(
@@ -511,8 +530,10 @@ export enum ModCallbackCustom {
511
530
  * For grid entities created with `spawnCustomGridEntity`, use the `POST_GRID_ENTITY_CUSTOM_INIT`
512
531
  * callback instead.
513
532
  *
514
- * When registering the callback, takes an optional second argument that will make the callback
515
- * only fire if it matches the `GridEntityType` provided.
533
+ * - When registering the callback, takes an optional second argument that will make the callback
534
+ * only fire if it matches the `GridEntityType` provided.
535
+ * - When registering the callback, takes an optional third argument that will make the callback
536
+ * only fire if it matches the variant provided.
516
537
  *
517
538
  * ```ts
518
539
  * function postGridEntityInit(gridEntity: GridEntity): void {}
@@ -531,8 +552,10 @@ export enum ModCallbackCustom {
531
552
  * For grid entities created with `spawnCustomGridEntity`, use the
532
553
  * `POST_GRID_ENTITY_CUSTOM_REMOVE` callback instead.
533
554
  *
534
- * When registering the callback, takes an optional second argument that will make the callback
535
- * only fire if it matches the `GridEntityType` provided.
555
+ * - When registering the callback, takes an optional second argument that will make the callback
556
+ * only fire if it matches the `GridEntityType` provided.
557
+ * - When registering the callback, takes an optional third argument that will make the callback
558
+ * only fire if it matches the variant provided.
536
559
  *
537
560
  * ```ts
538
561
  * function postGridEntityRemove(
@@ -546,14 +569,14 @@ export enum ModCallbackCustom {
546
569
  /**
547
570
  * Fires from the `POST_RENDER` callback on every frame that a grid entity exists.
548
571
  *
572
+ * For grid entities created with `spawnCustomGridEntity`, use the
573
+ * `POST_GRID_ENTITY_CUSTOM_RENDER` callback instead.
574
+ *
549
575
  * - When registering the callback, takes an optional second argument that will make the callback
550
576
  * only fire if it matches the `GridEntityType` provided.
551
577
  * - When registering the callback, takes an optional third argument that will make the callback
552
578
  * only fire if it matches the variant provided.
553
579
  *
554
- * For grid entities created with `spawnCustomGridEntity`, use the
555
- * `POST_GRID_ENTITY_CUSTOM_RENDER` callback instead.
556
- *
557
580
  * ```ts
558
581
  * function postGridEntityRender(gridEntity: GridEntity): void {}
559
582
  * ```
@@ -564,12 +587,14 @@ export enum ModCallbackCustom {
564
587
  * Fires from the `POST_UPDATE` callback when a grid entity changes its state. (In this context,
565
588
  * "state" refers to the `GridEntity.State` field.)
566
589
  *
567
- * When registering the callback, takes an optional second argument that will make the callback
568
- * only fire if it matches the `GridEntityType` provided.
569
- *
570
590
  * For grid entities created with `spawnCustomGridEntity`, use the
571
591
  * `POST_GRID_ENTITY_CUSTOM_STATE_CHANGED` callback instead.
572
592
  *
593
+ * - When registering the callback, takes an optional second argument that will make the callback
594
+ * only fire if it matches the `GridEntityType` provided.
595
+ * - When registering the callback, takes an optional third argument that will make the callback
596
+ * only fire if it matches the variant provided.
597
+ *
573
598
  * ```ts
574
599
  * function postGridEntityStateChanged(
575
600
  * gridEntity: GridEntity,
@@ -583,14 +608,14 @@ export enum ModCallbackCustom {
583
608
  /**
584
609
  * Fires from the `POST_UPDATE` callback on every frame that a grid entity exists.
585
610
  *
611
+ * For grid entities created with `spawnCustomGridEntity`, use the
612
+ * `POST_GRID_ENTITY_CUSTOM_UPDATE` callback instead.
613
+ *
586
614
  * - When registering the callback, takes an optional second argument that will make the callback
587
615
  * only fire if it matches the `GridEntityType` provided.
588
616
  * - When registering the callback, takes an optional third argument that will make the callback
589
617
  * only fire if it matches the variant provided.
590
618
  *
591
- * For grid entities created with `spawnCustomGridEntity`, use the
592
- * `POST_GRID_ENTITY_CUSTOM_UPDATE` callback instead.
593
- *
594
619
  * ```ts
595
620
  * function postGridEntityUpdate(gridEntity: GridEntity): void {}
596
621
  * ```
@@ -1251,7 +1276,8 @@ export enum ModCallbackCustom {
1251
1276
  * certain conditions, like if the slot entity is playing the "Idle" animation, and so on.
1252
1277
  *
1253
1278
  * When registering the callback, takes an optional second argument that will make the callback
1254
- * only fire if it matches the `SlotVariant` provided.
1279
+ * only fire if it matches the `SlotVariant` provided. (There is no need for any additional
1280
+ * arguments, since only players will cause this callback to fire.)
1255
1281
  *
1256
1282
  * ```ts
1257
1283
  * function postSlotCollision(
@@ -25,7 +25,7 @@ import {
25
25
  import { DEFAULT_BASE_STAGE } from "./exports";
26
26
  import v from "./v";
27
27
 
28
- /** For `GridEntityType.DECORATION` (1) */
28
+ /** For `GridEntityType.DECORATION` (1). */
29
29
  export function setCustomDecorationGraphics(
30
30
  customStage: CustomStage,
31
31
  gridEntity: GridEntity,
@@ -71,7 +71,7 @@ export function setCustomDecorationGraphics(
71
71
  }
72
72
  }
73
73
 
74
- /** For `GridEntityType.ROCK` (2) */
74
+ /** For `GridEntityType.ROCK` (2). */
75
75
  export function setCustomRockGraphics(
76
76
  customStage: CustomStage,
77
77
  gridEntity: GridEntity,
@@ -134,7 +134,7 @@ export function setCustomRockGraphics(
134
134
  }
135
135
  }
136
136
 
137
- /** For `GridEntityType.PIT` (7) */
137
+ /** For `GridEntityType.PIT` (7). */
138
138
  export function setCustomPitGraphics(
139
139
  customStage: CustomStage,
140
140
  gridEntity: GridEntity,
@@ -164,7 +164,7 @@ export function setCustomPitGraphics(
164
164
  }
165
165
  }
166
166
 
167
- /** For GridEntityType.DOOR (16) */
167
+ /** For `GridEntityType.DOOR` (16). */
168
168
  export function setCustomDoorGraphics(
169
169
  customStage: CustomStage,
170
170
  gridEntity: GridEntity,
@@ -1,6 +1,6 @@
1
1
  import { inRectangle } from "./math";
2
2
 
3
- /** For `EntityType.EFFECT` (1000), `EffectVariant.DICE_FLOOR` (76) */
3
+ /** For `EntityType.EFFECT` (1000), `EffectVariant.DICE_FLOOR` (76). */
4
4
  export const DICE_FLOOR_TRIGGER_SQUARE_SIZE = 75;
5
5
 
6
6
  /** Helper function to see if a player is close enough to activate a Dice Room floor. */
@@ -234,6 +234,10 @@ export function getFilteredNewEntities<T extends AnyEntity>(
234
234
  /**
235
235
  * Helper function to measure an entity's velocity to see if it is moving.
236
236
  *
237
+ * Use this helper function over checking if the velocity length is equal to 0 because entities can
238
+ * look like they are completely immobile but yet still have a non zero velocity. Thus, using a
239
+ * threshold is needed.
240
+ *
237
241
  * @param entity The entity whose velocity to measure.
238
242
  * @param threshold Optional. The threshold from 0 to consider to be moving. Default is 0.01.
239
243
  */
@@ -1,6 +1,6 @@
1
1
  import { EntityType } from "isaac-typescript-definitions";
2
2
 
3
- /** For `EntityType.SLOT` (6) */
3
+ /** For `EntityType.SLOT` (6). */
4
4
  export function isSlot(entity: Entity): entity is EntitySlot {
5
5
  return entity.Type === EntityType.SLOT;
6
6
  }
@@ -173,6 +173,21 @@ export function getTNT(variant = -1): GridEntityTNT[] {
173
173
  return tntArray;
174
174
  }
175
175
 
176
+ /**
177
+ * Helper function to get all of the grid entities of type `GridEntityType.TELEPORTER` (23) in the
178
+ * room.
179
+ *
180
+ * @param variant Optional. If specified, will only get the teleporters that match the variant.
181
+ * Default is -1, which matches every variant.
182
+ */
183
+ export function getTeleporters(variant = -1): GridEntity[] {
184
+ if (variant === -1) {
185
+ return getGridEntities(GridEntityType.TELEPORTER);
186
+ }
187
+
188
+ return getMatchingGridEntities(GridEntityType.TELEPORTER, variant);
189
+ }
190
+
176
191
  /**
177
192
  * Helper function to get all of the grid entities of type `GridEntityType.TRAPDOOR` (17) in the
178
193
  * room. Specify a specific trapdoor variant to select only trapdoors of that variant.
@@ -333,6 +348,26 @@ export function removeAllTNT(
333
348
  return removeGridEntities(tnt, updateRoom, cap);
334
349
  }
335
350
 
351
+ /**
352
+ * Helper function to remove all of the `GridEntityType.TELEPORTER` (23) in the room.
353
+ *
354
+ * @param variant Optional. If specified, will only remove the teleporters that match this variant.
355
+ * Default is -1, which matches every variant.
356
+ * @param updateRoom Optional. Whether or not to update the room after the teleporters are removed.
357
+ * Default is false. For more information, see the description of the
358
+ * `removeGridEntities` helper function.
359
+ * @param cap Optional. If specified, will only remove the given amount of teleporters.
360
+ * @returns The teleporters that were removed.
361
+ */
362
+ export function removeAllTeleporters(
363
+ variant = -1,
364
+ updateRoom = false,
365
+ cap?: int,
366
+ ): GridEntity[] {
367
+ const teleporters = getTeleporters(variant);
368
+ return removeGridEntities(teleporters, updateRoom, cap);
369
+ }
370
+
336
371
  /**
337
372
  * Helper function to remove all of the `GridEntityType.TRAPDOOR` (17) in the room.
338
373
  *
@@ -584,6 +619,25 @@ export function spawnTNTWithVariant(
584
619
  return tnt;
585
620
  }
586
621
 
622
+ /** Helper function to spawn a `GridEntityType.TELEPORTER` (23). */
623
+ export function spawnTeleporter(
624
+ gridIndexOrPosition: int | Vector,
625
+ ): GridEntity | undefined {
626
+ return spawnTeleporterWithVariant(0, gridIndexOrPosition);
627
+ }
628
+
629
+ /** Helper function to spawn a `GridEntityType.TELEPORTER` (23) with a specific variant. */
630
+ export function spawnTeleporterWithVariant(
631
+ variant: int,
632
+ gridIndexOrPosition: int | Vector,
633
+ ): GridEntity | undefined {
634
+ return spawnGridEntityWithVariant(
635
+ GridEntityType.TELEPORTER,
636
+ variant,
637
+ gridIndexOrPosition,
638
+ );
639
+ }
640
+
587
641
  /** Helper function to spawn a `GridEntityType.TRAPDOOR` (17). */
588
642
  export function spawnTrapdoor(
589
643
  gridIndexOrPosition: int | Vector,
@@ -2,59 +2,59 @@
2
2
 
3
3
  import { PickupVariant } from "isaac-typescript-definitions";
4
4
 
5
- /** For `PickupVariant.HEART` (10) */
5
+ /** For `PickupVariant.HEART` (10). */
6
6
  export function isHeart(pickup: EntityPickup): pickup is EntityPickupHeart {
7
7
  return pickup.Variant === PickupVariant.HEART;
8
8
  }
9
9
 
10
- /** For `PickupVariant.COIN` (20) */
10
+ /** For `PickupVariant.COIN` (20). */
11
11
  export function isCoin(pickup: EntityPickup): pickup is EntityPickupCoin {
12
12
  return pickup.Variant === PickupVariant.COIN;
13
13
  }
14
14
 
15
- /** For `PickupVariant.KEY` (30) */
15
+ /** For `PickupVariant.KEY` (30). */
16
16
  export function isKey(pickup: EntityPickup): pickup is EntityPickupKey {
17
17
  return pickup.Variant === PickupVariant.KEY;
18
18
  }
19
19
 
20
- /** For `PickupVariant.BOMB` (40) */
20
+ /** For `PickupVariant.BOMB` (40). */
21
21
  export function isBombPickup(pickup: EntityPickup): pickup is EntityPickupBomb {
22
22
  return pickup.Variant === PickupVariant.BOMB;
23
23
  }
24
24
 
25
- /** For `PickupVariant.POOP` (42) */
25
+ /** For `PickupVariant.POOP` (42). */
26
26
  export function isPoopPickup(pickup: EntityPickup): pickup is EntityPickupPoop {
27
27
  return pickup.Variant === PickupVariant.POOP;
28
28
  }
29
29
 
30
- /** For `PickupVariant.SACK` (69) */
30
+ /** For `PickupVariant.SACK` (69). */
31
31
  export function isSack(pickup: EntityPickup): pickup is EntityPickupSack {
32
32
  return pickup.Variant === PickupVariant.SACK;
33
33
  }
34
34
 
35
- /** For `PickupVariant.PILL` (70) */
35
+ /** For `PickupVariant.PILL` (70). */
36
36
  export function isPill(pickup: EntityPickup): pickup is EntityPickupPill {
37
37
  return pickup.Variant === PickupVariant.PILL;
38
38
  }
39
39
 
40
- /** For `PickupVariant.LIL_BATTERY` (90) */
40
+ /** For `PickupVariant.LIL_BATTERY` (90). */
41
41
  export function isBattery(pickup: EntityPickup): pickup is EntityPickupBattery {
42
42
  return pickup.Variant === PickupVariant.LIL_BATTERY;
43
43
  }
44
44
 
45
- /** For `PickupVariant.COLLECTIBLE` (100) */
45
+ /** For `PickupVariant.COLLECTIBLE` (100). */
46
46
  export function isCollectible(
47
47
  pickup: EntityPickup,
48
48
  ): pickup is EntityPickupCollectible {
49
49
  return pickup.Variant === PickupVariant.COLLECTIBLE;
50
50
  }
51
51
 
52
- /** For `PickupVariant.TAROT_CARD` (300) */
52
+ /** For `PickupVariant.TAROT_CARD` (300). */
53
53
  export function isCardPickup(pickup: EntityPickup): pickup is EntityPickupCard {
54
54
  return pickup.Variant === PickupVariant.TAROT_CARD;
55
55
  }
56
56
 
57
- /** For `PickupVariant.TRINKET` (350) */
57
+ /** For `PickupVariant.TRINKET` (350). */
58
58
  export function isTrinket(pickup: EntityPickup): pickup is EntityPickupTrinket {
59
59
  return pickup.Variant === PickupVariant.TRINKET;
60
60
  }
@@ -26,10 +26,12 @@ export function getRedHearts(): EntityPickupHeart[] {
26
26
  return hearts.filter((heart) => RED_HEART_SUB_TYPES_SET.has(heart.SubType));
27
27
  }
28
28
 
29
+ /** Helper function to test if the provided pickup matches one of the various chest variants. */
29
30
  export function isChest(pickup: EntityPickup): boolean {
30
31
  return CHEST_PICKUP_VARIANTS.has(pickup.Variant);
31
32
  }
32
33
 
34
+ /** Helper function to test if the provided pickup matches on of the various red heart sub types. */
33
35
  export function isRedHeart(pickup: EntityPickup): boolean {
34
36
  return isHeart(pickup) && RED_HEART_SUB_TYPES_SET.has(pickup.SubType);
35
37
  }