@eva/spine-base 1.2.2-type.0 → 1.2.4
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/dist/EVA.plugin.spineBase.js +89 -26
- package/dist/EVA.plugin.spineBase.min.js +1 -1
- package/dist/miniprogram.js +545 -0
- package/dist/spine-base.cjs.js +71 -23
- package/dist/spine-base.cjs.prod.js +1 -1
- package/dist/spine-base.d.ts +4 -1
- package/dist/spine-base.esm.js +71 -23
- package/package.json +3 -3
|
@@ -183,6 +183,23 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
+
function __values(o) {
|
|
187
|
+
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
188
|
+
m = s && o[s],
|
|
189
|
+
i = 0;
|
|
190
|
+
if (m) return m.call(o);
|
|
191
|
+
if (o && typeof o.length === "number") return {
|
|
192
|
+
next: function next() {
|
|
193
|
+
if (o && i >= o.length) o = void 0;
|
|
194
|
+
return {
|
|
195
|
+
value: o && o[i++],
|
|
196
|
+
done: !o
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
201
|
+
}
|
|
202
|
+
|
|
186
203
|
function getIDEPropsPropertyObj(target, propertyKey) {
|
|
187
204
|
if (!target.constructor.IDEProps) {
|
|
188
205
|
target.constructor.IDEProps = {};
|
|
@@ -213,17 +230,59 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
213
230
|
_this.resource = '';
|
|
214
231
|
_this.animationName = '';
|
|
215
232
|
_this.autoPlay = true;
|
|
233
|
+
_this.waitExecuteInfos = [];
|
|
216
234
|
return _this;
|
|
217
235
|
}
|
|
218
236
|
|
|
237
|
+
Object.defineProperty(Spine.prototype, "armature", {
|
|
238
|
+
get: function get() {
|
|
239
|
+
return this._armature;
|
|
240
|
+
},
|
|
241
|
+
set: function set(val) {
|
|
242
|
+
var e_1, _a;
|
|
243
|
+
|
|
244
|
+
this._armature = val;
|
|
245
|
+
if (!val) return;
|
|
246
|
+
|
|
247
|
+
if (this.autoPlay) {
|
|
248
|
+
this.play(this.animationName);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
for (var _b = __values(this.waitExecuteInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
253
|
+
var info = _c.value;
|
|
254
|
+
|
|
255
|
+
if (info.playType) {
|
|
256
|
+
var name_1 = info.name,
|
|
257
|
+
loop = info.loop,
|
|
258
|
+
track = info.track;
|
|
259
|
+
this.play(name_1, loop, track);
|
|
260
|
+
} else {
|
|
261
|
+
this.stop(info.track);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
} catch (e_1_1) {
|
|
265
|
+
e_1 = {
|
|
266
|
+
error: e_1_1
|
|
267
|
+
};
|
|
268
|
+
} finally {
|
|
269
|
+
try {
|
|
270
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
271
|
+
} finally {
|
|
272
|
+
if (e_1) throw e_1.error;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
this.waitExecuteInfos = [];
|
|
277
|
+
},
|
|
278
|
+
enumerable: false,
|
|
279
|
+
configurable: true
|
|
280
|
+
});
|
|
281
|
+
|
|
219
282
|
Spine.prototype.init = function (obj) {
|
|
220
283
|
if (!obj) return;
|
|
221
284
|
|
|
222
285
|
_extends(this, obj);
|
|
223
|
-
|
|
224
|
-
if (this.autoPlay) {
|
|
225
|
-
this.play(this.animationName);
|
|
226
|
-
}
|
|
227
286
|
};
|
|
228
287
|
|
|
229
288
|
Spine.prototype.onDestroy = function () {
|
|
@@ -234,7 +293,14 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
234
293
|
try {
|
|
235
294
|
if (name) this.animationName = name;
|
|
236
295
|
|
|
237
|
-
if (!this.armature) {
|
|
296
|
+
if (!this.armature) {
|
|
297
|
+
this.waitExecuteInfos.push({
|
|
298
|
+
playType: true,
|
|
299
|
+
name: name,
|
|
300
|
+
loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
|
|
301
|
+
track: track
|
|
302
|
+
});
|
|
303
|
+
} else {
|
|
238
304
|
if (track === undefined) {
|
|
239
305
|
track = 0;
|
|
240
306
|
}
|
|
@@ -248,6 +314,10 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
248
314
|
|
|
249
315
|
Spine.prototype.stop = function (track) {
|
|
250
316
|
if (!this.armature) {
|
|
317
|
+
this.waitExecuteInfos.push({
|
|
318
|
+
playType: false,
|
|
319
|
+
track: track
|
|
320
|
+
});
|
|
251
321
|
return;
|
|
252
322
|
}
|
|
253
323
|
|
|
@@ -536,24 +606,26 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
536
606
|
};
|
|
537
607
|
|
|
538
608
|
SpineSystem.prototype.add = function (changed, count) {
|
|
609
|
+
var _a, _b;
|
|
610
|
+
|
|
539
611
|
return __awaiter(this, void 0, void 0, function () {
|
|
540
612
|
var component, res, spineData, container, armature, tran;
|
|
541
613
|
|
|
542
614
|
var _this = this;
|
|
543
615
|
|
|
544
|
-
return __generator(this, function (
|
|
545
|
-
switch (
|
|
616
|
+
return __generator(this, function (_c) {
|
|
617
|
+
switch (_c.label) {
|
|
546
618
|
case 0:
|
|
547
619
|
component = changed.component;
|
|
548
620
|
clearTimeout(component.addHandler);
|
|
549
621
|
return [4, eva_js.resource.getResource(component.resource)];
|
|
550
622
|
|
|
551
623
|
case 1:
|
|
552
|
-
res =
|
|
624
|
+
res = _c.sent();
|
|
553
625
|
return [4, getSpineData(res, this.pixiSpine)];
|
|
554
626
|
|
|
555
627
|
case 2:
|
|
556
|
-
spineData =
|
|
628
|
+
spineData = _c.sent();
|
|
557
629
|
|
|
558
630
|
if (!spineData) {
|
|
559
631
|
component.addHandler = setTimeout(function () {
|
|
@@ -575,7 +647,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
575
647
|
}
|
|
576
648
|
|
|
577
649
|
this.remove(changed);
|
|
578
|
-
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
650
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
579
651
|
|
|
580
652
|
if (!container) {
|
|
581
653
|
return [2];
|
|
@@ -595,15 +667,6 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
595
667
|
armature.update();
|
|
596
668
|
armature.updateTransform();
|
|
597
669
|
component.armature = armature;
|
|
598
|
-
|
|
599
|
-
if (component.autoPlay) {
|
|
600
|
-
try {
|
|
601
|
-
armature.state.setAnimation(0, component.animationName, true);
|
|
602
|
-
} catch (e) {
|
|
603
|
-
console.log(e);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
670
|
component.emit('loaded', {
|
|
608
671
|
resource: component.resource
|
|
609
672
|
});
|
|
@@ -648,17 +711,17 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
648
711
|
};
|
|
649
712
|
|
|
650
713
|
SpineSystem.prototype.remove = function (changed) {
|
|
651
|
-
var _a, _b;
|
|
714
|
+
var _a, _b, _c, _d;
|
|
652
715
|
|
|
653
716
|
return __awaiter(this, void 0, void 0, function () {
|
|
654
717
|
var component, armature, container, res;
|
|
655
|
-
return __generator(this, function (
|
|
656
|
-
switch (
|
|
718
|
+
return __generator(this, function (_e) {
|
|
719
|
+
switch (_e.label) {
|
|
657
720
|
case 0:
|
|
658
721
|
component = changed.component;
|
|
659
722
|
clearTimeout(component.addHandler);
|
|
660
723
|
armature = this.armatures[changed.gameObject.id];
|
|
661
|
-
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
724
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
662
725
|
|
|
663
726
|
if (container && armature) {
|
|
664
727
|
container.removeChild(armature);
|
|
@@ -671,9 +734,9 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
671
734
|
return [4, eva_js.resource.getResource(component.lastResource)];
|
|
672
735
|
|
|
673
736
|
case 1:
|
|
674
|
-
res =
|
|
675
|
-
releaseSpineData(res.name, (
|
|
676
|
-
|
|
737
|
+
res = _e.sent();
|
|
738
|
+
releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
|
|
739
|
+
_e.label = 2;
|
|
677
740
|
|
|
678
741
|
case 2:
|
|
679
742
|
component.armature = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return
|
|
1
|
+
function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}var _EVA_IIFE_spineBase=function(t,e,r,n){"use strict";var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function a(t,e){function r(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function i(t,e,r,n){var o,a=arguments.length,i=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(o=t[u])&&(i=(a<3?o(i):a>3?o(e,r,i):o(e,r))||i);return a>3&&i&&Object.defineProperty(e,r,i),i}function u(t,e,r,n){return new(r||(r=Promise))((function(o,a){function i(t){try{s(n.next(t))}catch(t){a(t)}}function u(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,u)}s((n=n.apply(t,e||[])).next())}))}function s(t,e){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function c(t){return function(e,r){var n=function(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}(e,r);n.key=r,n.type=t}}var p=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.resource="",e.animationName="",e.autoPlay=!0,e.waitExecuteInfos=[],e}return a(e,t),Object.defineProperty(e.prototype,"armature",{get:function(){return this._armature},set:function(t){var e,r;if(this._armature=t,t){this.autoPlay&&this.play(this.animationName);try{for(var n=function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.waitExecuteInfos),o=n.next();!o.done;o=n.next()){var a=o.value;if(a.playType){var i=a.name,u=a.loop,s=a.track;this.play(i,u,s)}else this.stop(a.track)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(e)throw e.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),e.prototype.init=function(t){t&&_extends(this,t)},e.prototype.onDestroy=function(){this.destroied=!0},e.prototype.play=function(t,e,r){try{t&&(this.animationName=t),this.armature?(void 0===r&&(r=0),this.armature.state.setAnimation(r,this.animationName,e)):this.waitExecuteInfos.push({playType:!0,name:t,loop:null!=e?e:this.autoPlay,track:r})}catch(t){console.log(t)}},e.prototype.stop=function(t){this.armature?(void 0===t&&(t=0),this.armature.state.setEmptyAnimation(t,0)):this.waitExecuteInfos.push({playType:!1,track:t})},e.prototype.addAnimation=function(t,e,r,n){try{this.armature&&(void 0===n&&(n=0),this.armature.state.addAnimation(n,t,r,e))}catch(t){console.log(t)}},e.prototype.setMix=function(t,e,r){this.armature&&this.armature.stateData.setMix(t,e,r)},e.prototype.getAnim=function(t){void 0===t&&(t=0);try{if(this.armature)return this.armature.state.tracks[t].animation.name}catch(t){console.log(t)}},e.prototype.setDefaultMix=function(t){this.armature&&(this.armature.stateData.defaultMix=t)},e.prototype.setAttachment=function(t,e){this.armature&&this.armature.skeleton.setAttachment(t,e)},e.prototype.getBone=function(t){if(this.armature)return this.armature.skeleton.findBone(t)},e.componentName="Spine",i([c("string")],e.prototype,"resource",void 0),i([c("string")],e.prototype,"animationName",void 0),i([c("boolean")],e.prototype,"autoPlay",void 0),e}(e.Component),l={};function m(t){var e=t.image;return{tex:n.Texture.from(e),count:0}}var f={};function d(t,e,r,n){var o=null,a=function(t,e){var r=l[t];return r||(r=m(e),l[t]=r),r.tex}(e.image.src,e);new n.core.TextureAtlas(e.atlas,(function(t,e){e(a.baseTexture)}),(function(t){if(t){var a=new n.core.AtlasAttachmentLoader(t),i=new n.core.SkeletonJson(a);r&&(i.scale=r),o=i.readSkeletonData(e.ske)}}));var i={spineData:o,ref:0,imageSrc:e.image.src};return f[t]=i,i}function h(t,e){return u(this,void 0,void 0,(function(){var r;return s(this,(function(n){if(!(r=f[t.name]))if(t.complete)r=d(t.name,t.data,t.scale,e);else if(!r)return[2];return function(t,e){var r=l[t];r||(r=m(e),l[t]=r),r.count++,r.tex}(t.data.image.src,t.data),r.ref++,[2,r.spineData]}))}))}function y(t,e){var r=f[t];r&&(r.ref--,r.ref<=0&&(!function(t){t&&setTimeout((function(){var e=l[t];e&&(e.count--,e.count<=0&&(e.tex&&(e.tex.destroy(!0),e.tex=null),delete l[t]))}),100)}(e),delete f[t]))}var v=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.armatures={},e}return a(n,t),n.prototype.init=function(t){var n=this,o=t.pixiSpine;this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=o,this.game.canvas.addEventListener("webglcontextrestored",(function(){var t=n.game.gameObjects,r=[];for(var o in n.armatures)for(var a=+o,i=0;i<t.length;++i){var u=t[i];if(u.id===a){var s=u.getComponent(p);s&&(n.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:u,component:s,componentName:p.componentName}),r.push({type:e.OBSERVER_TYPE.ADD,gameObject:u,component:s,componentName:p.componentName}));break}}setTimeout((function(){r.forEach((function(t){n.add(t)}))}),1e3)}),!1)},n.prototype.update=function(e){for(var r in this.armatures)this.armatures[r].update(.001*e.deltaTime),this.armatures[r].updateTransform();t.prototype.update.call(this)},n.prototype.componentChanged=function(t){return u(this,void 0,void 0,(function(){return s(this,(function(r){if("Spine"===t.componentName)if(t.type===e.OBSERVER_TYPE.ADD)this.add(t);else if(t.type===e.OBSERVER_TYPE.CHANGE)switch(t.prop.prop[0]){case"resource":this.change(t)}else t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t);return[2]}))}))},n.prototype.add=function(t,r){var n,o;return u(this,void 0,void 0,(function(){var a,i,u,c,p,l=this;return s(this,(function(s){switch(s.label){case 0:return a=t.component,clearTimeout(a.addHandler),[4,e.resource.getResource(a.resource)];case 1:return[4,h(s.sent(),this.pixiSpine)];case 2:return(i=s.sent())?(this.remove(t),(u=null===(o=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===o?void 0:o.getContainer(t.gameObject.id))?(a.lastResource=a.resource,c=new this.pixiSpine.Spine(i),this.armatures[t.gameObject.id]=c,t.gameObject&&t.gameObject.transform&&(p=t.gameObject.transform,c.x=p.size.width*p.origin.x,c.y=p.size.height*p.origin.y),u.addChildAt(c,0),c.update(),c.updateTransform(),a.armature=c,a.emit("loaded",{resource:a.resource}),c.state.addListener({start:function(t,e){a.emit("start",{track:t,name:t.animation.name})},complete:function(t,e){a.emit("complete",{track:t,name:t.animation.name})},interrupt:function(t,e){a.emit("interrupt",{track:t,name:t.animation.name})},end:function(t,e){a.emit("end",{track:t,name:t.animation.name})},event:function(t,e){a.emit("event",t,e)}}),[2]):[2]):(a.addHandler=setTimeout((function(){a.destroied||(void 0===r&&(r=20),--r>0?l.add(t,r):console.log("retry exceed max times",a.resource))}),1e3),[2])}}))}))},n.prototype.change=function(t){this.remove(t),this.add(t)},n.prototype.remove=function(t){var r,n,o,a;return u(this,void 0,void 0,(function(){var i,u,c,p;return s(this,(function(s){switch(s.label){case 0:return i=t.component,clearTimeout(i.addHandler),u=this.armatures[t.gameObject.id],(c=null===(n=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===n?void 0:n.getContainer(t.gameObject.id))&&u&&c.removeChild(u),i.armature?(i.armature.destroy({children:!0}),[4,e.resource.getResource(i.lastResource)]):[3,2];case 1:y((p=s.sent()).name,null===(a=null===(o=p.data)||void 0===o?void 0:o.image)||void 0===a?void 0:a.src),s.label=2;case 2:return i.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE,[2]}}))}))},n.systemName="SpineSystem",n=i([e.decorators.componentObserver({Spine:["resource"]})],n)}(r.Renderer);return e.resource.registerResourceType("SPINE"),t.Spine=p,t.SpineSystem=v,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,PIXI);
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
|
|
4
|
+
import { __extends, __values, __decorate, __awaiter, __generator } from 'tslib';
|
|
5
|
+
import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
|
|
6
|
+
import { type } from '@eva/inspector-decorator';
|
|
7
|
+
import { Texture } from '@eva/miniprogram-pixi';
|
|
8
|
+
|
|
9
|
+
var Spine = function (_super) {
|
|
10
|
+
__extends(Spine, _super);
|
|
11
|
+
|
|
12
|
+
function Spine() {
|
|
13
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
14
|
+
|
|
15
|
+
_this.resource = '';
|
|
16
|
+
_this.animationName = '';
|
|
17
|
+
_this.autoPlay = true;
|
|
18
|
+
_this.waitExecuteInfos = [];
|
|
19
|
+
return _this;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Object.defineProperty(Spine.prototype, "armature", {
|
|
23
|
+
get: function get() {
|
|
24
|
+
return this._armature;
|
|
25
|
+
},
|
|
26
|
+
set: function set(val) {
|
|
27
|
+
var e_1, _a;
|
|
28
|
+
|
|
29
|
+
this._armature = val;
|
|
30
|
+
if (!val) return;
|
|
31
|
+
|
|
32
|
+
if (this.autoPlay) {
|
|
33
|
+
this.play(this.animationName);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
for (var _b = __values(this.waitExecuteInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
38
|
+
var info = _c.value;
|
|
39
|
+
|
|
40
|
+
if (info.playType) {
|
|
41
|
+
var name_1 = info.name,
|
|
42
|
+
loop = info.loop,
|
|
43
|
+
track = info.track;
|
|
44
|
+
this.play(name_1, loop, track);
|
|
45
|
+
} else {
|
|
46
|
+
this.stop(info.track);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch (e_1_1) {
|
|
50
|
+
e_1 = {
|
|
51
|
+
error: e_1_1
|
|
52
|
+
};
|
|
53
|
+
} finally {
|
|
54
|
+
try {
|
|
55
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
56
|
+
} finally {
|
|
57
|
+
if (e_1) throw e_1.error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.waitExecuteInfos = [];
|
|
62
|
+
},
|
|
63
|
+
enumerable: false,
|
|
64
|
+
configurable: true
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
Spine.prototype.init = function (obj) {
|
|
68
|
+
if (!obj) return;
|
|
69
|
+
|
|
70
|
+
_extends(this, obj);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
Spine.prototype.onDestroy = function () {
|
|
74
|
+
this.destroied = true;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
Spine.prototype.play = function (name, loop, track) {
|
|
78
|
+
try {
|
|
79
|
+
if (name) this.animationName = name;
|
|
80
|
+
|
|
81
|
+
if (!this.armature) {
|
|
82
|
+
this.waitExecuteInfos.push({
|
|
83
|
+
playType: true,
|
|
84
|
+
name: name,
|
|
85
|
+
loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
|
|
86
|
+
track: track
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
if (track === undefined) {
|
|
90
|
+
track = 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
94
|
+
}
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.log(e);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Spine.prototype.stop = function (track) {
|
|
101
|
+
if (!this.armature) {
|
|
102
|
+
this.waitExecuteInfos.push({
|
|
103
|
+
playType: false,
|
|
104
|
+
track: track
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (track === undefined) {
|
|
110
|
+
track = 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.armature.state.setEmptyAnimation(track, 0);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Spine.prototype.addAnimation = function (name, delay, loop, track) {
|
|
117
|
+
try {
|
|
118
|
+
if (!this.armature) {} else {
|
|
119
|
+
if (track === undefined) {
|
|
120
|
+
track = 0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
this.armature.state.addAnimation(track, name, loop, delay);
|
|
124
|
+
}
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.log(e);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
Spine.prototype.setMix = function (from, to, duration) {
|
|
131
|
+
if (!this.armature) ;else {
|
|
132
|
+
this.armature.stateData.setMix(from, to, duration);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
Spine.prototype.getAnim = function (track) {
|
|
137
|
+
if (track === void 0) {
|
|
138
|
+
track = 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
if (!this.armature) {} else {
|
|
143
|
+
return this.armature.state.tracks[track].animation.name;
|
|
144
|
+
}
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.log(e);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
Spine.prototype.setDefaultMix = function (duration) {
|
|
151
|
+
if (!this.armature) ;else {
|
|
152
|
+
this.armature.stateData.defaultMix = duration;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
Spine.prototype.setAttachment = function (slotName, attachmentName) {
|
|
157
|
+
if (!this.armature) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this.armature.skeleton.setAttachment(slotName, attachmentName);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
Spine.prototype.getBone = function (boneName) {
|
|
165
|
+
if (!this.armature) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return this.armature.skeleton.findBone(boneName);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
Spine.componentName = 'Spine';
|
|
173
|
+
|
|
174
|
+
__decorate([type('string')], Spine.prototype, "resource", void 0);
|
|
175
|
+
|
|
176
|
+
__decorate([type('string')], Spine.prototype, "animationName", void 0);
|
|
177
|
+
|
|
178
|
+
__decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
|
|
179
|
+
|
|
180
|
+
return Spine;
|
|
181
|
+
}(Component);
|
|
182
|
+
|
|
183
|
+
var Spine$1 = Spine;
|
|
184
|
+
var texCache = {};
|
|
185
|
+
|
|
186
|
+
function cacheImage(data) {
|
|
187
|
+
var oldImg = data.image;
|
|
188
|
+
return {
|
|
189
|
+
tex: Texture.from(oldImg),
|
|
190
|
+
count: 0
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function retainTexture(name, data) {
|
|
195
|
+
var cache = texCache[name];
|
|
196
|
+
|
|
197
|
+
if (!cache) {
|
|
198
|
+
cache = cacheImage(data);
|
|
199
|
+
texCache[name] = cache;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
cache.count++;
|
|
203
|
+
return cache.tex;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function getTexture(imageSrc, data) {
|
|
207
|
+
var cache = texCache[imageSrc];
|
|
208
|
+
|
|
209
|
+
if (!cache) {
|
|
210
|
+
cache = cacheImage(data);
|
|
211
|
+
texCache[imageSrc] = cache;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return cache.tex;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function releaseTexture(imageSrc) {
|
|
218
|
+
if (!imageSrc) return;
|
|
219
|
+
setTimeout(function () {
|
|
220
|
+
var cache = texCache[imageSrc];
|
|
221
|
+
|
|
222
|
+
if (cache) {
|
|
223
|
+
cache.count--;
|
|
224
|
+
|
|
225
|
+
if (cache.count <= 0) {
|
|
226
|
+
if (cache.tex) {
|
|
227
|
+
cache.tex.destroy(true);
|
|
228
|
+
cache.tex = null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
delete texCache[imageSrc];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}, 100);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
var dataMap = {};
|
|
238
|
+
|
|
239
|
+
function createSpineData(name, data, scale, pixiSpine) {
|
|
240
|
+
var spineData = null;
|
|
241
|
+
var img = getTexture(data.image.src, data);
|
|
242
|
+
new pixiSpine.core.TextureAtlas(data.atlas, function (line, callback) {
|
|
243
|
+
callback(img.baseTexture);
|
|
244
|
+
}, function (spineAtlas) {
|
|
245
|
+
if (spineAtlas) {
|
|
246
|
+
var attachmentLoader = new pixiSpine.core.AtlasAttachmentLoader(spineAtlas);
|
|
247
|
+
var spineJsonParser = new pixiSpine.core.SkeletonJson(attachmentLoader);
|
|
248
|
+
|
|
249
|
+
if (scale) {
|
|
250
|
+
spineJsonParser.scale = scale;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
spineData = spineJsonParser.readSkeletonData(data.ske);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
var obj = {
|
|
257
|
+
spineData: spineData,
|
|
258
|
+
ref: 0,
|
|
259
|
+
imageSrc: data.image.src
|
|
260
|
+
};
|
|
261
|
+
dataMap[name] = obj;
|
|
262
|
+
return obj;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function getSpineData(res, pixiSpine) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
267
|
+
var data;
|
|
268
|
+
return __generator(this, function (_a) {
|
|
269
|
+
data = dataMap[res.name];
|
|
270
|
+
|
|
271
|
+
if (!data) {
|
|
272
|
+
if (res.complete) {
|
|
273
|
+
data = createSpineData(res.name, res.data, res.scale, pixiSpine);
|
|
274
|
+
} else if (!data) {
|
|
275
|
+
return [2];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
retainTexture(res.data.image.src, res.data);
|
|
280
|
+
data.ref++;
|
|
281
|
+
return [2, data.spineData];
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function releaseSpineData(resourceName, imageSrc) {
|
|
287
|
+
var data = dataMap[resourceName];
|
|
288
|
+
|
|
289
|
+
if (!data) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
data.ref--;
|
|
294
|
+
|
|
295
|
+
if (data.ref <= 0) {
|
|
296
|
+
releaseTexture(imageSrc);
|
|
297
|
+
delete dataMap[resourceName];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
var MaxRetryCount = 20;
|
|
302
|
+
|
|
303
|
+
var SpineSystem = function (_super) {
|
|
304
|
+
__extends(SpineSystem, _super);
|
|
305
|
+
|
|
306
|
+
function SpineSystem() {
|
|
307
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
308
|
+
|
|
309
|
+
_this.armatures = {};
|
|
310
|
+
return _this;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
SpineSystem.prototype.init = function (_a) {
|
|
314
|
+
var _this = this;
|
|
315
|
+
|
|
316
|
+
var pixiSpine = _a.pixiSpine;
|
|
317
|
+
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
318
|
+
this.renderSystem.rendererManager.register(this);
|
|
319
|
+
this.pixiSpine = pixiSpine;
|
|
320
|
+
this.game.canvas.addEventListener('webglcontextrestored', function () {
|
|
321
|
+
var objs = _this.game.gameObjects;
|
|
322
|
+
var toAdd = [];
|
|
323
|
+
|
|
324
|
+
for (var k in _this.armatures) {
|
|
325
|
+
var id = +k;
|
|
326
|
+
|
|
327
|
+
for (var i = 0; i < objs.length; ++i) {
|
|
328
|
+
var obj = objs[i];
|
|
329
|
+
|
|
330
|
+
if (obj.id === id) {
|
|
331
|
+
var sp = obj.getComponent(Spine$1);
|
|
332
|
+
|
|
333
|
+
if (sp) {
|
|
334
|
+
_this.remove({
|
|
335
|
+
type: OBSERVER_TYPE.REMOVE,
|
|
336
|
+
gameObject: obj,
|
|
337
|
+
component: sp,
|
|
338
|
+
componentName: Spine$1.componentName
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
toAdd.push({
|
|
342
|
+
type: OBSERVER_TYPE.ADD,
|
|
343
|
+
gameObject: obj,
|
|
344
|
+
component: sp,
|
|
345
|
+
componentName: Spine$1.componentName
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
setTimeout(function () {
|
|
355
|
+
toAdd.forEach(function (obj) {
|
|
356
|
+
_this.add(obj);
|
|
357
|
+
});
|
|
358
|
+
}, 1000);
|
|
359
|
+
}, false);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
SpineSystem.prototype.update = function (e) {
|
|
363
|
+
for (var key in this.armatures) {
|
|
364
|
+
this.armatures[key].update(e.deltaTime * 0.001);
|
|
365
|
+
this.armatures[key].updateTransform();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
_super.prototype.update.call(this);
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
SpineSystem.prototype.componentChanged = function (changed) {
|
|
372
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
373
|
+
return __generator(this, function (_a) {
|
|
374
|
+
if (changed.componentName === 'Spine') {
|
|
375
|
+
if (changed.type === OBSERVER_TYPE.ADD) {
|
|
376
|
+
this.add(changed);
|
|
377
|
+
} else if (changed.type === OBSERVER_TYPE.CHANGE) {
|
|
378
|
+
switch (changed.prop.prop[0]) {
|
|
379
|
+
case 'resource':
|
|
380
|
+
this.change(changed);
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
} else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
384
|
+
this.remove(changed);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return [2];
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
SpineSystem.prototype.add = function (changed, count) {
|
|
394
|
+
var _a, _b;
|
|
395
|
+
|
|
396
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
397
|
+
var component, res, spineData, container, armature, tran;
|
|
398
|
+
|
|
399
|
+
var _this = this;
|
|
400
|
+
|
|
401
|
+
return __generator(this, function (_c) {
|
|
402
|
+
switch (_c.label) {
|
|
403
|
+
case 0:
|
|
404
|
+
component = changed.component;
|
|
405
|
+
clearTimeout(component.addHandler);
|
|
406
|
+
return [4, resource.getResource(component.resource)];
|
|
407
|
+
|
|
408
|
+
case 1:
|
|
409
|
+
res = _c.sent();
|
|
410
|
+
return [4, getSpineData(res, this.pixiSpine)];
|
|
411
|
+
|
|
412
|
+
case 2:
|
|
413
|
+
spineData = _c.sent();
|
|
414
|
+
|
|
415
|
+
if (!spineData) {
|
|
416
|
+
component.addHandler = setTimeout(function () {
|
|
417
|
+
if (!component.destroied) {
|
|
418
|
+
if (count === undefined) {
|
|
419
|
+
count = MaxRetryCount;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
count--;
|
|
423
|
+
|
|
424
|
+
if (count > 0) {
|
|
425
|
+
_this.add(changed, count);
|
|
426
|
+
} else {
|
|
427
|
+
console.log('retry exceed max times', component.resource);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}, 1000);
|
|
431
|
+
return [2];
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
this.remove(changed);
|
|
435
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
436
|
+
|
|
437
|
+
if (!container) {
|
|
438
|
+
return [2];
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
component.lastResource = component.resource;
|
|
442
|
+
armature = new this.pixiSpine.Spine(spineData);
|
|
443
|
+
this.armatures[changed.gameObject.id] = armature;
|
|
444
|
+
|
|
445
|
+
if (changed.gameObject && changed.gameObject.transform) {
|
|
446
|
+
tran = changed.gameObject.transform;
|
|
447
|
+
armature.x = tran.size.width * tran.origin.x;
|
|
448
|
+
armature.y = tran.size.height * tran.origin.y;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
container.addChildAt(armature, 0);
|
|
452
|
+
armature.update();
|
|
453
|
+
armature.updateTransform();
|
|
454
|
+
component.armature = armature;
|
|
455
|
+
component.emit('loaded', {
|
|
456
|
+
resource: component.resource
|
|
457
|
+
});
|
|
458
|
+
armature.state.addListener({
|
|
459
|
+
start: function start(track, event) {
|
|
460
|
+
component.emit('start', {
|
|
461
|
+
track: track,
|
|
462
|
+
name: track.animation.name
|
|
463
|
+
});
|
|
464
|
+
},
|
|
465
|
+
complete: function complete(track, event) {
|
|
466
|
+
component.emit('complete', {
|
|
467
|
+
track: track,
|
|
468
|
+
name: track.animation.name
|
|
469
|
+
});
|
|
470
|
+
},
|
|
471
|
+
interrupt: function interrupt(track, event) {
|
|
472
|
+
component.emit('interrupt', {
|
|
473
|
+
track: track,
|
|
474
|
+
name: track.animation.name
|
|
475
|
+
});
|
|
476
|
+
},
|
|
477
|
+
end: function end(track, event) {
|
|
478
|
+
component.emit('end', {
|
|
479
|
+
track: track,
|
|
480
|
+
name: track.animation.name
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
event: function event(track, _event) {
|
|
484
|
+
component.emit('event', track, _event);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
return [2];
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
SpineSystem.prototype.change = function (changed) {
|
|
494
|
+
this.remove(changed);
|
|
495
|
+
this.add(changed);
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
SpineSystem.prototype.remove = function (changed) {
|
|
499
|
+
var _a, _b, _c, _d;
|
|
500
|
+
|
|
501
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
502
|
+
var component, armature, container, res;
|
|
503
|
+
return __generator(this, function (_e) {
|
|
504
|
+
switch (_e.label) {
|
|
505
|
+
case 0:
|
|
506
|
+
component = changed.component;
|
|
507
|
+
clearTimeout(component.addHandler);
|
|
508
|
+
armature = this.armatures[changed.gameObject.id];
|
|
509
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
510
|
+
|
|
511
|
+
if (container && armature) {
|
|
512
|
+
container.removeChild(armature);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (!component.armature) return [3, 2];
|
|
516
|
+
component.armature.destroy({
|
|
517
|
+
children: true
|
|
518
|
+
});
|
|
519
|
+
return [4, resource.getResource(component.lastResource)];
|
|
520
|
+
|
|
521
|
+
case 1:
|
|
522
|
+
res = _e.sent();
|
|
523
|
+
releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
|
|
524
|
+
_e.label = 2;
|
|
525
|
+
|
|
526
|
+
case 2:
|
|
527
|
+
component.armature = null;
|
|
528
|
+
delete this.armatures[changed.gameObject.id];
|
|
529
|
+
if (changed.type === OBSERVER_TYPE.CHANGE) ;
|
|
530
|
+
return [2];
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
SpineSystem.systemName = 'SpineSystem';
|
|
537
|
+
SpineSystem = __decorate([decorators.componentObserver({
|
|
538
|
+
Spine: ['resource']
|
|
539
|
+
})], SpineSystem);
|
|
540
|
+
return SpineSystem;
|
|
541
|
+
}(Renderer);
|
|
542
|
+
|
|
543
|
+
var SpineSystem$1 = SpineSystem;
|
|
544
|
+
resource.registerResourceType('SPINE');
|
|
545
|
+
export { Spine$1 as Spine, SpineSystem$1 as SpineSystem };
|
package/dist/spine-base.cjs.js
CHANGED
|
@@ -78,6 +78,17 @@ function __generator(thisArg, body) {
|
|
|
78
78
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
79
79
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
80
|
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function __values(o) {
|
|
84
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
85
|
+
if (m) return m.call(o);
|
|
86
|
+
return {
|
|
87
|
+
next: function () {
|
|
88
|
+
if (o && i >= o.length) o = void 0;
|
|
89
|
+
return { value: o && o[i++], done: !o };
|
|
90
|
+
}
|
|
91
|
+
};
|
|
81
92
|
}
|
|
82
93
|
|
|
83
94
|
var Spine = (function (_super) {
|
|
@@ -87,15 +98,49 @@ var Spine = (function (_super) {
|
|
|
87
98
|
_this.resource = '';
|
|
88
99
|
_this.animationName = '';
|
|
89
100
|
_this.autoPlay = true;
|
|
101
|
+
_this.waitExecuteInfos = [];
|
|
90
102
|
return _this;
|
|
91
103
|
}
|
|
104
|
+
Object.defineProperty(Spine.prototype, "armature", {
|
|
105
|
+
get: function () {
|
|
106
|
+
return this._armature;
|
|
107
|
+
},
|
|
108
|
+
set: function (val) {
|
|
109
|
+
var e_1, _a;
|
|
110
|
+
this._armature = val;
|
|
111
|
+
if (!val)
|
|
112
|
+
return;
|
|
113
|
+
if (this.autoPlay) {
|
|
114
|
+
this.play(this.animationName);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
for (var _b = __values(this.waitExecuteInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
118
|
+
var info = _c.value;
|
|
119
|
+
if (info.playType) {
|
|
120
|
+
var name_1 = info.name, loop = info.loop, track = info.track;
|
|
121
|
+
this.play(name_1, loop, track);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.stop(info.track);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
129
|
+
finally {
|
|
130
|
+
try {
|
|
131
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
132
|
+
}
|
|
133
|
+
finally { if (e_1) throw e_1.error; }
|
|
134
|
+
}
|
|
135
|
+
this.waitExecuteInfos = [];
|
|
136
|
+
},
|
|
137
|
+
enumerable: false,
|
|
138
|
+
configurable: true
|
|
139
|
+
});
|
|
92
140
|
Spine.prototype.init = function (obj) {
|
|
93
141
|
if (!obj)
|
|
94
142
|
return;
|
|
95
143
|
Object.assign(this, obj);
|
|
96
|
-
if (this.autoPlay) {
|
|
97
|
-
this.play(this.animationName);
|
|
98
|
-
}
|
|
99
144
|
};
|
|
100
145
|
Spine.prototype.onDestroy = function () {
|
|
101
146
|
this.destroied = true;
|
|
@@ -105,6 +150,12 @@ var Spine = (function (_super) {
|
|
|
105
150
|
if (name)
|
|
106
151
|
this.animationName = name;
|
|
107
152
|
if (!this.armature) {
|
|
153
|
+
this.waitExecuteInfos.push({
|
|
154
|
+
playType: true,
|
|
155
|
+
name: name,
|
|
156
|
+
loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
|
|
157
|
+
track: track
|
|
158
|
+
});
|
|
108
159
|
}
|
|
109
160
|
else {
|
|
110
161
|
if (track === undefined) {
|
|
@@ -119,6 +170,10 @@ var Spine = (function (_super) {
|
|
|
119
170
|
};
|
|
120
171
|
Spine.prototype.stop = function (track) {
|
|
121
172
|
if (!this.armature) {
|
|
173
|
+
this.waitExecuteInfos.push({
|
|
174
|
+
playType: false,
|
|
175
|
+
track: track
|
|
176
|
+
});
|
|
122
177
|
return;
|
|
123
178
|
}
|
|
124
179
|
if (track === undefined) {
|
|
@@ -364,20 +419,21 @@ var SpineSystem = (function (_super) {
|
|
|
364
419
|
});
|
|
365
420
|
};
|
|
366
421
|
SpineSystem.prototype.add = function (changed, count) {
|
|
422
|
+
var _a, _b;
|
|
367
423
|
return __awaiter(this, void 0, void 0, function () {
|
|
368
424
|
var component, res, spineData, container, armature, tran;
|
|
369
425
|
var _this = this;
|
|
370
|
-
return __generator(this, function (
|
|
371
|
-
switch (
|
|
426
|
+
return __generator(this, function (_c) {
|
|
427
|
+
switch (_c.label) {
|
|
372
428
|
case 0:
|
|
373
429
|
component = changed.component;
|
|
374
430
|
clearTimeout(component.addHandler);
|
|
375
431
|
return [4, eva_js.resource.getResource(component.resource)];
|
|
376
432
|
case 1:
|
|
377
|
-
res =
|
|
433
|
+
res = _c.sent();
|
|
378
434
|
return [4, getSpineData(res, this.pixiSpine)];
|
|
379
435
|
case 2:
|
|
380
|
-
spineData =
|
|
436
|
+
spineData = _c.sent();
|
|
381
437
|
if (!spineData) {
|
|
382
438
|
component.addHandler = setTimeout(function () {
|
|
383
439
|
if (!component.destroied) {
|
|
@@ -396,7 +452,7 @@ var SpineSystem = (function (_super) {
|
|
|
396
452
|
return [2];
|
|
397
453
|
}
|
|
398
454
|
this.remove(changed);
|
|
399
|
-
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
455
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
400
456
|
if (!container) {
|
|
401
457
|
return [2];
|
|
402
458
|
}
|
|
@@ -412,14 +468,6 @@ var SpineSystem = (function (_super) {
|
|
|
412
468
|
armature.update();
|
|
413
469
|
armature.updateTransform();
|
|
414
470
|
component.armature = armature;
|
|
415
|
-
if (component.autoPlay) {
|
|
416
|
-
try {
|
|
417
|
-
armature.state.setAnimation(0, component.animationName, true);
|
|
418
|
-
}
|
|
419
|
-
catch (e) {
|
|
420
|
-
console.log(e);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
471
|
component.emit('loaded', { resource: component.resource });
|
|
424
472
|
armature.state.addListener({
|
|
425
473
|
start: function (track, event) {
|
|
@@ -448,16 +496,16 @@ var SpineSystem = (function (_super) {
|
|
|
448
496
|
this.add(changed);
|
|
449
497
|
};
|
|
450
498
|
SpineSystem.prototype.remove = function (changed) {
|
|
451
|
-
var _a, _b;
|
|
499
|
+
var _a, _b, _c, _d;
|
|
452
500
|
return __awaiter(this, void 0, void 0, function () {
|
|
453
501
|
var component, armature, container, res;
|
|
454
|
-
return __generator(this, function (
|
|
455
|
-
switch (
|
|
502
|
+
return __generator(this, function (_e) {
|
|
503
|
+
switch (_e.label) {
|
|
456
504
|
case 0:
|
|
457
505
|
component = changed.component;
|
|
458
506
|
clearTimeout(component.addHandler);
|
|
459
507
|
armature = this.armatures[changed.gameObject.id];
|
|
460
|
-
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
508
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
461
509
|
if (container && armature) {
|
|
462
510
|
container.removeChild(armature);
|
|
463
511
|
}
|
|
@@ -465,9 +513,9 @@ var SpineSystem = (function (_super) {
|
|
|
465
513
|
component.armature.destroy({ children: true });
|
|
466
514
|
return [4, eva_js.resource.getResource(component.lastResource)];
|
|
467
515
|
case 1:
|
|
468
|
-
res =
|
|
469
|
-
releaseSpineData(res.name, (
|
|
470
|
-
|
|
516
|
+
res = _e.sent();
|
|
517
|
+
releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
|
|
518
|
+
_e.label = 2;
|
|
471
519
|
case 2:
|
|
472
520
|
component.armature = null;
|
|
473
521
|
delete this.armatures[changed.gameObject.id];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),r=require("@eva/inspector-decorator"),n=require("pixi.js"),o=function(e,t){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),r=require("@eva/inspector-decorator"),n=require("pixi.js"),o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function a(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function i(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var u=e.length-1;u>=0;u--)(o=e[u])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i}function u(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{s(n.next(e))}catch(e){a(e)}}function u(e){try{s(n.throw(e))}catch(e){a(e)}}function s(e){e.done?o(e.value):new r((function(t){t(e.value)})).then(i,u)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}var c=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.animationName="",t.autoPlay=!0,t.waitExecuteInfos=[],t}return a(t,e),Object.defineProperty(t.prototype,"armature",{get:function(){return this._armature},set:function(e){var t,r;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var n=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(this.waitExecuteInfos),o=n.next();!o.done;o=n.next()){var a=o.value;if(a.playType){var i=a.name,u=a.loop,s=a.track;this.play(i,u,s)}else this.stop(a.track)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),t.prototype.init=function(e){e&&Object.assign(this,e)},t.prototype.onDestroy=function(){this.destroied=!0},t.prototype.play=function(e,t,r){try{e&&(this.animationName=e),this.armature?(void 0===r&&(r=0),this.armature.state.setAnimation(r,this.animationName,t)):this.waitExecuteInfos.push({playType:!0,name:e,loop:null!=t?t:this.autoPlay,track:r})}catch(e){console.log(e)}},t.prototype.stop=function(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})},t.prototype.addAnimation=function(e,t,r,n){try{this.armature&&(void 0===n&&(n=0),this.armature.state.addAnimation(n,e,r,t))}catch(e){console.log(e)}},t.prototype.setMix=function(e,t,r){this.armature&&this.armature.stateData.setMix(e,t,r)},t.prototype.getAnim=function(e){void 0===e&&(e=0);try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}},t.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},t.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},t.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},t.componentName="Spine",i([r.type("string")],t.prototype,"resource",void 0),i([r.type("string")],t.prototype,"animationName",void 0),i([r.type("boolean")],t.prototype,"autoPlay",void 0),t}(e.Component),p={};function l(e){var t=e.image;return{tex:n.Texture.from(t),count:0}}var m={};function f(e,t,r,n){var o=null,a=function(e,t){var r=p[e];return r||(r=l(t),p[e]=r),r.tex}(t.image.src,t);new n.core.TextureAtlas(t.atlas,(function(e,t){t(a.baseTexture)}),(function(e){if(e){var a=new n.core.AtlasAttachmentLoader(e),i=new n.core.SkeletonJson(a);r&&(i.scale=r),o=i.readSkeletonData(t.ske)}}));var i={spineData:o,ref:0,imageSrc:t.image.src};return m[e]=i,i}function d(e,t){return u(this,void 0,void 0,(function(){var r;return s(this,(function(n){if(!(r=m[e.name]))if(e.complete)r=f(e.name,e.data,e.scale,t);else if(!r)return[2];return function(e,t){var r=p[e];r||(r=l(t),p[e]=r),r.count++,r.tex}(e.data.image.src,e.data),r.ref++,[2,r.spineData]}))}))}function h(e,t){var r=m[e];r&&(r.ref--,r.ref<=0&&(!function(e){e&&setTimeout((function(){var t=p[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete p[e]))}),100)}(t),delete m[e]))}var y=function(r){function n(){var e=null!==r&&r.apply(this,arguments)||this;return e.armatures={},e}return a(n,r),n.prototype.init=function(r){var n=this,o=r.pixiSpine;this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=o,this.game.canvas.addEventListener("webglcontextrestored",(function(){var t=n.game.gameObjects,r=[];for(var o in n.armatures)for(var a=+o,i=0;i<t.length;++i){var u=t[i];if(u.id===a){var s=u.getComponent(c);s&&(n.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:u,component:s,componentName:c.componentName}),r.push({type:e.OBSERVER_TYPE.ADD,gameObject:u,component:s,componentName:c.componentName}));break}}setTimeout((function(){r.forEach((function(e){n.add(e)}))}),1e3)}),!1)},n.prototype.update=function(e){for(var t in this.armatures)this.armatures[t].update(.001*e.deltaTime),this.armatures[t].updateTransform();r.prototype.update.call(this)},n.prototype.componentChanged=function(t){return u(this,void 0,void 0,(function(){return s(this,(function(r){if("Spine"===t.componentName)if(t.type===e.OBSERVER_TYPE.ADD)this.add(t);else if(t.type===e.OBSERVER_TYPE.CHANGE)switch(t.prop.prop[0]){case"resource":this.change(t)}else t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t);return[2]}))}))},n.prototype.add=function(t,r){var n,o;return u(this,void 0,void 0,(function(){var a,i,u,c,p,l=this;return s(this,(function(s){switch(s.label){case 0:return a=t.component,clearTimeout(a.addHandler),[4,e.resource.getResource(a.resource)];case 1:return[4,d(s.sent(),this.pixiSpine)];case 2:return(i=s.sent())?(this.remove(t),(u=null===(o=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===o?void 0:o.getContainer(t.gameObject.id))?(a.lastResource=a.resource,c=new this.pixiSpine.Spine(i),this.armatures[t.gameObject.id]=c,t.gameObject&&t.gameObject.transform&&(p=t.gameObject.transform,c.x=p.size.width*p.origin.x,c.y=p.size.height*p.origin.y),u.addChildAt(c,0),c.update(),c.updateTransform(),a.armature=c,a.emit("loaded",{resource:a.resource}),c.state.addListener({start:function(e,t){a.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){a.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){a.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){a.emit("end",{track:e,name:e.animation.name})},event:function(e,t){a.emit("event",e,t)}}),[2]):[2]):(a.addHandler=setTimeout((function(){a.destroied||(void 0===r&&(r=20),--r>0?l.add(t,r):console.log("retry exceed max times",a.resource))}),1e3),[2])}}))}))},n.prototype.change=function(e){this.remove(e),this.add(e)},n.prototype.remove=function(t){var r,n,o,a;return u(this,void 0,void 0,(function(){var i,u,c,p;return s(this,(function(s){switch(s.label){case 0:return i=t.component,clearTimeout(i.addHandler),u=this.armatures[t.gameObject.id],(c=null===(n=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===n?void 0:n.getContainer(t.gameObject.id))&&u&&c.removeChild(u),i.armature?(i.armature.destroy({children:!0}),[4,e.resource.getResource(i.lastResource)]):[3,2];case 1:h((p=s.sent()).name,null===(a=null===(o=p.data)||void 0===o?void 0:o.image)||void 0===a?void 0:a.src),s.label=2;case 2:return i.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE,[2]}}))}))},n.systemName="SpineSystem",n=i([e.decorators.componentObserver({Spine:["resource"]})],n)}(t.Renderer);e.resource.registerResourceType("SPINE"),exports.Spine=c,exports.SpineSystem=y;
|
package/dist/spine-base.d.ts
CHANGED
|
@@ -13,7 +13,10 @@ export declare class Spine extends Component<SpineParams> {
|
|
|
13
13
|
resource: string;
|
|
14
14
|
animationName: string;
|
|
15
15
|
autoPlay: boolean;
|
|
16
|
-
|
|
16
|
+
private _armature;
|
|
17
|
+
private waitExecuteInfos;
|
|
18
|
+
set armature(val: any);
|
|
19
|
+
get armature(): any;
|
|
17
20
|
destroied: boolean;
|
|
18
21
|
addHandler: any;
|
|
19
22
|
lastResource: string;
|
package/dist/spine-base.esm.js
CHANGED
|
@@ -74,6 +74,17 @@ function __generator(thisArg, body) {
|
|
|
74
74
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
75
75
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
76
76
|
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function __values(o) {
|
|
80
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
81
|
+
if (m) return m.call(o);
|
|
82
|
+
return {
|
|
83
|
+
next: function () {
|
|
84
|
+
if (o && i >= o.length) o = void 0;
|
|
85
|
+
return { value: o && o[i++], done: !o };
|
|
86
|
+
}
|
|
87
|
+
};
|
|
77
88
|
}
|
|
78
89
|
|
|
79
90
|
var Spine = (function (_super) {
|
|
@@ -83,15 +94,49 @@ var Spine = (function (_super) {
|
|
|
83
94
|
_this.resource = '';
|
|
84
95
|
_this.animationName = '';
|
|
85
96
|
_this.autoPlay = true;
|
|
97
|
+
_this.waitExecuteInfos = [];
|
|
86
98
|
return _this;
|
|
87
99
|
}
|
|
100
|
+
Object.defineProperty(Spine.prototype, "armature", {
|
|
101
|
+
get: function () {
|
|
102
|
+
return this._armature;
|
|
103
|
+
},
|
|
104
|
+
set: function (val) {
|
|
105
|
+
var e_1, _a;
|
|
106
|
+
this._armature = val;
|
|
107
|
+
if (!val)
|
|
108
|
+
return;
|
|
109
|
+
if (this.autoPlay) {
|
|
110
|
+
this.play(this.animationName);
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
for (var _b = __values(this.waitExecuteInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
114
|
+
var info = _c.value;
|
|
115
|
+
if (info.playType) {
|
|
116
|
+
var name_1 = info.name, loop = info.loop, track = info.track;
|
|
117
|
+
this.play(name_1, loop, track);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this.stop(info.track);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
125
|
+
finally {
|
|
126
|
+
try {
|
|
127
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
128
|
+
}
|
|
129
|
+
finally { if (e_1) throw e_1.error; }
|
|
130
|
+
}
|
|
131
|
+
this.waitExecuteInfos = [];
|
|
132
|
+
},
|
|
133
|
+
enumerable: false,
|
|
134
|
+
configurable: true
|
|
135
|
+
});
|
|
88
136
|
Spine.prototype.init = function (obj) {
|
|
89
137
|
if (!obj)
|
|
90
138
|
return;
|
|
91
139
|
Object.assign(this, obj);
|
|
92
|
-
if (this.autoPlay) {
|
|
93
|
-
this.play(this.animationName);
|
|
94
|
-
}
|
|
95
140
|
};
|
|
96
141
|
Spine.prototype.onDestroy = function () {
|
|
97
142
|
this.destroied = true;
|
|
@@ -101,6 +146,12 @@ var Spine = (function (_super) {
|
|
|
101
146
|
if (name)
|
|
102
147
|
this.animationName = name;
|
|
103
148
|
if (!this.armature) {
|
|
149
|
+
this.waitExecuteInfos.push({
|
|
150
|
+
playType: true,
|
|
151
|
+
name: name,
|
|
152
|
+
loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
|
|
153
|
+
track: track
|
|
154
|
+
});
|
|
104
155
|
}
|
|
105
156
|
else {
|
|
106
157
|
if (track === undefined) {
|
|
@@ -115,6 +166,10 @@ var Spine = (function (_super) {
|
|
|
115
166
|
};
|
|
116
167
|
Spine.prototype.stop = function (track) {
|
|
117
168
|
if (!this.armature) {
|
|
169
|
+
this.waitExecuteInfos.push({
|
|
170
|
+
playType: false,
|
|
171
|
+
track: track
|
|
172
|
+
});
|
|
118
173
|
return;
|
|
119
174
|
}
|
|
120
175
|
if (track === undefined) {
|
|
@@ -360,20 +415,21 @@ var SpineSystem = (function (_super) {
|
|
|
360
415
|
});
|
|
361
416
|
};
|
|
362
417
|
SpineSystem.prototype.add = function (changed, count) {
|
|
418
|
+
var _a, _b;
|
|
363
419
|
return __awaiter(this, void 0, void 0, function () {
|
|
364
420
|
var component, res, spineData, container, armature, tran;
|
|
365
421
|
var _this = this;
|
|
366
|
-
return __generator(this, function (
|
|
367
|
-
switch (
|
|
422
|
+
return __generator(this, function (_c) {
|
|
423
|
+
switch (_c.label) {
|
|
368
424
|
case 0:
|
|
369
425
|
component = changed.component;
|
|
370
426
|
clearTimeout(component.addHandler);
|
|
371
427
|
return [4, resource.getResource(component.resource)];
|
|
372
428
|
case 1:
|
|
373
|
-
res =
|
|
429
|
+
res = _c.sent();
|
|
374
430
|
return [4, getSpineData(res, this.pixiSpine)];
|
|
375
431
|
case 2:
|
|
376
|
-
spineData =
|
|
432
|
+
spineData = _c.sent();
|
|
377
433
|
if (!spineData) {
|
|
378
434
|
component.addHandler = setTimeout(function () {
|
|
379
435
|
if (!component.destroied) {
|
|
@@ -392,7 +448,7 @@ var SpineSystem = (function (_super) {
|
|
|
392
448
|
return [2];
|
|
393
449
|
}
|
|
394
450
|
this.remove(changed);
|
|
395
|
-
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
451
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
396
452
|
if (!container) {
|
|
397
453
|
return [2];
|
|
398
454
|
}
|
|
@@ -408,14 +464,6 @@ var SpineSystem = (function (_super) {
|
|
|
408
464
|
armature.update();
|
|
409
465
|
armature.updateTransform();
|
|
410
466
|
component.armature = armature;
|
|
411
|
-
if (component.autoPlay) {
|
|
412
|
-
try {
|
|
413
|
-
armature.state.setAnimation(0, component.animationName, true);
|
|
414
|
-
}
|
|
415
|
-
catch (e) {
|
|
416
|
-
console.log(e);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
467
|
component.emit('loaded', { resource: component.resource });
|
|
420
468
|
armature.state.addListener({
|
|
421
469
|
start: function (track, event) {
|
|
@@ -444,16 +492,16 @@ var SpineSystem = (function (_super) {
|
|
|
444
492
|
this.add(changed);
|
|
445
493
|
};
|
|
446
494
|
SpineSystem.prototype.remove = function (changed) {
|
|
447
|
-
var _a, _b;
|
|
495
|
+
var _a, _b, _c, _d;
|
|
448
496
|
return __awaiter(this, void 0, void 0, function () {
|
|
449
497
|
var component, armature, container, res;
|
|
450
|
-
return __generator(this, function (
|
|
451
|
-
switch (
|
|
498
|
+
return __generator(this, function (_e) {
|
|
499
|
+
switch (_e.label) {
|
|
452
500
|
case 0:
|
|
453
501
|
component = changed.component;
|
|
454
502
|
clearTimeout(component.addHandler);
|
|
455
503
|
armature = this.armatures[changed.gameObject.id];
|
|
456
|
-
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
504
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
457
505
|
if (container && armature) {
|
|
458
506
|
container.removeChild(armature);
|
|
459
507
|
}
|
|
@@ -461,9 +509,9 @@ var SpineSystem = (function (_super) {
|
|
|
461
509
|
component.armature.destroy({ children: true });
|
|
462
510
|
return [4, resource.getResource(component.lastResource)];
|
|
463
511
|
case 1:
|
|
464
|
-
res =
|
|
465
|
-
releaseSpineData(res.name, (
|
|
466
|
-
|
|
512
|
+
res = _e.sent();
|
|
513
|
+
releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
|
|
514
|
+
_e.label = 2;
|
|
467
515
|
case 2:
|
|
468
516
|
component.armature = null;
|
|
469
517
|
delete this.armatures[changed.gameObject.id];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/spine-base",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "@eva/spine-base",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/spine-base.esm.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "1.2.
|
|
22
|
-
"@eva/plugin-renderer": "1.2.
|
|
21
|
+
"@eva/eva.js": "1.2.4",
|
|
22
|
+
"@eva/plugin-renderer": "1.2.4",
|
|
23
23
|
"@eva/inspector-decorator": "^0.0.5",
|
|
24
24
|
"pixi.js": "^4.8.9"
|
|
25
25
|
}
|