@urso/core 0.7.91 → 0.7.93-dev

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 (133) hide show
  1. package/.babelrc +11 -11
  2. package/LICENSE +20 -20
  3. package/README.md +227 -227
  4. package/build/162.js/index.js +1 -0
  5. package/build/24.js/index.js +1 -0
  6. package/build/js/index.js +1 -1
  7. package/package.json +50 -50
  8. package/src/js/app.js +104 -104
  9. package/src/js/components/base/controller.js +78 -78
  10. package/src/js/components/debug/controller.js +38 -38
  11. package/src/js/components/debug/coords.js +23 -23
  12. package/src/js/components/debug/fps.js +36 -36
  13. package/src/js/components/debug/template.js +55 -55
  14. package/src/js/components/debug/timescale.js +60 -60
  15. package/src/js/components/deviceRotate/controller.js +95 -95
  16. package/src/js/components/editor/api.js +127 -127
  17. package/src/js/components/editor/controller.js +12 -12
  18. package/src/js/components/fullscreen/android.js +104 -104
  19. package/src/js/components/fullscreen/controller.js +76 -76
  20. package/src/js/components/fullscreen/desktop.js +49 -49
  21. package/src/js/components/fullscreen/ios.js +115 -115
  22. package/src/js/components/layersSwitcher/config.js +26 -26
  23. package/src/js/components/layersSwitcher/controller.js +36 -36
  24. package/src/js/components/loader/controller.js +66 -66
  25. package/src/js/components/loader/template.js +70 -70
  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/controller.js +123 -123
  29. package/src/js/config/load.js +194 -194
  30. package/src/js/config/main.js +17 -17
  31. package/src/js/extra/browserEvents.js +57 -57
  32. package/src/js/extra/main.js +19 -19
  33. package/src/js/extra/pixiPatch.js +171 -171
  34. package/src/js/index.js +7 -7
  35. package/src/js/lib/cache.js +125 -125
  36. package/src/js/lib/composition.js +85 -85
  37. package/src/js/lib/device.js +1215 -1215
  38. package/src/js/lib/helper.js +678 -678
  39. package/src/js/lib/loader.js +211 -211
  40. package/src/js/lib/localData.js +28 -28
  41. package/src/js/lib/logger.js +69 -69
  42. package/src/js/lib/math.js +161 -161
  43. package/src/js/lib/objectPool.js +207 -207
  44. package/src/js/lib/time.js +18 -18
  45. package/src/js/lib/tween.js +152 -152
  46. package/src/js/modules/assets/baseModel.js +20 -20
  47. package/src/js/modules/assets/config.js +38 -38
  48. package/src/js/modules/assets/controller.js +65 -65
  49. package/src/js/modules/assets/models/atlas.js +18 -18
  50. package/src/js/modules/assets/models/audiosprite.js +28 -28
  51. package/src/js/modules/assets/models/bitmapFont.js +10 -10
  52. package/src/js/modules/assets/models/container.js +18 -18
  53. package/src/js/modules/assets/models/font.js +10 -10
  54. package/src/js/modules/assets/models/html.js +10 -10
  55. package/src/js/modules/assets/models/image.js +17 -17
  56. package/src/js/modules/assets/models/json.js +10 -10
  57. package/src/js/modules/assets/models/jsonAtlas.js +10 -10
  58. package/src/js/modules/assets/models/sound.js +16 -16
  59. package/src/js/modules/assets/models/spine.js +16 -16
  60. package/src/js/modules/assets/service.js +541 -541
  61. package/src/js/modules/i18n/config.js +17 -17
  62. package/src/js/modules/i18n/controller.js +71 -71
  63. package/src/js/modules/instances/controller.js +357 -357
  64. package/src/js/modules/logic/config/sounds.js +23 -23
  65. package/src/js/modules/logic/controller.js +52 -52
  66. package/src/js/modules/logic/main.js +8 -8
  67. package/src/js/modules/logic/sounds.js +103 -103
  68. package/src/js/modules/objects/baseModel.js +207 -207
  69. package/src/js/modules/objects/cache.js +99 -99
  70. package/src/js/modules/objects/config.js +9 -9
  71. package/src/js/modules/objects/controller.js +139 -139
  72. package/src/js/modules/objects/find.js +58 -58
  73. package/src/js/modules/objects/models/atlasImage.js +52 -52
  74. package/src/js/modules/objects/models/bitmapText.js +48 -48
  75. package/src/js/modules/objects/models/button.js +196 -196
  76. package/src/js/modules/objects/models/buttonComposite.js +37 -37
  77. package/src/js/modules/objects/models/checkbox.js +96 -96
  78. package/src/js/modules/objects/models/collection.js +54 -54
  79. package/src/js/modules/objects/models/component.js +48 -48
  80. package/src/js/modules/objects/models/container.js +21 -21
  81. package/src/js/modules/objects/models/dragContainer.js +664 -664
  82. package/src/js/modules/objects/models/emitter.js +69 -69
  83. package/src/js/modules/objects/models/emitterFx.js +114 -114
  84. package/src/js/modules/objects/models/graphics.js +40 -40
  85. package/src/js/modules/objects/models/group.js +21 -21
  86. package/src/js/modules/objects/models/hitArea.js +119 -119
  87. package/src/js/modules/objects/models/image.js +36 -36
  88. package/src/js/modules/objects/models/imagesAnimation.js +115 -115
  89. package/src/js/modules/objects/models/mask.js +40 -40
  90. package/src/js/modules/objects/models/nineSlicePlane.js +32 -32
  91. package/src/js/modules/objects/models/scrollbox.js +66 -66
  92. package/src/js/modules/objects/models/slider.js +352 -352
  93. package/src/js/modules/objects/models/spine.js +338 -338
  94. package/src/js/modules/objects/models/text.js +70 -70
  95. package/src/js/modules/objects/models/textInput.js +68 -68
  96. package/src/js/modules/objects/models/toggle.js +179 -179
  97. package/src/js/modules/objects/models/world.js +21 -21
  98. package/src/js/modules/objects/pool.js +68 -68
  99. package/src/js/modules/objects/propertyAdapter.js +588 -588
  100. package/src/js/modules/objects/proxy.js +298 -298
  101. package/src/js/modules/objects/selector.js +136 -136
  102. package/src/js/modules/objects/service.js +254 -254
  103. package/src/js/modules/objects/styles.js +210 -210
  104. package/src/js/modules/observer/controller.js +167 -167
  105. package/src/js/modules/observer/events.js +56 -56
  106. package/src/js/modules/scenes/controller.js +127 -127
  107. package/src/js/modules/scenes/model.js +28 -28
  108. package/src/js/modules/scenes/pixiWrapper.js +351 -351
  109. package/src/js/modules/scenes/resolutions.js +173 -173
  110. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  111. package/src/js/modules/scenes/service.js +146 -146
  112. package/src/js/modules/soundManager/controller.js +103 -103
  113. package/src/js/modules/soundManager/soundSprite.js +285 -285
  114. package/src/js/modules/statesManager/action.js +97 -97
  115. package/src/js/modules/statesManager/all.js +23 -23
  116. package/src/js/modules/statesManager/configStates.js +77 -77
  117. package/src/js/modules/statesManager/controller.js +218 -218
  118. package/src/js/modules/statesManager/functionsStorage.js +82 -82
  119. package/src/js/modules/statesManager/helper.js +27 -27
  120. package/src/js/modules/statesManager/race.js +91 -91
  121. package/src/js/modules/statesManager/sequence.js +48 -48
  122. package/src/js/modules/template/controller.js +28 -28
  123. package/src/js/modules/template/model.js +11 -11
  124. package/src/js/modules/template/service.js +137 -137
  125. package/src/js/modules/template/types.js +48 -48
  126. package/src/js/modules/transport/baseConnectionType.js +25 -25
  127. package/src/js/modules/transport/config.js +13 -13
  128. package/src/js/modules/transport/connectionTypes/websocket.js +76 -76
  129. package/src/js/modules/transport/connectionTypes/xhr.js +46 -46
  130. package/src/js/modules/transport/controller.js +48 -48
  131. package/src/js/modules/transport/decorator.js +17 -17
  132. package/src/js/modules/transport/service.js +150 -150
  133. package/webpack.config.js +47 -47
@@ -1,339 +1,339 @@
1
- const ModulesObjectsBaseModel = require('./../baseModel');
2
-
3
- class ModulesObjectsModelsSpine extends ModulesObjectsBaseModel {
4
- constructor(params) {
5
- super(params);
6
-
7
- this.type = Urso.types.objects.SPINE;
8
- this._addBaseObject();
9
- }
10
-
11
- /**
12
- * setup params to object model
13
- * @param {Object} params
14
- */
15
- setupParams(params) {
16
- super.setupParams(params);
17
-
18
- this.assetKey = Urso.helper.recursiveGet('assetKey', params, false);
19
-
20
- this.animation = {
21
- timeScale: Urso.helper.recursiveGet('animation.timeScale', params, 1),
22
- name: Urso.helper.recursiveGet('animation.name', params, false),
23
- skinName: Urso.helper.recursiveGet('animation.skinName', params, false),
24
- loop: Urso.helper.recursiveGet('animation.loop', params, false),
25
- onComplete: Urso.helper.recursiveGet('animation.onComplete', params, false)
26
- };
27
-
28
- params.animation = this.animation; //we redefine original property here
29
- this.contents = Urso.helper.recursiveGet('contents', params, []);
30
- }
31
-
32
- /**
33
- * play spine animation
34
- * @param {String} animationName
35
- * @param {Boolean} [loopFlag]
36
- * @param {Number} [track] - you can define track number for current animation
37
- */
38
- play(animationName, loopFlag = false, track = 0) {
39
- this._baseObject.state.setAnimation(track, animationName, loopFlag);
40
- }
41
-
42
- /**
43
- * set up the mixes between animations
44
- * @param {String} from - animation name
45
- * @param {String} to - animation name
46
- * @param {Number} duration - time in seconds
47
- * @example setMix("walk", "jump", 0.2)
48
- */
49
- setMix(from, to, duration) {
50
- this._baseObject.stateData.setMix(from, to, duration);
51
- }
52
-
53
- /**
54
- * Clears all listeners and resubscribes to spine events
55
- */
56
- clearListeners() {
57
- this._baseObject.state.clearListeners();
58
- this._baseObject.state.addListener({ event: this._eventHandler.bind(this) });
59
- }
60
-
61
- /**
62
- * set skin by name
63
- * @param {String} skinName
64
- */
65
- setSkinByName(skinName) {
66
- this._baseObject.skeleton.setSkinByName(skinName);
67
- }
68
-
69
- /**
70
- * reset animation to first frame
71
- */
72
- setToSetupPose() {
73
- this._baseObject.skeleton.setToSetupPose();
74
- }
75
-
76
- /**
77
- * set skin by name and reset animation to first frame
78
- * @param {String} skinName
79
- */
80
- setSkinByNameAndReset(skinName) {
81
- this.setSkinByName(skinName);
82
- this.setToSetupPose();
83
- }
84
-
85
- /**
86
- * play spine animation and execute function after animation completes
87
- * @param {String} animation - name of the animation to be played
88
- * @param {Function} func - function to be executed
89
- */
90
- playAndThen(animation, func) {
91
- this.playInSequenceAndThen([animation], func);
92
- }
93
-
94
- /**
95
- * play spine animations in sequence
96
- * @param {String[]} animations - names of the animations to be played
97
- */
98
- playInSequence(animations) {
99
- this._playInSequenceAndThen(animations);
100
- }
101
-
102
- /**
103
- * play spine animations in sequence and execute function after last animation completes
104
- * @param {String[]} animations - names of the animations to be played
105
- * @param {Function} func - function to be executed
106
- */
107
- playInSequenceAndThen(animations, func) {
108
- this._playInSequenceAndThen(animations, func);
109
- }
110
-
111
- /**
112
- * play spine animations in sequence and execute function after last animation completes
113
- * @param {String[]} animations - names of the animations to be played
114
- * @param {Function} func - function to be executed
115
- */
116
- _playInSequenceAndThen(animations, func) {
117
- this.stop();
118
- let removeSelf = () => { };
119
- let animationCount = 0;
120
-
121
- const completer = {
122
- complete: () => {
123
- animationCount++;
124
-
125
- if (animations[animationCount])
126
- this.play(animations[animationCount])
127
- else {
128
- func && func();
129
- removeSelf();
130
- }
131
- }
132
- }
133
-
134
- removeSelf = () => this._baseObject.state.removeListener(completer);
135
- this._baseObject.state.addListener(completer);
136
- this.play(animations[0]);
137
- }
138
-
139
- /**
140
- * stop track animation
141
- * @param {Number} [track] - you can define track number to stop
142
- */
143
- stopTrack(track) {
144
- this.clearTrack(track);
145
- this._baseObject.state.addEmptyAnimation(track, 0.2, 0); //int trackIndex, float mixDuration, float delay
146
- this.setToSetupPose();
147
- }
148
-
149
- /**
150
- * clear track animation
151
- * @param {Number} [track] - you can define track number to stop
152
- */
153
- clearTrack(track) {
154
- this._baseObject.state.clearTrack(track);
155
- }
156
-
157
- /**
158
- * stop all animations
159
- */
160
- stop() {
161
- this._baseObject.state.clearTracks();
162
- }
163
-
164
- /**
165
- * reset all animations
166
- */
167
- reset() {
168
- this._baseObject.state.setEmptyAnimations();
169
- }
170
-
171
- /**
172
- * add object to spine slot
173
- * @param {String} slotName
174
- * @param {Object} object - created by engine object
175
- */
176
- addToSlot(slotName, object) {
177
- this._addToSlot(slotName, object, false);
178
- }
179
-
180
- /**
181
- * replace spine slot with new object
182
- * @param {String} slotName
183
- * @param {Object} object - created by engine object
184
- */
185
- replaceSlotWith(slotName, object) {
186
- this._addToSlot(slotName, object, true);
187
- }
188
-
189
- /**
190
- * set/update animation config
191
- * @param {*} config
192
- * @param {boolean} [noObjectCreate] dont use this flag out of core
193
- *
194
- * config keys:
195
- timeScale
196
- onComplete
197
- */
198
- setAnimationConfig(config = {}, noObjectCreate) {
199
- this.animation = {
200
- ...this.animation,
201
- ...config
202
- };
203
-
204
- /*if (config.timeScale)
205
- this._baseObject.state.timeScale = config.timeScale;*/ //deprecated - now we use getTimeScale getter
206
-
207
- if (config.onComplete) {
208
- if (this._baseObject.state.listeners.length !== 0) {
209
- Urso.logger.warn('ModulesObjectsModelsSpine setAnimationConfig warning: animation state listeners will be cleared');
210
- }
211
-
212
- this._baseObject.state.clearListeners();
213
- this._baseObject.state.addListener({ complete: this.animation.onComplete });
214
- }
215
- }
216
-
217
- /**
218
- * returns skeleton's child by it's name
219
- * @param {string} name
220
- * @returns {DisplayObject}
221
- */
222
- getChildByName(name) {
223
- return this.children[this._baseObject.skeleton.findSlotIndex(name)];
224
- }
225
-
226
- /**
227
- * returns skeleton's slot by it's name
228
- * @param {string} name
229
- * @returns {Slot}
230
- */
231
- findSlot(name) {
232
- return this._baseObject.skeleton.findSlot(name)
233
- }
234
-
235
- /**
236
- * returns skeleton's bone by it's name
237
- * @param {string} name
238
- * @returns {Bone}
239
- */
240
- findBone(name) {
241
- return this._baseObject.skeleton.findBone(name)
242
- }
243
-
244
- /**
245
- * returns IK constraint
246
- * @param {string} name
247
- * @returns {Bone}
248
- */
249
- findIkConstraint(name) {
250
- return this._baseObject.skeleton.findIkConstraint(name)
251
- }
252
-
253
- /**
254
- * returns animation from spineData by it's name
255
- * @param {string} name
256
- * @returns {Animation}
257
- */
258
- findAnimation(name) {
259
- return this._baseObject.spineData.findAnimation(name)
260
- }
261
-
262
- /**
263
- * returns event from spineData by it's name
264
- * @param {string} name
265
- * @returns {EventData}
266
- */
267
- findEvent(name) {
268
- return this._baseObject.spineData.findEvent(name)
269
- }
270
-
271
- /**
272
- * system function
273
- * add object to pixi tree
274
- */
275
- _addBaseObject() {
276
- let spineAsset = Urso.cache.getSpine(this.assetKey);
277
-
278
- if (!spineAsset)
279
- Urso.logger.error('ModulesObjectsModelsSpine assets error: no spine object ' + this.assetKey);
280
-
281
- if (!spineAsset.spineData)
282
- Urso.logger.error('ModulesObjectsModelsSpine assets error: no spine correct object (no spineData) for key ' + this.assetKey);
283
-
284
- this._baseObject = new PIXI.spine.Spine(spineAsset.spineData);
285
- //this._baseObject.state.timeScale = this.animation.timeScale;
286
- Object.defineProperty(this._baseObject.state, 'timeScale', { get: this.getTimeScale.bind(this) });
287
-
288
- if (this.animation.onComplete)
289
- this._baseObject.state.addListener({ complete: this.animation.onComplete });
290
-
291
- if (this.animation.skinName)
292
- this.setSkinByName(this.animation.skinName);
293
-
294
- if (this.animation.name)
295
- this.play(this.animation.name, this.animation.loop);
296
-
297
- this._baseObject.state.addListener({ event: this._eventHandler.bind(this) });
298
- };
299
-
300
- _eventHandler(entry, event) {
301
- this.emit(Urso.events.MODULES_OBJECTS_SPINE_EVENT, { eventName: event.data.name, name: this.name, class: this.class });
302
- }
303
-
304
- _addToSlot(slotName, object, replaceSlotContents) {
305
- if (!object?._baseObject) {
306
- Urso.logger.warn('ModulesObjectsModelsSpine _addToSlot error: invalid object ' + object);
307
- return;
308
- }
309
-
310
- const spine = this._baseObject;
311
- const slotIndex = spine.spineData.slots.findIndex(({ name }) => name === slotName);
312
- const currentSlot = spine.slotContainers[slotIndex];
313
-
314
- if (currentSlot) {
315
- object._baseObject.scale.y = -1;
316
-
317
- Urso.objects.removeChild(object.parent, object, true);
318
-
319
- if (replaceSlotContents)
320
- currentSlot.removeChildren(); //todo check if its proxy and reset parent
321
-
322
- this.addChild(object); //todo make removeChild for addedToSlotObjects
323
- currentSlot.addChild(object._baseObject);
324
- Urso.objects.refreshStyles();
325
- } else {
326
- Urso.logger.warn('ModulesObjectsModelsSpine _addToSlot error: no spine slot ' + slotName);
327
- }
328
- }
329
-
330
- /**
331
- * get animation timeScale
332
- * @returns Number
333
- */
334
- getTimeScale() {
335
- return Urso.scenes.timeScale * this.animation.timeScale;
336
- }
337
- }
338
-
1
+ const ModulesObjectsBaseModel = require('./../baseModel');
2
+
3
+ class ModulesObjectsModelsSpine extends ModulesObjectsBaseModel {
4
+ constructor(params) {
5
+ super(params);
6
+
7
+ this.type = Urso.types.objects.SPINE;
8
+ this._addBaseObject();
9
+ }
10
+
11
+ /**
12
+ * setup params to object model
13
+ * @param {Object} params
14
+ */
15
+ setupParams(params) {
16
+ super.setupParams(params);
17
+
18
+ this.assetKey = Urso.helper.recursiveGet('assetKey', params, false);
19
+
20
+ this.animation = {
21
+ timeScale: Urso.helper.recursiveGet('animation.timeScale', params, 1),
22
+ name: Urso.helper.recursiveGet('animation.name', params, false),
23
+ skinName: Urso.helper.recursiveGet('animation.skinName', params, false),
24
+ loop: Urso.helper.recursiveGet('animation.loop', params, false),
25
+ onComplete: Urso.helper.recursiveGet('animation.onComplete', params, false)
26
+ };
27
+
28
+ params.animation = this.animation; //we redefine original property here
29
+ this.contents = Urso.helper.recursiveGet('contents', params, []);
30
+ }
31
+
32
+ /**
33
+ * play spine animation
34
+ * @param {String} animationName
35
+ * @param {Boolean} [loopFlag]
36
+ * @param {Number} [track] - you can define track number for current animation
37
+ */
38
+ play(animationName, loopFlag = false, track = 0) {
39
+ this._baseObject.state.setAnimation(track, animationName, loopFlag);
40
+ }
41
+
42
+ /**
43
+ * set up the mixes between animations
44
+ * @param {String} from - animation name
45
+ * @param {String} to - animation name
46
+ * @param {Number} duration - time in seconds
47
+ * @example setMix("walk", "jump", 0.2)
48
+ */
49
+ setMix(from, to, duration) {
50
+ this._baseObject.stateData.setMix(from, to, duration);
51
+ }
52
+
53
+ /**
54
+ * Clears all listeners and resubscribes to spine events
55
+ */
56
+ clearListeners() {
57
+ this._baseObject.state.clearListeners();
58
+ this._baseObject.state.addListener({ event: this._eventHandler.bind(this) });
59
+ }
60
+
61
+ /**
62
+ * set skin by name
63
+ * @param {String} skinName
64
+ */
65
+ setSkinByName(skinName) {
66
+ this._baseObject.skeleton.setSkinByName(skinName);
67
+ }
68
+
69
+ /**
70
+ * reset animation to first frame
71
+ */
72
+ setToSetupPose() {
73
+ this._baseObject.skeleton.setToSetupPose();
74
+ }
75
+
76
+ /**
77
+ * set skin by name and reset animation to first frame
78
+ * @param {String} skinName
79
+ */
80
+ setSkinByNameAndReset(skinName) {
81
+ this.setSkinByName(skinName);
82
+ this.setToSetupPose();
83
+ }
84
+
85
+ /**
86
+ * play spine animation and execute function after animation completes
87
+ * @param {String} animation - name of the animation to be played
88
+ * @param {Function} func - function to be executed
89
+ */
90
+ playAndThen(animation, func) {
91
+ this.playInSequenceAndThen([animation], func);
92
+ }
93
+
94
+ /**
95
+ * play spine animations in sequence
96
+ * @param {String[]} animations - names of the animations to be played
97
+ */
98
+ playInSequence(animations) {
99
+ this._playInSequenceAndThen(animations);
100
+ }
101
+
102
+ /**
103
+ * play spine animations in sequence and execute function after last animation completes
104
+ * @param {String[]} animations - names of the animations to be played
105
+ * @param {Function} func - function to be executed
106
+ */
107
+ playInSequenceAndThen(animations, func) {
108
+ this._playInSequenceAndThen(animations, func);
109
+ }
110
+
111
+ /**
112
+ * play spine animations in sequence and execute function after last animation completes
113
+ * @param {String[]} animations - names of the animations to be played
114
+ * @param {Function} func - function to be executed
115
+ */
116
+ _playInSequenceAndThen(animations, func) {
117
+ this.stop();
118
+ let removeSelf = () => { };
119
+ let animationCount = 0;
120
+
121
+ const completer = {
122
+ complete: () => {
123
+ animationCount++;
124
+
125
+ if (animations[animationCount])
126
+ this.play(animations[animationCount])
127
+ else {
128
+ func && func();
129
+ removeSelf();
130
+ }
131
+ }
132
+ }
133
+
134
+ removeSelf = () => this._baseObject.state.removeListener(completer);
135
+ this._baseObject.state.addListener(completer);
136
+ this.play(animations[0]);
137
+ }
138
+
139
+ /**
140
+ * stop track animation
141
+ * @param {Number} [track] - you can define track number to stop
142
+ */
143
+ stopTrack(track) {
144
+ this.clearTrack(track);
145
+ this._baseObject.state.addEmptyAnimation(track, 0.2, 0); //int trackIndex, float mixDuration, float delay
146
+ this.setToSetupPose();
147
+ }
148
+
149
+ /**
150
+ * clear track animation
151
+ * @param {Number} [track] - you can define track number to stop
152
+ */
153
+ clearTrack(track) {
154
+ this._baseObject.state.clearTrack(track);
155
+ }
156
+
157
+ /**
158
+ * stop all animations
159
+ */
160
+ stop() {
161
+ this._baseObject.state.clearTracks();
162
+ }
163
+
164
+ /**
165
+ * reset all animations
166
+ */
167
+ reset() {
168
+ this._baseObject.state.setEmptyAnimations();
169
+ }
170
+
171
+ /**
172
+ * add object to spine slot
173
+ * @param {String} slotName
174
+ * @param {Object} object - created by engine object
175
+ */
176
+ addToSlot(slotName, object) {
177
+ this._addToSlot(slotName, object, false);
178
+ }
179
+
180
+ /**
181
+ * replace spine slot with new object
182
+ * @param {String} slotName
183
+ * @param {Object} object - created by engine object
184
+ */
185
+ replaceSlotWith(slotName, object) {
186
+ this._addToSlot(slotName, object, true);
187
+ }
188
+
189
+ /**
190
+ * set/update animation config
191
+ * @param {*} config
192
+ * @param {boolean} [noObjectCreate] dont use this flag out of core
193
+ *
194
+ * config keys:
195
+ timeScale
196
+ onComplete
197
+ */
198
+ setAnimationConfig(config = {}, noObjectCreate) {
199
+ this.animation = {
200
+ ...this.animation,
201
+ ...config
202
+ };
203
+
204
+ /*if (config.timeScale)
205
+ this._baseObject.state.timeScale = config.timeScale;*/ //deprecated - now we use getTimeScale getter
206
+
207
+ if (config.onComplete) {
208
+ if (this._baseObject.state.listeners.length !== 0) {
209
+ Urso.logger.warn('ModulesObjectsModelsSpine setAnimationConfig warning: animation state listeners will be cleared');
210
+ }
211
+
212
+ this._baseObject.state.clearListeners();
213
+ this._baseObject.state.addListener({ complete: this.animation.onComplete });
214
+ }
215
+ }
216
+
217
+ /**
218
+ * returns skeleton's child by it's name
219
+ * @param {string} name
220
+ * @returns {DisplayObject}
221
+ */
222
+ getChildByName(name) {
223
+ return this.children[this._baseObject.skeleton.findSlotIndex(name)];
224
+ }
225
+
226
+ /**
227
+ * returns skeleton's slot by it's name
228
+ * @param {string} name
229
+ * @returns {Slot}
230
+ */
231
+ findSlot(name) {
232
+ return this._baseObject.skeleton.findSlot(name)
233
+ }
234
+
235
+ /**
236
+ * returns skeleton's bone by it's name
237
+ * @param {string} name
238
+ * @returns {Bone}
239
+ */
240
+ findBone(name) {
241
+ return this._baseObject.skeleton.findBone(name)
242
+ }
243
+
244
+ /**
245
+ * returns IK constraint
246
+ * @param {string} name
247
+ * @returns {Bone}
248
+ */
249
+ findIkConstraint(name) {
250
+ return this._baseObject.skeleton.findIkConstraint(name)
251
+ }
252
+
253
+ /**
254
+ * returns animation from spineData by it's name
255
+ * @param {string} name
256
+ * @returns {Animation}
257
+ */
258
+ findAnimation(name) {
259
+ return this._baseObject.spineData.findAnimation(name)
260
+ }
261
+
262
+ /**
263
+ * returns event from spineData by it's name
264
+ * @param {string} name
265
+ * @returns {EventData}
266
+ */
267
+ findEvent(name) {
268
+ return this._baseObject.spineData.findEvent(name)
269
+ }
270
+
271
+ /**
272
+ * system function
273
+ * add object to pixi tree
274
+ */
275
+ _addBaseObject() {
276
+ let spineAsset = Urso.cache.getSpine(this.assetKey);
277
+
278
+ if (!spineAsset)
279
+ Urso.logger.error('ModulesObjectsModelsSpine assets error: no spine object ' + this.assetKey);
280
+
281
+ if (!spineAsset.spineData)
282
+ Urso.logger.error('ModulesObjectsModelsSpine assets error: no spine correct object (no spineData) for key ' + this.assetKey);
283
+
284
+ this._baseObject = new PIXI.spine.Spine(spineAsset.spineData);
285
+ //this._baseObject.state.timeScale = this.animation.timeScale;
286
+ Object.defineProperty(this._baseObject.state, 'timeScale', { get: this.getTimeScale.bind(this) });
287
+
288
+ if (this.animation.onComplete)
289
+ this._baseObject.state.addListener({ complete: this.animation.onComplete });
290
+
291
+ if (this.animation.skinName)
292
+ this.setSkinByName(this.animation.skinName);
293
+
294
+ if (this.animation.name)
295
+ this.play(this.animation.name, this.animation.loop);
296
+
297
+ this._baseObject.state.addListener({ event: this._eventHandler.bind(this) });
298
+ };
299
+
300
+ _eventHandler(entry, event) {
301
+ this.emit(Urso.events.MODULES_OBJECTS_SPINE_EVENT, { eventName: event.data.name, name: this.name, class: this.class });
302
+ }
303
+
304
+ _addToSlot(slotName, object, replaceSlotContents) {
305
+ if (!object?._baseObject) {
306
+ Urso.logger.warn('ModulesObjectsModelsSpine _addToSlot error: invalid object ' + object);
307
+ return;
308
+ }
309
+
310
+ const spine = this._baseObject;
311
+ const slotIndex = spine.spineData.slots.findIndex(({ name }) => name === slotName);
312
+ const currentSlot = spine.slotContainers[slotIndex];
313
+
314
+ if (currentSlot) {
315
+ object._baseObject.scale.y = -1;
316
+
317
+ Urso.objects.removeChild(object.parent, object, true);
318
+
319
+ if (replaceSlotContents)
320
+ currentSlot.removeChildren(); //todo check if its proxy and reset parent
321
+
322
+ this.addChild(object); //todo make removeChild for addedToSlotObjects
323
+ currentSlot.addChild(object._baseObject);
324
+ Urso.objects.refreshStyles();
325
+ } else {
326
+ Urso.logger.warn('ModulesObjectsModelsSpine _addToSlot error: no spine slot ' + slotName);
327
+ }
328
+ }
329
+
330
+ /**
331
+ * get animation timeScale
332
+ * @returns Number
333
+ */
334
+ getTimeScale() {
335
+ return Urso.scenes.timeScale * this.animation.timeScale;
336
+ }
337
+ }
338
+
339
339
  module.exports = ModulesObjectsModelsSpine;