isaacscript-common 7.6.0 → 7.7.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/features/customGridEntity.d.ts +6 -3
  2. package/dist/features/customGridEntity.d.ts.map +1 -1
  3. package/dist/features/customGridEntity.lua +20 -11
  4. package/dist/features/customStage/customStageConstants.d.ts +1 -0
  5. package/dist/features/customStage/customStageConstants.d.ts.map +1 -1
  6. package/dist/features/customStage/customStageConstants.lua +1 -0
  7. package/dist/features/customStage/init.d.ts.map +1 -1
  8. package/dist/features/customStage/init.lua +3 -1
  9. package/dist/features/customStage/versusScreen.d.ts.map +1 -1
  10. package/dist/features/customStage/versusScreen.lua +6 -0
  11. package/dist/features/customTrapdoor/spawn.d.ts.map +1 -1
  12. package/dist/features/customTrapdoor/spawn.lua +3 -4
  13. package/dist/features/extraConsoleCommands/commandsSubroutines.d.ts +1 -0
  14. package/dist/features/extraConsoleCommands/commandsSubroutines.d.ts.map +1 -1
  15. package/dist/features/extraConsoleCommands/commandsSubroutines.lua +31 -7
  16. package/dist/features/extraConsoleCommands/init.lua +1 -0
  17. package/dist/features/extraConsoleCommands/listCommands.d.ts +2 -0
  18. package/dist/features/extraConsoleCommands/listCommands.d.ts.map +1 -1
  19. package/dist/features/extraConsoleCommands/listCommands.lua +5 -0
  20. package/dist/functions/levelGrid.d.ts +44 -12
  21. package/dist/functions/levelGrid.d.ts.map +1 -1
  22. package/dist/functions/levelGrid.lua +97 -59
  23. package/dist/interfaces/CustomStageTSConfig.d.ts +1 -1
  24. package/dist/interfaces/GridEntityCustomData.d.ts +2 -2
  25. package/dist/interfaces/GridEntityCustomData.d.ts.map +1 -1
  26. package/dist/objects/roomTypeNames.d.ts +0 -1
  27. package/dist/objects/roomTypeNames.d.ts.map +1 -1
  28. package/dist/objects/roomTypeNames.lua +0 -1
  29. package/package.json +1 -1
  30. package/src/features/customGridEntity.ts +30 -20
  31. package/src/features/customStage/customStageConstants.ts +2 -0
  32. package/src/features/customStage/init.ts +2 -1
  33. package/src/features/customStage/versusScreen.ts +7 -1
  34. package/src/features/customTrapdoor/spawn.ts +3 -4
  35. package/src/features/extraConsoleCommands/commandsSubroutines.ts +30 -9
  36. package/src/features/extraConsoleCommands/init.ts +1 -0
  37. package/src/features/extraConsoleCommands/listCommands.ts +6 -0
  38. package/src/functions/levelGrid.ts +126 -61
  39. package/src/interfaces/CustomStageTSConfig.ts +1 -1
  40. package/src/interfaces/GridEntityCustomData.ts +2 -2
  41. package/src/objects/roomTypeNames.ts +0 -2
@@ -47,7 +47,37 @@ const DOWN = LEVEL_GRID_ROW_WIDTH;
47
47
  const ADJACENT_ROOM_GRID_INDEX_DELTAS: readonly int[] = [LEFT, UP, RIGHT, DOWN];
48
48
 
49
49
  /**
50
- * Helper function to get the room grid indexes that are adjacent to a given room grid index.
50
+ * Helper function to get only the adjacent room grid indexes that exist (i.e. have room data).
51
+ *
52
+ * This is just a filtering of the results of the `getAdjacentExistingRoomGridIndexes` function. See
53
+ * that function for more information.
54
+ */
55
+ export function getAdjacentExistingRoomGridIndexes(roomGridIndex?: int): int[] {
56
+ const adjacentRoomGridIndexes = getAdjacentRoomGridIndexes(roomGridIndex);
57
+ return adjacentRoomGridIndexes.filter(
58
+ (adjacentRoomGridIndex) => getRoomData(adjacentRoomGridIndex) !== undefined,
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Helper function to get only the adjacent room grid indexes that do not exist (i.e. do not have
64
+ * room data).
65
+ *
66
+ * This is just a filtering of the results of the `getAdjacentExistingRoomGridIndexes` function. See
67
+ * that function for more information.
68
+ */
69
+ export function getAdjacentNonExistingRoomGridIndexes(
70
+ roomGridIndex?: int,
71
+ ): int[] {
72
+ const adjacentRoomGridIndexes = getAdjacentRoomGridIndexes(roomGridIndex);
73
+ return adjacentRoomGridIndexes.filter(
74
+ (adjacentRoomGridIndex) => getRoomData(adjacentRoomGridIndex) === undefined,
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Helper function to get all of the room grid indexes that are adjacent to a given room grid index
80
+ * (even if those room grid indexes do not have any rooms in them).
51
81
  *
52
82
  * Adjacent room grid indexes that are outside of the grid will not be included in the returned
53
83
  * array.
@@ -127,7 +157,7 @@ export function getNewRoomCandidatesBesideRoom(
127
157
  return [];
128
158
  }
129
159
 
130
- const doorSlotToRoomGridIndexes = getRoomShapeNeighborGridIndexes(
160
+ const doorSlotToRoomGridIndexes = getRoomShapeAdjacentNonExistingGridIndexes(
131
161
  roomDescriptor.SafeGridIndex,
132
162
  roomData.Shape,
133
163
  );
@@ -136,29 +166,24 @@ export function getNewRoomCandidatesBesideRoom(
136
166
 
137
167
  for (const [
138
168
  doorSlot,
139
- neighborRoomGridIndex,
169
+ adjacentRoomGridIndex,
140
170
  ] of doorSlotToRoomGridIndexes.entries()) {
141
- // The "getRoomShapeNeighborGridIndexes" returns grid indexes for every possible door, but the
142
- // real room we are examining will only have a subset of these doors. Thus, we have to exclude
143
- // neighbor grid indexes where it would not be possible to place a door.
171
+ // The "getRoomShapeAdjacentNonExistingGridIndexes" returns grid indexes for every possible
172
+ // door, but the real room we are examining will only have a subset of these doors. Thus, we
173
+ // have to exclude adjacent grid indexes where it would not be possible to place a door.
144
174
  const doorSlotFlag = doorSlotToDoorSlotFlag(doorSlot);
145
175
  if (!hasFlag(roomData.Doors, doorSlotFlag)) {
146
176
  continue;
147
177
  }
148
178
 
149
- // If the neighboring room already exists, then it is not a possible candidate for a new room.
150
- if (roomExists(neighborRoomGridIndex)) {
151
- continue;
152
- }
153
-
154
179
  // Check to see if hypothetically creating a room at the given room grid index would be a dead
155
180
  // end. In other words, if we created the room, we would only want it to connect to one other
156
181
  // room (this one).
157
- if (!isDeadEnd(neighborRoomGridIndex)) {
182
+ if (!isDeadEnd(adjacentRoomGridIndex)) {
158
183
  continue;
159
184
  }
160
185
 
161
- roomCandidates.push([doorSlot, neighborRoomGridIndex]);
186
+ roomCandidates.push([doorSlot, adjacentRoomGridIndex]);
162
187
  }
163
188
 
164
189
  return roomCandidates;
@@ -196,6 +221,36 @@ export function getNewRoomCandidatesForLevel(): Array<
196
221
  return newRoomCandidates;
197
222
  }
198
223
 
224
+ /**
225
+ * Helper function to get the grid indexes of all the rooms connected to the given room index,
226
+ * taking the shape of the room into account. (This will only include rooms with valid data.)
227
+ *
228
+ * Returns an empty map if the provided room grid index is out of bounds or has no associated room
229
+ * data.
230
+ *
231
+ * @param roomGridIndex Optional. Default is the current room index.
232
+ * @returns A map of `DoorSlot` to the corresponding room grid index.
233
+ */
234
+ export function getRoomAdjacentGridIndexes(
235
+ roomGridIndex?: int,
236
+ ): Map<DoorSlot, int> {
237
+ const roomDescriptor = getRoomDescriptor(roomGridIndex);
238
+
239
+ if (!isRoomInsideGrid(roomDescriptor.SafeGridIndex)) {
240
+ return new Map();
241
+ }
242
+
243
+ const roomData = roomDescriptor.Data;
244
+ if (roomData === undefined) {
245
+ return new Map();
246
+ }
247
+
248
+ return getRoomShapeAdjacentExistingGridIndexes(
249
+ roomDescriptor.SafeGridIndex,
250
+ roomData.Shape,
251
+ );
252
+ }
253
+
199
254
  /**
200
255
  * Helper function to get an array of all of the safe grid indexes for rooms that match the
201
256
  * specified room type.
@@ -219,57 +274,43 @@ export function getRoomGridIndexesForType(...roomTypes: RoomType[]): int[] {
219
274
  }
220
275
 
221
276
  /**
222
- * Helper function to get the grid indexes of all the rooms connected to the given room index,
223
- * taking the shape of the room into account. (This will only include rooms with valid data.)
224
- *
225
- * Returns an empty map if the provided room grid index is out of bounds or has no associated room
226
- * data.
277
+ * Helper function to get only the adjacent room grid indexes for a room shape that exist (i.e. have
278
+ * room data).
227
279
  *
228
- * @param roomGridIndex Optional. Default is the current room index.
229
- * @returns A map of `DoorSlot` to the corresponding room grid index.
280
+ * This is just a filtering of the results of the `getRoomShapeAdjacentGridIndexes` function. See
281
+ * that function for more information.
230
282
  */
231
- export function getRoomNeighbors(roomGridIndex?: int): Map<DoorSlot, int> {
232
- const roomDescriptor = getRoomDescriptor(roomGridIndex);
233
-
234
- if (!isRoomInsideGrid(roomDescriptor.SafeGridIndex)) {
235
- return new Map();
236
- }
237
-
238
- const roomData = roomDescriptor.Data;
239
- if (roomData === undefined) {
240
- return new Map();
241
- }
242
-
243
- const doorSlotToRoomGridIndexes = getRoomShapeNeighborGridIndexes(
244
- roomDescriptor.SafeGridIndex,
245
- roomData.Shape,
283
+ export function getRoomShapeAdjacentExistingGridIndexes(
284
+ safeRoomGridIndex: int,
285
+ roomShape: RoomShape,
286
+ ): Map<DoorSlot, int> {
287
+ const roomShapeAdjacentGridIndexes = getRoomShapeAdjacentGridIndexes(
288
+ safeRoomGridIndex,
289
+ roomShape,
246
290
  );
247
291
 
248
- // The "getRoomShapeNeighborGridIndexes" returns grid indexes for every possible door, but the
249
- // real room we are examining will only have a subset of these doors. However, we do not have to
250
- // worry about filtering the map, since we perform a room existence check below.
251
- const roomNeighbors = new Map<DoorSlot, int>();
252
292
  for (const [
253
293
  doorSlot,
254
- neighborRoomGridIndex,
255
- ] of doorSlotToRoomGridIndexes.entries()) {
256
- if (roomExists(neighborRoomGridIndex)) {
257
- roomNeighbors.set(doorSlot, neighborRoomGridIndex);
294
+ roomGridIndex,
295
+ ] of roomShapeAdjacentGridIndexes.entries()) {
296
+ const roomData = getRoomData(roomGridIndex);
297
+ if (roomData === undefined) {
298
+ roomShapeAdjacentGridIndexes.delete(doorSlot);
258
299
  }
259
300
  }
260
301
 
261
- return roomNeighbors;
302
+ return roomShapeAdjacentGridIndexes;
262
303
  }
263
304
 
264
305
  /**
265
306
  * Helper function to get the room grid index delta that each hypothetical door in a given room
266
307
  * shape would go to.
267
308
  *
268
- * This is used by the `getRoomShapeNeighborGridIndexes` function.
309
+ * This is used by the `getRoomShapeAdjacentGridIndexes` function.
269
310
  *
270
311
  * @returns A map of `DoorSlot` to the corresponding room grid index delta.
271
312
  */
272
- export function getRoomShapeNeighborGridIndexDeltas(
313
+ export function getRoomShapeAdjacentGridIndexDeltas(
273
314
  roomShape: RoomShape,
274
315
  ): Map<DoorSlot, int> {
275
316
  return ROOM_SHAPE_TO_DOOR_SLOTS_TO_GRID_INDEX_DELTA[roomShape];
@@ -284,22 +325,51 @@ export function getRoomShapeNeighborGridIndexDeltas(
284
325
  * @param roomShape The shape of the room.
285
326
  * @returns A map of `DoorSlot` to the corresponding room grid index.
286
327
  */
287
- export function getRoomShapeNeighborGridIndexes(
328
+ export function getRoomShapeAdjacentGridIndexes(
288
329
  safeRoomGridIndex: int,
289
330
  roomShape: RoomShape,
290
331
  ): Map<DoorSlot, int> {
291
- const roomShapeNeighborGridIndexDeltas =
292
- getRoomShapeNeighborGridIndexDeltas(roomShape);
332
+ const roomShapeAdjacentGridIndexDeltas =
333
+ getRoomShapeAdjacentGridIndexDeltas(roomShape);
293
334
 
294
- const neighborGridIndexes = new Map<DoorSlot, int>();
295
- for (const [doorSlot, delta] of roomShapeNeighborGridIndexDeltas.entries()) {
335
+ const adjacentGridIndexes = new Map<DoorSlot, int>();
336
+ for (const [doorSlot, delta] of roomShapeAdjacentGridIndexDeltas.entries()) {
296
337
  const roomGridIndex = safeRoomGridIndex + delta;
297
338
  if (isRoomInsideGrid(roomGridIndex)) {
298
- neighborGridIndexes.set(doorSlot, roomGridIndex);
339
+ adjacentGridIndexes.set(doorSlot, roomGridIndex);
340
+ }
341
+ }
342
+
343
+ return adjacentGridIndexes;
344
+ }
345
+
346
+ /**
347
+ * Helper function to get only the adjacent room grid indexes for a room shape that do not exist
348
+ * (i.e. do not have room data).
349
+ *
350
+ * This is just a filtering of the results of the `getRoomShapeAdjacentGridIndexes` function. See
351
+ * that function for more information.
352
+ */
353
+ export function getRoomShapeAdjacentNonExistingGridIndexes(
354
+ safeRoomGridIndex: int,
355
+ roomShape: RoomShape,
356
+ ): Map<DoorSlot, int> {
357
+ const roomShapeAdjacentGridIndexes = getRoomShapeAdjacentGridIndexes(
358
+ safeRoomGridIndex,
359
+ roomShape,
360
+ );
361
+
362
+ for (const [
363
+ doorSlot,
364
+ roomGridIndex,
365
+ ] of roomShapeAdjacentGridIndexes.entries()) {
366
+ const roomData = getRoomData(roomGridIndex);
367
+ if (roomData !== undefined) {
368
+ roomShapeAdjacentGridIndexes.delete(doorSlot);
299
369
  }
300
370
  }
301
371
 
302
- return neighborGridIndexes;
372
+ return roomShapeAdjacentGridIndexes;
303
373
  }
304
374
 
305
375
  /**
@@ -315,15 +385,10 @@ export function getRoomShapeNeighborGridIndexes(
315
385
  * @param roomGridIndex Optional. Default is the current room index.
316
386
  */
317
387
  export function isDeadEnd(roomGridIndex?: int): boolean {
318
- const adjacentRoomGridIndexes = getAdjacentRoomGridIndexes(roomGridIndex);
319
- const adjacentRoomData = adjacentRoomGridIndexes.map(
320
- (adjacentRoomGridIndex) => getRoomData(adjacentRoomGridIndex),
321
- );
322
- const existingRoomData = adjacentRoomData.filter(
323
- (data): data is RoomConfig => data !== undefined,
324
- );
388
+ const adjacentNonExistingRoomGridIndexes =
389
+ getAdjacentNonExistingRoomGridIndexes(roomGridIndex);
325
390
 
326
- return existingRoomData.length === 1;
391
+ return adjacentNonExistingRoomGridIndexes.length === 1;
327
392
  }
328
393
 
329
394
  export function isDoorSlotValidAtGridIndex(
@@ -32,7 +32,7 @@ export interface CustomStageTSConfig {
32
32
  * https://isaacscript.github.io/main/custom-stages
33
33
  *
34
34
  * @minimum 101
35
- * @maximum 109
35
+ * @maximum 999
36
36
  */
37
37
  roomVariantPrefix: number;
38
38
 
@@ -18,7 +18,7 @@ export interface GridEntityCustomData {
18
18
 
19
19
  roomListIndex: int;
20
20
  gridIndex: int;
21
- anm2Path: string;
21
+ gridCollisionClass?: GridCollisionClass;
22
+ anm2Path?: string;
22
23
  defaultAnimation?: string;
23
- gridCollisionClass: GridCollisionClass;
24
24
  }
@@ -1,7 +1,5 @@
1
1
  import { RoomType } from "isaac-typescript-definitions";
2
2
 
3
- export const DEFAULT_ROOM_TYPE_NAME = "Unknown";
4
-
5
3
  export const ROOM_TYPE_NAMES: { readonly [key in RoomType]: string } = {
6
4
  [RoomType.DEFAULT]: "default room", // 1
7
5
  [RoomType.SHOP]: "shop", // 2