isaacscript-common 21.6.6 → 21.8.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 (49) hide show
  1. package/dist/index.rollup.d.ts +160 -99
  2. package/dist/isaacscript-common.lua +4200 -4036
  3. package/dist/src/arrays/cachedEnumValues.d.ts +2 -1
  4. package/dist/src/arrays/cachedEnumValues.d.ts.map +1 -1
  5. package/dist/src/arrays/cachedEnumValues.lua +2 -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 +54 -53
  10. package/dist/src/callbacks.d.ts.map +1 -1
  11. package/dist/src/callbacks.lua +1 -0
  12. package/dist/src/classes/callbacks/PostPickupChanged.d.ts +8 -0
  13. package/dist/src/classes/callbacks/PostPickupChanged.d.ts.map +1 -0
  14. package/dist/src/classes/callbacks/PostPickupChanged.lua +20 -0
  15. package/dist/src/classes/features/callbackLogic/PickupChangeDetection.d.ts +18 -0
  16. package/dist/src/classes/features/callbackLogic/PickupChangeDetection.d.ts.map +1 -0
  17. package/dist/src/classes/features/callbackLogic/PickupChangeDetection.lua +47 -0
  18. package/dist/src/enums/ISCFeature.d.ts +47 -46
  19. package/dist/src/enums/ISCFeature.d.ts.map +1 -1
  20. package/dist/src/enums/ISCFeature.lua +48 -46
  21. package/dist/src/enums/ModCallbackCustom.d.ts +74 -53
  22. package/dist/src/enums/ModCallbackCustom.d.ts.map +1 -1
  23. package/dist/src/enums/ModCallbackCustom.lua +55 -53
  24. package/dist/src/features.d.ts +49 -46
  25. package/dist/src/features.d.ts.map +1 -1
  26. package/dist/src/features.lua +3 -0
  27. package/dist/src/functions/itemPool.d.ts +8 -0
  28. package/dist/src/functions/itemPool.d.ts.map +1 -0
  29. package/dist/src/functions/itemPool.lua +63 -0
  30. package/dist/src/index.d.ts +1 -0
  31. package/dist/src/index.d.ts.map +1 -1
  32. package/dist/src/index.lua +8 -0
  33. package/dist/src/interfaces/private/AddCallbackParametersCustom.d.ts +5 -0
  34. package/dist/src/interfaces/private/AddCallbackParametersCustom.d.ts.map +1 -1
  35. package/dist/src/shouldFire.d.ts +7 -1
  36. package/dist/src/shouldFire.d.ts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/arrays/cachedEnumValues.ts +4 -0
  39. package/src/callbackClasses.ts +1 -0
  40. package/src/callbacks.ts +1 -0
  41. package/src/classes/callbacks/PostPickupChanged.ts +14 -0
  42. package/src/classes/features/callbackLogic/PickupChangeDetection.ts +61 -0
  43. package/src/enums/ISCFeature.ts +1 -0
  44. package/src/enums/ModCallbackCustom.ts +22 -0
  45. package/src/features.ts +6 -0
  46. package/src/functions/itemPool.ts +50 -0
  47. package/src/index.ts +1 -0
  48. package/src/interfaces/private/AddCallbackParametersCustom.ts +12 -0
  49. package/src/shouldFire.ts +8 -1
@@ -10,6 +10,7 @@ import {
10
10
  GridEntityXMLType,
11
11
  ItemConfigCardType,
12
12
  ItemConfigTag,
13
+ ItemPoolType,
13
14
  Keyboard,
14
15
  PillColor,
15
16
  PlayerForm,
@@ -48,6 +49,9 @@ export const ITEM_CONFIG_TAG_VALUES: readonly ItemConfigTag[] =
48
49
  export const ITEM_CONFIG_CARD_TYPE_VALUES: readonly ItemConfigCardType[] =
49
50
  getEnumValues(ItemConfigCardType);
50
51
 
52
+ export const ITEM_POOL_TYPE_VALUES: readonly ItemPoolType[] =
53
+ getEnumValues(ItemPoolType);
54
+
51
55
  export const KEYBOARD_VALUES: readonly Keyboard[] = getEnumValues(Keyboard);
52
56
 
53
57
  export const HEALTH_TYPE_VALUES: readonly HealthType[] =
@@ -58,6 +58,7 @@ export { PostNPCRenderFilter } from "./classes/callbacks/PostNPCRenderFilter";
58
58
  export { PostNPCStateChanged } from "./classes/callbacks/PostNPCStateChanged";
59
59
  export { PostNPCUpdateFilter } from "./classes/callbacks/PostNPCUpdateFilter";
60
60
  export { PostPEffectUpdateReordered } from "./classes/callbacks/PostPEffectUpdateReordered";
61
+ export { PostPickupChanged } from "./classes/callbacks/PostPickupChanged";
61
62
  export { PostPickupCollect } from "./classes/callbacks/PostPickupCollect";
62
63
  export { PostPickupInitFilter } from "./classes/callbacks/PostPickupInitFilter";
63
64
  export { PostPickupInitFirst } from "./classes/callbacks/PostPickupInitFirst";
package/src/callbacks.ts CHANGED
@@ -70,6 +70,7 @@ const MOD_CALLBACK_CUSTOM_TO_CLASS = {
70
70
  [ModCallbackCustom.POST_NPC_UPDATE_FILTER]: cc.PostNPCUpdateFilter,
71
71
  [ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED]:
72
72
  cc.PostPEffectUpdateReordered,
73
+ [ModCallbackCustom.POST_PICKUP_CHANGED]: cc.PostPickupChanged,
73
74
  [ModCallbackCustom.POST_PICKUP_COLLECT]: cc.PostPickupCollect,
74
75
  [ModCallbackCustom.POST_PICKUP_INIT_FILTER]: cc.PostPickupInitFilter,
75
76
  [ModCallbackCustom.POST_PICKUP_INIT_FIRST]: cc.PostPickupInitFirst,
@@ -0,0 +1,14 @@
1
+ import { ISCFeature } from "../../enums/ISCFeature";
2
+ import { ModCallbackCustom } from "../../enums/ModCallbackCustom";
3
+ import { shouldFirePickup } from "../../shouldFire";
4
+ import { CustomCallback } from "../private/CustomCallback";
5
+
6
+ export class PostPickupChanged extends CustomCallback<ModCallbackCustom.POST_PICKUP_CHANGED> {
7
+ constructor() {
8
+ super();
9
+
10
+ this.featuresUsed = [ISCFeature.PICKUP_CHANGE_DETECTION];
11
+ }
12
+
13
+ protected override shouldFire = shouldFirePickup;
14
+ }
@@ -0,0 +1,61 @@
1
+ import { ModCallback, PickupVariant } from "isaac-typescript-definitions";
2
+ import { ISCFeature } from "../../../enums/ISCFeature";
3
+ import { PickupIndex } from "../../../types/PickupIndex";
4
+ import { PostPickupChanged } from "../../callbacks/PostPickupChanged";
5
+ import { Feature } from "../../private/Feature";
6
+ import { PickupIndexCreation } from "../other/PickupIndexCreation";
7
+
8
+ export class PickupChangeDetection extends Feature {
9
+ public override v = {
10
+ room: {
11
+ pickupVariants: new Map<PickupIndex, PickupVariant>(),
12
+ pickupSubTypes: new Map<PickupIndex, int>(),
13
+ },
14
+ };
15
+
16
+ private postPickupChanged: PostPickupChanged;
17
+ private pickupIndexCreation: PickupIndexCreation;
18
+
19
+ constructor(
20
+ postPickupChanged: PostPickupChanged,
21
+ pickupIndexCreation: PickupIndexCreation,
22
+ ) {
23
+ super();
24
+
25
+ this.featuresUsed = [ISCFeature.PICKUP_INDEX_CREATION];
26
+
27
+ this.callbacksUsed = [
28
+ // 35
29
+ [ModCallback.POST_PICKUP_UPDATE, this.postPickupUpdate],
30
+ ];
31
+
32
+ this.postPickupChanged = postPickupChanged;
33
+ this.pickupIndexCreation = pickupIndexCreation;
34
+ }
35
+
36
+ // ModCallback.POST_PICKUP_UPDATE (35)
37
+ private postPickupUpdate = (pickup: EntityPickup) => {
38
+ const pickupIndex = this.pickupIndexCreation.getPickupIndex(pickup);
39
+
40
+ const oldVariant = this.v.room.pickupVariants.get(pickupIndex);
41
+ this.v.room.pickupVariants.set(pickupIndex, pickup.Variant);
42
+
43
+ const oldSubType = this.v.room.pickupSubTypes.get(pickupIndex);
44
+ this.v.room.pickupSubTypes.set(pickupIndex, pickup.SubType);
45
+
46
+ // If this is the first update frame for the pickup, it cannot have changed.
47
+ if (oldVariant === undefined || oldSubType === undefined) {
48
+ return;
49
+ }
50
+
51
+ if (oldVariant !== pickup.Variant || oldSubType !== pickup.SubType) {
52
+ this.postPickupChanged.fire(
53
+ pickup,
54
+ oldVariant,
55
+ oldSubType,
56
+ pickup.Variant,
57
+ pickup.SubType,
58
+ );
59
+ }
60
+ };
61
+ }
@@ -8,6 +8,7 @@ export enum ISCFeature {
8
8
  GRID_ENTITY_UPDATE_DETECTION,
9
9
  GAME_REORDERED_CALLBACKS,
10
10
  ITEM_PICKUP_DETECTION,
11
+ PICKUP_CHANGE_DETECTION,
11
12
  PLAYER_COLLECTIBLE_DETECTION,
12
13
  PLAYER_REORDERED_CALLBACKS,
13
14
  SLOT_DESTROYED_DETECTION,
@@ -1058,6 +1058,28 @@ export enum ModCallbackCustom {
1058
1058
  */
1059
1059
  POST_PEFFECT_UPDATE_REORDERED,
1060
1060
 
1061
+ /**
1062
+ * Fires from the `POST_PICKUP_UPDATE` callback when a pickup has a different variant or sub-type
1063
+ * than what it was on the previous frame.
1064
+ *
1065
+ * When registering the callback with the `ModUpgraded.AddCallbackCustom` method:
1066
+ * - You can provide an optional third argument that will make the callback only fire if the new
1067
+ * pickup matches the `PickupVariant` provided.
1068
+ * - You can provide an optional third argument that will make the callback only fire if the new
1069
+ * pickup matches the sub-type provided.
1070
+ *
1071
+ * ```ts
1072
+ * function postPickupChanged(
1073
+ * pickup: EntityPickup,
1074
+ * oldVariant: PickupVariant,
1075
+ * oldSubType: int,
1076
+ * newVariant: PickupVariant,
1077
+ * newSubType: int,
1078
+ * ): void {}
1079
+ * ```
1080
+ */
1081
+ POST_PICKUP_CHANGED,
1082
+
1061
1083
  /**
1062
1084
  * Fires on the first `POST_RENDER` frame that a pickup plays the "Collect" animation.
1063
1085
  *
package/src/features.ts CHANGED
@@ -8,6 +8,7 @@ import { GridEntityCollisionDetection } from "./classes/features/callbackLogic/G
8
8
  import { GridEntityRenderDetection } from "./classes/features/callbackLogic/GridEntityRenderDetection";
9
9
  import { GridEntityUpdateDetection } from "./classes/features/callbackLogic/GridEntityUpdateDetection";
10
10
  import { ItemPickupDetection } from "./classes/features/callbackLogic/ItemPickupDetection";
11
+ import { PickupChangeDetection } from "./classes/features/callbackLogic/PickupChangeDetection";
11
12
  import { PlayerCollectibleDetection } from "./classes/features/callbackLogic/PlayerCollectibleDetection";
12
13
  import { PlayerReorderedCallbacks } from "./classes/features/callbackLogic/PlayerReorderedCallbacks";
13
14
  import { SlotDestroyedDetection } from "./classes/features/callbackLogic/SlotDestroyedDetection";
@@ -69,6 +70,7 @@ export interface ISCFeatureToClass {
69
70
  [ISCFeature.GRID_ENTITY_UPDATE_DETECTION]: GridEntityUpdateDetection;
70
71
  [ISCFeature.GAME_REORDERED_CALLBACKS]: GameReorderedCallbacks;
71
72
  [ISCFeature.ITEM_PICKUP_DETECTION]: ItemPickupDetection;
73
+ [ISCFeature.PICKUP_CHANGE_DETECTION]: PickupChangeDetection;
72
74
  [ISCFeature.PLAYER_COLLECTIBLE_DETECTION]: PlayerCollectibleDetection;
73
75
  [ISCFeature.PLAYER_REORDERED_CALLBACKS]: PlayerReorderedCallbacks;
74
76
  [ISCFeature.SLOT_DESTROYED_DETECTION]: SlotDestroyedDetection;
@@ -213,6 +215,10 @@ export function getFeatures(
213
215
  callbacks[ModCallbackCustom.POST_ITEM_PICKUP],
214
216
  callbacks[ModCallbackCustom.PRE_ITEM_PICKUP],
215
217
  ),
218
+ [ISCFeature.PICKUP_CHANGE_DETECTION]: new PickupChangeDetection(
219
+ callbacks[ModCallbackCustom.POST_PICKUP_CHANGED],
220
+ pickupIndexCreation,
221
+ ),
216
222
  [ISCFeature.PLAYER_COLLECTIBLE_DETECTION]: new PlayerCollectibleDetection(
217
223
  callbacks[ModCallbackCustom.POST_PLAYER_COLLECTIBLE_ADDED],
218
224
  callbacks[ModCallbackCustom.POST_PLAYER_COLLECTIBLE_REMOVED],
@@ -0,0 +1,50 @@
1
+ import { ItemPoolType } from "isaac-typescript-definitions";
2
+ import { ITEM_POOL_TYPE_VALUES } from "../arrays/cachedEnumValues";
3
+ import { arrayRemove, getRandomArrayElement } from "./array";
4
+ import { isGreedMode } from "./run";
5
+
6
+ const NORMAL_MODE_ONLY_ITEM_POOL_TYPES = [
7
+ ItemPoolType.TREASURE, // 0
8
+ ItemPoolType.BOSS, // 2
9
+ ItemPoolType.SHOP, // 1
10
+ ItemPoolType.DEVIL, // 3
11
+ ItemPoolType.ANGEL, // 4
12
+ ItemPoolType.CURSE, // 12
13
+ ItemPoolType.SECRET, // 5
14
+ ] as const;
15
+
16
+ const GREED_MODE_ONLY_ITEM_POOL_TYPES = [
17
+ ItemPoolType.GREED_TREASURE, // 16
18
+ ItemPoolType.GREED_BOSS, // 17
19
+ ItemPoolType.GREED_SHOP, // 18
20
+ ItemPoolType.GREED_DEVIL, // 19
21
+ ItemPoolType.GREED_ANGEL, // 20
22
+ ItemPoolType.GREED_CURSE, // 21
23
+ ItemPoolType.GREED_SECRET, // 22
24
+ ] as const;
25
+
26
+ const FAKE_ITEM_POOL_TYPES = [ItemPoolType.SHELL_GAME] as const;
27
+
28
+ const NORMAL_MODE_ITEM_POOL_TYPES: readonly ItemPoolType[] = arrayRemove(
29
+ ITEM_POOL_TYPE_VALUES,
30
+ ...GREED_MODE_ONLY_ITEM_POOL_TYPES,
31
+ ...FAKE_ITEM_POOL_TYPES,
32
+ );
33
+
34
+ const GREED_MODE_ITEM_POOL_TYPES: readonly ItemPoolType[] = arrayRemove(
35
+ ITEM_POOL_TYPE_VALUES,
36
+ ...NORMAL_MODE_ONLY_ITEM_POOL_TYPES,
37
+ ...FAKE_ITEM_POOL_TYPES,
38
+ );
39
+
40
+ /**
41
+ * Helper function to get a random item pool. This is as simple as getting a random value from the
42
+ * `ItemPoolType` enum, since `ItemPoolType.SHELL_GAME` (7) is not a real item pool and the Greed
43
+ * Mode item pools should be excluded if not playing in Greed Mode.
44
+ */
45
+ export function getRandomItemPool(): ItemPoolType {
46
+ const itemPoolTypes = isGreedMode()
47
+ ? GREED_MODE_ITEM_POOL_TYPES
48
+ : NORMAL_MODE_ITEM_POOL_TYPES;
49
+ return getRandomArrayElement(itemPoolTypes);
50
+ }
package/src/index.ts CHANGED
@@ -61,6 +61,7 @@ export * from "./functions/hex";
61
61
  export * from "./functions/initArray";
62
62
  export * from "./functions/input";
63
63
  export * from "./functions/isaacAPIClass";
64
+ export * from "./functions/itemPool";
64
65
  export * from "./functions/jsonHelpers";
65
66
  export * from "./functions/jsonRoom";
66
67
  export * from "./functions/kColor";
@@ -439,6 +439,18 @@ export interface AddCallbackParametersCustom {
439
439
  character?: PlayerType,
440
440
  ];
441
441
 
442
+ [ModCallbackCustom.POST_PICKUP_CHANGED]: [
443
+ callback: (
444
+ pickup: EntityPickup,
445
+ oldVariant: PickupVariant,
446
+ oldSubType: int,
447
+ newVariant: PickupVariant,
448
+ newSubType: int,
449
+ ) => void,
450
+ pickupVariant?: PickupVariant,
451
+ subType?: int,
452
+ ];
453
+
442
454
  [ModCallbackCustom.POST_PICKUP_COLLECT]: [
443
455
  callback: (pickup: EntityPickup, player: EntityPlayer) => void,
444
456
  pickupVariant?: PickupVariant,
package/src/shouldFire.ts CHANGED
@@ -267,7 +267,14 @@ export function shouldFirePickup(
267
267
  | [pickup: EntityPickup]
268
268
  | [pickup: EntityPickup, renderOffset: Vector]
269
269
  | [pickup: EntityPickup, player: EntityPlayer]
270
- | [pickup: EntityPickup, previousState: int, currentState: int],
270
+ | [pickup: EntityPickup, previousState: int, currentState: int]
271
+ | [
272
+ pickup: EntityPickup,
273
+ oldVariant: PickupVariant,
274
+ oldSubType: int,
275
+ newVariant: PickupVariant,
276
+ newSubType: int,
277
+ ],
271
278
  optionalArgs: [pickupVariant?: PickupVariant, subType?: int],
272
279
  ): boolean {
273
280
  const [pickup] = fireArgs;