@urso/core 0.4.34 → 0.4.37
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/build/js/index.js +1 -1
- package/package.json +1 -1
- package/src/js/modules/logic/sounds.js +14 -7
- package/src/js/modules/objects/baseModel.js +6 -0
- package/src/js/modules/objects/models/spine.js +36 -3
- package/src/js/modules/objects/proxy.js +49 -4
- package/src/js/modules/soundManager/controller.js +1 -0
- package/src/js/modules/soundManager/soundSprite.js +45 -7
- package/src/js/modules/template/service.js +1 -1
package/package.json
CHANGED
|
@@ -19,19 +19,26 @@ class ModulesLogicSounds {
|
|
|
19
19
|
const cfg = this._cfg[configName];
|
|
20
20
|
|
|
21
21
|
cfg.forEach(obj => {
|
|
22
|
-
const
|
|
23
|
-
action
|
|
24
|
-
relaunch
|
|
25
|
-
loop
|
|
26
|
-
volume
|
|
27
|
-
|
|
22
|
+
const {
|
|
23
|
+
action = 'play',
|
|
24
|
+
relaunch = false,
|
|
25
|
+
loop = false,
|
|
26
|
+
volume = 1,
|
|
27
|
+
...otherParams
|
|
28
|
+
} = obj;
|
|
28
29
|
|
|
29
30
|
if (!mappedCfg[obj.soundKey])
|
|
30
31
|
mappedCfg[obj.soundKey] = {
|
|
31
32
|
events: {}
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
mappedCfg[obj.soundKey].events[obj.event] =
|
|
35
|
+
mappedCfg[obj.soundKey].events[obj.event] = {
|
|
36
|
+
...otherParams,
|
|
37
|
+
action,
|
|
38
|
+
relaunch,
|
|
39
|
+
loop,
|
|
40
|
+
volume,
|
|
41
|
+
};;
|
|
35
42
|
});
|
|
36
43
|
});
|
|
37
44
|
|
|
@@ -13,6 +13,7 @@ class ModulesObjectsBaseModel {
|
|
|
13
13
|
this._uid = Urso.helper.recursiveGet('_uid', params, false); //will setup on create
|
|
14
14
|
this._templatePath = false;
|
|
15
15
|
this._parsed = false;
|
|
16
|
+
this._transitions = { tweens: {} };
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -44,6 +45,11 @@ class ModulesObjectsBaseModel {
|
|
|
44
45
|
this.visible = Urso.helper.recursiveGet('visible', params, true);
|
|
45
46
|
this.alpha = Urso.helper.recursiveGet('alpha', params, 1);
|
|
46
47
|
this.blendMode = Urso.helper.recursiveGet('blendMode', params, 1);
|
|
48
|
+
|
|
49
|
+
this.transitionDelay = Urso.helper.recursiveGet('transitionDelay', params, false); //time in ms
|
|
50
|
+
this.transitionDuration = Urso.helper.recursiveGet('transitionDuration', params, false); //time in ms
|
|
51
|
+
this.transitionProperty = Urso.helper.recursiveGet('transitionProperty', params, false); //props list ex: 'x', 'x y', 'x y alpha'
|
|
52
|
+
|
|
47
53
|
this.append = Urso.helper.recursiveGet('append', params, true); //if false - object will not created //TODO
|
|
48
54
|
this.custom = Urso.helper.recursiveGet('custom', params, {}); //custom params
|
|
49
55
|
}
|
|
@@ -35,6 +35,21 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
35
35
|
this._baseObject.state.setAnimation(track, animationName, loopFlag);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* set skin by name
|
|
40
|
+
* @param {String} skinName
|
|
41
|
+
*/
|
|
42
|
+
setSkinByName(skinName) {
|
|
43
|
+
this._baseObject.skeleton.setSkinByName(skinName);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* reset animation to first frame
|
|
48
|
+
*/
|
|
49
|
+
setToSetupPose() {
|
|
50
|
+
this._baseObject.skeleton.setToSetupPose();
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
/**
|
|
39
54
|
* play spine animation and execute function after animation completes
|
|
40
55
|
* @param {String} animation - name of the animation to be played
|
|
@@ -50,8 +65,24 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
50
65
|
*/
|
|
51
66
|
playInSequence(animations) {
|
|
52
67
|
this.stop();
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
let removeSelf = () => { };
|
|
69
|
+
let animationCount = 0;
|
|
70
|
+
|
|
71
|
+
const completer = {
|
|
72
|
+
complete: () => {
|
|
73
|
+
animationCount++;
|
|
74
|
+
|
|
75
|
+
if (animations[animationCount])
|
|
76
|
+
this.play(animations[animationCount])
|
|
77
|
+
else {
|
|
78
|
+
removeSelf();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
removeSelf = () => this._baseObject.state.removeListener(completer);
|
|
84
|
+
this._baseObject.state.addListener(completer);
|
|
85
|
+
this.play(animations[0]);
|
|
55
86
|
}
|
|
56
87
|
|
|
57
88
|
/**
|
|
@@ -62,14 +93,16 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
62
93
|
playInSequenceAndThen(animations, func) {
|
|
63
94
|
let animationsLeft = animations.length;
|
|
64
95
|
let removeSelf = () => { };
|
|
96
|
+
|
|
65
97
|
let completer = {
|
|
66
98
|
complete: () => {
|
|
67
99
|
if (--animationsLeft === 0) {
|
|
68
|
-
func();
|
|
100
|
+
func && func();
|
|
69
101
|
removeSelf();
|
|
70
102
|
}
|
|
71
103
|
}
|
|
72
104
|
};
|
|
105
|
+
|
|
73
106
|
removeSelf = () => this._baseObject.state.removeListener(completer);
|
|
74
107
|
this._baseObject.state.addListener(completer);
|
|
75
108
|
this.playInSequence(animations);
|
|
@@ -19,8 +19,9 @@ class ModulesObjectsProxy {
|
|
|
19
19
|
},
|
|
20
20
|
|
|
21
21
|
set(target, key, value, receiver) {
|
|
22
|
+
const oldValue = target._baseObject[key];
|
|
22
23
|
const rv = Reflect.set(target, key, value, receiver);
|
|
23
|
-
_this._customSetLogic(target, key, value, proxy);
|
|
24
|
+
_this._customSetLogic(target, key, value, proxy, oldValue);
|
|
24
25
|
return rv;
|
|
25
26
|
}
|
|
26
27
|
});
|
|
@@ -32,13 +33,15 @@ class ModulesObjectsProxy {
|
|
|
32
33
|
* propertyName - property to adapt for PIXI object
|
|
33
34
|
* value - value to set
|
|
34
35
|
*/
|
|
35
|
-
_setProperty(target, propertyName, value) {
|
|
36
|
+
_setProperty(target, propertyName, value, oldValue) {
|
|
36
37
|
const isAdaptiveProperty = this._propertyAdapter.isAdaptiveProperty(propertyName);
|
|
37
38
|
|
|
38
39
|
if (isAdaptiveProperty)
|
|
39
40
|
this._propertyAdapter.propertyChangeHandler(target, propertyName);
|
|
40
41
|
else
|
|
41
42
|
Urso.helper.recursiveSet(propertyName, value, target._baseObject);
|
|
43
|
+
|
|
44
|
+
this._checkNeedTransitions(target, propertyName, value, oldValue);
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
safeSetValueToTarget(target, key, value) {
|
|
@@ -66,7 +69,7 @@ class ModulesObjectsProxy {
|
|
|
66
69
|
return Urso.helper.recursiveGet(wrapKey, target._baseObject, reflectValue);
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
_customSetLogic(target, key, value, proxy) {
|
|
72
|
+
_customSetLogic(target, key, value, proxy, oldValue) {
|
|
70
73
|
if (!this._getOriginalModelExceptions().includes(key))
|
|
71
74
|
target._originalModel[key] = value;
|
|
72
75
|
|
|
@@ -83,7 +86,7 @@ class ModulesObjectsProxy {
|
|
|
83
86
|
|
|
84
87
|
this._checkSelectorProperties(key);
|
|
85
88
|
|
|
86
|
-
this._setProperty(target, propertyName, value);
|
|
89
|
+
this._setProperty(target, propertyName, value, oldValue);
|
|
87
90
|
|
|
88
91
|
this._checkMaxSize(target);
|
|
89
92
|
|
|
@@ -131,6 +134,48 @@ class ModulesObjectsProxy {
|
|
|
131
134
|
}
|
|
132
135
|
}
|
|
133
136
|
|
|
137
|
+
/**
|
|
138
|
+
* transitions tweens creation
|
|
139
|
+
* @param {Object} target - ObjectsModel
|
|
140
|
+
* @param {String} propertyName
|
|
141
|
+
* @param {Number} value
|
|
142
|
+
* @param {Number} oldValue
|
|
143
|
+
*/
|
|
144
|
+
_checkNeedTransitions(target, propertyName, value, oldValue) {
|
|
145
|
+
if (
|
|
146
|
+
typeof oldValue === 'undefined' ||
|
|
147
|
+
!target.transitionProperty ||
|
|
148
|
+
!target.transitionDuration ||
|
|
149
|
+
!target.transitionProperty.split(' ').includes(propertyName)
|
|
150
|
+
)
|
|
151
|
+
return;
|
|
152
|
+
|
|
153
|
+
const baseNewValue = target._baseObject[propertyName];
|
|
154
|
+
|
|
155
|
+
//remove old active tween
|
|
156
|
+
const currentTween = target._transitions.tweens[propertyName];
|
|
157
|
+
|
|
158
|
+
if (currentTween)
|
|
159
|
+
currentTween.kill();
|
|
160
|
+
|
|
161
|
+
//set base value
|
|
162
|
+
target._baseObject[propertyName] = oldValue;
|
|
163
|
+
|
|
164
|
+
//create new tween
|
|
165
|
+
const tweenParams = { duration: target.transitionDuration / 1000, ease: "none" };
|
|
166
|
+
tweenParams[propertyName] = baseNewValue;
|
|
167
|
+
|
|
168
|
+
if (target.transitionDelay)
|
|
169
|
+
tweenParams.delay = target.transitionDelay / 1000;
|
|
170
|
+
|
|
171
|
+
const newTween = gsap.to(target._baseObject, tweenParams);
|
|
172
|
+
target._transitions.tweens[propertyName] = newTween;
|
|
173
|
+
|
|
174
|
+
newTween.eventCallback("onComplete", () => {
|
|
175
|
+
target._transitions.tweens[propertyName] = null;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
134
179
|
_getSelectorProperties() {
|
|
135
180
|
return [
|
|
136
181
|
'id', 'name', 'class'
|
|
@@ -10,6 +10,7 @@ class SoundSprite {
|
|
|
10
10
|
this._soundsState = this._initSoundsState();
|
|
11
11
|
|
|
12
12
|
this._eventsCfg = {};
|
|
13
|
+
this._fadeTweens = {};
|
|
13
14
|
this._eventsQueue = [];
|
|
14
15
|
this._isAudioUnlocked = false;
|
|
15
16
|
|
|
@@ -97,10 +98,12 @@ class SoundSprite {
|
|
|
97
98
|
this._player.loop(loop, this._soundsState[soundKey].id);
|
|
98
99
|
};
|
|
99
100
|
|
|
100
|
-
setVolume(soundKey, volume = 1) {
|
|
101
|
-
this._soundsState[soundKey].volume = volume;
|
|
102
|
-
|
|
101
|
+
setVolume(soundKey, volume = 1, saveVolumeState = true) {
|
|
103
102
|
this._player.volume(volume, this._soundsState[soundKey].id);
|
|
103
|
+
|
|
104
|
+
if(saveVolumeState) {
|
|
105
|
+
this._soundsState[soundKey].volume = volume;
|
|
106
|
+
}
|
|
104
107
|
};
|
|
105
108
|
|
|
106
109
|
setAllVolume(volume) {
|
|
@@ -113,9 +116,12 @@ class SoundSprite {
|
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
_updateVolume() {
|
|
116
|
-
const
|
|
119
|
+
const soundKeys = Object.keys(this._soundsState);
|
|
117
120
|
this._player._volume = this._totalVolume;
|
|
118
|
-
|
|
121
|
+
soundKeys.forEach(soundKey => {
|
|
122
|
+
const soundVolume = this._soundsState[soundKey].volume * this._totalVolume;
|
|
123
|
+
this.setVolume(soundKey, soundVolume, false);
|
|
124
|
+
});
|
|
119
125
|
}
|
|
120
126
|
|
|
121
127
|
setRelaunch(soundKey, needRelaunch = false) {
|
|
@@ -146,6 +152,38 @@ class SoundSprite {
|
|
|
146
152
|
this._customSubscribe();
|
|
147
153
|
};
|
|
148
154
|
|
|
155
|
+
_stopPrevFade(soundKey) {
|
|
156
|
+
if(this._fadeTweens[soundKey]) {
|
|
157
|
+
this._fadeTweens[soundKey].kill();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
delete this._fadeTweens[soundKey];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
_startFade({ fadeTo, fadeDuration, soundKey }) {
|
|
164
|
+
const fadeFrom = this._soundsState[soundKey].volume;
|
|
165
|
+
const delta = fadeTo - fadeFrom;
|
|
166
|
+
|
|
167
|
+
const onUpdate = () => {
|
|
168
|
+
const volume = fadeFrom + (delta * this._fadeTweens[soundKey].ratio);
|
|
169
|
+
this.setVolume(soundKey, volume);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
this._fadeTweens[soundKey] = gsap.to({}, fadeDuration / 1000, { onUpdate });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
fade({ fadeTo = 1, fadeDuration = 200, startSound = false, soundKey, ...others }) {
|
|
176
|
+
if(startSound) {
|
|
177
|
+
this.play({ ...others, soundKey });
|
|
178
|
+
}
|
|
179
|
+
if(this._soundsState[soundKey].id === null) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
this._stopPrevFade(soundKey);
|
|
184
|
+
this._startFade({ fadeTo, fadeDuration, soundKey });
|
|
185
|
+
}
|
|
186
|
+
|
|
149
187
|
_saveEvents(eventsCfg) {
|
|
150
188
|
this._eventsCfg = eventsCfg;
|
|
151
189
|
}
|
|
@@ -172,10 +210,10 @@ class SoundSprite {
|
|
|
172
210
|
this._eventsQueue.push(data);
|
|
173
211
|
};
|
|
174
212
|
|
|
175
|
-
_reactToEvent(soundKey, { action,
|
|
213
|
+
_reactToEvent(soundKey, { action, volume, ...otherParams }) {
|
|
176
214
|
volume *= this._totalVolume;
|
|
177
215
|
const self = this;
|
|
178
|
-
const params = {
|
|
216
|
+
const params = { ...otherParams, action, soundKey, volume };
|
|
179
217
|
|
|
180
218
|
if (!self[action])
|
|
181
219
|
return Urso.logger.error(`SoundSprite error: Sound action '${action}' not found!`);
|
|
@@ -79,7 +79,7 @@ class ModulesTemplateService {
|
|
|
79
79
|
this._mergeStylesAndAssets({ styles: groupTemplate.styles, assets: groupTemplate.assets })
|
|
80
80
|
|
|
81
81
|
//objects
|
|
82
|
-
obj.contents = groupTemplate.objects;
|
|
82
|
+
obj.contents = groupTemplate.objects || [];
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
_processComponent(obj) {
|