@eva/spine-base 1.2.2-mini.1 → 1.2.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/dist/EVA.plugin.spineBase.js +89 -26
- package/dist/EVA.plugin.spineBase.min.js +1 -1
- package/dist/miniprogram.js +73 -27
- 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,
|
|
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(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var
|
|
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:e,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);
|
package/dist/miniprogram.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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
2
|
|
|
3
3
|
import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
|
|
4
|
-
import { __extends, __decorate, __awaiter, __generator } from 'tslib';
|
|
4
|
+
import { __extends, __values, __decorate, __awaiter, __generator } from 'tslib';
|
|
5
5
|
import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
|
|
6
6
|
import { type } from '@eva/inspector-decorator';
|
|
7
7
|
import { Texture } from '@eva/miniprogram-pixi';
|
|
@@ -15,17 +15,59 @@ var Spine = function (_super) {
|
|
|
15
15
|
_this.resource = '';
|
|
16
16
|
_this.animationName = '';
|
|
17
17
|
_this.autoPlay = true;
|
|
18
|
+
_this.waitExecuteInfos = [];
|
|
18
19
|
return _this;
|
|
19
20
|
}
|
|
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
|
+
|
|
21
67
|
Spine.prototype.init = function (obj) {
|
|
22
68
|
if (!obj) return;
|
|
23
69
|
|
|
24
70
|
_extends(this, obj);
|
|
25
|
-
|
|
26
|
-
if (this.autoPlay) {
|
|
27
|
-
this.play(this.animationName);
|
|
28
|
-
}
|
|
29
71
|
};
|
|
30
72
|
|
|
31
73
|
Spine.prototype.onDestroy = function () {
|
|
@@ -36,7 +78,14 @@ var Spine = function (_super) {
|
|
|
36
78
|
try {
|
|
37
79
|
if (name) this.animationName = name;
|
|
38
80
|
|
|
39
|
-
if (!this.armature) {
|
|
81
|
+
if (!this.armature) {
|
|
82
|
+
this.waitExecuteInfos.push({
|
|
83
|
+
playType: true,
|
|
84
|
+
name: name,
|
|
85
|
+
loop: loop,
|
|
86
|
+
track: track
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
40
89
|
if (track === undefined) {
|
|
41
90
|
track = 0;
|
|
42
91
|
}
|
|
@@ -50,6 +99,10 @@ var Spine = function (_super) {
|
|
|
50
99
|
|
|
51
100
|
Spine.prototype.stop = function (track) {
|
|
52
101
|
if (!this.armature) {
|
|
102
|
+
this.waitExecuteInfos.push({
|
|
103
|
+
playType: false,
|
|
104
|
+
track: track
|
|
105
|
+
});
|
|
53
106
|
return;
|
|
54
107
|
}
|
|
55
108
|
|
|
@@ -338,24 +391,26 @@ var SpineSystem = function (_super) {
|
|
|
338
391
|
};
|
|
339
392
|
|
|
340
393
|
SpineSystem.prototype.add = function (changed, count) {
|
|
394
|
+
var _a, _b;
|
|
395
|
+
|
|
341
396
|
return __awaiter(this, void 0, void 0, function () {
|
|
342
397
|
var component, res, spineData, container, armature, tran;
|
|
343
398
|
|
|
344
399
|
var _this = this;
|
|
345
400
|
|
|
346
|
-
return __generator(this, function (
|
|
347
|
-
switch (
|
|
401
|
+
return __generator(this, function (_c) {
|
|
402
|
+
switch (_c.label) {
|
|
348
403
|
case 0:
|
|
349
404
|
component = changed.component;
|
|
350
405
|
clearTimeout(component.addHandler);
|
|
351
406
|
return [4, resource.getResource(component.resource)];
|
|
352
407
|
|
|
353
408
|
case 1:
|
|
354
|
-
res =
|
|
409
|
+
res = _c.sent();
|
|
355
410
|
return [4, getSpineData(res, this.pixiSpine)];
|
|
356
411
|
|
|
357
412
|
case 2:
|
|
358
|
-
spineData =
|
|
413
|
+
spineData = _c.sent();
|
|
359
414
|
|
|
360
415
|
if (!spineData) {
|
|
361
416
|
component.addHandler = setTimeout(function () {
|
|
@@ -377,7 +432,7 @@ var SpineSystem = function (_super) {
|
|
|
377
432
|
}
|
|
378
433
|
|
|
379
434
|
this.remove(changed);
|
|
380
|
-
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
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);
|
|
381
436
|
|
|
382
437
|
if (!container) {
|
|
383
438
|
return [2];
|
|
@@ -397,15 +452,6 @@ var SpineSystem = function (_super) {
|
|
|
397
452
|
armature.update();
|
|
398
453
|
armature.updateTransform();
|
|
399
454
|
component.armature = armature;
|
|
400
|
-
|
|
401
|
-
if (component.autoPlay) {
|
|
402
|
-
try {
|
|
403
|
-
armature.state.setAnimation(0, component.animationName, true);
|
|
404
|
-
} catch (e) {
|
|
405
|
-
console.log(e);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
455
|
component.emit('loaded', {
|
|
410
456
|
resource: component.resource
|
|
411
457
|
});
|
|
@@ -450,17 +496,17 @@ var SpineSystem = function (_super) {
|
|
|
450
496
|
};
|
|
451
497
|
|
|
452
498
|
SpineSystem.prototype.remove = function (changed) {
|
|
453
|
-
var _a, _b;
|
|
499
|
+
var _a, _b, _c, _d;
|
|
454
500
|
|
|
455
501
|
return __awaiter(this, void 0, void 0, function () {
|
|
456
502
|
var component, armature, container, res;
|
|
457
|
-
return __generator(this, function (
|
|
458
|
-
switch (
|
|
503
|
+
return __generator(this, function (_e) {
|
|
504
|
+
switch (_e.label) {
|
|
459
505
|
case 0:
|
|
460
506
|
component = changed.component;
|
|
461
507
|
clearTimeout(component.addHandler);
|
|
462
508
|
armature = this.armatures[changed.gameObject.id];
|
|
463
|
-
container = this.renderSystem.containerManager.getContainer(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);
|
|
464
510
|
|
|
465
511
|
if (container && armature) {
|
|
466
512
|
container.removeChild(armature);
|
|
@@ -473,9 +519,9 @@ var SpineSystem = function (_super) {
|
|
|
473
519
|
return [4, resource.getResource(component.lastResource)];
|
|
474
520
|
|
|
475
521
|
case 1:
|
|
476
|
-
res =
|
|
477
|
-
releaseSpineData(res.name, (
|
|
478
|
-
|
|
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;
|
|
479
525
|
|
|
480
526
|
case 2:
|
|
481
527
|
component.armature = null;
|
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,
|
|
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(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
|
|
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:t,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 m(e){var t=e.image;return{tex:n.Texture.from(t),count:0}}var l={};function f(e,t,r,n){var o=null,a=function(e,t){var r=p[e];return r||(r=m(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 l[e]=i,i}function d(e,t){return u(this,void 0,void 0,(function(){var r;return s(this,(function(n){if(!(r=l[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=m(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=l[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 l[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,m=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?m.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,
|
|
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.2
|
|
3
|
+
"version": "1.2.2",
|
|
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.2
|
|
22
|
-
"@eva/plugin-renderer": "1.2.2
|
|
21
|
+
"@eva/eva.js": "1.2.2",
|
|
22
|
+
"@eva/plugin-renderer": "1.2.2",
|
|
23
23
|
"@eva/inspector-decorator": "^0.0.5",
|
|
24
24
|
"pixi.js": "^4.8.9"
|
|
25
25
|
}
|