pixi-rainman-game-engine 0.1.40 → 0.1.42

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,8 +5,13 @@ import Slider from "rc-slider";
5
5
  import React from "react";
6
6
  import { RainMan } from "../../../Rainman";
7
7
  import { useStores } from "../../hooks";
8
+ const onBeforeChange = () => {
9
+ RainMan.settingsStore.flipSoundsEnabled();
10
+ };
8
11
  const onChange = (newVolumeLevel) => {
9
12
  RainMan.settingsStore.setVolumeLevel(newVolumeLevel);
13
+ };
14
+ const onAfterChange = (newVolumeLevel) => {
10
15
  RainMan.settingsStore.flipSoundsEnabled(newVolumeLevel);
11
16
  };
12
17
  export const VolumeSettings = observer(() => {
@@ -27,7 +32,7 @@ export const VolumeSettings = observer(() => {
27
32
  backgroundColor: COLOR,
28
33
  height: "5px",
29
34
  borderRadius: "1px",
30
- }} onChange={onChange}/>
35
+ }} onBeforeChange={onBeforeChange} onChange={onChange} onAfterChange={onAfterChange}/>
31
36
  <p className="volume-control__text" style={{
32
37
  color: COLOR,
33
38
  }}>
@@ -1,6 +1,5 @@
1
1
  import i18n from "i18next";
2
2
  import { sample } from "lodash";
3
- import { pixiSoundContext } from "../../application";
4
3
  import { AutoplayButton, Background, BUTTONS, COMPONENTS, FreeSpinButton, MessageBox, SpeedControlButton, VolumeButton, } from "../../components";
5
4
  import { RainMan } from "../../Rainman";
6
5
  import { allUiItems, hideLayerIfPresent, UI_ITEMS } from "../../utils";
@@ -187,7 +186,6 @@ export class ButtonsEventManager {
187
186
  RainMan.settingsStore.setUpdateVolumeButtonTexture(() => RainMan.componentRegistry.get(VolumeButton.registryName).changeTextureDependOnVolume());
188
187
  RainMan.componentRegistry.get(VolumeButton.registryName).setOnClick(() => {
189
188
  RainMan.settingsStore.flipSoundsEnabled();
190
- pixiSoundContext.refresh();
191
189
  RainMan.componentRegistry.get(VolumeButton.registryName).changeTextureDependOnVolume();
192
190
  this.handleModalInvocation(UI_ITEMS.volume);
193
191
  });
@@ -45,6 +45,16 @@ export declare class SoundManagerInstance implements SpeedAdapterInterface<Sound
45
45
  * @param {SoundTrack} soundName
46
46
  */
47
47
  play(soundName: SoundTrack): void;
48
+ /**
49
+ * Function for resuming all sounds in game
50
+ * If sound is not playing, it will be skipped
51
+ */
52
+ resumeAll(): void;
53
+ /**
54
+ * Function for pausing all sounds in game
55
+ * If sound is not playing, it will be skipped
56
+ */
57
+ pauseAll(): void;
48
58
  /**
49
59
  * Function for pausing sound with given name
50
60
  *
@@ -76,7 +76,6 @@ export class SoundManagerInstance {
76
76
  */
77
77
  setPlayStatus(soundName, flag) {
78
78
  flag ? this.play(soundName) : this.pause(soundName);
79
- pixiSoundContext.refresh();
80
79
  }
81
80
  /**
82
81
  * Function for playing sound with given name
@@ -96,6 +95,20 @@ export class SoundManagerInstance {
96
95
  return;
97
96
  sound.play({ loop: soundsToLoop.includes(soundName) });
98
97
  }
98
+ /**
99
+ * Function for resuming all sounds in game
100
+ * If sound is not playing, it will be skipped
101
+ */
102
+ resumeAll() {
103
+ this.musicCatalogue.forEach((sound) => sound.paused && sound.resume());
104
+ }
105
+ /**
106
+ * Function for pausing all sounds in game
107
+ * If sound is not playing, it will be skipped
108
+ */
109
+ pauseAll() {
110
+ this.musicCatalogue.forEach((sound) => sound.pause());
111
+ }
99
112
  /**
100
113
  * Function for pausing sound with given name
101
114
  *
@@ -14,6 +14,8 @@
14
14
  * @property {string} mysteryFxEnd - on mystery fx hides
15
15
  * @property {string} mysteryFxLoop - when mystery fx in visible in loop
16
16
  * @property {string} line - default win line sound, for both single and multiple lines
17
+ * @property {string} fewLine - sound for few lines
18
+ * @property {string} oneLine - sound for single line
17
19
  * @property {string} freeLine - win line sound for free spins
18
20
  * @property {string} mysteryDrawLoop - on show mystery popup, play during randomizing win
19
21
  * @property {string} rollStop - single reel stopping
@@ -38,6 +40,8 @@ export interface SoundTracks {
38
40
  mysteryFxEnd: "mysteryFxEnd";
39
41
  mysteryFxLoop: "mysteryFxLoop";
40
42
  line: "line";
43
+ fewLine: "fewLine";
44
+ oneLine: "oneLine";
41
45
  freeLine: "freeLine";
42
46
  mysteryDrawLoop: "mysteryDrawLoop";
43
47
  rollStop: "rollStop";
@@ -14,6 +14,8 @@
14
14
  * @property {string} mysteryFxEnd - on mystery fx hides
15
15
  * @property {string} mysteryFxLoop - when mystery fx in visible in loop
16
16
  * @property {string} line - default win line sound, for both single and multiple lines
17
+ * @property {string} fewLine - sound for few lines
18
+ * @property {string} oneLine - sound for single line
17
19
  * @property {string} freeLine - win line sound for free spins
18
20
  * @property {string} mysteryDrawLoop - on show mystery popup, play during randomizing win
19
21
  * @property {string} rollStop - single reel stopping
@@ -37,10 +39,12 @@ export const SoundTracks = {
37
39
  mysteryFxEnd: "mysteryFxEnd",
38
40
  mysteryFxLoop: "mysteryFxLoop",
39
41
  line: "line",
42
+ freeLine: "freeLine",
43
+ fewLine: "fewLine",
44
+ oneLine: "oneLine",
40
45
  mysteryDrawLoop: "mysteryDrawLoop",
41
46
  rollStop: "rollStop",
42
47
  specialSymbolOnReel: "specialSymbolOnReel",
43
48
  start: "start",
44
- freeLine: "freeLine",
45
49
  symbol: "symbol",
46
50
  };
@@ -1,7 +1,7 @@
1
1
  import { createRoot } from "react-dom/client";
2
2
  import { RainMan } from "../Rainman";
3
3
  import { SettingsUI } from "../SettingsUI";
4
- import { changeResolution, disableMagnifyingGlassOnIOS, getDeviceOrientation, invokeStatsBoard, resizeCanvas, setupFullscreenForIOS, } from "../utils";
4
+ import { changeResolution, disableMagnifyingGlassOnIOS, getDeviceOrientation, invokeStatsBoard, loadSoundsOnTabChange, resizeCanvas, setupFullscreenForIOS, } from "../utils";
5
5
  /**
6
6
  * This function is for setup the whole games
7
7
  *
@@ -13,6 +13,7 @@ export const setup = () => {
13
13
  changeResolution(RainMan.settingsStore.HiResolutionFlag);
14
14
  resizeCanvas();
15
15
  setupFullscreenForIOS();
16
+ loadSoundsOnTabChange();
16
17
  const gameRoot = document.createElement("div");
17
18
  gameRoot.setAttribute("class", "game-container");
18
19
  document.body.appendChild(gameRoot);
@@ -2,7 +2,6 @@ import { Container, Graphics } from "pixi.js";
2
2
  import { ButtonsEventManager, SoundManager, SoundTracks } from "../../application";
3
3
  import { AnimationLayer, BackgroundLayer, FrameLayer, UXLayer } from "../../layers";
4
4
  import { RainMan } from "../../Rainman";
5
- import { settingStore } from "../../SettingsUI/hooks";
6
5
  import { getDeviceOrientation, globalMinRatio } from "../../utils";
7
6
  import { BUTTONS, LeftButtons, LeftButtonsLandscape, LeftButtonsMobile, MiddleButtons, RefreshButton, RightButtons, RightButtonsLandscape, RightButtonsMobile, } from "../buttons";
8
7
  import { GambleGame } from "../GambleGame";
@@ -57,8 +56,8 @@ export class AbstractMainContainer extends Container {
57
56
  this.name = AbstractMainContainer.registryName;
58
57
  this.buttonsEventManager = new ButtonsEventManager();
59
58
  this.messageBox = new MessageBox();
60
- if (settingStore.ambientMusicFlag)
61
- SoundManager.play(SoundTracks.music);
59
+ if (RainMan.settingsStore.ambientMusicFlag)
60
+ SoundManager.setPlayStatus(SoundTracks.music, true);
62
61
  RainMan.app.renderer.on("resize", () => this.resize());
63
62
  }
64
63
  /**
@@ -118,12 +118,9 @@ export class AbstractColumnsContainer extends Container {
118
118
  });
119
119
  const promises = [];
120
120
  columnsToPlay.forEach((column, index) => {
121
- column.forEach((symbolIndex) => {
122
- const promise = this.getColumnAtPosition(index).playSymbolAtPosition(symbolIndex, true);
123
- promises.push(promise);
124
- });
121
+ column.forEach((symbolIndex) => promises.push(this.getColumnAtPosition(index).playSymbolAtPosition(symbolIndex, true)));
125
122
  });
126
- SoundManager.play(RainMan.settingsStore.isFreeSpinsPlayEnabled ? SoundTracks.freeLine : SoundTracks.line);
123
+ SoundManager.play(SoundTracks.fewLine);
127
124
  await Promise.allSettled(promises);
128
125
  }
129
126
  resetPlayedSounds() {
@@ -139,8 +136,7 @@ export class AbstractColumnsContainer extends Container {
139
136
  this.playedSounds.push(sound);
140
137
  return;
141
138
  }
142
- if (this.playLineSoundOnEachStreak)
143
- SoundManager.play(RainMan.settingsStore.isFreeSpinsPlayEnabled ? SoundTracks.freeLine : SoundTracks.line);
139
+ SoundManager.play(RainMan.settingsStore.isFreeSpinsPlayEnabled ? SoundTracks.freeLine : SoundTracks.oneLine);
144
140
  }
145
141
  /**
146
142
  * Function for playing animation of streak
@@ -105,7 +105,7 @@ export declare abstract class AbstractController<T> {
105
105
  /**
106
106
  * Function for autoplay spin
107
107
  */
108
- private autoplaySpin;
108
+ protected autoplaySpin(): void;
109
109
  protected clearAndDestroyActions(): void;
110
110
  /**
111
111
  * Function disabling autoplay functionality
@@ -3,6 +3,7 @@ export * from "./functions";
3
3
  export * from "./logger";
4
4
  export * from "./placementHelpers";
5
5
  export * from "./screenHelpers";
6
+ export * from "./sound";
6
7
  export * from "./stats";
7
8
  export * from "./types";
8
9
  export * from "./uiItems";
@@ -3,6 +3,7 @@ export * from "./functions";
3
3
  export * from "./logger";
4
4
  export * from "./placementHelpers";
5
5
  export * from "./screenHelpers";
6
+ export * from "./sound";
6
7
  export * from "./stats";
7
8
  export * from "./types";
8
9
  export * from "./uiItems";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This function is required for setting up the sound while changing the tab
3
+ * This is using the visibilitychange event
4
+ */
5
+ export declare const loadSoundsOnTabChange: () => void;
@@ -0,0 +1,26 @@
1
+ import { SoundManager } from "../../application";
2
+ import { RainMan } from "../../Rainman";
3
+ /**
4
+ * This function using the visibilitychange event to resume sounds
5
+ * If any time the sounds was enable than this will be resumed
6
+ * If the sounds was disabled than this will be not triggered
7
+ */
8
+ const resumeAudioContext = () => {
9
+ if (RainMan.settingsStore.isSoundEnabled()) {
10
+ if (document.hidden) {
11
+ SoundManager.pauseAll();
12
+ return;
13
+ }
14
+ else {
15
+ SoundManager.resumeAll();
16
+ return;
17
+ }
18
+ }
19
+ };
20
+ /**
21
+ * This function is required for setting up the sound while changing the tab
22
+ * This is using the visibilitychange event
23
+ */
24
+ export const loadSoundsOnTabChange = () => {
25
+ document.addEventListener("visibilitychange", resumeAudioContext);
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixi-rainman-game-engine",
3
- "version": "0.1.40",
3
+ "version": "0.1.42",
4
4
  "description": "This repository contains all of the mechanics that used in rainman games.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",