@m2c2kit/core 0.3.25 → 0.3.26

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/dist/index.d.ts CHANGED
@@ -1254,6 +1254,7 @@ interface M2Sound {
1254
1254
  soundName: string;
1255
1255
  data: ArrayBuffer | undefined;
1256
1256
  audioBuffer: AudioBuffer | undefined;
1257
+ audioBufferSource: AudioBufferSourceNode | undefined;
1257
1258
  url: string;
1258
1259
  status: M2SoundStatus;
1259
1260
  }
@@ -4633,6 +4634,37 @@ declare class SoundPlayer extends M2Node implements SoundPlayerOptions {
4633
4634
  */
4634
4635
  constructor(options: SoundPlayerOptions);
4635
4636
  initialize(): void;
4637
+ /**
4638
+ * Remove an action from this node. If the action is running, it will be
4639
+ * stopped.
4640
+ *
4641
+ * @privateRemarks This methods overrides the `removeAction` method from the
4642
+ * `M2Node` class. It is necessary to override this method because the
4643
+ * `SoundPlayer` class has a special case for removing actions that play
4644
+ * sounds.
4645
+ *
4646
+ * @param key - key (string identifier) of the action to remove
4647
+ */
4648
+ removeAction(key: string): void;
4649
+ /**
4650
+ * Remove all actions from this node. If actions are running, they will be
4651
+ * stopped.
4652
+ *
4653
+ * @privateRemarks This methods overrides the `removeAllActions` method from
4654
+ * the `M2Node` class. It is necessary to override this method because the
4655
+ * `SoundPlayer` class has a special case for removing actions that play
4656
+ * sounds.
4657
+ */
4658
+ removeAllActions(): void;
4659
+ /**
4660
+ * Stops the audio source node for a sound play action.
4661
+ *
4662
+ * @remarks When a SoundPlayer play action is removed, the audio source node
4663
+ * must be stopped and disconnected.
4664
+ *
4665
+ * @param playAction - the play action of the sound to stop
4666
+ */
4667
+ private stopSoundActionAudio;
4636
4668
  dispose(): void;
4637
4669
  /**
4638
4670
  * Duplicates a node using deep copy.
package/dist/index.js CHANGED
@@ -1892,16 +1892,18 @@ class Action {
1892
1892
  if (!playAction.started) {
1893
1893
  const m2Sound = soundManager.getSound(soundPlayer.soundName);
1894
1894
  if (m2Sound.audioBuffer) {
1895
- const source = soundManager.audioContext.createBufferSource();
1896
- source.buffer = m2Sound.audioBuffer;
1897
- source.onended = () => {
1895
+ m2Sound.audioBufferSource = soundManager.audioContext.createBufferSource();
1896
+ m2Sound.audioBufferSource.buffer = m2Sound.audioBuffer;
1897
+ m2Sound.audioBufferSource.onended = () => {
1898
1898
  playAction.running = false;
1899
1899
  playAction.completed = true;
1900
1900
  const knownDuration = performance.now() - (action.runStartTime + action.startOffset.value);
1901
1901
  action.duration.assign(knownDuration);
1902
1902
  };
1903
- source.connect(soundManager.audioContext.destination);
1904
- source.start();
1903
+ m2Sound.audioBufferSource.connect(
1904
+ soundManager.audioContext.destination
1905
+ );
1906
+ m2Sound.audioBufferSource.start();
1905
1907
  playAction.started = true;
1906
1908
  } else {
1907
1909
  if (m2Sound.status === M2SoundStatus.Error) {
@@ -8032,6 +8034,7 @@ class SoundManager {
8032
8034
  soundName: sound.soundName,
8033
8035
  data: void 0,
8034
8036
  audioBuffer: void 0,
8037
+ audioBufferSource: void 0,
8035
8038
  url,
8036
8039
  status: sound.lazy ? M2SoundStatus.Deferred : M2SoundStatus.WillFetch
8037
8040
  };
@@ -10981,9 +10984,13 @@ class Game {
10981
10984
  this.raiseTapDownEvent(node, nodeEvent, domPointerEvent);
10982
10985
  }
10983
10986
  if (node.children) {
10984
- node.children.filter((node2) => !node2.hidden).filter((node2) => node2.isDrawable).sort(
10985
- (a, b) => b.zPosition - a.zPosition
10986
- ).forEach(
10987
+ node.children.filter((node2) => !node2.hidden).filter((node2) => node2.isDrawable).sort((a, b) => {
10988
+ const zDiff = b.zPosition - a.zPosition;
10989
+ if (zDiff !== 0) {
10990
+ return zDiff;
10991
+ }
10992
+ return node.children.indexOf(b) - node.children.indexOf(a);
10993
+ }).forEach(
10987
10994
  (node2) => this.processDomPointerDown(node2, nodeEvent, domPointerEvent)
10988
10995
  );
10989
10996
  }
@@ -10997,7 +11004,6 @@ class Game {
10997
11004
  node.pressed = false;
10998
11005
  node.pressedAndWithinHitArea = false;
10999
11006
  this.raiseM2DragEndEvent(node, nodeEvent, domPointerEvent);
11000
- nodeEvent.handled = true;
11001
11007
  return;
11002
11008
  }
11003
11009
  if (node.isUserInteractionEnabled && node.pressed && node.pressedAndWithinHitArea) {
@@ -11020,9 +11026,13 @@ class Game {
11020
11026
  this.raiseM2PointerUpEvent(node, nodeEvent, domPointerEvent);
11021
11027
  }
11022
11028
  if (node.children) {
11023
- node.children.filter((node2) => !node2.hidden).filter((node2) => node2.isDrawable).sort(
11024
- (a, b) => b.zPosition - a.zPosition
11025
- ).forEach(
11029
+ node.children.filter((node2) => !node2.hidden).filter((node2) => node2.isDrawable).sort((a, b) => {
11030
+ const zDiff = b.zPosition - a.zPosition;
11031
+ if (zDiff !== 0) {
11032
+ return zDiff;
11033
+ }
11034
+ return node.children.indexOf(b) - node.children.indexOf(a);
11035
+ }).forEach(
11026
11036
  (node2) => this.processDomPointerUp(node2, nodeEvent, domPointerEvent)
11027
11037
  );
11028
11038
  }
@@ -11050,7 +11060,6 @@ class Game {
11050
11060
  x: domPointerEvent.offsetX,
11051
11061
  y: domPointerEvent.offsetY
11052
11062
  };
11053
- nodeEvent.handled = true;
11054
11063
  if (firstMoveOfDrag) {
11055
11064
  this.raiseM2DragStartEvent(node, nodeEvent, domPointerEvent);
11056
11065
  } else {
@@ -11083,9 +11092,13 @@ class Game {
11083
11092
  this.raiseM2PointerLeaveEvent(node, nodeEvent, domPointerEvent);
11084
11093
  }
11085
11094
  if (node.children) {
11086
- node.children.filter((node2) => !node2.hidden).filter((node2) => node2.isDrawable).sort(
11087
- (a, b) => b.zPosition - a.zPosition
11088
- ).forEach(
11095
+ node.children.filter((node2) => !node2.hidden).filter((node2) => node2.isDrawable).sort((a, b) => {
11096
+ const zDiff = b.zPosition - a.zPosition;
11097
+ if (zDiff !== 0) {
11098
+ return zDiff;
11099
+ }
11100
+ return node.children.indexOf(b) - node.children.indexOf(a);
11101
+ }).forEach(
11089
11102
  (node2) => this.processDomPointerMove(node2, nodeEvent, domPointerEvent)
11090
11103
  );
11091
11104
  }
@@ -11124,9 +11137,13 @@ class Game {
11124
11137
  this.raiseM2PointerLeaveEvent(node, nodeEvent, domPointerEvent);
11125
11138
  }
11126
11139
  if (node.children) {
11127
- node.children.filter((node2) => !node2.hidden).filter((node2) => node2.isDrawable).sort(
11128
- (a, b) => b.zPosition - a.zPosition
11129
- ).forEach(
11140
+ node.children.filter((node2) => !node2.hidden).filter((node2) => node2.isDrawable).sort((a, b) => {
11141
+ const zDiff = b.zPosition - a.zPosition;
11142
+ if (zDiff !== 0) {
11143
+ return zDiff;
11144
+ }
11145
+ return node.children.indexOf(b) - node.children.indexOf(a);
11146
+ }).forEach(
11130
11147
  (node2) => this.processDomPointerLeave(node2, nodeEvent, domPointerEvent)
11131
11148
  );
11132
11149
  }
@@ -11728,6 +11745,56 @@ class SoundPlayer extends M2Node {
11728
11745
  }
11729
11746
  initialize() {
11730
11747
  }
11748
+ /**
11749
+ * Remove an action from this node. If the action is running, it will be
11750
+ * stopped.
11751
+ *
11752
+ * @privateRemarks This methods overrides the `removeAction` method from the
11753
+ * `M2Node` class. It is necessary to override this method because the
11754
+ * `SoundPlayer` class has a special case for removing actions that play
11755
+ * sounds.
11756
+ *
11757
+ * @param key - key (string identifier) of the action to remove
11758
+ */
11759
+ removeAction(key) {
11760
+ const actionToRemove = this.actions.find((action) => action.key === key);
11761
+ if (actionToRemove?.type === ActionType.Play) {
11762
+ this.stopSoundActionAudio(actionToRemove);
11763
+ }
11764
+ this.actions = this.actions.filter((action) => action.key !== key);
11765
+ }
11766
+ /**
11767
+ * Remove all actions from this node. If actions are running, they will be
11768
+ * stopped.
11769
+ *
11770
+ * @privateRemarks This methods overrides the `removeAllActions` method from
11771
+ * the `M2Node` class. It is necessary to override this method because the
11772
+ * `SoundPlayer` class has a special case for removing actions that play
11773
+ * sounds.
11774
+ */
11775
+ removeAllActions() {
11776
+ while (this.actions.length) {
11777
+ const removedAction = this.actions.pop();
11778
+ if (removedAction?.type === ActionType.Play) {
11779
+ this.stopSoundActionAudio(removedAction);
11780
+ }
11781
+ }
11782
+ }
11783
+ /**
11784
+ * Stops the audio source node for a sound play action.
11785
+ *
11786
+ * @remarks When a SoundPlayer play action is removed, the audio source node
11787
+ * must be stopped and disconnected.
11788
+ *
11789
+ * @param playAction - the play action of the sound to stop
11790
+ */
11791
+ stopSoundActionAudio(playAction) {
11792
+ if (playAction.running) {
11793
+ const m2Sound = this.game.soundManager.getSound(this.soundName);
11794
+ m2Sound.audioBufferSource?.stop();
11795
+ m2Sound.audioBufferSource?.disconnect();
11796
+ }
11797
+ }
11731
11798
  dispose() {
11732
11799
  }
11733
11800
  /**
@@ -12045,7 +12112,7 @@ class Story {
12045
12112
  }
12046
12113
  }
12047
12114
 
12048
- console.log("\u26AA @m2c2kit/core version 0.3.25 (af00d1f0)");
12115
+ console.log("\u26AA @m2c2kit/core version 0.3.26 (8bba62e1)");
12049
12116
 
12050
12117
  export { Action, ActivityType, CanvasKitHelpers, ColorfulMutablePath, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Equal, Equals, EventStore, EventStoreMode, FadeAlphaAction, FontManager, Game, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LegacyTimer, M2EventType, M2ImageStatus, M2Node, M2NodeFactory, M2NodeType, M2SoundStatus, M2c2KitHelpers, MoveAction, MutablePath, NoneTransition, PlayAction, RandomDraws, RepeatAction, RepeatForeverAction, RotateAction, ScaleAction, Scene, SceneTransition, SequenceAction, Shape, ShapeType, SlideTransition, SoundManager, SoundPlayer, SoundRecorder, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
12051
12118
  //# sourceMappingURL=index.js.map