@urso/core 0.2.5 → 0.3.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 (146) hide show
  1. package/.babelrc +11 -11
  2. package/README.md +10 -10
  3. package/build/js/index.js +1 -1
  4. package/build/js/index.js.LICENSE.txt +75 -47
  5. package/package.json +51 -52
  6. package/src/js/app.js +77 -76
  7. package/src/js/components/_info.js +8 -8
  8. package/src/js/components/base/_info.js +3 -3
  9. package/src/js/components/base/controller.js +78 -78
  10. package/src/js/components/debug/_info.js +6 -6
  11. package/src/js/components/debug/controller.js +38 -38
  12. package/src/js/components/debug/coords.js +23 -23
  13. package/src/js/components/debug/fps.js +34 -34
  14. package/src/js/components/debug/template.js +33 -33
  15. package/src/js/components/deviceRotate/_info.js +3 -3
  16. package/src/js/components/deviceRotate/controller.js +86 -86
  17. package/src/js/components/fullscreen/_info.js +6 -6
  18. package/src/js/components/fullscreen/android.js +104 -104
  19. package/src/js/components/fullscreen/controller.js +64 -64
  20. package/src/js/components/fullscreen/desktop.js +49 -49
  21. package/src/js/components/fullscreen/ios.js +111 -111
  22. package/src/js/components/loader/_info.js +4 -4
  23. package/src/js/components/loader/controller.js +66 -66
  24. package/src/js/components/loader/template.js +70 -70
  25. package/src/js/components/soundInitialPopup/_info.js +3 -3
  26. package/src/js/components/soundInitialPopup/controller.js +42 -42
  27. package/src/js/components/soundInitialPopup/template.js +109 -109
  28. package/src/js/components/stateDriven/_info.js +3 -3
  29. package/src/js/components/stateDriven/controller.js +96 -96
  30. package/src/js/config/load.js +5 -5
  31. package/src/js/config/main.js +10 -9
  32. package/src/js/extra/_info.js +21 -23
  33. package/src/js/extra/browserEvents.js +32 -32
  34. package/src/js/index.js +8 -8
  35. package/src/js/lib/_info.js +13 -13
  36. package/src/js/lib/cache.js +98 -98
  37. package/src/js/lib/composition.js +89 -89
  38. package/src/js/lib/device.js +1276 -1276
  39. package/src/js/lib/helper.js +539 -524
  40. package/src/js/lib/loader.js +121 -121
  41. package/src/js/lib/localData.js +15 -15
  42. package/src/js/lib/logger.js +22 -22
  43. package/src/js/lib/math.js +20 -20
  44. package/src/js/lib/objectPool.js +54 -54
  45. package/src/js/lib/time.js +18 -18
  46. package/src/js/lib/tween.js +147 -147
  47. package/src/js/modules/_info.js +11 -11
  48. package/src/js/modules/assets/_info.js +7 -7
  49. package/src/js/modules/assets/baseModel.js +18 -18
  50. package/src/js/modules/assets/config.js +35 -35
  51. package/src/js/modules/assets/controller.js +39 -37
  52. package/src/js/modules/assets/models/_info.js +11 -12
  53. package/src/js/modules/assets/models/atlas.js +8 -8
  54. package/src/js/modules/assets/models/audiosprite.js +27 -27
  55. package/src/js/modules/assets/models/bitmapFont.js +8 -8
  56. package/src/js/modules/assets/models/container.js +16 -16
  57. package/src/js/modules/assets/models/font.js +8 -8
  58. package/src/js/modules/assets/models/image.js +14 -14
  59. package/src/js/modules/assets/models/json.js +8 -8
  60. package/src/js/modules/assets/models/sound.js +14 -14
  61. package/src/js/modules/assets/models/spine.js +8 -8
  62. package/src/js/modules/assets/service.js +327 -330
  63. package/src/js/modules/instances/_info.js +3 -3
  64. package/src/js/modules/instances/controller.js +219 -218
  65. package/src/js/modules/logic/_info.js +4 -5
  66. package/src/js/modules/logic/config/_info.js +2 -3
  67. package/src/js/modules/logic/config/sounds.js +23 -23
  68. package/src/js/modules/logic/controller.js +48 -48
  69. package/src/js/modules/logic/sounds.js +96 -96
  70. package/src/js/modules/objects/_info.js +11 -11
  71. package/src/js/modules/objects/baseModel.js +161 -161
  72. package/src/js/modules/objects/cache.js +99 -99
  73. package/src/js/modules/objects/controller.js +121 -115
  74. package/src/js/modules/objects/create.js +230 -246
  75. package/src/js/modules/objects/find.js +140 -140
  76. package/src/js/modules/objects/models/_info.js +24 -25
  77. package/src/js/modules/objects/models/atlasImage.js +50 -50
  78. package/src/js/modules/objects/models/bitmapText.js +23 -23
  79. package/src/js/modules/objects/models/button.js +184 -184
  80. package/src/js/modules/objects/models/buttonComposite.js +35 -35
  81. package/src/js/modules/objects/models/checkbox.js +95 -96
  82. package/src/js/modules/objects/models/collection.js +54 -54
  83. package/src/js/modules/objects/models/component.js +44 -44
  84. package/src/js/modules/objects/models/container.js +19 -19
  85. package/src/js/modules/objects/models/emitter.js +54 -54
  86. package/src/js/modules/objects/models/graphics.js +38 -38
  87. package/src/js/modules/objects/models/group.js +19 -19
  88. package/src/js/modules/objects/models/hitArea.js +104 -104
  89. package/src/js/modules/objects/models/image.js +34 -34
  90. package/src/js/modules/objects/models/imagesAnimation.js +113 -113
  91. package/src/js/modules/objects/models/mask.js +38 -38
  92. package/src/js/modules/objects/models/scrollbox.js +61 -61
  93. package/src/js/modules/objects/models/slider.js +199 -154
  94. package/src/js/modules/objects/models/spine.js +83 -83
  95. package/src/js/modules/objects/models/text.js +38 -38
  96. package/src/js/modules/objects/models/textInput.js +55 -55
  97. package/src/js/modules/objects/models/toggle.js +169 -169
  98. package/src/js/modules/objects/models/world.js +19 -19
  99. package/src/js/modules/objects/propertyAdapter.js +421 -421
  100. package/src/js/modules/objects/proxy.js +179 -179
  101. package/src/js/modules/objects/styles.js +116 -116
  102. package/src/js/modules/observer/_info.js +4 -4
  103. package/src/js/modules/observer/controller.js +99 -99
  104. package/src/js/modules/observer/events.js +33 -32
  105. package/src/js/modules/scenes/_info.js +8 -8
  106. package/src/js/modules/scenes/controller.js +34 -34
  107. package/src/js/modules/scenes/model.js +35 -35
  108. package/src/js/modules/scenes/pixiWrapper.js +194 -194
  109. package/src/js/modules/scenes/resolutions.js +168 -161
  110. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  111. package/src/js/modules/scenes/service.js +84 -84
  112. package/src/js/modules/soundManager/_info.js +3 -3
  113. package/src/js/modules/soundManager/controller.js +99 -99
  114. package/src/js/modules/soundManager/soundSprite.js +202 -202
  115. package/src/js/modules/statesManager/_info.js +12 -12
  116. package/src/js/modules/statesManager/action.js +55 -55
  117. package/src/js/modules/statesManager/actions/_info.js +3 -3
  118. package/src/js/modules/statesManager/all.js +23 -23
  119. package/src/js/modules/statesManager/configStates.js +71 -71
  120. package/src/js/modules/statesManager/controller.js +131 -132
  121. package/src/js/modules/statesManager/functionsStorage.js +82 -82
  122. package/src/js/modules/statesManager/helper.js +27 -27
  123. package/src/js/modules/statesManager/race.js +75 -75
  124. package/src/js/modules/statesManager/sequence.js +47 -47
  125. package/src/js/modules/template/_info.js +6 -6
  126. package/src/js/modules/template/controller.js +28 -28
  127. package/src/js/modules/template/model.js +11 -11
  128. package/src/js/modules/template/service.js +125 -125
  129. package/src/js/modules/template/types.js +44 -46
  130. package/src/js/modules/transport/_info.js +8 -8
  131. package/src/js/modules/transport/baseConnectionType.js +24 -24
  132. package/src/js/modules/transport/config.js +22 -22
  133. package/src/js/modules/transport/connectionTypes/_info.js +3 -3
  134. package/src/js/modules/transport/connectionTypes/websocket.js +74 -74
  135. package/src/js/modules/transport/connectionTypes/xhr.js +41 -41
  136. package/src/js/modules/transport/controller.js +48 -48
  137. package/src/js/modules/transport/decorator.js +16 -16
  138. package/src/js/modules/transport/service.js +140 -138
  139. package/src/js/templates/_info.js +4 -4
  140. package/src/js/templates/groups/_info.js +1 -1
  141. package/src/js/templates/scenes/_info.js +1 -1
  142. package/webpack.config.js +47 -47
  143. package/src/js/modules/assets/models/dragonBones.js +0 -27
  144. package/src/js/modules/logic/buttons.js +0 -120
  145. package/src/js/modules/logic/config/buttons.js +0 -63
  146. package/src/js/modules/objects/models/dragonBones.js +0 -250
@@ -1,99 +1,99 @@
1
- class SoundManagerController {
2
- constructor() {
3
- this._systemVolume = 1;
4
- this._globalVolume = 0;
5
-
6
- this._howler = null;
7
- this._codecsToCheck = ['ogg', 'm4a', 'mp3', 'wav'];
8
- this._selectedCodec = null;
9
- this._sounds = {};
10
-
11
- this._setCodec();
12
-
13
- this._updateSoundsCfgHandler = this._updateSoundsCfgHandler.bind(this);
14
- this._doHandler = this._doHandler.bind(this);
15
- }
16
-
17
- _setCodec() {
18
- for (const codec of this._codecsToCheck) {
19
- if (Howler.Howler.codecs(codec)) {
20
- this._selectedCodec = codec;
21
- return;
22
- }
23
- }
24
- };
25
-
26
- _createSounds(soundData) {
27
- const { eventsCfg, sounds } = soundData;
28
-
29
- for (const soundKey in sounds) {
30
-
31
- if (this._sounds[soundKey])
32
- continue;
33
-
34
- const { audiosprite, json } = sounds[soundKey];
35
-
36
- const soundSptite = this.getInstance('SoundSprite', {
37
- sprite: json.sprite,
38
- name: soundKey,
39
- audiosprite
40
- });
41
-
42
- this._sounds[soundKey] = soundSptite;
43
-
44
- soundSptite.updateEvents(eventsCfg);
45
- }
46
- };
47
-
48
- _setEventsHandler() {
49
- const soundsCfg = Urso.localData.get('sounds.cfg') || {};
50
-
51
- for (const key in this._sounds)
52
- if (soundsCfg[key])
53
- this._sounds[key].updateEvents(soundsCfg[key]);
54
- };
55
-
56
- _checkSoundExists(name) {
57
- if (this._sounds[name])
58
- return true;
59
-
60
- Urso.logger.error(`Sound with key ${name} wasn't found!`);
61
- };
62
-
63
- _updateSoundsCfgHandler(soundsCfg) {
64
- this._createSounds(soundsCfg);
65
- };
66
-
67
- _doHandler({ action, name, behavior }) {
68
- if (this._checkSoundExists(name))
69
- this._sounds[name][action](behavior);
70
- };
71
-
72
- /**
73
- *
74
- * @param {Number} volume (0-1)
75
- */
76
- _globalVolumeChange(volume) {
77
- this._globalVolume = Urso.math.intMakeBetween(volume, 0, 1);
78
- this._updateSoundVolume();
79
- }
80
-
81
- _visibilityChange(state) {
82
- this._systemVolume = ~~(state === 'visible');
83
- this._updateSoundVolume();
84
- }
85
- _updateSoundVolume() {
86
- const totalVolume = this._globalVolume * this._systemVolume;
87
- for (const key in this._sounds)
88
- this._sounds[key].setAllVolume(totalVolume);
89
- }
90
-
91
- _subscribe() {
92
- this.addListener(Urso.events.MODULES_SOUND_MANAGER_UPDATE_CFG, this._updateSoundsCfgHandler, true);
93
- this.addListener(Urso.events.MODULES_LOGIC_SOUNDS_DO, this._doHandler, true);
94
- this.addListener(Urso.events.MODULES_SOUND_MANAGER_SET_GLOBAL_VOLUME, this._globalVolumeChange.bind(this), true);
95
- this.addListener(Urso.events.EXTRA_BROWSEREVENTS_WINDOW_VISIBILITYCHANGE, this._visibilityChange.bind(this), true);
96
- };
97
- };
98
-
99
- module.exports = SoundManagerController;
1
+ class SoundManagerController {
2
+ constructor() {
3
+ this._systemVolume = 1;
4
+ this._globalVolume = 0;
5
+
6
+ this._howler = null;
7
+ this._codecsToCheck = ['ogg', 'm4a', 'mp3', 'wav'];
8
+ this._selectedCodec = null;
9
+ this._sounds = {};
10
+
11
+ this._setCodec();
12
+
13
+ this._updateSoundsCfgHandler = this._updateSoundsCfgHandler.bind(this);
14
+ this._doHandler = this._doHandler.bind(this);
15
+ }
16
+
17
+ _setCodec() {
18
+ for (const codec of this._codecsToCheck) {
19
+ if (Howler.Howler.codecs(codec)) {
20
+ this._selectedCodec = codec;
21
+ return;
22
+ }
23
+ }
24
+ };
25
+
26
+ _createSounds(soundData) {
27
+ const { eventsCfg, sounds } = soundData;
28
+
29
+ for (const soundKey in sounds) {
30
+
31
+ if (this._sounds[soundKey])
32
+ continue;
33
+
34
+ const { audiosprite, json } = sounds[soundKey];
35
+
36
+ const soundSptite = this.getInstance('SoundSprite', {
37
+ sprite: json.sprite,
38
+ name: soundKey,
39
+ audiosprite
40
+ });
41
+
42
+ this._sounds[soundKey] = soundSptite;
43
+
44
+ soundSptite.updateEvents(eventsCfg);
45
+ }
46
+ };
47
+
48
+ _setEventsHandler() {
49
+ const soundsCfg = Urso.localData.get('sounds.cfg') || {};
50
+
51
+ for (const key in this._sounds)
52
+ if (soundsCfg[key])
53
+ this._sounds[key].updateEvents(soundsCfg[key]);
54
+ };
55
+
56
+ _checkSoundExists(name) {
57
+ if (this._sounds[name])
58
+ return true;
59
+
60
+ Urso.logger.error(`Sound with key ${name} wasn't found!`);
61
+ };
62
+
63
+ _updateSoundsCfgHandler(soundsCfg) {
64
+ this._createSounds(soundsCfg);
65
+ };
66
+
67
+ _doHandler({ action, name, behavior }) {
68
+ if (this._checkSoundExists(name))
69
+ this._sounds[name][action](behavior);
70
+ };
71
+
72
+ /**
73
+ *
74
+ * @param {Number} volume (0-1)
75
+ */
76
+ _globalVolumeChange(volume) {
77
+ this._globalVolume = Urso.math.intMakeBetween(volume, 0, 1);
78
+ this._updateSoundVolume();
79
+ }
80
+
81
+ _visibilityChange(state) {
82
+ this._systemVolume = ~~(state === 'visible');
83
+ this._updateSoundVolume();
84
+ }
85
+ _updateSoundVolume() {
86
+ const totalVolume = this._globalVolume * this._systemVolume;
87
+ for (const key in this._sounds)
88
+ this._sounds[key].setAllVolume(totalVolume);
89
+ }
90
+
91
+ _subscribe() {
92
+ this.addListener(Urso.events.MODULES_SOUND_MANAGER_UPDATE_CFG, this._updateSoundsCfgHandler, true);
93
+ this.addListener(Urso.events.MODULES_LOGIC_SOUNDS_DO, this._doHandler, true);
94
+ this.addListener(Urso.events.MODULES_SOUND_MANAGER_SET_GLOBAL_VOLUME, this._globalVolumeChange.bind(this), true);
95
+ this.addListener(Urso.events.EXTRA_BROWSEREVENTS_WINDOW_VISIBILITYCHANGE, this._visibilityChange.bind(this), true);
96
+ };
97
+ };
98
+
99
+ module.exports = SoundManagerController;
@@ -1,203 +1,203 @@
1
- class SoundSprite {
2
- constructor({ name, sprite, audiosprite }) {
3
- this._player = null;
4
- this._totalVolume = 0;
5
- this._makePlayer(sprite, audiosprite);
6
-
7
- this._name = name;
8
- this._sprite = sprite;
9
-
10
- this._soundsState = this._initSoundsState();
11
-
12
- this._eventsCfg = {};
13
- this._eventsQueue = [];
14
- this._isAudioUnlocked = false;
15
-
16
- this._reactToEvent = this._reactToEvent.bind(this);
17
- };
18
-
19
-
20
- _initSoundsState() {
21
- const soundsNames = Object.keys(this._sprite);
22
- const soundsStateObj = {};
23
-
24
- soundsNames.forEach(soundName => {
25
- soundsStateObj[soundName] = {
26
- id: null,
27
- loop: false,
28
- volume: 1,
29
- relaunch: false
30
- }
31
- });
32
-
33
- return soundsStateObj;
34
- }
35
-
36
- _makePlayer(sprite, audiosprite) {
37
- var reader = new FileReader();
38
- reader.readAsDataURL(audiosprite);
39
- reader.onloadend = () => {
40
- var base64data = reader.result;
41
- this._player = new Howl({
42
- src: base64data,
43
- sprite
44
- });
45
- this._subscribePlayerEvents();
46
- }
47
- };
48
-
49
- _subscribePlayerEvents() {
50
- this._player.on('unlock', () => setTimeout(() => {
51
- this._isAudioUnlocked = true;
52
- this._onUnlock();
53
- }, 1000));
54
-
55
- this._player.on('end', id => {
56
- const soundState = this._getSoundStateById(id);
57
-
58
- if (!soundState.loop)
59
- soundState.id = null;
60
- });
61
- };
62
-
63
- _getSoundStateById(id) {
64
- for (const [name, state] of Object.entries(this._soundsState)) {
65
- if (state.id === id) {
66
- return {
67
- id: { ...state, name }
68
- }
69
- }
70
- }
71
- }
72
-
73
- canPlayCheck() {
74
- return this._isAudioUnlocked;
75
- };
76
-
77
- play({ loop = false, volume = this._volume, relaunch = false, soundKey }) {
78
- if (!this.canPlayCheck() || (this._soundsState[soundKey].id !== null && !relaunch))
79
- return false;
80
-
81
- this.stop({ soundKey });
82
-
83
- this._soundsState[soundKey].id = this._player.play(soundKey);
84
-
85
- this.setRelaunch(soundKey, relaunch);
86
- this.setLoop(soundKey, loop);
87
- this.setVolume(soundKey, volume);
88
-
89
- return true;
90
- };
91
-
92
- setLoop(soundKey, loop = false) {
93
- this._soundsState[soundKey].loop = loop;
94
- this._player.loop(loop, this._soundsState[soundKey].id);
95
- };
96
-
97
- setVolume(soundKey, volume = 1) {
98
- this._soundsState[soundKey].volume = volume;
99
-
100
- this._player.volume(volume, this._soundsState[soundKey].id);
101
- };
102
-
103
- setAllVolume(volume) {
104
- this._totalVolume = volume;
105
- this._player._volume = volume;
106
-
107
- if (this.canPlayCheck()) {
108
- this._updateVolume();
109
- }
110
- }
111
-
112
- _updateVolume() {
113
- const keys = Object.keys(this._soundsState);
114
- this._player._volume = this._totalVolume;
115
- keys.forEach(key => this.setVolume(key, this._totalVolume));
116
- }
117
-
118
- setRelaunch(soundKey, needRelaunch = false) {
119
- this._soundsState[soundKey].relaunch = needRelaunch;
120
- };
121
-
122
- stop({ soundKey }) {
123
- if (!this._soundsState[soundKey].id)
124
- return;
125
-
126
- this._player.stop(this._soundsState[soundKey].id);
127
- this._soundsState[soundKey].id = null;
128
- };
129
-
130
- pause({ soundKey }) {
131
- if (this.canPlayCheck() || this._player.playing(this._soundsState[soundKey].id))
132
- this._player.pause(this._soundsState[soundKey].id);
133
- };
134
-
135
- resume({ soundKey }) {
136
- if (this.canPlayCheck() && !this._player.playing(this._soundsState[soundKey].id))
137
- this._player.play(this._soundsState[soundKey].id);
138
- };
139
-
140
- updateEvents(eventsCfg) {
141
- this._customUnsubscribe();
142
- this._saveEvents(eventsCfg);
143
- this._customSubscribe();
144
- };
145
-
146
- _saveEvents(eventsCfg) {
147
- this._eventsCfg = eventsCfg;
148
- }
149
-
150
- _setEventCallback(soundKey, event) {
151
- return function () {
152
- const params = this._eventsCfg[soundKey].events[event];
153
-
154
- this._reactToEvent(soundKey, params);
155
- };
156
- };
157
-
158
- _onUnlock() {
159
- this._runEventsFromQueue();
160
- this._updateVolume();
161
- };
162
-
163
- _runEventsFromQueue() {
164
- this._eventsQueue.forEach(event => this._reactToEvent(event.soundKey, event));
165
- this._eventsQueue = [];
166
- };
167
-
168
- _addEventToQueue(data) {
169
- this._eventsQueue.push(data);
170
- };
171
-
172
- _reactToEvent(soundKey, { action, loop, relaunch, volume = 0 }) {
173
- volume *= this._totalVolume;
174
- const self = this;
175
- const params = { loop, relaunch, volume, soundKey };
176
-
177
- if (!self[action])
178
- Urso.logger.error(`Sound action '${action}' not found!`);
179
-
180
- if (!this._isAudioUnlocked)
181
- this._addEventToQueue({ ...params, action });
182
-
183
- self[action](params);
184
- };
185
-
186
- _customSubscribe() {
187
- for (const soundKey in this._eventsCfg) {
188
- const { events = {} } = this._eventsCfg[soundKey];
189
-
190
- for (const event in events) {
191
- this.addListener(event, this._setEventCallback(soundKey, event).bind(this), true);
192
- }
193
- }
194
- };
195
-
196
- _customUnsubscribe() {
197
- for (const event in this._eventsCfg) {
198
- this.removeListener(event, this._setEventCallback(event).bind(this), true);
199
- }
200
- };
201
- };
202
-
1
+ class SoundSprite {
2
+ constructor({ name, sprite, audiosprite }) {
3
+ this._player = null;
4
+ this._totalVolume = 0;
5
+ this._makePlayer(sprite, audiosprite);
6
+
7
+ this._name = name;
8
+ this._sprite = sprite;
9
+
10
+ this._soundsState = this._initSoundsState();
11
+
12
+ this._eventsCfg = {};
13
+ this._eventsQueue = [];
14
+ this._isAudioUnlocked = false;
15
+
16
+ this._reactToEvent = this._reactToEvent.bind(this);
17
+ };
18
+
19
+
20
+ _initSoundsState() {
21
+ const soundsNames = Object.keys(this._sprite);
22
+ const soundsStateObj = {};
23
+
24
+ soundsNames.forEach(soundName => {
25
+ soundsStateObj[soundName] = {
26
+ id: null,
27
+ loop: false,
28
+ volume: 1,
29
+ relaunch: false
30
+ }
31
+ });
32
+
33
+ return soundsStateObj;
34
+ }
35
+
36
+ _makePlayer(sprite, audiosprite) {
37
+ var reader = new FileReader();
38
+ reader.readAsDataURL(audiosprite);
39
+ reader.onloadend = () => {
40
+ var base64data = reader.result;
41
+ this._player = new Howl({
42
+ src: base64data,
43
+ sprite
44
+ });
45
+ this._subscribePlayerEvents();
46
+ }
47
+ };
48
+
49
+ _subscribePlayerEvents() {
50
+ this._player.on('unlock', () => setTimeout(() => {
51
+ this._isAudioUnlocked = true;
52
+ this._onUnlock();
53
+ }, 1000));
54
+
55
+ this._player.on('end', id => {
56
+ const soundState = this._getSoundStateById(id);
57
+
58
+ if (!soundState.loop)
59
+ soundState.id = null;
60
+ });
61
+ };
62
+
63
+ _getSoundStateById(id) {
64
+ for (const [name, state] of Object.entries(this._soundsState)) {
65
+ if (state.id === id) {
66
+ return {
67
+ id: { ...state, name }
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+ canPlayCheck() {
74
+ return this._isAudioUnlocked;
75
+ };
76
+
77
+ play({ loop = false, volume = this._volume, relaunch = false, soundKey }) {
78
+ if (!this.canPlayCheck() || (this._soundsState[soundKey].id !== null && !relaunch))
79
+ return false;
80
+
81
+ this.stop({ soundKey });
82
+
83
+ this._soundsState[soundKey].id = this._player.play(soundKey);
84
+
85
+ this.setRelaunch(soundKey, relaunch);
86
+ this.setLoop(soundKey, loop);
87
+ this.setVolume(soundKey, volume);
88
+
89
+ return true;
90
+ };
91
+
92
+ setLoop(soundKey, loop = false) {
93
+ this._soundsState[soundKey].loop = loop;
94
+ this._player.loop(loop, this._soundsState[soundKey].id);
95
+ };
96
+
97
+ setVolume(soundKey, volume = 1) {
98
+ this._soundsState[soundKey].volume = volume;
99
+
100
+ this._player.volume(volume, this._soundsState[soundKey].id);
101
+ };
102
+
103
+ setAllVolume(volume) {
104
+ this._totalVolume = volume;
105
+ this._player._volume = volume;
106
+
107
+ if (this.canPlayCheck()) {
108
+ this._updateVolume();
109
+ }
110
+ }
111
+
112
+ _updateVolume() {
113
+ const keys = Object.keys(this._soundsState);
114
+ this._player._volume = this._totalVolume;
115
+ keys.forEach(key => this.setVolume(key, this._totalVolume));
116
+ }
117
+
118
+ setRelaunch(soundKey, needRelaunch = false) {
119
+ this._soundsState[soundKey].relaunch = needRelaunch;
120
+ };
121
+
122
+ stop({ soundKey }) {
123
+ if (!this._soundsState[soundKey].id)
124
+ return;
125
+
126
+ this._player.stop(this._soundsState[soundKey].id);
127
+ this._soundsState[soundKey].id = null;
128
+ };
129
+
130
+ pause({ soundKey }) {
131
+ if (this.canPlayCheck() || this._player.playing(this._soundsState[soundKey].id))
132
+ this._player.pause(this._soundsState[soundKey].id);
133
+ };
134
+
135
+ resume({ soundKey }) {
136
+ if (this.canPlayCheck() && !this._player.playing(this._soundsState[soundKey].id))
137
+ this._player.play(this._soundsState[soundKey].id);
138
+ };
139
+
140
+ updateEvents(eventsCfg) {
141
+ this._customUnsubscribe();
142
+ this._saveEvents(eventsCfg);
143
+ this._customSubscribe();
144
+ };
145
+
146
+ _saveEvents(eventsCfg) {
147
+ this._eventsCfg = eventsCfg;
148
+ }
149
+
150
+ _setEventCallback(soundKey, event) {
151
+ return function () {
152
+ const params = this._eventsCfg[soundKey].events[event];
153
+
154
+ this._reactToEvent(soundKey, params);
155
+ };
156
+ };
157
+
158
+ _onUnlock() {
159
+ this._runEventsFromQueue();
160
+ this._updateVolume();
161
+ };
162
+
163
+ _runEventsFromQueue() {
164
+ this._eventsQueue.forEach(event => this._reactToEvent(event.soundKey, event));
165
+ this._eventsQueue = [];
166
+ };
167
+
168
+ _addEventToQueue(data) {
169
+ this._eventsQueue.push(data);
170
+ };
171
+
172
+ _reactToEvent(soundKey, { action, loop, relaunch, volume = 0 }) {
173
+ volume *= this._totalVolume;
174
+ const self = this;
175
+ const params = { loop, relaunch, volume, soundKey };
176
+
177
+ if (!self[action])
178
+ Urso.logger.error(`Sound action '${action}' not found!`);
179
+
180
+ if (!this._isAudioUnlocked)
181
+ this._addEventToQueue({ ...params, action });
182
+
183
+ self[action](params);
184
+ };
185
+
186
+ _customSubscribe() {
187
+ for (const soundKey in this._eventsCfg) {
188
+ const { events = {} } = this._eventsCfg[soundKey];
189
+
190
+ for (const event in events) {
191
+ this.addListener(event, this._setEventCallback(soundKey, event).bind(this), true);
192
+ }
193
+ }
194
+ };
195
+
196
+ _customUnsubscribe() {
197
+ for (const event in this._eventsCfg) {
198
+ this.removeListener(event, this._setEventCallback(event).bind(this), true);
199
+ }
200
+ };
201
+ };
202
+
203
203
  module.exports = SoundSprite;
@@ -1,12 +1,12 @@
1
- Urso.Core.Modules.StatesManager = {
2
- Action: require('./action.js'),
3
- All: require('./all.js'),
4
- ConfigStates: require('./configStates.js'),
5
- Controller: require('./controller.js'),
6
- FunctionsStorage: require('./functionsStorage.js'),
7
- Helper: require('./helper.js'),
8
- Race: require('./race.js'),
9
- Sequence: require('./sequence.js')
10
- };
11
-
12
- require('./actions/_info.js');
1
+ Urso.Core.Modules.StatesManager = {
2
+ Action: require('./action.js'),
3
+ All: require('./all.js'),
4
+ ConfigStates: require('./configStates.js'),
5
+ Controller: require('./controller.js'),
6
+ FunctionsStorage: require('./functionsStorage.js'),
7
+ Helper: require('./helper.js'),
8
+ Race: require('./race.js'),
9
+ Sequence: require('./sequence.js')
10
+ };
11
+
12
+ require('./actions/_info.js');