isaacscript-common 59.4.1 → 59.6.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 (51) hide show
  1. package/dist/index.rollup.d.ts +110 -1
  2. package/dist/isaacscript-common.lua +182 -58
  3. package/dist/src/classes/ModUpgraded.d.ts.map +1 -1
  4. package/dist/src/classes/ModUpgraded.lua +2 -2
  5. package/dist/src/classes/callbacks/PostCursedTeleport.d.ts.map +1 -1
  6. package/dist/src/classes/callbacks/PostCursedTeleport.lua +3 -2
  7. package/dist/src/classes/callbacks/PostItemDischarge.d.ts.map +1 -1
  8. package/dist/src/classes/callbacks/PostPickupInitFirst.d.ts.map +1 -1
  9. package/dist/src/classes/callbacks/PostPickupInitFirst.lua +3 -5
  10. package/dist/src/classes/features/callbackLogic/GameReorderedCallbacks.d.ts.map +1 -1
  11. package/dist/src/classes/features/callbackLogic/GameReorderedCallbacks.lua +5 -5
  12. package/dist/src/classes/features/other/CustomTrapdoors.d.ts.map +1 -1
  13. package/dist/src/classes/features/other/CustomTrapdoors.lua +10 -12
  14. package/dist/src/classes/features/other/PickupIndexCreation.d.ts.map +1 -1
  15. package/dist/src/classes/features/other/PickupIndexCreation.lua +3 -2
  16. package/dist/src/classes/features/other/PreventCollectibleRotation.d.ts.map +1 -1
  17. package/dist/src/classes/features/other/PreventCollectibleRotation.lua +3 -2
  18. package/dist/src/classes/features/other/SaveDataManager.d.ts.map +1 -1
  19. package/dist/src/classes/features/other/SaveDataManager.lua +3 -4
  20. package/dist/src/classes/features/other/customStages/streakText.d.ts.map +1 -1
  21. package/dist/src/classes/features/other/customStages/streakText.lua +6 -5
  22. package/dist/src/functions/debugFunctions.d.ts +7 -1
  23. package/dist/src/functions/debugFunctions.d.ts.map +1 -1
  24. package/dist/src/functions/debugFunctions.lua +22 -16
  25. package/dist/src/functions/frames.d.ts +68 -0
  26. package/dist/src/functions/frames.d.ts.map +1 -0
  27. package/dist/src/functions/frames.lua +119 -0
  28. package/dist/src/functions/gridEntities.d.ts +22 -0
  29. package/dist/src/functions/gridEntities.d.ts.map +1 -1
  30. package/dist/src/functions/gridEntities.lua +40 -11
  31. package/dist/src/functions/revive.d.ts.map +1 -1
  32. package/dist/src/functions/revive.lua +3 -4
  33. package/dist/src/index.d.ts +1 -0
  34. package/dist/src/index.d.ts.map +1 -1
  35. package/dist/src/index.lua +8 -0
  36. package/package.json +1 -1
  37. package/src/classes/ModUpgraded.ts +2 -3
  38. package/src/classes/callbacks/PostCursedTeleport.ts +2 -2
  39. package/src/classes/callbacks/PostItemDischarge.ts +2 -0
  40. package/src/classes/callbacks/PostPickupInitFirst.ts +2 -4
  41. package/src/classes/features/callbackLogic/GameReorderedCallbacks.ts +4 -6
  42. package/src/classes/features/other/CustomTrapdoors.ts +11 -14
  43. package/src/classes/features/other/PickupIndexCreation.ts +2 -2
  44. package/src/classes/features/other/PreventCollectibleRotation.ts +2 -3
  45. package/src/classes/features/other/SaveDataManager.ts +2 -3
  46. package/src/classes/features/other/customStages/streakText.ts +10 -6
  47. package/src/functions/debugFunctions.ts +10 -1
  48. package/src/functions/frames.ts +172 -0
  49. package/src/functions/gridEntities.ts +59 -13
  50. package/src/functions/revive.ts +2 -3
  51. package/src/index.ts +1 -0
@@ -0,0 +1,172 @@
1
+ import { game } from "../core/cachedClasses";
2
+
3
+ export function getElapsedGameFramesSince(gameFrameCount: int): int {
4
+ const thisGameFrameCount = game.GetFrameCount();
5
+ return thisGameFrameCount - gameFrameCount;
6
+ }
7
+
8
+ export function getElapsedRenderFramesSince(renderFrameCount: int): int {
9
+ const thisRenderFrameCount = Isaac.GetFrameCount();
10
+ return thisRenderFrameCount - renderFrameCount;
11
+ }
12
+
13
+ export function getElapsedRoomFramesSince(roomFrameCount: int): int {
14
+ const room = game.GetRoom();
15
+ const thisRoomFrameCount = room.GetFrameCount();
16
+ return thisRoomFrameCount - roomFrameCount;
17
+ }
18
+
19
+ /**
20
+ * Helper function to check if the current game frame count is higher than a specific game frame
21
+ * count.
22
+ *
23
+ * This returns false if the submitted game frame count is null or undefined.
24
+ */
25
+ export function isPastGameFrame(
26
+ gameFrameCount: int | null | undefined,
27
+ ): boolean {
28
+ if (gameFrameCount === null || gameFrameCount === undefined) {
29
+ return false;
30
+ }
31
+
32
+ const thisGameFrameCount = game.GetFrameCount();
33
+ return thisGameFrameCount > gameFrameCount;
34
+ }
35
+
36
+ /**
37
+ * Helper function to check if the current render frame count is higher than a specific render frame
38
+ * count.
39
+ *
40
+ * This returns false if the submitted render frame count is null or undefined.
41
+ */
42
+ export function isPastRenderFrame(
43
+ renderFrameCount: int | null | undefined,
44
+ ): boolean {
45
+ if (renderFrameCount === null || renderFrameCount === undefined) {
46
+ return false;
47
+ }
48
+
49
+ const thisRenderFrameCount = Isaac.GetFrameCount();
50
+ return thisRenderFrameCount >= renderFrameCount;
51
+ }
52
+
53
+ /**
54
+ * Helper function to check if the current room frame count is higher than a specific room frame
55
+ * count.
56
+ *
57
+ * This returns false if the submitted room frame count is null or undefined.
58
+ */
59
+ export function isPastRoomFrame(
60
+ roomFrameCount: int | null | undefined,
61
+ ): boolean {
62
+ if (roomFrameCount === null || roomFrameCount === undefined) {
63
+ return false;
64
+ }
65
+
66
+ const room = game.GetRoom();
67
+
68
+ const thisGameFrameCount = room.GetFrameCount();
69
+ return thisGameFrameCount > roomFrameCount;
70
+ }
71
+
72
+ /**
73
+ * Helper function to check if the current game frame count is exactly equal to a specific game
74
+ * frame count.
75
+ *
76
+ * This returns false if the submitted game frame count is null or undefined.
77
+ */
78
+ export function onGameFrame(gameFrameCount: int | null | undefined): boolean {
79
+ if (gameFrameCount === null || gameFrameCount === undefined) {
80
+ return false;
81
+ }
82
+
83
+ const thisGameFrameCount = game.GetFrameCount();
84
+ return thisGameFrameCount === gameFrameCount;
85
+ }
86
+
87
+ /**
88
+ * Helper function to check if the current game frame count is equal to or higher than a specific
89
+ * game frame count.
90
+ *
91
+ * This returns false if the submitted game frame count is null or undefined.
92
+ */
93
+ export function onOrPastGameFrame(
94
+ gameFrameCount: int | null | undefined,
95
+ ): boolean {
96
+ if (gameFrameCount === null || gameFrameCount === undefined) {
97
+ return false;
98
+ }
99
+
100
+ const thisGameFrameCount = game.GetFrameCount();
101
+ return thisGameFrameCount >= gameFrameCount;
102
+ }
103
+
104
+ /**
105
+ * Helper function to check if the current render frame count is equal to or higher than a specific
106
+ * render frame count.
107
+ *
108
+ * This returns false if the submitted render frame count is null or undefined.
109
+ */
110
+ export function onOrPastRenderFrame(
111
+ renderFrameCount: int | null | undefined,
112
+ ): boolean {
113
+ if (renderFrameCount === null || renderFrameCount === undefined) {
114
+ return false;
115
+ }
116
+
117
+ const thisRenderFrameCount = Isaac.GetFrameCount();
118
+ return thisRenderFrameCount >= renderFrameCount;
119
+ }
120
+
121
+ /**
122
+ * Helper function to check if the current room frame count is equal to or higher than a specific
123
+ * room frame count.
124
+ *
125
+ * This returns false if the submitted room frame count is null or undefined.
126
+ */
127
+ export function onOrPastRoomFrame(
128
+ roomFrameCount: int | null | undefined,
129
+ ): boolean {
130
+ if (roomFrameCount === null || roomFrameCount === undefined) {
131
+ return false;
132
+ }
133
+
134
+ const room = game.GetRoom();
135
+
136
+ const thisGameFrameCount = room.GetFrameCount();
137
+ return thisGameFrameCount >= roomFrameCount;
138
+ }
139
+
140
+ /**
141
+ * Helper function to check if the current render frame count is exactly equal to a specific render
142
+ * frame count.
143
+ *
144
+ * This returns false if the submitted render frame count is null or undefined.
145
+ */
146
+ export function onRenderFrame(
147
+ renderFrameCount: int | null | undefined,
148
+ ): boolean {
149
+ if (renderFrameCount === null || renderFrameCount === undefined) {
150
+ return false;
151
+ }
152
+
153
+ const thisRenderFrameCount = Isaac.GetFrameCount();
154
+ return thisRenderFrameCount >= renderFrameCount;
155
+ }
156
+
157
+ /**
158
+ * Helper function to check if the current room frame count is exactly equal to a specific room
159
+ * frame count.
160
+ *
161
+ * This returns false if the submitted room frame count is null or undefined.
162
+ */
163
+ export function onRoomFrame(roomFrameCount: int | null | undefined): boolean {
164
+ if (roomFrameCount === null || roomFrameCount === undefined) {
165
+ return false;
166
+ }
167
+
168
+ const room = game.GetRoom();
169
+
170
+ const thisGameFrameCount = room.GetFrameCount();
171
+ return thisGameFrameCount === roomFrameCount;
172
+ }
@@ -690,21 +690,9 @@ export function getSurroundingGridEntities(
690
690
  gridEntity: GridEntity,
691
691
  ): GridEntity[] {
692
692
  const room = game.GetRoom();
693
- const gridWidth = room.GetGridWidth();
694
693
  const gridIndex = gridEntity.GetGridIndex();
695
694
 
696
- const surroundingGridIndexes: int[] = [
697
- gridIndex - 1, // Left
698
- gridIndex + 1, // Right
699
-
700
- gridIndex - gridWidth - 1, // Top-left
701
- gridIndex - gridWidth, // Top
702
- gridIndex - gridWidth + 1, // Top-right
703
-
704
- gridIndex + gridWidth - 1, // Bottom-left
705
- gridIndex + gridWidth, // Bottom
706
- gridIndex + gridWidth + 1, // Bottom-right
707
- ];
695
+ const surroundingGridIndexes = getSurroundingGridIndexes(gridIndex);
708
696
 
709
697
  const surroundingGridEntities: GridEntity[] = [];
710
698
  for (const surroundingGridIndex of surroundingGridIndexes) {
@@ -717,6 +705,42 @@ export function getSurroundingGridEntities(
717
705
  return surroundingGridEntities;
718
706
  }
719
707
 
708
+ /**
709
+ * Helper function to get the grid indexes on the surrounding tiles from the provided grid index.
710
+ *
711
+ * There are always 8 grid indexes returned (e.g. top-left + top + top-right + left + right +
712
+ * bottom-left + bottom + right), even if the computed values would be negative or otherwise
713
+ * invalid.
714
+ */
715
+ export function getSurroundingGridIndexes(
716
+ gridIndex: int,
717
+ ): [
718
+ topLeft: int,
719
+ top: int,
720
+ topRight: int,
721
+ left: int,
722
+ right: int,
723
+ bottomLeft: int,
724
+ bottom: int,
725
+ bottomRight: int,
726
+ ] {
727
+ const room = game.GetRoom();
728
+ const gridWidth = room.GetGridWidth();
729
+
730
+ return [
731
+ gridIndex - gridWidth - 1, // Top-left
732
+ gridIndex - gridWidth, // Top
733
+ gridIndex - gridWidth + 1, // Top-right
734
+
735
+ gridIndex - 1, // Left
736
+ gridIndex + 1, // Right
737
+
738
+ gridIndex + gridWidth - 1, // Bottom-left
739
+ gridIndex + gridWidth, // Bottom
740
+ gridIndex + gridWidth + 1, // Bottom-right
741
+ ];
742
+ }
743
+
720
744
  /**
721
745
  * Helper function to get the top left wall in the current room.
722
746
  *
@@ -785,6 +809,28 @@ export function isGridEntityXMLType(num: number): num is GridEntityXMLType {
785
809
  return GRID_ENTITY_XML_TYPES_SET.has(num); // eslint-disable-line isaacscript/strict-enums
786
810
  }
787
811
 
812
+ /**
813
+ * Helper function to check if the provided grid index has a door on it or if the surrounding 8 grid
814
+ * indexes have a door on it.
815
+ */
816
+ export function isGridIndexAdjacentToDoor(gridIndex: int): boolean {
817
+ const room = game.GetRoom();
818
+ const surroundingGridIndexes = getSurroundingGridIndexes(gridIndex);
819
+ const gridIndexes = [gridIndex, ...surroundingGridIndexes];
820
+
821
+ for (const gridIndexToInspect of gridIndexes) {
822
+ const gridEntity = room.GetGridEntity(gridIndexToInspect);
823
+ if (gridEntity !== undefined) {
824
+ const door = gridEntity.ToDoor();
825
+ if (door !== undefined) {
826
+ return true;
827
+ }
828
+ }
829
+ }
830
+
831
+ return false;
832
+ }
833
+
788
834
  /** Helper function to see if a `GridEntityXMLType` is some kind of poop. */
789
835
  export function isPoopGridEntityXMLType(
790
836
  gridEntityXMLType: GridEntityXMLType,
@@ -5,13 +5,13 @@ import {
5
5
  PlayerType,
6
6
  TrinketType,
7
7
  } from "isaac-typescript-definitions";
8
- import { game } from "../core/cachedClasses";
9
8
  import {
10
9
  MAX_TAINTED_SAMSON_BERSERK_CHARGE,
11
10
  TAINTED_SAMSON_BERSERK_CHARGE_FROM_TAKING_DAMAGE,
12
11
  } from "../core/constants";
13
12
  import { MysteriousPaperEffect } from "../enums/MysteriousPaperEffect";
14
13
  import { getCharacterDeathAnimationName } from "./characters";
14
+ import { onGameFrame } from "./frames";
15
15
  import { getPlayerMaxHeartContainers } from "./playerHealth";
16
16
  import { getPlayerNumHitsRemaining, hasLostCurse, isKeeper } from "./players";
17
17
  import { getLastFrameOfAnimation } from "./sprites";
@@ -28,7 +28,6 @@ export function isDamageToPlayerFatal(
28
28
  source: EntityRef,
29
29
  lastDamageGameFrame: int | undefined,
30
30
  ): boolean {
31
- const gameFrameCount = game.GetFrameCount();
32
31
  const character = player.GetPlayerType();
33
32
  const effects = player.GetEffects();
34
33
  const isBerserk = effects.HasCollectibleEffect(CollectibleType.BERSERK);
@@ -91,7 +90,7 @@ export function isDamageToPlayerFatal(
91
90
  // damage on the same frame.
92
91
  if (
93
92
  player.HasCollectible(CollectibleType.BROKEN_GLASS_CANNON) &&
94
- gameFrameCount === lastDamageGameFrame
93
+ onGameFrame(lastDamageGameFrame)
95
94
  ) {
96
95
  return false;
97
96
  }
package/src/index.ts CHANGED
@@ -54,6 +54,7 @@ export * from "./functions/enums";
54
54
  export * from "./functions/external";
55
55
  export * from "./functions/familiars";
56
56
  export * from "./functions/flag";
57
+ export * from "./functions/frames";
57
58
  export * from "./functions/globals";
58
59
  export * from "./functions/gridEntities";
59
60
  export * from "./functions/gridEntitiesSpecific";