isaacscript-common 6.19.0 → 6.20.2

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/constants.d.ts +5 -0
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/constants.lua +4 -0
  4. package/dist/features/customStage/exports.d.ts +6 -1
  5. package/dist/features/customStage/exports.d.ts.map +1 -1
  6. package/dist/features/customStage/exports.lua +14 -11
  7. package/dist/features/customTrapdoor/blackSprite.d.ts.map +1 -1
  8. package/dist/features/customTrapdoor/blackSprite.lua +1 -0
  9. package/dist/features/customTrapdoor/init.d.ts.map +1 -1
  10. package/dist/features/customTrapdoor/init.lua +10 -2
  11. package/dist/features/extraConsoleCommands/commandsSubroutines.d.ts.map +1 -1
  12. package/dist/features/extraConsoleCommands/commandsSubroutines.lua +2 -1
  13. package/dist/features/extraConsoleCommands/listCommands.d.ts.map +1 -1
  14. package/dist/features/extraConsoleCommands/listCommands.lua +2 -1
  15. package/dist/functions/curses.d.ts +3 -0
  16. package/dist/functions/curses.d.ts.map +1 -0
  17. package/dist/functions/curses.lua +11 -0
  18. package/dist/functions/dimensions.d.ts +12 -0
  19. package/dist/functions/dimensions.d.ts.map +1 -0
  20. package/dist/functions/dimensions.lua +35 -0
  21. package/dist/functions/level.d.ts.map +1 -1
  22. package/dist/functions/level.lua +8 -7
  23. package/dist/functions/levelGrid.d.ts +155 -0
  24. package/dist/functions/levelGrid.d.ts.map +1 -0
  25. package/dist/functions/levelGrid.lua +349 -0
  26. package/dist/functions/roomData.d.ts +6 -1
  27. package/dist/functions/roomData.d.ts.map +1 -1
  28. package/dist/functions/roomData.lua +6 -0
  29. package/dist/functions/roomGrid.d.ts +8 -0
  30. package/dist/functions/roomGrid.d.ts.map +1 -1
  31. package/dist/functions/rooms.d.ts +67 -68
  32. package/dist/functions/rooms.d.ts.map +1 -1
  33. package/dist/functions/rooms.lua +176 -203
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.lua +24 -0
  37. package/package.json +2 -2
  38. package/src/constants.ts +8 -0
  39. package/src/features/customStage/exports.ts +25 -14
  40. package/src/features/customTrapdoor/blackSprite.ts +1 -0
  41. package/src/features/customTrapdoor/init.ts +7 -3
  42. package/src/features/extraConsoleCommands/commandsSubroutines.ts +2 -1
  43. package/src/features/extraConsoleCommands/listCommands.ts +2 -1
  44. package/src/functions/curses.ts +9 -0
  45. package/src/functions/dimensions.ts +41 -0
  46. package/src/functions/level.ts +7 -10
  47. package/src/functions/levelGrid.ts +468 -0
  48. package/src/functions/roomData.ts +13 -1
  49. package/src/functions/roomGrid.ts +9 -0
  50. package/src/functions/rooms.ts +161 -219
  51. package/src/index.ts +3 -0
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  EntityType,
3
- GridRoom,
4
3
  LevelStage,
5
4
  RoomShape,
6
5
  RoomType,
@@ -11,9 +10,11 @@ import { reorderedCallbacksSetStage } from "../../callbacks/reorderedCallbacks";
11
10
  import { getEntityIDFromConstituents } from "../../functions/entities";
12
11
  import { log, logError } from "../../functions/log";
13
12
  import { newRNG } from "../../functions/rng";
14
- import { getRoomData } from "../../functions/roomData";
15
- import { getRooms } from "../../functions/rooms";
16
- import { getGotoCommand, setStage } from "../../functions/stage";
13
+ import {
14
+ getRoomDataForTypeVariant,
15
+ getRoomsInGrid,
16
+ } from "../../functions/rooms";
17
+ import { setStage } from "../../functions/stage";
17
18
  import { getRandomCustomStageRoom } from "./customStageUtils";
18
19
  import { topStreakTextStart } from "./streakText";
19
20
  import v, {
@@ -30,12 +31,21 @@ const DEFAULT_BASE_STAGE_TYPE = StageType.ORIGINAL;
30
31
  *
31
32
  * Custom stages/levels must first be defined in the "tsconfig.json" file. See the documentation for
32
33
  * more details: https://isaacscript.github.io/main/custom-stages/
34
+ *
35
+ * @param name The name of the custom stage, corresponding to what is in the "tsconfig.json" file.
36
+ * @param _firstFloor Whether to go to the first floor or the second floor. For example, if you have
37
+ * a custom stage emulating Caves, then the first floor would be Caves 1, and the
38
+ * second floor would be Caves 2.
33
39
  */
34
- export function setCustomStage(name: string, verbose = false): void {
40
+ export function setCustomStage(
41
+ name: string,
42
+ _firstFloor = true,
43
+ verbose = false,
44
+ ): void {
35
45
  const customStage = customStagesMap.get(name);
36
46
  if (customStage === undefined) {
37
47
  error(
38
- `Failed to set the custom stage of "${name}" because it was not found in the custom stages map. (Try restarting IsaacScript / recompiling the mod, and try again. If that does not work, you probably forgot to define it in your "tsconfig.json" file.) See the website for more details on how to set up custom stages.`,
48
+ `Failed to set the custom stage of "${name}" because it was not found in the custom stages map. (Try restarting IsaacScript / recompiling the mod / restarting the game, and try again. If that does not work, you probably forgot to define it in your "tsconfig.json" file.) See the website for more details on how to set up custom stages.`,
39
49
  );
40
50
  }
41
51
 
@@ -58,7 +68,7 @@ export function setCustomStage(name: string, verbose = false): void {
58
68
  setStage(baseStage, baseStageType);
59
69
 
60
70
  // Now, we need to pick a custom room for each vanilla room.
61
- for (const room of getRooms()) {
71
+ for (const room of getRoomsInGrid()) {
62
72
  // The starting floor of each room should stay empty.
63
73
  if (room.SafeGridIndex === startingRoomGridIndex) {
64
74
  continue;
@@ -103,18 +113,19 @@ export function setCustomStage(name: string, verbose = false): void {
103
113
 
104
114
  let newRoomData = customStageCachedRoomData.get(randomRoom.variant);
105
115
  if (newRoomData === undefined) {
106
- // We need the room data for this room. We can leverage the "goto" console command to load it
107
- // into the "debug" slot. This is convenient because we do not actually have to travel to the
108
- // room.
109
- const command = getGotoCommand(roomType, randomRoom.variant);
110
- Isaac.ExecuteCommand(command);
111
- newRoomData = getRoomData(GridRoom.DEBUG);
116
+ // We do not already have the room data for this room cached.
117
+ newRoomData = getRoomDataForTypeVariant(
118
+ roomType,
119
+ randomRoom.variant,
120
+ false,
121
+ );
112
122
  if (newRoomData === undefined) {
113
123
  logError(
114
124
  `Failed to get the room data for room variant ${randomRoom.variant} for custom stage: ${name}`,
115
125
  );
116
126
  continue;
117
127
  }
128
+
118
129
  customStageCachedRoomData.set(randomRoom.variant, newRoomData);
119
130
  }
120
131
 
@@ -134,7 +145,7 @@ export function setCustomStage(name: string, verbose = false): void {
134
145
  // Furthermore, we need to cancel the queued warp to the `GridRoom.DEBUG` room. We can accomplish
135
146
  // both of these things by initiating a room transition to an arbitrary room. However, we rely on
136
147
  // the parent function to do this, since for normal purposes, we need to initiate a room
137
- // transition for pixelation purposes.
148
+ // transition for the pixelation effect.
138
149
  }
139
150
 
140
151
  export function setCustomStageDebug(): void {
@@ -16,6 +16,7 @@ export function drawBlackSprite(): void {
16
16
  if (!blackSprite.IsLoaded()) {
17
17
  blackSprite.Load("gfx/ui/boss/versusscreen.anm2", true);
18
18
  blackSprite.SetFrame("Scene", 0);
19
+ blackSprite.Scale = Vector(100, 100);
19
20
  }
20
21
 
21
22
  blackSprite.RenderLayer(0, VectorZero);
@@ -10,6 +10,7 @@ import { StageTravelState } from "../../enums/private/StageTravelState";
10
10
  import { movePlayersToCenter } from "../../functions/playerCenter";
11
11
  import { getAllPlayers } from "../../functions/playerIndex";
12
12
  import { getRoomGridIndex, getRoomListIndex } from "../../functions/roomData";
13
+ import { teleport } from "../../functions/rooms";
13
14
  import { setStage } from "../../functions/stage";
14
15
  import { isString } from "../../functions/types";
15
16
  import { setCustomStage } from "../customStage/exports";
@@ -65,8 +66,10 @@ function checkAllPlayersJumpComplete() {
65
66
  v.run.stateRenderFrame = renderFrameCount;
66
67
 
67
68
  // In order to display the pixelation effect that should happen when we go to a new floor, we need
68
- // to start a room transition. We arbitrarily pick the current room for this purpose.
69
- game.StartRoomTransition(
69
+ // to start a room transition. We arbitrarily pick the current room for this purpose. (We do not
70
+ // have to worry about Curse of the Maze here, because even if we are taken to a different room,
71
+ // it will not matter, since we will be traveling to a new floor after the screen fades to black.)
72
+ teleport(
70
73
  roomGridIndex,
71
74
  Direction.NO_DIRECTION,
72
75
  RoomTransitionAnim.PIXELATION,
@@ -99,10 +102,11 @@ function checkPixelationToBlackComplete() {
99
102
 
100
103
  // Start another pixelation effect. This time, we will keep the screen black with the sprite, and
101
104
  // then remove the black sprite once the pixelation effect is halfway complete.
102
- game.StartRoomTransition(
105
+ teleport(
103
106
  roomGridIndex,
104
107
  Direction.NO_DIRECTION,
105
108
  RoomTransitionAnim.PIXELATION,
109
+ true,
106
110
  );
107
111
  }
108
112
 
@@ -9,10 +9,11 @@ import { game } from "../../cachedClasses";
9
9
  import { HealthType } from "../../enums/HealthType";
10
10
  import { directionToVector } from "../../functions/direction";
11
11
  import { spawnGridEntityWithVariant } from "../../functions/gridEntities";
12
+ import { getRoomGridIndexesForType } from "../../functions/levelGrid";
12
13
  import { logAllEntities, logAllGridEntities } from "../../functions/log";
13
14
  import { addPlayerHealthType } from "../../functions/playerHealth";
14
15
  import { getRoomData, getRoomDescriptor } from "../../functions/roomData";
15
- import { changeRoom, getRoomGridIndexesForType } from "../../functions/rooms";
16
+ import { changeRoom } from "../../functions/rooms";
16
17
  import { printConsole } from "../../functions/utils";
17
18
  import {
18
19
  DEFAULT_ROOM_TYPE_NAME,
@@ -63,6 +63,7 @@ import { getNPCs } from "../../functions/entitiesSpecific";
63
63
  import { getEnumValues } from "../../functions/enums";
64
64
  import { addFlag } from "../../functions/flag";
65
65
  import { spawnGridEntity } from "../../functions/gridEntities";
66
+ import { getRoomGridIndexesForType } from "../../functions/levelGrid";
66
67
  import {
67
68
  logPlayerEffects,
68
69
  logRoom,
@@ -85,7 +86,7 @@ import {
85
86
  useActiveItemTemp,
86
87
  } from "../../functions/players";
87
88
  import { gridCoordinatesToWorldPosition } from "../../functions/roomGrid";
88
- import { changeRoom, getRoomGridIndexesForType } from "../../functions/rooms";
89
+ import { changeRoom } from "../../functions/rooms";
89
90
  import { onSetSeed, restart, setUnseeded } from "../../functions/run";
90
91
  import { getGoldenTrinketType } from "../../functions/trinkets";
91
92
  import { irange, printConsole, printEnabled } from "../../functions/utils";
@@ -0,0 +1,9 @@
1
+ import { LevelCurse } from "isaac-typescript-definitions";
2
+ import { game } from "../cachedClasses";
3
+ import { hasFlag } from "./flag";
4
+
5
+ export function hasCurse(curse: LevelCurse): boolean {
6
+ const level = game.GetLevel();
7
+ const curses = level.GetCurses();
8
+ return hasFlag(curses, curse);
9
+ }
@@ -0,0 +1,41 @@
1
+ import { Dimension } from "isaac-typescript-definitions";
2
+ import { game } from "../cachedClasses";
3
+ import { NUM_DIMENSIONS } from "../constants";
4
+ import { getRoomGridIndex } from "./roomData";
5
+ import { erange } from "./utils";
6
+
7
+ /**
8
+ * Helper function to get an array with every valid `Dimension` (not including `Dimension.CURRENT`).
9
+ */
10
+ export function getAllDimensions(): Dimension[] {
11
+ return erange(NUM_DIMENSIONS) as Dimension[];
12
+ }
13
+
14
+ /**
15
+ * Helper function to get the current dimension. Most of the time, this will be `Dimension.MAIN`,
16
+ * but it can change if e.g. the player is in the mirror world of Downpour/Dross.
17
+ */
18
+ export function getDimension(): Dimension {
19
+ const level = game.GetLevel();
20
+ const roomGridIndex = getRoomGridIndex();
21
+ const roomDescription = level.GetRoomByIdx(roomGridIndex, Dimension.CURRENT);
22
+ const currentRoomHash = GetPtrHash(roomDescription);
23
+
24
+ for (const dimension of getAllDimensions()) {
25
+ const dimensionRoomDescription = level.GetRoomByIdx(
26
+ roomGridIndex,
27
+ dimension,
28
+ );
29
+ const dimensionRoomHash = GetPtrHash(dimensionRoomDescription);
30
+
31
+ if (dimensionRoomHash === currentRoomHash) {
32
+ return dimension;
33
+ }
34
+ }
35
+
36
+ error("Failed to get the current dimension.");
37
+ }
38
+
39
+ export function inDimension(dimension: Dimension): boolean {
40
+ return dimension === getDimension();
41
+ }
@@ -1,21 +1,18 @@
1
1
  import { DoorSlot } from "isaac-typescript-definitions";
2
2
  import { game } from "../cachedClasses";
3
3
  import { getEnumValues } from "./enums";
4
- import {
5
- getNumRooms,
6
- getRooms,
7
- isDoorSlotValidAtGridIndexForRedRoom,
8
- } from "./rooms";
4
+ import { isDoorSlotValidAtGridIndexForRedRoom } from "./levelGrid";
5
+ import { getNumRooms, getRoomsInGrid } from "./rooms";
9
6
 
10
7
  export function fillLevelWithRedRooms(): void {
11
8
  const level = game.GetLevel();
12
9
 
13
- let numRooms: int;
10
+ let numRoomsInGrid: int;
14
11
  do {
15
- const rooms = getRooms();
16
- numRooms = rooms.length;
12
+ const roomsInGrid = getRoomsInGrid();
13
+ numRoomsInGrid = roomsInGrid.length;
17
14
 
18
- for (const roomDescriptor of rooms) {
15
+ for (const roomDescriptor of roomsInGrid) {
19
16
  for (const doorSlot of getEnumValues(DoorSlot)) {
20
17
  if (
21
18
  isDoorSlotValidAtGridIndexForRedRoom(
@@ -27,5 +24,5 @@ export function fillLevelWithRedRooms(): void {
27
24
  }
28
25
  }
29
26
  }
30
- } while (numRooms !== getNumRooms());
27
+ } while (numRoomsInGrid !== getNumRooms());
31
28
  }