isaacscript-common 72.1.1 → 72.2.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.
@@ -5,6 +5,7 @@ import type {
5
5
  import { ItemPoolType } from "isaac-typescript-definitions";
6
6
  import { ITEM_POOL_TYPE_VALUES } from "../arrays/cachedEnumValues";
7
7
  import { game } from "../core/cachedClasses";
8
+ import { ITEM_POOL_TYPE_TO_COLLECTIBLE_TYPES_SET } from "../objects/itemPoolTypeToCollectibleTypesSet";
8
9
  import { arrayRemove, getRandomArrayElement } from "./array";
9
10
 
10
11
  const NORMAL_MODE_ONLY_ITEM_POOL_TYPES = [
@@ -41,6 +42,39 @@ const GREED_MODE_ITEM_POOL_TYPES: readonly ItemPoolType[] = arrayRemove(
41
42
  ...FAKE_ITEM_POOL_TYPES,
42
43
  );
43
44
 
45
+ /**
46
+ * Helper function to get the collectibles that are in a particular item pool at the beginning of a
47
+ * vanilla run.
48
+ */
49
+ export function getDefaultCollectibleTypesInItemPool(
50
+ itemPoolType: ItemPoolType,
51
+ ): Set<CollectibleType> {
52
+ return ITEM_POOL_TYPE_TO_COLLECTIBLE_TYPES_SET[itemPoolType];
53
+ }
54
+
55
+ /**
56
+ * Helper function to get the item pools that a particular collectible starts in at the beginning of
57
+ * a vanilla run.
58
+ *
59
+ * This function will automatically account for Greed Mode. In other words, it will not return the
60
+ * "normal" item pools when playing in Greed Mode.
61
+ */
62
+ export function getDefaultItemPoolsForCollectibleType(
63
+ collectibleType: CollectibleType,
64
+ ): ItemPoolType[] {
65
+ const itemPoolTypes: ItemPoolType[] = [];
66
+
67
+ for (const itemPoolType of ITEM_POOL_TYPE_VALUES) {
68
+ const collectibleTypesSet =
69
+ ITEM_POOL_TYPE_TO_COLLECTIBLE_TYPES_SET[itemPoolType];
70
+ if (collectibleTypesSet.has(collectibleType)) {
71
+ itemPoolTypes.push(itemPoolType);
72
+ }
73
+ }
74
+
75
+ return itemPoolTypes;
76
+ }
77
+
44
78
  /**
45
79
  * Helper function to get a random item pool. This is not as simple as getting a random value from
46
80
  * the `ItemPoolType` enum, since `ItemPoolType.SHELL_GAME` (7) is not a real item pool and the
@@ -432,6 +432,17 @@ export function getRoomShapeAdjacentNonExistingGridIndexes(
432
432
  return roomShapeAdjacentGridIndexes;
433
433
  }
434
434
 
435
+ /**
436
+ * Helper function to determine if the current room grid index is inside of the normal 13x13 level
437
+ * grid.
438
+ *
439
+ * For example, Devil Rooms and the Mega Satan room are not considered to be inside the grid.
440
+ */
441
+ export function inGrid(): boolean {
442
+ const roomGridIndex = getRoomGridIndex();
443
+ return isRoomInsideGrid(roomGridIndex);
444
+ }
445
+
435
446
  /**
436
447
  * Helper function to detect if the current room was created by the Red Key item.
437
448
  *
@@ -0,0 +1,36 @@
1
+ import { ItemPoolType } from "isaac-typescript-definitions";
2
+
3
+ /** From "itempools.xml". */
4
+ export const ITEM_POOL_TYPE_TO_ITEM_POOL_NAME = {
5
+ [ItemPoolType.TREASURE]: "treasure", // 0
6
+ [ItemPoolType.SHOP]: "shop", // 1
7
+ [ItemPoolType.BOSS]: "boss", // 2
8
+ [ItemPoolType.DEVIL]: "devil", // 3
9
+ [ItemPoolType.ANGEL]: "angel", // 4
10
+ [ItemPoolType.SECRET]: "secret", // 5
11
+ [ItemPoolType.LIBRARY]: "library", // 6
12
+ [ItemPoolType.SHELL_GAME]: "shellGame", // 7
13
+ [ItemPoolType.GOLDEN_CHEST]: "goldenChest", // 8
14
+ [ItemPoolType.RED_CHEST]: "redChest", // 9
15
+ [ItemPoolType.BEGGAR]: "beggar", // 10
16
+ [ItemPoolType.DEMON_BEGGAR]: "demonBeggar", // 11
17
+ [ItemPoolType.CURSE]: "curse", // 12
18
+ [ItemPoolType.KEY_MASTER]: "keyMaster", // 13
19
+ [ItemPoolType.BATTERY_BUM]: "batteryBum", // 14
20
+ [ItemPoolType.MOMS_CHEST]: "momsChest", // 15
21
+ [ItemPoolType.GREED_TREASURE]: "greedTreasure", // 16
22
+ [ItemPoolType.GREED_BOSS]: "greedBoss", // 17
23
+ [ItemPoolType.GREED_SHOP]: "greedShop", // 18
24
+ [ItemPoolType.GREED_DEVIL]: "greedDevil", // 19
25
+ [ItemPoolType.GREED_ANGEL]: "greedAngel", // 20
26
+ [ItemPoolType.GREED_CURSE]: "greedCurse", // 21
27
+ [ItemPoolType.GREED_SECRET]: "greedSecret", // 22
28
+ [ItemPoolType.CRANE_GAME]: "craneGame", // 23
29
+ [ItemPoolType.ULTRA_SECRET]: "ultraSecret", // 24
30
+ [ItemPoolType.BOMB_BUM]: "bombBum", // 25
31
+ [ItemPoolType.PLANETARIUM]: "planetarium", // 26
32
+ [ItemPoolType.OLD_CHEST]: "oldChest", // 27
33
+ [ItemPoolType.BABY_SHOP]: "babyShop", // 28
34
+ [ItemPoolType.WOODEN_CHEST]: "woodenChest", // 29
35
+ [ItemPoolType.ROTTEN_BEGGAR]: "rottenBeggar", // 30
36
+ } as const satisfies Record<ItemPoolType, string>;
@@ -0,0 +1,54 @@
1
+ import type {
2
+ CollectibleType,
3
+ ItemPoolType,
4
+ } from "isaac-typescript-definitions";
5
+ import { ITEM_POOL_TYPE_VALUES } from "../arrays/cachedEnumValues";
6
+ import itemPoolsJSON from "../data/itempools.json";
7
+ import { asCollectibleType } from "../functions/types";
8
+ import { ITEM_POOL_TYPE_TO_ITEM_POOL_NAME } from "../maps/itemPoolTypeToItemPoolName";
9
+
10
+ export const ITEM_POOL_TYPE_TO_COLLECTIBLE_TYPES_SET: Readonly<
11
+ Record<ItemPoolType, Set<CollectibleType>>
12
+ > = (() => {
13
+ const itemPoolTypeToCollectibleTypes: Partial<
14
+ Record<ItemPoolType, Set<CollectibleType>>
15
+ > = {};
16
+
17
+ for (const itemPoolType of ITEM_POOL_TYPE_VALUES) {
18
+ const itemPoolJSON = getItemPoolJSON(itemPoolType);
19
+ if (itemPoolJSON === undefined) {
20
+ itemPoolTypeToCollectibleTypes[itemPoolType] = new Set();
21
+ } else {
22
+ const collectibleTypesSet = new Set<CollectibleType>();
23
+
24
+ for (const itemPoolJSONElement of itemPoolJSON.Item) {
25
+ const collectibleTypeNumber = tonumber(itemPoolJSONElement.$.Id);
26
+ if (collectibleTypeNumber === undefined) {
27
+ error(
28
+ `Failed to parse a collectible type in the "itempools.json" file: ${itemPoolJSONElement.$.Id}`,
29
+ );
30
+ }
31
+
32
+ const collectibleType = asCollectibleType(collectibleTypeNumber);
33
+ collectibleTypesSet.add(collectibleType);
34
+ }
35
+
36
+ itemPoolTypeToCollectibleTypes[itemPoolType] = collectibleTypesSet;
37
+ }
38
+ }
39
+
40
+ return itemPoolTypeToCollectibleTypes as Record<
41
+ ItemPoolType,
42
+ Set<CollectibleType>
43
+ >;
44
+ })();
45
+
46
+ function getItemPoolJSON(itemPoolType: ItemPoolType) {
47
+ const itemPoolName = ITEM_POOL_TYPE_TO_ITEM_POOL_NAME[itemPoolType];
48
+
49
+ const itemPoolsJSONArray = itemPoolsJSON.ItemPools.Pool;
50
+
51
+ return itemPoolsJSONArray.find(
52
+ (itemPoolJSON) => itemPoolJSON.$.Name === itemPoolName,
53
+ );
54
+ }