isaacscript-common 30.4.4 → 30.4.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "30.4.4",
3
+ "version": "30.4.6",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -1,3 +1,10 @@
1
+ import {
2
+ CardType,
3
+ CollectibleType,
4
+ ModCallback,
5
+ PillEffect,
6
+ } from "isaac-typescript-definitions";
7
+ import { game } from "../../core/cachedClasses";
1
8
  import { ModCallbackCustom } from "../../enums/ModCallbackCustom";
2
9
  import { getPickups } from "../../functions/entitiesSpecific";
3
10
  import {
@@ -19,6 +26,7 @@ const v = {
19
26
  playersHoldingItemOnLastFrameMap: new DefaultMap<PlayerIndex, boolean>(
20
27
  false,
21
28
  ),
29
+ playersUsedItemOnFrame: new DefaultMap<PlayerIndex, int>(0),
22
30
  },
23
31
  };
24
32
 
@@ -28,6 +36,17 @@ export class PostPurchase extends CustomCallback<T> {
28
36
  constructor() {
29
37
  super();
30
38
 
39
+ this.callbacksUsed = [
40
+ // 3
41
+ [ModCallback.POST_USE_ITEM, this.postUseItem],
42
+
43
+ // 5
44
+ [ModCallback.POST_USE_CARD, this.postUseCard],
45
+
46
+ // 10
47
+ [ModCallback.POST_USE_PILL, this.postUsePill],
48
+ ];
49
+
31
50
  this.customCallbacksUsed = [
32
51
  [
33
52
  ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED,
@@ -51,6 +70,28 @@ export class PostPurchase extends CustomCallback<T> {
51
70
  );
52
71
  };
53
72
 
73
+ // ModCallback.POST_USE_ITEM (3)
74
+ private postUseItem = (
75
+ _collectibleType: CollectibleType,
76
+ _rng: RNG,
77
+ player: EntityPlayer,
78
+ ): boolean | undefined => {
79
+ markUsedItemOnThisFrame(player);
80
+ return undefined;
81
+ };
82
+
83
+ // ModCallback.POST_USE_CARD (5)
84
+ private postUseCard = (_cardType: CardType, player: EntityPlayer) => {
85
+ markUsedItemOnThisFrame(player);
86
+ return undefined;
87
+ };
88
+
89
+ // ModCallback.POST_USE_PILL (10)
90
+ private postUsePill = (_pillEffect: PillEffect, player: EntityPlayer) => {
91
+ markUsedItemOnThisFrame(player);
92
+ return undefined;
93
+ };
94
+
54
95
  // ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED
55
96
  private postPEffectUpdateReordered = (player: EntityPlayer) => {
56
97
  const isHoldingItem = player.IsHoldingItem();
@@ -64,11 +105,29 @@ export class PostPurchase extends CustomCallback<T> {
64
105
  isHoldingItem,
65
106
  );
66
107
 
67
- if (!wasHoldingItemOnLastFrame && isHoldingItem) {
108
+ // Assume that if the player did not use an active item, card, or pill recently, then they
109
+ // purchased an item.
110
+ if (
111
+ !wasHoldingItemOnLastFrame &&
112
+ isHoldingItem &&
113
+ !this.playerUsedItemRecently(player)
114
+ ) {
68
115
  this.playerPickedUpNewItem(player);
69
116
  }
70
117
  };
71
118
 
119
+ private playerUsedItemRecently(player: EntityPlayer): boolean {
120
+ const gameFrameCount = game.GetFrameCount();
121
+ const usedCollectibleOnFrame = defaultMapGetPlayer(
122
+ v.room.playersUsedItemOnFrame,
123
+ player,
124
+ );
125
+ return (
126
+ gameFrameCount === usedCollectibleOnFrame ||
127
+ gameFrameCount === usedCollectibleOnFrame + 1
128
+ );
129
+ }
130
+
72
131
  private playerPickedUpNewItem(player: EntityPlayer) {
73
132
  const pickups = getPickups();
74
133
  const disappearingPickup = pickups.find(
@@ -79,3 +138,8 @@ export class PostPurchase extends CustomCallback<T> {
79
138
  }
80
139
  }
81
140
  }
141
+
142
+ function markUsedItemOnThisFrame(player: EntityPlayer) {
143
+ const gameFrameCount = game.GetFrameCount();
144
+ mapSetPlayer(v.room.playersUsedItemOnFrame, player, gameFrameCount);
145
+ }
@@ -26,6 +26,7 @@ import { removeUrnRewards } from "../../../functions/rockAlt";
26
26
  import {
27
27
  getRoomDataForTypeVariant,
28
28
  getRoomsInsideGrid,
29
+ inRoomType,
29
30
  } from "../../../functions/rooms";
30
31
  import { getMusicForStage } from "../../../functions/sound";
31
32
  import { setStage } from "../../../functions/stage";
@@ -203,6 +204,17 @@ export class CustomStages extends Feature {
203
204
 
204
205
  streakTextPostRender();
205
206
  versusScreenPostRender(this.pause, this.disableAllSound);
207
+
208
+ // Fix the bug where the music will stop after loading a new room. (This does not work if placed
209
+ // in the `POST_NEW_ROOM_REORDERED` callback or the `POST_UPDATE` callback.)
210
+ if (customStage.music !== undefined) {
211
+ const currentMusic = musicManager.GetCurrentMusicID();
212
+ const music = Isaac.GetMusicIdByName(customStage.music);
213
+ if (currentMusic === music) {
214
+ musicManager.Resume();
215
+ musicManager.UpdateVolume();
216
+ }
217
+ }
206
218
  };
207
219
 
208
220
  // ModCallback.POST_CURSE_EVAL (12)
@@ -293,6 +305,16 @@ export class CustomStages extends Feature {
293
305
  this.pause,
294
306
  this.runInNFrames,
295
307
  );
308
+
309
+ // Fix the bug where music from special rooms (like the "Boss Over" music) will persist for the
310
+ // rest of the floor.
311
+ if (customStage.music !== undefined && inRoomType(RoomType.DEFAULT)) {
312
+ const music = Isaac.GetMusicIdByName(customStage.music);
313
+ const currentMusic = musicManager.GetCurrentMusicID();
314
+ if (currentMusic !== music) {
315
+ musicManager.Fadein(music);
316
+ }
317
+ }
296
318
  };
297
319
 
298
320
  /** Pick a custom room for each vanilla room. */
@@ -501,10 +523,9 @@ export class CustomStages extends Feature {
501
523
  : customStageMusic;
502
524
 
503
525
  this.runInNFrames.runInNRenderFrames(() => {
504
- // By default, the `MusicManager.Play` method will play the music at max volume (1.0), which
505
- // is around twice as loud as the vanilla music plays.
506
526
  musicManager.Enable();
507
- musicManager.Crossfade(music);
527
+ musicManager.Play(music);
528
+ musicManager.UpdateVolume();
508
529
  }, MUSIC_DELAY_RENDER_FRAMES);
509
530
 
510
531
  // We must reload the current room in order for the `Level.SetStage` method to take effect.