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