@urso/core 0.5.8 → 0.5.11

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 (159) hide show
  1. package/.babelrc +11 -11
  2. package/LICENSE +20 -20
  3. package/README.md +220 -220
  4. package/build/js/index.js +1 -1
  5. package/build/js/index.js.LICENSE.txt +38 -222
  6. package/package.json +52 -52
  7. package/src/js/app.js +78 -78
  8. package/src/js/components/_info.js +10 -10
  9. package/src/js/components/base/_info.js +3 -3
  10. package/src/js/components/base/controller.js +78 -78
  11. package/src/js/components/debug/_info.js +7 -7
  12. package/src/js/components/debug/controller.js +38 -38
  13. package/src/js/components/debug/coords.js +23 -23
  14. package/src/js/components/debug/fps.js +34 -34
  15. package/src/js/components/debug/template.js +55 -55
  16. package/src/js/components/debug/timescale.js +60 -60
  17. package/src/js/components/deviceRotate/_info.js +3 -3
  18. package/src/js/components/deviceRotate/controller.js +86 -86
  19. package/src/js/components/editor/_info.js +4 -0
  20. package/src/js/components/editor/api.js +72 -0
  21. package/src/js/components/editor/controller.js +13 -0
  22. package/src/js/components/fullscreen/_info.js +6 -6
  23. package/src/js/components/fullscreen/android.js +104 -104
  24. package/src/js/components/fullscreen/controller.js +76 -76
  25. package/src/js/components/fullscreen/desktop.js +49 -49
  26. package/src/js/components/fullscreen/ios.js +115 -115
  27. package/src/js/components/layersSwitcher/_info.js +4 -4
  28. package/src/js/components/layersSwitcher/config.js +26 -26
  29. package/src/js/components/layersSwitcher/controller.js +34 -34
  30. package/src/js/components/loader/_info.js +4 -4
  31. package/src/js/components/loader/controller.js +65 -66
  32. package/src/js/components/loader/template.js +70 -70
  33. package/src/js/components/soundInitialPopup/_info.js +3 -3
  34. package/src/js/components/soundInitialPopup/controller.js +42 -42
  35. package/src/js/components/soundInitialPopup/template.js +109 -109
  36. package/src/js/components/stateDriven/_info.js +3 -3
  37. package/src/js/components/stateDriven/controller.js +118 -118
  38. package/src/js/config/load.js +5 -5
  39. package/src/js/config/main.js +12 -12
  40. package/src/js/extra/_info.js +26 -26
  41. package/src/js/extra/browserEvents.js +51 -38
  42. package/src/js/extra/pixiPatch.js +148 -79
  43. package/src/js/extra/setTimeout.js +7 -7
  44. package/src/js/index.js +8 -8
  45. package/src/js/lib/_info.js +13 -13
  46. package/src/js/lib/cache.js +105 -105
  47. package/src/js/lib/composition.js +85 -85
  48. package/src/js/lib/device.js +1286 -1286
  49. package/src/js/lib/helper.js +539 -539
  50. package/src/js/lib/loader.js +136 -136
  51. package/src/js/lib/localData.js +15 -15
  52. package/src/js/lib/logger.js +69 -69
  53. package/src/js/lib/math.js +35 -35
  54. package/src/js/lib/objectPool.js +54 -54
  55. package/src/js/lib/time.js +18 -18
  56. package/src/js/lib/tween.js +147 -147
  57. package/src/js/modules/_info.js +12 -12
  58. package/src/js/modules/assets/_info.js +7 -7
  59. package/src/js/modules/assets/baseModel.js +18 -18
  60. package/src/js/modules/assets/config.js +37 -37
  61. package/src/js/modules/assets/controller.js +46 -46
  62. package/src/js/modules/assets/models/_info.js +11 -11
  63. package/src/js/modules/assets/models/atlas.js +8 -8
  64. package/src/js/modules/assets/models/audiosprite.js +27 -27
  65. package/src/js/modules/assets/models/bitmapFont.js +8 -8
  66. package/src/js/modules/assets/models/container.js +16 -16
  67. package/src/js/modules/assets/models/font.js +8 -8
  68. package/src/js/modules/assets/models/image.js +13 -13
  69. package/src/js/modules/assets/models/json.js +8 -8
  70. package/src/js/modules/assets/models/sound.js +14 -14
  71. package/src/js/modules/assets/models/spine.js +14 -14
  72. package/src/js/modules/assets/service.js +365 -365
  73. package/src/js/modules/i18n/_info.js +4 -4
  74. package/src/js/modules/i18n/config.js +17 -17
  75. package/src/js/modules/i18n/controller.js +79 -79
  76. package/src/js/modules/instances/_info.js +3 -3
  77. package/src/js/modules/instances/controller.js +261 -261
  78. package/src/js/modules/logic/_info.js +4 -4
  79. package/src/js/modules/logic/config/_info.js +2 -2
  80. package/src/js/modules/logic/config/sounds.js +23 -23
  81. package/src/js/modules/logic/controller.js +48 -48
  82. package/src/js/modules/logic/sounds.js +103 -103
  83. package/src/js/modules/objects/_info.js +13 -13
  84. package/src/js/modules/objects/baseModel.js +198 -197
  85. package/src/js/modules/objects/cache.js +99 -99
  86. package/src/js/modules/objects/controller.js +131 -131
  87. package/src/js/modules/objects/find.js +58 -58
  88. package/src/js/modules/objects/models/_info.js +27 -26
  89. package/src/js/modules/objects/models/atlasImage.js +50 -50
  90. package/src/js/modules/objects/models/bitmapText.js +37 -37
  91. package/src/js/modules/objects/models/button.js +189 -189
  92. package/src/js/modules/objects/models/buttonComposite.js +35 -35
  93. package/src/js/modules/objects/models/checkbox.js +96 -96
  94. package/src/js/modules/objects/models/collection.js +54 -54
  95. package/src/js/modules/objects/models/component.js +44 -44
  96. package/src/js/modules/objects/models/container.js +19 -19
  97. package/src/js/modules/objects/models/dragContainer.js +675 -0
  98. package/src/js/modules/objects/models/emitter.js +67 -67
  99. package/src/js/modules/objects/models/emitterFx.js +99 -99
  100. package/src/js/modules/objects/models/graphics.js +38 -38
  101. package/src/js/modules/objects/models/group.js +19 -19
  102. package/src/js/modules/objects/models/hitArea.js +104 -104
  103. package/src/js/modules/objects/models/image.js +34 -34
  104. package/src/js/modules/objects/models/imagesAnimation.js +113 -113
  105. package/src/js/modules/objects/models/mask.js +38 -38
  106. package/src/js/modules/objects/models/nineSlicePlane.js +30 -30
  107. package/src/js/modules/objects/models/scrollbox.js +64 -64
  108. package/src/js/modules/objects/models/slider.js +253 -253
  109. package/src/js/modules/objects/models/spine.js +276 -276
  110. package/src/js/modules/objects/models/text.js +59 -59
  111. package/src/js/modules/objects/models/textInput.js +66 -66
  112. package/src/js/modules/objects/models/toggle.js +180 -180
  113. package/src/js/modules/objects/models/world.js +19 -19
  114. package/src/js/modules/objects/propertyAdapter.js +587 -423
  115. package/src/js/modules/objects/proxy.js +294 -294
  116. package/src/js/modules/objects/selector.js +136 -136
  117. package/src/js/modules/objects/service.js +242 -240
  118. package/src/js/modules/objects/styles.js +210 -210
  119. package/src/js/modules/observer/_info.js +4 -4
  120. package/src/js/modules/observer/controller.js +99 -99
  121. package/src/js/modules/observer/events.js +51 -45
  122. package/src/js/modules/scenes/_info.js +8 -8
  123. package/src/js/modules/scenes/controller.js +103 -103
  124. package/src/js/modules/scenes/model.js +28 -28
  125. package/src/js/modules/scenes/pixiWrapper.js +237 -237
  126. package/src/js/modules/scenes/resolutions.js +173 -173
  127. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  128. package/src/js/modules/scenes/service.js +142 -142
  129. package/src/js/modules/soundManager/_info.js +3 -3
  130. package/src/js/modules/soundManager/controller.js +100 -100
  131. package/src/js/modules/soundManager/soundSprite.js +250 -250
  132. package/src/js/modules/statesManager/_info.js +12 -12
  133. package/src/js/modules/statesManager/action.js +60 -60
  134. package/src/js/modules/statesManager/actions/_info.js +3 -3
  135. package/src/js/modules/statesManager/all.js +23 -23
  136. package/src/js/modules/statesManager/configStates.js +71 -71
  137. package/src/js/modules/statesManager/controller.js +170 -170
  138. package/src/js/modules/statesManager/functionsStorage.js +82 -82
  139. package/src/js/modules/statesManager/helper.js +27 -27
  140. package/src/js/modules/statesManager/race.js +75 -75
  141. package/src/js/modules/statesManager/sequence.js +47 -47
  142. package/src/js/modules/template/_info.js +6 -6
  143. package/src/js/modules/template/controller.js +28 -28
  144. package/src/js/modules/template/model.js +11 -11
  145. package/src/js/modules/template/service.js +137 -137
  146. package/src/js/modules/template/types.js +47 -46
  147. package/src/js/modules/transport/_info.js +8 -8
  148. package/src/js/modules/transport/baseConnectionType.js +24 -24
  149. package/src/js/modules/transport/config.js +13 -13
  150. package/src/js/modules/transport/connectionTypes/_info.js +3 -3
  151. package/src/js/modules/transport/connectionTypes/websocket.js +74 -74
  152. package/src/js/modules/transport/connectionTypes/xhr.js +44 -44
  153. package/src/js/modules/transport/controller.js +48 -48
  154. package/src/js/modules/transport/decorator.js +17 -17
  155. package/src/js/modules/transport/service.js +153 -153
  156. package/src/js/templates/_info.js +4 -4
  157. package/src/js/templates/groups/_info.js +1 -1
  158. package/src/js/templates/scenes/_info.js +1 -1
  159. package/webpack.config.js +47 -47
@@ -1,251 +1,251 @@
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._fadeTweens = {};
14
- this._eventsQueue = [];
15
- this._isAudioUnlocked = false;
16
-
17
- this._reactToEvent = this._reactToEvent.bind(this);
18
- };
19
-
20
-
21
- _initSoundsState() {
22
- const soundsNames = Object.keys(this._sprite);
23
- const soundsStateObj = {};
24
-
25
- soundsNames.forEach(soundName => {
26
- soundsStateObj[soundName] = {
27
- id: null,
28
- loop: false,
29
- volume: 1,
30
- relaunch: false,
31
- _muted: false
32
- }
33
- });
34
-
35
- return soundsStateObj;
36
- }
37
-
38
- _makePlayer(sprite, audiosprite) {
39
- var reader = new FileReader();
40
- reader.readAsDataURL(audiosprite);
41
- reader.onloadend = () => {
42
- var base64data = reader.result;
43
- this._player = new Howl({
44
- src: base64data,
45
- sprite
46
- });
47
- this._subscribePlayerEvents();
48
- }
49
- };
50
-
51
- _subscribePlayerEvents() {
52
- this._player.on('unlock', () => setTimeout(() => {
53
- this._isAudioUnlocked = true;
54
- this._onUnlock();
55
- }, 1000));
56
-
57
- this._player.on('end', id => {
58
- const soundState = this._getSoundStateById(id);
59
-
60
- if (!soundState)
61
- return Urso.logger.error(`SoundSprite error: soundState for id '${id}' not found!`);
62
-
63
- if (!soundState.loop)
64
- soundState.id = null;
65
- });
66
- };
67
-
68
- _getSoundStateById(soundId) {
69
- return Object.values(this._soundsState).find(({ id }) => id === soundId);
70
- }
71
-
72
- canPlayCheck() {
73
- return this._isAudioUnlocked;
74
- };
75
-
76
- play({ loop = false, volume = this._volume, relaunch = false, soundKey }) {
77
- if (!this.canPlayCheck() || (this._soundsState[soundKey].id !== null && !relaunch))
78
- return false;
79
-
80
- this.stop({ soundKey });
81
-
82
- this._soundsState[soundKey].id = this._player.play(soundKey);
83
-
84
- this.setRelaunch(soundKey, relaunch);
85
- this.setLoop(soundKey, loop);
86
- this.setVolume(soundKey, volume);
87
-
88
- return true;
89
- };
90
-
91
- setLoop(soundKey, loop = false) {
92
- this._soundsState[soundKey].loop = loop;
93
- this._player.loop(loop, this._soundsState[soundKey].id);
94
- };
95
-
96
- setVolume(soundKey, volume = 1, saveVolumeState = true) {
97
- this._player.volume(volume, this._soundsState[soundKey].id);
98
-
99
- if(volume === 0) {
100
- this._changeSoundMute(true, soundKey);
101
- return;
102
- }else if(this._soundsState[soundKey]._muted) {
103
- this._changeSoundMute(false, soundKey);
104
- }
105
-
106
- if(saveVolumeState) {
107
- this._soundsState[soundKey].volume = volume;
108
- }
109
- };
110
-
111
- setAllVolume(volume) {
112
- this._totalVolume = volume;
113
- this._player._volume = volume;
114
-
115
- if (this.canPlayCheck()) {
116
- this._updateVolume();
117
- }
118
- }
119
-
120
- _updateVolume() {
121
- const soundKeys = Object.keys(this._soundsState);
122
- this._player._volume = this._totalVolume;
123
- soundKeys.forEach(soundKey => {
124
- const soundVolume = this._soundsState[soundKey].volume * this._totalVolume;
125
- this.setVolume(soundKey, soundVolume, false);
126
- });
127
- }
128
-
129
- _changeSoundMute(needMute, soundKey) {
130
- this._player.mute(needMute, soundKey);
131
- this._soundsState[soundKey]._muted = needMute;
132
- }
133
-
134
- setRelaunch(soundKey, needRelaunch = false) {
135
- this._soundsState[soundKey].relaunch = needRelaunch;
136
- };
137
-
138
- stop({ soundKey }) {
139
- if (!this._soundsState[soundKey].id)
140
- return;
141
-
142
- this._player.stop(this._soundsState[soundKey].id);
143
- this._soundsState[soundKey].id = null;
144
- };
145
-
146
- pause({ soundKey }) {
147
- if (this.canPlayCheck() || this._player.playing(this._soundsState[soundKey].id))
148
- this._player.pause(this._soundsState[soundKey].id);
149
- };
150
-
151
- resume({ soundKey }) {
152
- if (this.canPlayCheck() && !this._player.playing(this._soundsState[soundKey].id))
153
- this._player.play(this._soundsState[soundKey].id);
154
- };
155
-
156
- updateEvents(eventsCfg) {
157
- this._customUnsubscribe();
158
- this._saveEvents(eventsCfg);
159
- this._customSubscribe();
160
- };
161
-
162
- _stopPrevFade(soundKey) {
163
- if(this._fadeTweens[soundKey]) {
164
- this._fadeTweens[soundKey].kill();
165
- }
166
-
167
- delete this._fadeTweens[soundKey];
168
- }
169
-
170
- _startFade({ fadeTo, fadeDuration, soundKey }) {
171
- const fadeFrom = this._soundsState[soundKey].volume;
172
- const delta = fadeTo - fadeFrom;
173
-
174
- const onUpdate = () => {
175
- const volume = (fadeFrom + (delta * this._fadeTweens[soundKey].ratio)) * this._totalVolume;
176
- this.setVolume(soundKey, volume);
177
- };
178
-
179
- this._fadeTweens[soundKey] = gsap.to({}, fadeDuration / 1000, { onUpdate });
180
- }
181
-
182
- fade({ fadeTo = 1, fadeDuration = 200, startSound = false, soundKey, ...others }) {
183
- if(startSound) {
184
- this.play({ ...others, soundKey });
185
- }
186
- if(this._soundsState[soundKey].id === null) {
187
- return;
188
- }
189
-
190
- this._stopPrevFade(soundKey);
191
- this._startFade({ fadeTo, fadeDuration, soundKey });
192
- }
193
-
194
- _saveEvents(eventsCfg) {
195
- this._eventsCfg = eventsCfg;
196
- }
197
-
198
- _setEventCallback(soundKey, event) {
199
- return function () {
200
- const params = this._eventsCfg[soundKey].events[event];
201
-
202
- this._reactToEvent(soundKey, params);
203
- };
204
- };
205
-
206
- _onUnlock() {
207
- this._runEventsFromQueue();
208
- this._updateVolume();
209
- };
210
-
211
- _runEventsFromQueue() {
212
- this._eventsQueue.forEach(event => this._reactToEvent(event.soundKey, event));
213
- this._eventsQueue = [];
214
- };
215
-
216
- _addEventToQueue(data) {
217
- this._eventsQueue.push(data);
218
- };
219
-
220
- _reactToEvent(soundKey, { action, volume, ...otherParams }) {
221
- volume *= this._totalVolume;
222
- const self = this;
223
- const params = { ...otherParams, action, soundKey, volume };
224
-
225
- if (!self[action])
226
- return Urso.logger.error(`SoundSprite error: Sound action '${action}' not found!`);
227
-
228
- if (!this._isAudioUnlocked)
229
- this._addEventToQueue({ ...params, action });
230
-
231
- self[action](params);
232
- };
233
-
234
- _customSubscribe() {
235
- for (const soundKey in this._eventsCfg) {
236
- const { events = {} } = this._eventsCfg[soundKey];
237
-
238
- for (const event in events) {
239
- this.addListener(event, this._setEventCallback(soundKey, event).bind(this), true);
240
- }
241
- }
242
- };
243
-
244
- _customUnsubscribe() {
245
- for (const event in this._eventsCfg) {
246
- this.removeListener(event, this._setEventCallback(event).bind(this), true);
247
- }
248
- };
249
- };
250
-
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._fadeTweens = {};
14
+ this._eventsQueue = [];
15
+ this._isAudioUnlocked = false;
16
+
17
+ this._reactToEvent = this._reactToEvent.bind(this);
18
+ };
19
+
20
+
21
+ _initSoundsState() {
22
+ const soundsNames = Object.keys(this._sprite);
23
+ const soundsStateObj = {};
24
+
25
+ soundsNames.forEach(soundName => {
26
+ soundsStateObj[soundName] = {
27
+ id: null,
28
+ loop: false,
29
+ volume: 1,
30
+ relaunch: false,
31
+ _muted: false
32
+ }
33
+ });
34
+
35
+ return soundsStateObj;
36
+ }
37
+
38
+ _makePlayer(sprite, audiosprite) {
39
+ var reader = new FileReader();
40
+ reader.readAsDataURL(audiosprite);
41
+ reader.onloadend = () => {
42
+ var base64data = reader.result;
43
+ this._player = new Howl({
44
+ src: base64data,
45
+ sprite
46
+ });
47
+ this._subscribePlayerEvents();
48
+ }
49
+ };
50
+
51
+ _subscribePlayerEvents() {
52
+ this._player.on('unlock', () => setTimeout(() => {
53
+ this._isAudioUnlocked = true;
54
+ this._onUnlock();
55
+ }, 1000));
56
+
57
+ this._player.on('end', id => {
58
+ const soundState = this._getSoundStateById(id);
59
+
60
+ if (!soundState)
61
+ return Urso.logger.error(`SoundSprite error: soundState for id '${id}' not found!`);
62
+
63
+ if (!soundState.loop)
64
+ soundState.id = null;
65
+ });
66
+ };
67
+
68
+ _getSoundStateById(soundId) {
69
+ return Object.values(this._soundsState).find(({ id }) => id === soundId);
70
+ }
71
+
72
+ canPlayCheck() {
73
+ return this._isAudioUnlocked;
74
+ };
75
+
76
+ play({ loop = false, volume = this._volume, relaunch = false, soundKey }) {
77
+ if (!this.canPlayCheck() || (this._soundsState[soundKey].id !== null && !relaunch))
78
+ return false;
79
+
80
+ this.stop({ soundKey });
81
+
82
+ this._soundsState[soundKey].id = this._player.play(soundKey);
83
+
84
+ this.setRelaunch(soundKey, relaunch);
85
+ this.setLoop(soundKey, loop);
86
+ this.setVolume(soundKey, volume);
87
+
88
+ return true;
89
+ };
90
+
91
+ setLoop(soundKey, loop = false) {
92
+ this._soundsState[soundKey].loop = loop;
93
+ this._player.loop(loop, this._soundsState[soundKey].id);
94
+ };
95
+
96
+ setVolume(soundKey, volume = 1, saveVolumeState = true) {
97
+ this._player.volume(volume, this._soundsState[soundKey].id);
98
+
99
+ if(volume === 0) {
100
+ this._changeSoundMute(true, soundKey);
101
+ return;
102
+ }else if(this._soundsState[soundKey]._muted) {
103
+ this._changeSoundMute(false, soundKey);
104
+ }
105
+
106
+ if(saveVolumeState) {
107
+ this._soundsState[soundKey].volume = volume;
108
+ }
109
+ };
110
+
111
+ setAllVolume(volume) {
112
+ this._totalVolume = volume;
113
+ this._player._volume = volume;
114
+
115
+ if (this.canPlayCheck()) {
116
+ this._updateVolume();
117
+ }
118
+ }
119
+
120
+ _updateVolume() {
121
+ const soundKeys = Object.keys(this._soundsState);
122
+ this._player._volume = this._totalVolume;
123
+ soundKeys.forEach(soundKey => {
124
+ const soundVolume = this._soundsState[soundKey].volume * this._totalVolume;
125
+ this.setVolume(soundKey, soundVolume, false);
126
+ });
127
+ }
128
+
129
+ _changeSoundMute(needMute, soundKey) {
130
+ this._player.mute(needMute, soundKey);
131
+ this._soundsState[soundKey]._muted = needMute;
132
+ }
133
+
134
+ setRelaunch(soundKey, needRelaunch = false) {
135
+ this._soundsState[soundKey].relaunch = needRelaunch;
136
+ };
137
+
138
+ stop({ soundKey }) {
139
+ if (!this._soundsState[soundKey].id)
140
+ return;
141
+
142
+ this._player.stop(this._soundsState[soundKey].id);
143
+ this._soundsState[soundKey].id = null;
144
+ };
145
+
146
+ pause({ soundKey }) {
147
+ if (this.canPlayCheck() || this._player.playing(this._soundsState[soundKey].id))
148
+ this._player.pause(this._soundsState[soundKey].id);
149
+ };
150
+
151
+ resume({ soundKey }) {
152
+ if (this.canPlayCheck() && !this._player.playing(this._soundsState[soundKey].id))
153
+ this._player.play(this._soundsState[soundKey].id);
154
+ };
155
+
156
+ updateEvents(eventsCfg) {
157
+ this._customUnsubscribe();
158
+ this._saveEvents(eventsCfg);
159
+ this._customSubscribe();
160
+ };
161
+
162
+ _stopPrevFade(soundKey) {
163
+ if(this._fadeTweens[soundKey]) {
164
+ this._fadeTweens[soundKey].kill();
165
+ }
166
+
167
+ delete this._fadeTweens[soundKey];
168
+ }
169
+
170
+ _startFade({ fadeTo, fadeDuration, soundKey }) {
171
+ const fadeFrom = this._soundsState[soundKey].volume;
172
+ const delta = fadeTo - fadeFrom;
173
+
174
+ const onUpdate = () => {
175
+ const volume = (fadeFrom + (delta * this._fadeTweens[soundKey].ratio)) * this._totalVolume;
176
+ this.setVolume(soundKey, volume);
177
+ };
178
+
179
+ this._fadeTweens[soundKey] = gsap.to({}, fadeDuration / 1000, { onUpdate });
180
+ }
181
+
182
+ fade({ fadeTo = 1, fadeDuration = 200, startSound = false, soundKey, ...others }) {
183
+ if(startSound) {
184
+ this.play({ ...others, soundKey });
185
+ }
186
+ if(this._soundsState[soundKey].id === null) {
187
+ return;
188
+ }
189
+
190
+ this._stopPrevFade(soundKey);
191
+ this._startFade({ fadeTo, fadeDuration, soundKey });
192
+ }
193
+
194
+ _saveEvents(eventsCfg) {
195
+ this._eventsCfg = eventsCfg;
196
+ }
197
+
198
+ _setEventCallback(soundKey, event) {
199
+ return function () {
200
+ const params = this._eventsCfg[soundKey].events[event];
201
+
202
+ this._reactToEvent(soundKey, params);
203
+ };
204
+ };
205
+
206
+ _onUnlock() {
207
+ this._runEventsFromQueue();
208
+ this._updateVolume();
209
+ };
210
+
211
+ _runEventsFromQueue() {
212
+ this._eventsQueue.forEach(event => this._reactToEvent(event.soundKey, event));
213
+ this._eventsQueue = [];
214
+ };
215
+
216
+ _addEventToQueue(data) {
217
+ this._eventsQueue.push(data);
218
+ };
219
+
220
+ _reactToEvent(soundKey, { action, volume, ...otherParams }) {
221
+ volume *= this._totalVolume;
222
+ const self = this;
223
+ const params = { ...otherParams, action, soundKey, volume };
224
+
225
+ if (!self[action])
226
+ return Urso.logger.error(`SoundSprite error: Sound action '${action}' not found!`);
227
+
228
+ if (!this._isAudioUnlocked)
229
+ this._addEventToQueue({ ...params, action });
230
+
231
+ self[action](params);
232
+ };
233
+
234
+ _customSubscribe() {
235
+ for (const soundKey in this._eventsCfg) {
236
+ const { events = {} } = this._eventsCfg[soundKey];
237
+
238
+ for (const event in events) {
239
+ this.addListener(event, this._setEventCallback(soundKey, event).bind(this), true);
240
+ }
241
+ }
242
+ };
243
+
244
+ _customUnsubscribe() {
245
+ for (const event in this._eventsCfg) {
246
+ this.removeListener(event, this._setEventCallback(event).bind(this), true);
247
+ }
248
+ };
249
+ };
250
+
251
251
  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');
@@ -1,60 +1,60 @@
1
- class ModulesStatesManagerAction {
2
-
3
- constructor(name) {
4
- this.name = name;
5
-
6
- this._terminating = false;
7
- this.finished = false;
8
- this._onFinishCallback = false;
9
-
10
- this._onFinish = this._onFinish.bind(this);
11
- }
12
-
13
- //can we start this action?
14
- guard() {
15
- return this.getInstance('Controller').checkActionGuard(this.name);
16
- }
17
-
18
- run(onFinishCallback) {
19
- log(`%c action run ---> ${this.name}`, 'color: blue');
20
-
21
- this.emit(Urso.events.MODULES_STATES_MANAGER_ACTION_START, this.name);
22
-
23
- this.finished = false;
24
- this._onFinishCallback = onFinishCallback;
25
-
26
- Urso.statesManager.runAction(this.name, this._onFinish);
27
-
28
- //TODO remove temp for debug
29
- //let timeout = Math.floor(Math.random() * 2000);
30
- //Urso.statesManager.runAction(this.name, () => setTimeout(() => { this._onFinish(); }, timeout));
31
- }
32
-
33
- terminate() {
34
- if (this._terminating) {
35
- Urso.logger.error('ModulesStatesManagerAction: action alredy terminating', this.name);
36
- return;
37
- }
38
-
39
- log(`%c action terminate X ${this.name}`, 'color: blue');
40
- this._terminating = true;
41
- Urso.statesManager.terminateAction(this.name);
42
- }
43
-
44
- _onFinish() {
45
- if (this.finished) {
46
- Urso.logger.error('ModulesStatesManagerAction: action alredy finished', this.name);
47
- return;
48
- }
49
-
50
- this._terminating = false;
51
- this.finished = true;
52
-
53
- this.emit(Urso.events.MODULES_STATES_MANAGER_ACTION_FINISH, this.name);
54
-
55
- log(`%c action finish <--- ${this.name}`, 'color: blue');
56
- this._onFinishCallback();
57
- }
58
- }
59
-
60
- module.exports = ModulesStatesManagerAction;
1
+ class ModulesStatesManagerAction {
2
+
3
+ constructor(name) {
4
+ this.name = name;
5
+
6
+ this._terminating = false;
7
+ this.finished = false;
8
+ this._onFinishCallback = false;
9
+
10
+ this._onFinish = this._onFinish.bind(this);
11
+ }
12
+
13
+ //can we start this action?
14
+ guard() {
15
+ return this.getInstance('Controller').checkActionGuard(this.name);
16
+ }
17
+
18
+ run(onFinishCallback) {
19
+ log(`%c action run ---> ${this.name}`, 'color: blue');
20
+
21
+ this.emit(Urso.events.MODULES_STATES_MANAGER_ACTION_START, this.name);
22
+
23
+ this.finished = false;
24
+ this._onFinishCallback = onFinishCallback;
25
+
26
+ Urso.statesManager.runAction(this.name, this._onFinish);
27
+
28
+ //TODO remove temp for debug
29
+ //let timeout = Math.floor(Math.random() * 2000);
30
+ //Urso.statesManager.runAction(this.name, () => setTimeout(() => { this._onFinish(); }, timeout));
31
+ }
32
+
33
+ terminate() {
34
+ if (this._terminating) {
35
+ Urso.logger.error('ModulesStatesManagerAction: action alredy terminating', this.name);
36
+ return;
37
+ }
38
+
39
+ log(`%c action terminate X ${this.name}`, 'color: blue');
40
+ this._terminating = true;
41
+ Urso.statesManager.terminateAction(this.name);
42
+ }
43
+
44
+ _onFinish() {
45
+ if (this.finished) {
46
+ Urso.logger.error('ModulesStatesManagerAction: action alredy finished', this.name);
47
+ return;
48
+ }
49
+
50
+ this._terminating = false;
51
+ this.finished = true;
52
+
53
+ this.emit(Urso.events.MODULES_STATES_MANAGER_ACTION_FINISH, this.name);
54
+
55
+ log(`%c action finish <--- ${this.name}`, 'color: blue');
56
+ this._onFinishCallback();
57
+ }
58
+ }
59
+
60
+ module.exports = ModulesStatesManagerAction;
@@ -1,3 +1,3 @@
1
- Urso.Core.Modules.StatesManager.Actions = {
2
- //todo
3
- };
1
+ Urso.Core.Modules.StatesManager.Actions = {
2
+ //todo
3
+ };