@urso/core 0.4.1 → 0.4.2
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/package.json
CHANGED
|
@@ -36,49 +36,83 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @param {
|
|
39
|
+
* play spine animation and execute function after animation completes
|
|
40
|
+
* @param {String} animation - name of the animation to be played
|
|
41
|
+
* @param {Function} func - function to be executed
|
|
41
42
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this._baseObject.state.clearTrack(track);
|
|
45
|
-
else
|
|
46
|
-
this._baseObject.state.clearTracks();
|
|
43
|
+
playAndThen(animation, func) {
|
|
44
|
+
this.playInSequenceAndThen([animation], func);
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
/**
|
|
50
|
-
*
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {String} slotName
|
|
53
|
-
* @param {Boolean} replaceSlotContent - will replace other slot content
|
|
48
|
+
* play spine animations in sequence
|
|
49
|
+
* @param {String[]} animations - names of the animations to be played
|
|
54
50
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
51
|
+
playInSequence(animations) {
|
|
52
|
+
this.stop();
|
|
53
|
+
const defaultTrack = 0;
|
|
54
|
+
animations.forEach(e => this._baseObject.state.addAnimation(defaultTrack, e));
|
|
55
|
+
}
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
/**
|
|
58
|
+
* play spine animations in sequence and execute function after last animation completes
|
|
59
|
+
* @param {String[]} animations - names of the animations to be played
|
|
60
|
+
* @param {Function} func - function to be executed
|
|
61
|
+
*/
|
|
62
|
+
playInSequenceAndThen(animations, func) {
|
|
63
|
+
let animationsLeft = animations.length;
|
|
64
|
+
let removeSelf = () => { };
|
|
65
|
+
let completer = {
|
|
66
|
+
complete: () => {
|
|
67
|
+
if (--animationsLeft === 0) {
|
|
68
|
+
func();
|
|
69
|
+
removeSelf();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
removeSelf = () => this._baseObject.state.removeListener(completer);
|
|
74
|
+
this._baseObject.state.addListener(completer);
|
|
75
|
+
this.playInSequence(animations);
|
|
76
|
+
}
|
|
62
77
|
|
|
63
|
-
|
|
78
|
+
/**
|
|
79
|
+
* stop track animation
|
|
80
|
+
* @param {Number} [track] - you can define track number to stop
|
|
81
|
+
*/
|
|
82
|
+
stopTrack(track) {
|
|
83
|
+
this._baseObject.state.clearTrack(track);
|
|
84
|
+
}
|
|
64
85
|
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
/**
|
|
87
|
+
* stop all animations
|
|
88
|
+
*/
|
|
89
|
+
stop() {
|
|
90
|
+
this._baseObject.state.clearTracks();
|
|
91
|
+
}
|
|
67
92
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
93
|
+
/**
|
|
94
|
+
* reset all animations
|
|
95
|
+
*/
|
|
96
|
+
reset() {
|
|
97
|
+
this._baseObject.state.setEmptyAnimations();
|
|
73
98
|
}
|
|
74
99
|
|
|
75
100
|
/**
|
|
76
|
-
*
|
|
101
|
+
* add object to spine slot
|
|
102
|
+
* @param {String} slotName
|
|
77
103
|
* @param {Object} object - created by engine object
|
|
104
|
+
*/
|
|
105
|
+
addToSlot(slotName, object) {
|
|
106
|
+
this._addToSlot(slotName, object, false);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* replace spine slot with new object
|
|
78
111
|
* @param {String} slotName
|
|
112
|
+
* @param {Object} object - created by engine object
|
|
79
113
|
*/
|
|
80
|
-
replaceSlotWith(
|
|
81
|
-
this.
|
|
114
|
+
replaceSlotWith(slotName, object) {
|
|
115
|
+
this._addToSlot(slotName, object, true);
|
|
82
116
|
}
|
|
83
117
|
|
|
84
118
|
/**
|
|
@@ -100,6 +134,9 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
100
134
|
this._baseObject.state.timeScale = config.timeScale;*/ //deprecated - now we use getTimeScale getter
|
|
101
135
|
|
|
102
136
|
if (config.onComplete) {
|
|
137
|
+
if (this._baseObject.state.listeners.length !== 0) {
|
|
138
|
+
Urso.logger.warn('ModulesObjectsModelsSpine setAnimationConfig warning: animation state listeners will be cleared');
|
|
139
|
+
}
|
|
103
140
|
this._baseObject.state.clearListeners();
|
|
104
141
|
this._baseObject.state.addListener({ complete: this.animation.onComplete });
|
|
105
142
|
}
|
|
@@ -126,6 +163,26 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
126
163
|
this.play(this.animation.name, this.animation.loop);
|
|
127
164
|
};
|
|
128
165
|
|
|
166
|
+
_addToSlot(slotName, object, replaceSlotContents) {
|
|
167
|
+
const spine = this._baseObject;
|
|
168
|
+
const slotIndex = spine.spineData.slots.findIndex(({ name }) => name === slotName);
|
|
169
|
+
const currentSlot = spine.slotContainers[slotIndex];
|
|
170
|
+
|
|
171
|
+
if (currentSlot) {
|
|
172
|
+
object._baseObject.scale.y = -1;
|
|
173
|
+
|
|
174
|
+
Urso.objects.removeChild(object.parent, object);
|
|
175
|
+
|
|
176
|
+
if (replaceSlotContents)
|
|
177
|
+
currentSlot.removeChildren(); //todo check if its proxy and reset parent
|
|
178
|
+
|
|
179
|
+
//object.parent = this; //todo && make removeChild
|
|
180
|
+
currentSlot.addChild(object._baseObject);
|
|
181
|
+
} else {
|
|
182
|
+
Urso.logger.warn('ModulesObjectsModelsSpine _addToSlot error: no spine slot ' + slotName);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
129
186
|
/**
|
|
130
187
|
* get animation timeScale
|
|
131
188
|
* @returns Number
|