isaacscript-common 21.2.0 → 21.3.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 (105) hide show
  1. package/dist/index.d.ts +174 -88
  2. package/dist/isaacscript-common.lua +529 -448
  3. package/dist/src/arrays/cachedEnumValues.d.ts +24 -0
  4. package/dist/src/arrays/cachedEnumValues.d.ts.map +1 -0
  5. package/dist/src/arrays/cachedEnumValues.lua +46 -0
  6. package/dist/src/callbackClasses.d.ts +1 -0
  7. package/dist/src/callbackClasses.d.ts.map +1 -1
  8. package/dist/src/callbackClasses.lua +5 -0
  9. package/dist/src/callbacks.d.ts +66 -65
  10. package/dist/src/callbacks.d.ts.map +1 -1
  11. package/dist/src/callbacks.lua +1 -0
  12. package/dist/src/classes/callbacks/PostItemDischarge.d.ts.map +1 -1
  13. package/dist/src/classes/callbacks/PostItemDischarge.lua +3 -4
  14. package/dist/src/classes/callbacks/PostKeyboardPressed.d.ts +14 -0
  15. package/dist/src/classes/callbacks/PostKeyboardPressed.d.ts.map +1 -0
  16. package/dist/src/classes/callbacks/PostKeyboardPressed.lua +49 -0
  17. package/dist/src/classes/callbacks/PostPlayerChangeHealth.d.ts.map +1 -1
  18. package/dist/src/classes/callbacks/PostPlayerChangeHealth.lua +3 -5
  19. package/dist/src/classes/callbacks/PostPlayerChangeStat.d.ts.map +1 -1
  20. package/dist/src/classes/callbacks/PostPlayerChangeStat.lua +3 -5
  21. package/dist/src/classes/callbacks/PostTransformation.d.ts.map +1 -1
  22. package/dist/src/classes/callbacks/PostTransformation.lua +3 -5
  23. package/dist/src/classes/features/callbackLogic/PlayerCollectibleDetection.lua +3 -4
  24. package/dist/src/classes/features/other/CustomStages.d.ts.map +1 -1
  25. package/dist/src/classes/features/other/DebugDisplay.d.ts +91 -19
  26. package/dist/src/classes/features/other/DebugDisplay.d.ts.map +1 -1
  27. package/dist/src/classes/features/other/DebugDisplay.lua +42 -38
  28. package/dist/src/classes/features/other/DeployJSONRoom.d.ts.map +1 -1
  29. package/dist/src/classes/features/other/DeployJSONRoom.lua +3 -5
  30. package/dist/src/classes/features/other/ExtraConsoleCommands.d.ts.map +1 -1
  31. package/dist/src/classes/features/other/ExtraConsoleCommands.lua +0 -1
  32. package/dist/src/classes/features/other/ModdedElementSets.d.ts.map +1 -1
  33. package/dist/src/classes/features/other/ModdedElementSets.lua +9 -7
  34. package/dist/src/classes/features/other/customStages/streakText.d.ts.map +1 -1
  35. package/dist/src/classes/features/other/customStages/streakText.lua +3 -4
  36. package/dist/src/classes/features/other/extraConsoleCommands/commands.d.ts.map +1 -1
  37. package/dist/src/classes/features/other/extraConsoleCommands/commands.lua +5 -7
  38. package/dist/src/enums/ModCallbackCustom.d.ts +74 -65
  39. package/dist/src/enums/ModCallbackCustom.d.ts.map +1 -1
  40. package/dist/src/enums/ModCallbackCustom.lua +67 -65
  41. package/dist/src/functions/doors.d.ts.map +1 -1
  42. package/dist/src/functions/doors.lua +5 -6
  43. package/dist/src/functions/input.d.ts.map +1 -1
  44. package/dist/src/functions/input.lua +4 -6
  45. package/dist/src/functions/level.d.ts.map +1 -1
  46. package/dist/src/functions/level.lua +3 -5
  47. package/dist/src/functions/pills.d.ts.map +1 -1
  48. package/dist/src/functions/pills.lua +3 -5
  49. package/dist/src/functions/playerHealth.d.ts.map +1 -1
  50. package/dist/src/functions/playerHealth.lua +3 -4
  51. package/dist/src/functions/players.d.ts.map +1 -1
  52. package/dist/src/functions/players.lua +6 -7
  53. package/dist/src/functions/pocketItems.d.ts.map +1 -1
  54. package/dist/src/functions/pocketItems.lua +3 -5
  55. package/dist/src/functions/roomData.d.ts +1 -1
  56. package/dist/src/functions/roomData.d.ts.map +1 -1
  57. package/dist/src/functions/roomData.lua +3 -6
  58. package/dist/src/functions/roomShapeWalls.lua +3 -3
  59. package/dist/src/functions/serialization.lua +3 -6
  60. package/dist/src/functions/sound.d.ts.map +1 -1
  61. package/dist/src/functions/sound.lua +3 -3
  62. package/dist/src/functions/transformations.d.ts.map +1 -1
  63. package/dist/src/functions/transformations.lua +4 -5
  64. package/dist/src/index.d.ts +1 -0
  65. package/dist/src/index.d.ts.map +1 -1
  66. package/dist/src/interfaces/CustomStageTSConfig.d.ts +8 -7
  67. package/dist/src/interfaces/CustomStageTSConfig.d.ts.map +1 -1
  68. package/dist/src/interfaces/private/AddCallbackParametersCustom.d.ts +5 -1
  69. package/dist/src/interfaces/private/AddCallbackParametersCustom.d.ts.map +1 -1
  70. package/dist/src/patchErrorFunctions.lua +3 -3
  71. package/package.json +2 -2
  72. package/src/arrays/cachedEnumValues.ts +75 -0
  73. package/src/callbackClasses.ts +1 -0
  74. package/src/callbacks.ts +1 -0
  75. package/src/classes/ModFeature.ts +4 -1
  76. package/src/classes/callbacks/PostItemDischarge.ts +2 -2
  77. package/src/classes/callbacks/PostKeyboardPressed.ts +52 -0
  78. package/src/classes/callbacks/PostPlayerChangeHealth.ts +2 -2
  79. package/src/classes/callbacks/PostPlayerChangeStat.ts +2 -2
  80. package/src/classes/callbacks/PostTransformation.ts +2 -2
  81. package/src/classes/features/callbackLogic/PlayerCollectibleDetection.ts +2 -2
  82. package/src/classes/features/other/CustomStages.ts +1 -1
  83. package/src/classes/features/other/DebugDisplay.ts +120 -39
  84. package/src/classes/features/other/DeployJSONRoom.ts +2 -3
  85. package/src/classes/features/other/ExtraConsoleCommands.ts +2 -1
  86. package/src/classes/features/other/ModdedElementSets.ts +10 -6
  87. package/src/classes/features/other/customStages/streakText.ts +2 -2
  88. package/src/classes/features/other/extraConsoleCommands/commands.ts +6 -7
  89. package/src/enums/ModCallbackCustom.ts +10 -0
  90. package/src/functions/doors.ts +7 -4
  91. package/src/functions/input.ts +3 -5
  92. package/src/functions/level.ts +2 -3
  93. package/src/functions/pills.ts +2 -4
  94. package/src/functions/playerHealth.ts +2 -2
  95. package/src/functions/players.ts +7 -6
  96. package/src/functions/pocketItems.ts +2 -3
  97. package/src/functions/roomData.ts +3 -8
  98. package/src/functions/roomShapeWalls.ts +2 -2
  99. package/src/functions/serialization.ts +4 -4
  100. package/src/functions/sound.ts +2 -1
  101. package/src/functions/transformations.ts +3 -4
  102. package/src/index.ts +1 -0
  103. package/src/interfaces/CustomStageTSConfig.ts +8 -7
  104. package/src/interfaces/private/AddCallbackParametersCustom.ts +6 -0
  105. package/src/patchErrorFunctions.ts +1 -9
@@ -6,14 +6,16 @@ import {
6
6
  NullItemID,
7
7
  PlayerForm,
8
8
  PlayerType,
9
- TrinketSlot,
10
9
  TrinketType,
11
10
  } from "isaac-typescript-definitions";
11
+ import {
12
+ ACTIVE_SLOT_VALUES,
13
+ TRINKET_SLOT_VALUES,
14
+ } from "../arrays/cachedEnumValues";
12
15
  import { game, itemConfig } from "../core/cachedClasses";
13
16
  import { getLastElement, sumArray } from "./array";
14
17
  import { getCharacterName, isVanillaCharacter } from "./characters";
15
18
  import { getCollectibleMaxCharges } from "./collectibles";
16
- import { getEnumValues } from "./enums";
17
19
  import {
18
20
  getAllPlayers,
19
21
  getPlayerIndexVanilla,
@@ -119,8 +121,7 @@ export function getActiveItemSlot(
119
121
  player: EntityPlayer,
120
122
  collectibleType: CollectibleType,
121
123
  ): ActiveSlot | undefined {
122
- const activeSlots = getEnumValues(ActiveSlot);
123
- return activeSlots.find((activeSlot) => {
124
+ return ACTIVE_SLOT_VALUES.find((activeSlot) => {
124
125
  const activeItem = player.GetActiveItem(activeSlot);
125
126
  return activeItem === collectibleType;
126
127
  });
@@ -660,7 +661,7 @@ export function playerHasForm(
660
661
  * and any pocket actives.
661
662
  */
662
663
  export function removeAllActiveItems(player: EntityPlayer): void {
663
- for (const activeSlot of getEnumValues(ActiveSlot)) {
664
+ for (const activeSlot of ACTIVE_SLOT_VALUES) {
664
665
  const collectibleType = player.GetActiveItem(activeSlot);
665
666
  if (collectibleType === CollectibleType.NULL) {
666
667
  continue;
@@ -681,7 +682,7 @@ export function removeAllActiveItems(player: EntityPlayer): void {
681
682
  * they also have smelted. (In that case, both the held and the smelted trinket will be removed.)
682
683
  */
683
684
  export function removeAllPlayerTrinkets(player: EntityPlayer): void {
684
- for (const trinketSlot of getEnumValues(TrinketSlot)) {
685
+ for (const trinketSlot of TRINKET_SLOT_VALUES) {
685
686
  const trinketType = player.GetTrinket(trinketSlot);
686
687
  if (trinketType === TrinketType.NULL) {
687
688
  continue;
@@ -6,9 +6,9 @@ import {
6
6
  PlayerType,
7
7
  PocketItemSlot,
8
8
  } from "isaac-typescript-definitions";
9
+ import { POCKET_ITEM_SLOT_VALUES } from "../arrays/cachedEnumValues";
9
10
  import { PocketItemType } from "../enums/PocketItemType";
10
11
  import { PocketItemDescription } from "../interfaces/PocketItemDescription";
11
- import { getEnumValues } from "./enums";
12
12
  import { isCharacter } from "./players";
13
13
  import { asNumber } from "./types";
14
14
 
@@ -58,12 +58,11 @@ export function getPocketItems(player: EntityPlayer): PocketItemDescription[] {
58
58
  const hasPocketItem2 = pocketItem2 !== CollectibleType.NULL;
59
59
 
60
60
  const maxPocketItems = player.GetMaxPocketItems();
61
- const pocketItemSlots = getEnumValues(PocketItemSlot);
62
61
 
63
62
  const pocketItems: PocketItemDescription[] = [];
64
63
  let pocketItemIdentified = false;
65
64
  let pocketItem2Identified = false;
66
- for (const slot of pocketItemSlots) {
65
+ for (const slot of POCKET_ITEM_SLOT_VALUES) {
67
66
  const cardType = player.GetCard(slot);
68
67
  const pillColor = player.GetPill(slot);
69
68
 
@@ -1,13 +1,12 @@
1
1
  import {
2
2
  DoorSlot,
3
- DoorSlotFlag,
4
3
  RoomShape,
5
4
  RoomType,
6
5
  StageID,
7
6
  } from "isaac-typescript-definitions";
7
+ import { DOOR_SLOT_FLAG_VALUES } from "../arrays/cachedEnumValues";
8
8
  import { game } from "../core/cachedClasses";
9
9
  import { doorSlotFlagToDoorSlot } from "./doors";
10
- import { getEnumValues } from "./enums";
11
10
  import { hasFlag } from "./flag";
12
11
 
13
12
  /**
@@ -22,8 +21,7 @@ export function getRoomAllowedDoors(roomGridIndex?: int): Set<DoorSlot> {
22
21
  return allowedDoors;
23
22
  }
24
23
 
25
- const doorSlotFlags = getEnumValues(DoorSlotFlag);
26
- for (const doorSlotFlag of doorSlotFlags) {
24
+ for (const doorSlotFlag of DOOR_SLOT_FLAG_VALUES) {
27
25
  if (hasFlag(roomData.Doors, doorSlotFlag)) {
28
26
  const doorSlot = doorSlotFlagToDoorSlot(doorSlotFlag);
29
27
  allowedDoors.add(doorSlot);
@@ -203,10 +201,7 @@ export function getRoomVisitedCount(roomGridIndex?: int): int {
203
201
  * Helper function to set the data for a given room. This will change the room type, contents, and
204
202
  * so on.
205
203
  */
206
- export function setRoomData(
207
- roomGridIndex: int,
208
- roomData: Readonly<RoomConfig>,
209
- ): void {
204
+ export function setRoomData(roomGridIndex: int, roomData: RoomConfig): void {
210
205
  const roomDescriptor = getRoomDescriptor(roomGridIndex);
211
206
  roomDescriptor.Data = roomData;
212
207
  }
@@ -1,8 +1,8 @@
1
1
  import { BossID, RoomShape } from "isaac-typescript-definitions";
2
+ import { ROOM_SHAPE_VALUES } from "../arrays/cachedEnumValues";
2
3
  import { game } from "../core/cachedClasses";
3
4
  import { CornerType } from "../enums/CornerType";
4
5
  import { Corner } from "../interfaces/Corner";
5
- import { getEnumValues } from "./enums";
6
6
  import { getGridIndexesBetween } from "./gridIndex";
7
7
  import { inBossRoomOf, inHomeCloset } from "./rooms";
8
8
  import { getRoomShapeCorners, isLRoom } from "./roomShape";
@@ -13,7 +13,7 @@ const ROOM_SHAPE_TO_WALL_GRID_INDEX_SET: ReadonlyMap<
13
13
  > = (() => {
14
14
  const roomShapeToWallGridIndexSet = new Map<RoomShape, ReadonlySet<int>>();
15
15
 
16
- for (const roomShape of getEnumValues(RoomShape)) {
16
+ for (const roomShape of ROOM_SHAPE_VALUES) {
17
17
  const gridIndexSet = getVanillaWallGridIndexSetForRoomShape(roomShape);
18
18
  roomShapeToWallGridIndexSet.set(roomShape, gridIndexSet);
19
19
  }
@@ -1,5 +1,5 @@
1
1
  import { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
2
- import { SerializationBrand } from "../enums/SerializationBrand";
2
+ import { SERIALIZATION_BRAND_VALUES } from "../arrays/cachedEnumValues";
3
3
  import { ISAAC_API_CLASS_TYPE_TO_BRAND } from "../objects/isaacAPIClassTypeToBrand";
4
4
  import {
5
5
  CopyableIsaacAPIClass,
@@ -10,12 +10,12 @@ import {
10
10
  SerializedIsaacAPIClass,
11
11
  } from "../objects/isaacAPIClassTypeToFunctions";
12
12
  import { ReadonlySet } from "../types/ReadonlySet";
13
- import { getEnumValues } from "./enums";
14
13
  import { getIsaacAPIClassName } from "./isaacAPIClass";
15
14
  import { isString, isTable, isUserdata } from "./types";
16
15
 
17
- const SERIALIZATION_BRANDS = getEnumValues(SerializationBrand);
18
- const SERIALIZATION_BRAND_SET = new ReadonlySet<string>(SERIALIZATION_BRANDS);
16
+ const SERIALIZATION_BRAND_SET = new ReadonlySet<string>(
17
+ SERIALIZATION_BRAND_VALUES,
18
+ );
19
19
 
20
20
  /**
21
21
  * Helper function to generically copy an Isaac API class without knowing what specific type of
@@ -4,6 +4,7 @@ import {
4
4
  SoundEffect,
5
5
  StageType,
6
6
  } from "isaac-typescript-definitions";
7
+ import { SOUND_EFFECT_VALUES } from "../arrays/cachedEnumValues";
7
8
  import { game, sfxManager } from "../core/cachedClasses";
8
9
  import { STAGE_TO_MUSIC } from "../objects/stageToMusic";
9
10
  import { getEnumValues } from "./enums";
@@ -42,7 +43,7 @@ export function getMusicForStage(
42
43
  * your mod.
43
44
  */
44
45
  export function stopAllSoundEffects(soundEffectCustom?: unknown): void {
45
- for (const soundEffect of getEnumValues(SoundEffect)) {
46
+ for (const soundEffect of SOUND_EFFECT_VALUES) {
46
47
  sfxManager.Stop(soundEffect);
47
48
  }
48
49
 
@@ -3,11 +3,11 @@ import {
3
3
  ItemConfigTag,
4
4
  PlayerForm,
5
5
  } from "isaac-typescript-definitions";
6
+ import { PLAYER_FORM_VALUES } from "../arrays/cachedEnumValues";
6
7
  import { TRANSFORMATION_NAMES } from "../objects/transformationNames";
7
8
  import { ReadonlyMap } from "../types/ReadonlyMap";
8
9
  import { ReadonlySet } from "../types/ReadonlySet";
9
10
  import { getCollectibleTags } from "./collectibles";
10
- import { getEnumValues } from "./enums";
11
11
  import { hasFlag } from "./flag";
12
12
 
13
13
  const TRANSFORMATION_TO_TAG_MAP = new ReadonlyMap<PlayerForm, ItemConfigTag>([
@@ -39,7 +39,7 @@ export function getPlayerTransformations(
39
39
  player: EntityPlayer,
40
40
  ): Set<PlayerForm> {
41
41
  const transformations = new Set<PlayerForm>();
42
- for (const playerForm of getEnumValues(PlayerForm)) {
42
+ for (const playerForm of PLAYER_FORM_VALUES) {
43
43
  if (player.HasPlayerForm(playerForm)) {
44
44
  transformations.add(playerForm);
45
45
  }
@@ -71,9 +71,8 @@ export function getTransformationsForCollectibleType(
71
71
  ): Set<PlayerForm> {
72
72
  const itemConfigTags = getCollectibleTags(collectibleType);
73
73
 
74
- const playerForms = getEnumValues(PlayerForm);
75
74
  const transformationSet = new Set<PlayerForm>();
76
- for (const playerForm of playerForms) {
75
+ for (const playerForm of PLAYER_FORM_VALUES) {
77
76
  const itemConfigTag = TRANSFORMATION_TO_TAG_MAP.get(playerForm);
78
77
  if (itemConfigTag === undefined) {
79
78
  continue;
package/src/index.ts CHANGED
@@ -134,6 +134,7 @@ export * from "./interfaces/RoomDescription";
134
134
  export * from "./interfaces/SaveData";
135
135
  export * from "./interfaces/StatTypeType";
136
136
  export * from "./interfaces/TrinketSituation";
137
+ export * from "./interfaces/TSTLClassMetatable";
137
138
  export * from "./maps/cardNameToTypeMap";
138
139
  export * from "./maps/characterNameToTypeMap";
139
140
  export * from "./maps/pillNameToEffectMap";
@@ -568,13 +568,7 @@ export interface CustomStageBossPoolEntry {
568
568
  };
569
569
  }
570
570
 
571
- /**
572
- * An object that represents a custom stage. The "customStageMetadata.lua" file contains an array of
573
- * these objects. Besides the room metadata, the data is the same as what is specified inside the
574
- * "tsconfig.json" file.
575
- *
576
- * The `CustomStage` interface extends this, adding more data.
577
- */
571
+ /** An intermediate type that is never actually used. See `CustomStageLua`. */
578
572
  interface CustomStageLuaUnsafe extends CustomStageTSConfig {
579
573
  /**
580
574
  * This contains metadata about each room in a custom stage, which is used at run-time.
@@ -584,6 +578,13 @@ interface CustomStageLuaUnsafe extends CustomStageTSConfig {
584
578
  roomsMetadata: CustomStageRoomMetadata[];
585
579
  }
586
580
 
581
+ /**
582
+ * An object that represents a custom stage. The "customStageMetadata.lua" file contains an array of
583
+ * these objects. Besides the room metadata, the data is the same as what is specified inside the
584
+ * "tsconfig.json" file.
585
+ *
586
+ * The `CustomStage` interface extends this, adding more data.
587
+ */
587
588
  export type CustomStageLua = Immutable<CustomStageLuaUnsafe>;
588
589
 
589
590
  /**
@@ -13,6 +13,7 @@ import {
13
13
  GridEntityXMLType,
14
14
  InputHook,
15
15
  ItemType,
16
+ Keyboard,
16
17
  KnifeVariant,
17
18
  LaserVariant,
18
19
  PickupVariant,
@@ -366,6 +367,11 @@ export interface AddCallbackParametersCustom {
366
367
  trinketType?: TrinketType,
367
368
  ];
368
369
 
370
+ [ModCallbackCustom.POST_KEYBOARD_PRESSED]: [
371
+ callback: (keyboard: Keyboard) => void,
372
+ keyboard?: Keyboard,
373
+ ];
374
+
369
375
  [ModCallbackCustom.POST_KNIFE_INIT_LATE]: [
370
376
  callback: (knife: EntityKnife) => void,
371
377
  knifeVariant?: KnifeVariant,
@@ -46,19 +46,11 @@ export function patchErrorFunction(): void {
46
46
  error = errorWithTraceback;
47
47
  }
48
48
 
49
- function errorWithTraceback(
50
- this: void,
51
- message: string,
52
- level?: number,
53
- ): never {
49
+ function errorWithTraceback(this: void, message: string, level = 1): never {
54
50
  if (vanillaError === undefined) {
55
51
  error(message, level);
56
52
  }
57
53
 
58
- if (level === undefined) {
59
- level = 1;
60
- }
61
-
62
54
  const tracebackOutput = getTraceback();
63
55
  const slimmedTracebackOutput = slimTracebackOutput(tracebackOutput);
64
56
  message += "\n";