@eva/spine-base 1.2.2-alpha.4 → 1.2.2-alpha.5

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.
@@ -606,24 +606,26 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
606
606
  };
607
607
 
608
608
  SpineSystem.prototype.add = function (changed, count) {
609
+ var _a, _b;
610
+
609
611
  return __awaiter(this, void 0, void 0, function () {
610
612
  var component, res, spineData, container, armature, tran;
611
613
 
612
614
  var _this = this;
613
615
 
614
- return __generator(this, function (_a) {
615
- switch (_a.label) {
616
+ return __generator(this, function (_c) {
617
+ switch (_c.label) {
616
618
  case 0:
617
619
  component = changed.component;
618
620
  clearTimeout(component.addHandler);
619
621
  return [4, eva_js.resource.getResource(component.resource)];
620
622
 
621
623
  case 1:
622
- res = _a.sent();
624
+ res = _c.sent();
623
625
  return [4, getSpineData(res, this.pixiSpine)];
624
626
 
625
627
  case 2:
626
- spineData = _a.sent();
628
+ spineData = _c.sent();
627
629
 
628
630
  if (!spineData) {
629
631
  component.addHandler = setTimeout(function () {
@@ -645,7 +647,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
645
647
  }
646
648
 
647
649
  this.remove(changed);
648
- 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);
649
651
 
650
652
  if (!container) {
651
653
  return [2];
@@ -709,17 +711,17 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
709
711
  };
710
712
 
711
713
  SpineSystem.prototype.remove = function (changed) {
712
- var _a, _b;
714
+ var _a, _b, _c, _d;
713
715
 
714
716
  return __awaiter(this, void 0, void 0, function () {
715
717
  var component, armature, container, res;
716
- return __generator(this, function (_c) {
717
- switch (_c.label) {
718
+ return __generator(this, function (_e) {
719
+ switch (_e.label) {
718
720
  case 0:
719
721
  component = changed.component;
720
722
  clearTimeout(component.addHandler);
721
723
  armature = this.armatures[changed.gameObject.id];
722
- 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);
723
725
 
724
726
  if (container && armature) {
725
727
  container.removeChild(armature);
@@ -732,9 +734,9 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
732
734
  return [4, eva_js.resource.getResource(component.lastResource)];
733
735
 
734
736
  case 1:
735
- res = _c.sent();
736
- releaseSpineData(res.name, (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.image) === null || _b === void 0 ? void 0 : _b.src);
737
- _c.label = 2;
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;
738
740
 
739
741
  case 2:
740
742
  component.armature = null;
@@ -1 +1 @@
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 s=t.length-1;s>=0;s--)(o=t[s])&&(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 s(t,e,r,n){return new(r||(r=Promise))((function(o,a){function i(t){try{u(n.next(t))}catch(t){a(t)}}function s(t){try{u(n.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,s)}u((n=n.apply(t,e||[])).next())}))}function u(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:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){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,s])}}}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,s=a.loop,u=a.track;this.play(i,s,u)}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),m={};function l(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=m[t];return r||(r=l(e),m[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 s(this,void 0,void 0,(function(){var r;return u(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=m[t];r||(r=l(e),m[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=m[t];e&&(e.count--,e.count<=0&&(e.tex&&(e.tex.destroy(!0),e.tex=null),delete m[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 s=t[i];if(s.id===a){var u=s.getComponent(p);u&&(n.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:p.componentName}),r.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:u,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 s(this,void 0,void 0,(function(){return u(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){return s(this,void 0,void 0,(function(){var n,o,a,i,s,c=this;return u(this,(function(u){switch(u.label){case 0:return n=t.component,clearTimeout(n.addHandler),[4,e.resource.getResource(n.resource)];case 1:return[4,h(u.sent(),this.pixiSpine)];case 2:return(o=u.sent())?(this.remove(t),(a=this.renderSystem.containerManager.getContainer(t.gameObject.id))?(n.lastResource=n.resource,i=new this.pixiSpine.Spine(o),this.armatures[t.gameObject.id]=i,t.gameObject&&t.gameObject.transform&&(s=t.gameObject.transform,i.x=s.size.width*s.origin.x,i.y=s.size.height*s.origin.y),a.addChildAt(i,0),i.update(),i.updateTransform(),n.armature=i,n.emit("loaded",{resource:n.resource}),i.state.addListener({start:function(t,e){n.emit("start",{track:t,name:t.animation.name})},complete:function(t,e){n.emit("complete",{track:t,name:t.animation.name})},interrupt:function(t,e){n.emit("interrupt",{track:t,name:t.animation.name})},end:function(t,e){n.emit("end",{track:t,name:t.animation.name})},event:function(t,e){n.emit("event",t,e)}}),[2]):[2]):(n.addHandler=setTimeout((function(){n.destroied||(void 0===r&&(r=20),--r>0?c.add(t,r):console.log("retry exceed max times",n.resource))}),1e3),[2])}}))}))},n.prototype.change=function(t){this.remove(t),this.add(t)},n.prototype.remove=function(t){var r,n;return s(this,void 0,void 0,(function(){var o,a,i,s;return u(this,(function(u){switch(u.label){case 0:return o=t.component,clearTimeout(o.addHandler),a=this.armatures[t.gameObject.id],(i=this.renderSystem.containerManager.getContainer(t.gameObject.id))&&a&&i.removeChild(a),o.armature?(o.armature.destroy({children:!0}),[4,e.resource.getResource(o.lastResource)]):[3,2];case 1:y((s=u.sent()).name,null===(n=null===(r=s.data)||void 0===r?void 0:r.image)||void 0===n?void 0:n.src),u.label=2;case 2:return o.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);
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);
@@ -391,24 +391,26 @@ var SpineSystem = function (_super) {
391
391
  };
392
392
 
393
393
  SpineSystem.prototype.add = function (changed, count) {
394
+ var _a, _b;
395
+
394
396
  return __awaiter(this, void 0, void 0, function () {
395
397
  var component, res, spineData, container, armature, tran;
396
398
 
397
399
  var _this = this;
398
400
 
399
- return __generator(this, function (_a) {
400
- switch (_a.label) {
401
+ return __generator(this, function (_c) {
402
+ switch (_c.label) {
401
403
  case 0:
402
404
  component = changed.component;
403
405
  clearTimeout(component.addHandler);
404
406
  return [4, resource.getResource(component.resource)];
405
407
 
406
408
  case 1:
407
- res = _a.sent();
409
+ res = _c.sent();
408
410
  return [4, getSpineData(res, this.pixiSpine)];
409
411
 
410
412
  case 2:
411
- spineData = _a.sent();
413
+ spineData = _c.sent();
412
414
 
413
415
  if (!spineData) {
414
416
  component.addHandler = setTimeout(function () {
@@ -430,7 +432,7 @@ var SpineSystem = function (_super) {
430
432
  }
431
433
 
432
434
  this.remove(changed);
433
- 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);
434
436
 
435
437
  if (!container) {
436
438
  return [2];
@@ -494,17 +496,17 @@ var SpineSystem = function (_super) {
494
496
  };
495
497
 
496
498
  SpineSystem.prototype.remove = function (changed) {
497
- var _a, _b;
499
+ var _a, _b, _c, _d;
498
500
 
499
501
  return __awaiter(this, void 0, void 0, function () {
500
502
  var component, armature, container, res;
501
- return __generator(this, function (_c) {
502
- switch (_c.label) {
503
+ return __generator(this, function (_e) {
504
+ switch (_e.label) {
503
505
  case 0:
504
506
  component = changed.component;
505
507
  clearTimeout(component.addHandler);
506
508
  armature = this.armatures[changed.gameObject.id];
507
- 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);
508
510
 
509
511
  if (container && armature) {
510
512
  container.removeChild(armature);
@@ -517,9 +519,9 @@ var SpineSystem = function (_super) {
517
519
  return [4, resource.getResource(component.lastResource)];
518
520
 
519
521
  case 1:
520
- res = _c.sent();
521
- releaseSpineData(res.name, (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.image) === null || _b === void 0 ? void 0 : _b.src);
522
- _c.label = 2;
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;
523
525
 
524
526
  case 2:
525
527
  component.armature = null;
@@ -419,20 +419,21 @@ var SpineSystem = (function (_super) {
419
419
  });
420
420
  };
421
421
  SpineSystem.prototype.add = function (changed, count) {
422
+ var _a, _b;
422
423
  return __awaiter(this, void 0, void 0, function () {
423
424
  var component, res, spineData, container, armature, tran;
424
425
  var _this = this;
425
- return __generator(this, function (_a) {
426
- switch (_a.label) {
426
+ return __generator(this, function (_c) {
427
+ switch (_c.label) {
427
428
  case 0:
428
429
  component = changed.component;
429
430
  clearTimeout(component.addHandler);
430
431
  return [4, eva_js.resource.getResource(component.resource)];
431
432
  case 1:
432
- res = _a.sent();
433
+ res = _c.sent();
433
434
  return [4, getSpineData(res, this.pixiSpine)];
434
435
  case 2:
435
- spineData = _a.sent();
436
+ spineData = _c.sent();
436
437
  if (!spineData) {
437
438
  component.addHandler = setTimeout(function () {
438
439
  if (!component.destroied) {
@@ -451,7 +452,7 @@ var SpineSystem = (function (_super) {
451
452
  return [2];
452
453
  }
453
454
  this.remove(changed);
454
- 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);
455
456
  if (!container) {
456
457
  return [2];
457
458
  }
@@ -495,16 +496,16 @@ var SpineSystem = (function (_super) {
495
496
  this.add(changed);
496
497
  };
497
498
  SpineSystem.prototype.remove = function (changed) {
498
- var _a, _b;
499
+ var _a, _b, _c, _d;
499
500
  return __awaiter(this, void 0, void 0, function () {
500
501
  var component, armature, container, res;
501
- return __generator(this, function (_c) {
502
- switch (_c.label) {
502
+ return __generator(this, function (_e) {
503
+ switch (_e.label) {
503
504
  case 0:
504
505
  component = changed.component;
505
506
  clearTimeout(component.addHandler);
506
507
  armature = this.armatures[changed.gameObject.id];
507
- 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);
508
509
  if (container && armature) {
509
510
  container.removeChild(armature);
510
511
  }
@@ -512,9 +513,9 @@ var SpineSystem = (function (_super) {
512
513
  component.armature.destroy({ children: true });
513
514
  return [4, eva_js.resource.getResource(component.lastResource)];
514
515
  case 1:
515
- res = _c.sent();
516
- releaseSpineData(res.name, (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.image) === null || _b === void 0 ? void 0 : _b.src);
517
- _c.label = 2;
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;
518
519
  case 2:
519
520
  component.armature = null;
520
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"),a=function(e,t){return(a=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 o(e,t){function r(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function i(e,t,r,n){var a,o=arguments.length,i=o<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 s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,r,i):a(t,r))||i);return o>3&&i&&Object.defineProperty(t,r,i),i}function s(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){e.done?a(e.value):new r((function(t){t(e.value)})).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function u(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}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 o(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),a=n.next();!a.done;a=n.next()){var o=a.value;if(o.playType){var i=o.name,s=o.loop,u=o.track;this.play(i,s,u)}else this.stop(o.track)}}catch(e){t={error:e}}finally{try{a&&!a.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 a=null,o=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(o.baseTexture)}),(function(e){if(e){var o=new n.core.AtlasAttachmentLoader(e),i=new n.core.SkeletonJson(o);r&&(i.scale=r),a=i.readSkeletonData(t.ske)}}));var i={spineData:a,ref:0,imageSrc:t.image.src};return l[e]=i,i}function d(e,t){return s(this,void 0,void 0,(function(){var r;return u(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 o(n,r),n.prototype.init=function(r){var n=this,a=r.pixiSpine;this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=a,this.game.canvas.addEventListener("webglcontextrestored",(function(){var t=n.game.gameObjects,r=[];for(var a in n.armatures)for(var o=+a,i=0;i<t.length;++i){var s=t[i];if(s.id===o){var u=s.getComponent(c);u&&(n.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:c.componentName}),r.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:u,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 s(this,void 0,void 0,(function(){return u(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){return s(this,void 0,void 0,(function(){var n,a,o,i,s,c=this;return u(this,(function(u){switch(u.label){case 0:return n=t.component,clearTimeout(n.addHandler),[4,e.resource.getResource(n.resource)];case 1:return[4,d(u.sent(),this.pixiSpine)];case 2:return(a=u.sent())?(this.remove(t),(o=this.renderSystem.containerManager.getContainer(t.gameObject.id))?(n.lastResource=n.resource,i=new this.pixiSpine.Spine(a),this.armatures[t.gameObject.id]=i,t.gameObject&&t.gameObject.transform&&(s=t.gameObject.transform,i.x=s.size.width*s.origin.x,i.y=s.size.height*s.origin.y),o.addChildAt(i,0),i.update(),i.updateTransform(),n.armature=i,n.emit("loaded",{resource:n.resource}),i.state.addListener({start:function(e,t){n.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){n.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){n.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){n.emit("end",{track:e,name:e.animation.name})},event:function(e,t){n.emit("event",e,t)}}),[2]):[2]):(n.addHandler=setTimeout((function(){n.destroied||(void 0===r&&(r=20),--r>0?c.add(t,r):console.log("retry exceed max times",n.resource))}),1e3),[2])}}))}))},n.prototype.change=function(e){this.remove(e),this.add(e)},n.prototype.remove=function(t){var r,n;return s(this,void 0,void 0,(function(){var a,o,i,s;return u(this,(function(u){switch(u.label){case 0:return a=t.component,clearTimeout(a.addHandler),o=this.armatures[t.gameObject.id],(i=this.renderSystem.containerManager.getContainer(t.gameObject.id))&&o&&i.removeChild(o),a.armature?(a.armature.destroy({children:!0}),[4,e.resource.getResource(a.lastResource)]):[3,2];case 1:h((s=u.sent()).name,null===(n=null===(r=s.data)||void 0===r?void 0:r.image)||void 0===n?void 0:n.src),u.label=2;case 2:return a.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;
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;
@@ -415,20 +415,21 @@ var SpineSystem = (function (_super) {
415
415
  });
416
416
  };
417
417
  SpineSystem.prototype.add = function (changed, count) {
418
+ var _a, _b;
418
419
  return __awaiter(this, void 0, void 0, function () {
419
420
  var component, res, spineData, container, armature, tran;
420
421
  var _this = this;
421
- return __generator(this, function (_a) {
422
- switch (_a.label) {
422
+ return __generator(this, function (_c) {
423
+ switch (_c.label) {
423
424
  case 0:
424
425
  component = changed.component;
425
426
  clearTimeout(component.addHandler);
426
427
  return [4, resource.getResource(component.resource)];
427
428
  case 1:
428
- res = _a.sent();
429
+ res = _c.sent();
429
430
  return [4, getSpineData(res, this.pixiSpine)];
430
431
  case 2:
431
- spineData = _a.sent();
432
+ spineData = _c.sent();
432
433
  if (!spineData) {
433
434
  component.addHandler = setTimeout(function () {
434
435
  if (!component.destroied) {
@@ -447,7 +448,7 @@ var SpineSystem = (function (_super) {
447
448
  return [2];
448
449
  }
449
450
  this.remove(changed);
450
- 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);
451
452
  if (!container) {
452
453
  return [2];
453
454
  }
@@ -491,16 +492,16 @@ var SpineSystem = (function (_super) {
491
492
  this.add(changed);
492
493
  };
493
494
  SpineSystem.prototype.remove = function (changed) {
494
- var _a, _b;
495
+ var _a, _b, _c, _d;
495
496
  return __awaiter(this, void 0, void 0, function () {
496
497
  var component, armature, container, res;
497
- return __generator(this, function (_c) {
498
- switch (_c.label) {
498
+ return __generator(this, function (_e) {
499
+ switch (_e.label) {
499
500
  case 0:
500
501
  component = changed.component;
501
502
  clearTimeout(component.addHandler);
502
503
  armature = this.armatures[changed.gameObject.id];
503
- 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);
504
505
  if (container && armature) {
505
506
  container.removeChild(armature);
506
507
  }
@@ -508,9 +509,9 @@ var SpineSystem = (function (_super) {
508
509
  component.armature.destroy({ children: true });
509
510
  return [4, resource.getResource(component.lastResource)];
510
511
  case 1:
511
- res = _c.sent();
512
- releaseSpineData(res.name, (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.image) === null || _b === void 0 ? void 0 : _b.src);
513
- _c.label = 2;
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;
514
515
  case 2:
515
516
  component.armature = null;
516
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-alpha.4",
3
+ "version": "1.2.2-alpha.5",
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-alpha.4",
22
- "@eva/plugin-renderer": "1.2.2-alpha.4",
21
+ "@eva/eva.js": "1.2.2-alpha.5",
22
+ "@eva/plugin-renderer": "1.2.2-alpha.5",
23
23
  "@eva/inspector-decorator": "^0.0.5",
24
24
  "pixi.js": "^4.8.9"
25
25
  }