@eva/spine-base 1.2.8 → 2.0.0-beta.1

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.
@@ -1 +1 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(this,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,r){"use strict";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},o(e,t)};function a(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function i(e,t,n,r){var o,a=arguments.length,i=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,n,i):o(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i}function s(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function u(e,t){var n,r,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(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=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++,r=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],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function c(e){return function(t,n){var r=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,n);r.key=n,r.type=e}}var p=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,n;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var r=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.waitExecuteInfos),o=r.next();!o.done;o=r.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(e){t={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),t.prototype.init=function(e){e&&_extends(this,e)},t.prototype.onDestroy=function(){this.destroied=!0},t.prototype.play=function(e,t,n){try{e&&(this.animationName=e),this.armature?(void 0===n&&(n=0),this.armature.state.setAnimation(n,this.animationName,t)):this.waitExecuteInfos.push({playType:!0,name:e,loop:null!=t?t:this.autoPlay,track:n})}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,n,r){try{this.armature&&(void 0===r&&(r=0),this.armature.state.addAnimation(r,e,n,t))}catch(e){console.log(e)}},t.prototype.setMix=function(e,t,n){this.armature&&this.armature.stateData.setMix(e,t,n)},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([c("string")],t.prototype,"resource",void 0),i([c("string")],t.prototype,"animationName",void 0),i([c("boolean")],t.prototype,"autoPlay",void 0),t}(t.Component),l=p,m={};function f(e){var t=e.image;return{tex:r.Texture.from(t),count:0}}var d={};function h(e,t,n,r){var o=null,a=function(e,t){var n=m[e];return n||(n=f(t),m[e]=n),n.tex}(t.image.src,t);new r.core.TextureAtlas(t.atlas,(function(e,t){t(a.baseTexture)}),(function(e){if(e){var a=new r.core.AtlasAttachmentLoader(e),i=new r.core.SkeletonJson(a);n&&(i.scale=n),o=i.readSkeletonData(t.ske)}}));var i={spineData:o,ref:0,imageSrc:t.image.src};return d[e]=i,i}function y(e,t){return s(this,void 0,void 0,(function(){var n;return u(this,(function(r){if(!(n=d[e.name]))if(e.complete)n=h(e.name,e.data,e.scale,t);else if(!n)return[2];return function(e,t){var n=m[e];n||(n=f(t),m[e]=n),n.count++,n.tex}(e.data.image.src,e.data),n.ref++,[2,n.spineData]}))}))}function v(e,t){var n=d[e];n&&(n.ref--,n.ref<=0&&(!function(e){e&&setTimeout((function(){var t=m[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete m[e]))}),100)}(t),delete d[e]))}var g=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.armatures={},t}return a(r,e),r.prototype.init=function(e){var r=this,o=e.pixiSpine;this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=o,this.game.canvas.addEventListener("webglcontextrestored",(function(){var e=r.game.gameObjects,n=[];for(var o in r.armatures)for(var a=+o,i=0;i<e.length;++i){var s=e[i];if(s.id===a){var u=s.getComponent(l);u&&(r.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:l.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:l.componentName}));break}}setTimeout((function(){n.forEach((function(e){r.add(e)}))}),1e3)}),!1)},r.prototype.update=function(t){for(var n in this.armatures)this.armatures[n].update(.001*t.deltaTime),this.armatures[n].updateTransform();e.prototype.update.call(this)},r.prototype.componentChanged=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(n){if("Spine"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD)this.add(e);else if(e.type===t.OBSERVER_TYPE.CHANGE){if("resource"===e.prop.prop[0])this.change(e)}else e.type===t.OBSERVER_TYPE.REMOVE&&this.remove(e);return[2]}))}))},r.prototype.add=function(e,n){var r,o;return s(this,void 0,void 0,(function(){var a,i,s,c,p,l,m,f,d=this;return u(this,(function(u){switch(u.label){case 0:return a=e.component,clearTimeout(a.addHandler),i=e.gameObject.id,s=this.increaseAsyncId(i),[4,t.resource.getResource(a.resource)];case 1:return c=u.sent(),this.validateAsyncId(i,s)?[4,y(c,this.pixiSpine)]:[2];case 2:return p=u.sent(),this.validateAsyncId(i,s)?p?(this.remove(e),(l=null===(o=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===o?void 0:o.getContainer(e.gameObject.id))?(a.lastResource=a.resource,m=new this.pixiSpine.Spine(p),this.armatures[e.gameObject.id]=m,e.gameObject&&e.gameObject.transform&&(f=e.gameObject.transform,m.x=f.size.width*f.origin.x,m.y=f.size.height*f.origin.y),l.addChildAt(m,0),m.update(),m.updateTransform(),a.armature=m,a.emit("loaded",{resource:a.resource}),m.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===n&&(n=20),--n>0?d.add(e,n):console.log("retry exceed max times",a.resource))}),1e3),[2]):[2]}}))}))},r.prototype.change=function(e){this.remove(e),this.add(e)},r.prototype.remove=function(e){var n,r,o,a;return s(this,void 0,void 0,(function(){var i,s,c,p;return u(this,(function(u){switch(u.label){case 0:return this.increaseAsyncId(e.gameObject.id),i=e.component,clearTimeout(i.addHandler),s=this.armatures[e.gameObject.id],(c=null===(r=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===r?void 0:r.getContainer(e.gameObject.id))&&s&&c.removeChild(s),i.armature?(i.armature.destroy({children:!0}),[4,t.resource.getResource(i.lastResource)]):[3,2];case 1:v((p=u.sent()).name,null===(a=null===(o=p.data)||void 0===o?void 0:o.image)||void 0===a?void 0:a.src),u.label=2;case 2:return i.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE,[2]}}))}))},r.systemName="SpineSystem",r=i([t.decorators.componentObserver({Spine:["resource"]})],r)}(n.Renderer),b=g;return t.resource.registerResourceType("SPINE"),e.Spine=l,e.SpineSystem=b,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);window.EVA.plugin.spineBase=window.EVA.plugin.spineBase||_EVA_IIFE_spineBase;
1
+ function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(null,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,r){"use strict";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},o(e,t)};function a(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function i(e,t,n,r){var o,a=arguments.length,i=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,n,i):o(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i}function s(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function u(e,t){var n,r,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(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=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++,r=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],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function c(e){return function(t,n){var r=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,n);r.key=n,r.type=e}}var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.scale=1,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,n;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var r=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.waitExecuteInfos),o=r.next();!o.done;o=r.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(e){t={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),t.prototype.init=function(e){e&&_extends(this,e)},t.prototype.onDestroy=function(){this.destroied=!0},t.prototype.play=function(e,t,n){try{e&&(this.animationName=e),this.armature?(void 0===n&&(n=0),this.armature.state.setAnimation(n,this.animationName,t)):this.waitExecuteInfos.push({playType:!0,name:e,loop:null!=t?t:this.autoPlay,track:n})}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,n,r){try{this.armature&&(void 0===r&&(r=0),this.armature.state.addAnimation(r,e,n,t))}catch(e){console.log(e)}},t.prototype.setMix=function(e,t,n){this.armature&&this.armature.stateData.setMix(e,t,n)},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([c("string")],t.prototype,"resource",void 0),i([c("number")],t.prototype,"scale",void 0),i([c("string")],t.prototype,"animationName",void 0),i([c("boolean")],t.prototype,"autoPlay",void 0),t}(t.Component),p=l,m={};function f(e,t){var n=m[e];return n||(n=function(e){var t=e.image;return{tex:t instanceof r.Texture?t:r.Texture.from(t),count:0}}(t),m[e]=n),n.count++,n.tex}var d={};function h(e,t,n){return s(this,void 0,void 0,(function(){var r;return u(this,(function(o){if(!(r=d[e.name]))if(e.complete)r=function(e,t,n,r){var o=t.ske,a=t.atlas,i=new r.AtlasAttachmentLoader(a),s=o instanceof Uint8Array?new r.SkeletonBinary(i):new r.SkeletonJson(i);s.scale=n||1;var u={spineData:s.readSkeletonData(o),ref:0,imageSrc:t.image.label};return d[e]=u,u}(e.name,e.data,t,n);else if(!r)return[2];return f(e.data.image.label,e.data),r.ref++,[2,r.spineData]}))}))}function y(e,t){var n=d[e];n&&(n.ref--,n.ref<=0&&(!function(e){e&&setTimeout((function(){var t=m[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete m[e]))}),100)}(t),delete d[e]))}var v=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.armatures={},t}return a(r,e),r.prototype.init=function(e){var r=this,o=e.pixiSpine;this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=o,this.game.canvas.addEventListener("webglcontextrestored",(function(){var e=r.game.gameObjects,n=[];for(var o in r.armatures)for(var a=+o,i=0;i<e.length;++i){var s=e[i];if(s.id===a){var u=s.getComponent(p);u&&(r.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:p.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:p.componentName}));break}}setTimeout((function(){n.forEach((function(e){r.add(e)}))}),1e3)}),!1)},r.prototype.update=function(t){for(var n in this.armatures)this.armatures[n].update(.001*t.deltaTime);e.prototype.update.call(this)},r.prototype.componentChanged=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(n){if("Spine"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD)this.add(e);else if(e.type===t.OBSERVER_TYPE.CHANGE){if("resource"===e.prop.prop[0])this.change(e)}else e.type===t.OBSERVER_TYPE.REMOVE&&this.remove(e);return[2]}))}))},r.prototype.add=function(e,n){var r,o;return s(this,void 0,void 0,(function(){var a,i,s,c,l,p,m,f,d=this;return u(this,(function(u){switch(u.label){case 0:return a=e.component,clearTimeout(a.addHandler),i=e.gameObject.id,s=this.increaseAsyncId(i),[4,t.resource.getResource(a.resource)];case 1:return c=u.sent(),this.validateAsyncId(i,s)?[4,h(c,a.scale,this.pixiSpine)]:[2];case 2:return l=u.sent(),this.validateAsyncId(i,s)?l?(this.remove(e),(p=null===(o=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===o?void 0:o.getContainer(e.gameObject.id))?(a.lastResource=a.resource,m=new this.pixiSpine.Spine({skeletonData:l,autoUpdate:!1}),this.armatures[e.gameObject.id]=m,e.gameObject&&e.gameObject.transform&&(f=e.gameObject.transform,m.x=f.size.width*f.origin.x,m.y=f.size.height*f.origin.y),p.addChildAt(m,0),m.update(),a.armature=m,a.emit("loaded",{resource:a.resource}),m.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===n&&(n=20),--n>0?d.add(e,n):console.log("retry exceed max times",a.resource))}),1e3),[2]):[2]}}))}))},r.prototype.change=function(e){this.remove(e),this.add(e)},r.prototype.remove=function(e){var n,r,o,a;return s(this,void 0,void 0,(function(){var i,s,c,l;return u(this,(function(u){switch(u.label){case 0:return this.increaseAsyncId(e.gameObject.id),i=e.component,clearTimeout(i.addHandler),s=this.armatures[e.gameObject.id],(c=null===(r=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===r?void 0:r.getContainer(e.gameObject.id))&&s&&c.removeChild(s),i.armature?(i.armature.destroy({children:!0}),[4,t.resource.getResource(i.lastResource)]):[3,2];case 1:y((l=u.sent()).name,null===(a=null===(o=l.data)||void 0===o?void 0:o.image)||void 0===a?void 0:a.src),u.label=2;case 2:return i.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE,[2]}}))}))},r.systemName="SpineSystem",r=i([t.decorators.componentObserver({Spine:["resource"]})],r)}(n.Renderer),g=v;return t.resource.registerResourceType("SPINE"),e.Spine=p,e.SpineSystem=g,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);window.EVA.plugin.spineBase=window.EVA.plugin.spineBase||_EVA_IIFE_spineBase;
@@ -96,6 +96,7 @@ var Spine = (function (_super) {
96
96
  function Spine() {
97
97
  var _this = _super !== null && _super.apply(this, arguments) || this;
98
98
  _this.resource = '';
99
+ _this.scale = 1;
99
100
  _this.animationName = '';
100
101
  _this.autoPlay = true;
101
102
  _this.waitExecuteInfos = [];
@@ -154,7 +155,7 @@ var Spine = (function (_super) {
154
155
  playType: true,
155
156
  name: name,
156
157
  loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
157
- track: track
158
+ track: track,
158
159
  });
159
160
  }
160
161
  else {
@@ -172,7 +173,7 @@ var Spine = (function (_super) {
172
173
  if (!this.armature) {
173
174
  this.waitExecuteInfos.push({
174
175
  playType: false,
175
- track: track
176
+ track: track,
176
177
  });
177
178
  return;
178
179
  }
@@ -237,6 +238,9 @@ var Spine = (function (_super) {
237
238
  __decorate([
238
239
  inspectorDecorator.type('string')
239
240
  ], Spine.prototype, "resource", void 0);
241
+ __decorate([
242
+ inspectorDecorator.type('number')
243
+ ], Spine.prototype, "scale", void 0);
240
244
  __decorate([
241
245
  inspectorDecorator.type('string')
242
246
  ], Spine.prototype, "animationName", void 0);
@@ -251,7 +255,7 @@ var texCache = {};
251
255
  function cacheImage(data) {
252
256
  var oldImg = data.image;
253
257
  return {
254
- tex: pixi_js.Texture.from(oldImg),
258
+ tex: oldImg instanceof pixi_js.Texture ? oldImg : pixi_js.Texture.from(oldImg),
255
259
  count: 0,
256
260
  };
257
261
  }
@@ -264,14 +268,6 @@ function retainTexture(name, data) {
264
268
  cache.count++;
265
269
  return cache.tex;
266
270
  }
267
- function getTexture(imageSrc, data) {
268
- var cache = texCache[imageSrc];
269
- if (!cache) {
270
- cache = cacheImage(data);
271
- texCache[imageSrc] = cache;
272
- }
273
- return cache.tex;
274
- }
275
271
  function releaseTexture(imageSrc) {
276
272
  if (!imageSrc)
277
273
  return;
@@ -292,38 +288,32 @@ function releaseTexture(imageSrc) {
292
288
 
293
289
  var dataMap = {};
294
290
  function createSpineData(name, data, scale, pixiSpine) {
295
- var spineData = null;
296
- var img = getTexture(data.image.src, data);
297
- new pixiSpine.core.TextureAtlas(data.atlas, function (line, callback) {
298
- callback(img.baseTexture);
299
- }, function (spineAtlas) {
300
- if (spineAtlas) {
301
- var attachmentLoader = new pixiSpine.core.AtlasAttachmentLoader(spineAtlas);
302
- var spineJsonParser = new pixiSpine.core.SkeletonJson(attachmentLoader);
303
- if (scale) {
304
- spineJsonParser.scale = scale;
305
- }
306
- spineData = spineJsonParser.readSkeletonData(data.ske);
307
- }
308
- });
309
- var obj = { spineData: spineData, ref: 0, imageSrc: data.image.src };
291
+ var skeletonAsset = data.ske;
292
+ var atlasAsset = data.atlas;
293
+ var attachmentLoader = new pixiSpine.AtlasAttachmentLoader(atlasAsset);
294
+ var parser = skeletonAsset instanceof Uint8Array
295
+ ? new pixiSpine.SkeletonBinary(attachmentLoader)
296
+ : new pixiSpine.SkeletonJson(attachmentLoader);
297
+ parser.scale = scale || 1;
298
+ var skeletonData = parser.readSkeletonData(skeletonAsset);
299
+ var obj = { spineData: skeletonData, ref: 0, imageSrc: data.image.label };
310
300
  dataMap[name] = obj;
311
301
  return obj;
312
302
  }
313
- function getSpineData(res, pixiSpine) {
303
+ function getSpineData(res, scale, pixiSpine) {
314
304
  return __awaiter(this, void 0, void 0, function () {
315
305
  var data;
316
306
  return __generator(this, function (_a) {
317
307
  data = dataMap[res.name];
318
308
  if (!data) {
319
309
  if (res.complete) {
320
- data = createSpineData(res.name, res.data, res.scale, pixiSpine);
310
+ data = createSpineData(res.name, res.data, scale, pixiSpine);
321
311
  }
322
312
  else if (!data) {
323
313
  return [2];
324
314
  }
325
315
  }
326
- retainTexture(res.data.image.src, res.data);
316
+ retainTexture(res.data.image.label, res.data);
327
317
  data.ref++;
328
318
  return [2, data.spineData];
329
319
  });
@@ -392,7 +382,6 @@ var SpineSystem = (function (_super) {
392
382
  SpineSystem.prototype.update = function (e) {
393
383
  for (var key in this.armatures) {
394
384
  this.armatures[key].update(e.deltaTime * 0.001);
395
- this.armatures[key].updateTransform();
396
385
  }
397
386
  _super.prototype.update.call(this);
398
387
  };
@@ -435,7 +424,7 @@ var SpineSystem = (function (_super) {
435
424
  res = _c.sent();
436
425
  if (!this.validateAsyncId(gameObjectId, asyncId))
437
426
  return [2];
438
- return [4, getSpineData(res, this.pixiSpine)];
427
+ return [4, getSpineData(res, component.scale, this.pixiSpine)];
439
428
  case 2:
440
429
  spineData = _c.sent();
441
430
  if (!this.validateAsyncId(gameObjectId, asyncId))
@@ -463,7 +452,10 @@ var SpineSystem = (function (_super) {
463
452
  return [2];
464
453
  }
465
454
  component.lastResource = component.resource;
466
- armature = new this.pixiSpine.Spine(spineData);
455
+ armature = new this.pixiSpine.Spine({
456
+ skeletonData: spineData,
457
+ autoUpdate: false,
458
+ });
467
459
  this.armatures[changed.gameObject.id] = armature;
468
460
  if (changed.gameObject && changed.gameObject.transform) {
469
461
  tran = changed.gameObject.transform;
@@ -472,7 +464,6 @@ var SpineSystem = (function (_super) {
472
464
  }
473
465
  container.addChildAt(armature, 0);
474
466
  armature.update();
475
- armature.updateTransform();
476
467
  component.armature = armature;
477
468
  component.emit('loaded', { resource: component.resource });
478
469
  armature.state.addListener({
@@ -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])},a(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:null!=t?t:this.autoPlay,track:r})}catch(e){console.log(e)}},t.prototype.stop=function(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})},t.prototype.addAnimation=function(e,t,r,n){try{this.armature&&(void 0===n&&(n=0),this.armature.state.addAnimation(n,e,r,t))}catch(e){console.log(e)}},t.prototype.setMix=function(e,t,r){this.armature&&this.armature.stateData.setMix(e,t,r)},t.prototype.getAnim=function(e){void 0===e&&(e=0);try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}},t.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},t.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},t.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},t.componentName="Spine",i([r.type("string")],t.prototype,"resource",void 0),i([r.type("string")],t.prototype,"animationName",void 0),i([r.type("boolean")],t.prototype,"autoPlay",void 0),t}(e.Component),p={};function l(e){var t=e.image;return{tex:n.Texture.from(t),count:0}}var m={};function f(e,t,r,n){var a=null,o=function(e,t){var r=p[e];return r||(r=l(t),p[e]=r),r.tex}(t.image.src,t);new n.core.TextureAtlas(t.atlas,(function(e,t){t(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 m[e]=i,i}function d(e,t){return s(this,void 0,void 0,(function(){var r;return u(this,(function(n){if(!(r=m[e.name]))if(e.complete)r=f(e.name,e.data,e.scale,t);else if(!r)return[2];return function(e,t){var r=p[e];r||(r=l(t),p[e]=r),r.count++,r.tex}(e.data.image.src,e.data),r.ref++,[2,r.spineData]}))}))}function h(e,t){var r=m[e];r&&(r.ref--,r.ref<=0&&(!function(e){e&&setTimeout((function(){var t=p[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete p[e]))}),100)}(t),delete m[e]))}var y=function(r){function n(){var e=null!==r&&r.apply(this,arguments)||this;return e.armatures={},e}return 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){if("resource"===t.prop.prop[0])this.change(t)}else t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t);return[2]}))}))},n.prototype.add=function(t,r){var n,a;return s(this,void 0,void 0,(function(){var o,i,s,c,p,l,m,f,h=this;return u(this,(function(u){switch(u.label){case 0:return o=t.component,clearTimeout(o.addHandler),i=t.gameObject.id,s=this.increaseAsyncId(i),[4,e.resource.getResource(o.resource)];case 1:return c=u.sent(),this.validateAsyncId(i,s)?[4,d(c,this.pixiSpine)]:[2];case 2:return p=u.sent(),this.validateAsyncId(i,s)?p?(this.remove(t),(l=null===(a=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===a?void 0:a.getContainer(t.gameObject.id))?(o.lastResource=o.resource,m=new this.pixiSpine.Spine(p),this.armatures[t.gameObject.id]=m,t.gameObject&&t.gameObject.transform&&(f=t.gameObject.transform,m.x=f.size.width*f.origin.x,m.y=f.size.height*f.origin.y),l.addChildAt(m,0),m.update(),m.updateTransform(),o.armature=m,o.emit("loaded",{resource:o.resource}),m.state.addListener({start:function(e,t){o.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){o.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){o.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){o.emit("end",{track:e,name:e.animation.name})},event:function(e,t){o.emit("event",e,t)}}),[2]):[2]):(o.addHandler=setTimeout((function(){o.destroied||(void 0===r&&(r=20),--r>0?h.add(t,r):console.log("retry exceed max times",o.resource))}),1e3),[2]):[2]}}))}))},n.prototype.change=function(e){this.remove(e),this.add(e)},n.prototype.remove=function(t){var r,n,a,o;return s(this,void 0,void 0,(function(){var i,s,c,p;return u(this,(function(u){switch(u.label){case 0:return this.increaseAsyncId(t.gameObject.id),i=t.component,clearTimeout(i.addHandler),s=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))&&s&&c.removeChild(s),i.armature?(i.armature.destroy({children:!0}),[4,e.resource.getResource(i.lastResource)]):[3,2];case 1:h((p=u.sent()).name,null===(o=null===(a=p.data)||void 0===a?void 0:a.image)||void 0===o?void 0:o.src),u.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;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),n=require("@eva/inspector-decorator"),r=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 n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},a(e,t)};function o(e,t){function n(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function i(e,t,n,r){var a,o=arguments.length,i=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,n,i):a(t,n))||i);return o>3&&i&&Object.defineProperty(t,n,i),i}function s(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?a(e.value):new n((function(t){t(e.value)})).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function u(e,t){var n,r,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(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=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++,r=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],r=0}finally{n=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.scale=1,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,n;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var r=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}(this.waitExecuteInfos),a=r.next();!a.done;a=r.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&&(n=r.return)&&n.call(r)}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,n){try{e&&(this.animationName=e),this.armature?(void 0===n&&(n=0),this.armature.state.setAnimation(n,this.animationName,t)):this.waitExecuteInfos.push({playType:!0,name:e,loop:null!=t?t:this.autoPlay,track:n})}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,n,r){try{this.armature&&(void 0===r&&(r=0),this.armature.state.addAnimation(r,e,n,t))}catch(e){console.log(e)}},t.prototype.setMix=function(e,t,n){this.armature&&this.armature.stateData.setMix(e,t,n)},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([n.type("string")],t.prototype,"resource",void 0),i([n.type("number")],t.prototype,"scale",void 0),i([n.type("string")],t.prototype,"animationName",void 0),i([n.type("boolean")],t.prototype,"autoPlay",void 0),t}(e.Component),p={};function l(e,t){var n=p[e];return n||(n=function(e){var t=e.image;return{tex:t instanceof r.Texture?t:r.Texture.from(t),count:0}}(t),p[e]=n),n.count++,n.tex}var m={};function d(e,t,n){return s(this,void 0,void 0,(function(){var r;return u(this,(function(a){if(!(r=m[e.name]))if(e.complete)r=function(e,t,n,r){var a=t.ske,o=t.atlas,i=new r.AtlasAttachmentLoader(o),s=a instanceof Uint8Array?new r.SkeletonBinary(i):new r.SkeletonJson(i);s.scale=n||1;var u={spineData:s.readSkeletonData(a),ref:0,imageSrc:t.image.label};return m[e]=u,u}(e.name,e.data,t,n);else if(!r)return[2];return l(e.data.image.label,e.data),r.ref++,[2,r.spineData]}))}))}function f(e,t){var n=m[e];n&&(n.ref--,n.ref<=0&&(!function(e){e&&setTimeout((function(){var t=p[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete p[e]))}),100)}(t),delete m[e]))}var h=function(n){function r(){var e=null!==n&&n.apply(this,arguments)||this;return e.armatures={},e}return o(r,n),r.prototype.init=function(n){var r=this,a=n.pixiSpine;this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=a,this.game.canvas.addEventListener("webglcontextrestored",(function(){var t=r.game.gameObjects,n=[];for(var a in r.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&&(r.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:c.componentName}),n.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:c.componentName}));break}}setTimeout((function(){n.forEach((function(e){r.add(e)}))}),1e3)}),!1)},r.prototype.update=function(e){for(var t in this.armatures)this.armatures[t].update(.001*e.deltaTime);n.prototype.update.call(this)},r.prototype.componentChanged=function(t){return s(this,void 0,void 0,(function(){return u(this,(function(n){if("Spine"===t.componentName)if(t.type===e.OBSERVER_TYPE.ADD)this.add(t);else if(t.type===e.OBSERVER_TYPE.CHANGE){if("resource"===t.prop.prop[0])this.change(t)}else t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t);return[2]}))}))},r.prototype.add=function(t,n){var r,a;return s(this,void 0,void 0,(function(){var o,i,s,c,p,l,m,f,h=this;return u(this,(function(u){switch(u.label){case 0:return o=t.component,clearTimeout(o.addHandler),i=t.gameObject.id,s=this.increaseAsyncId(i),[4,e.resource.getResource(o.resource)];case 1:return c=u.sent(),this.validateAsyncId(i,s)?[4,d(c,o.scale,this.pixiSpine)]:[2];case 2:return p=u.sent(),this.validateAsyncId(i,s)?p?(this.remove(t),(l=null===(a=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===a?void 0:a.getContainer(t.gameObject.id))?(o.lastResource=o.resource,m=new this.pixiSpine.Spine({skeletonData:p,autoUpdate:!1}),this.armatures[t.gameObject.id]=m,t.gameObject&&t.gameObject.transform&&(f=t.gameObject.transform,m.x=f.size.width*f.origin.x,m.y=f.size.height*f.origin.y),l.addChildAt(m,0),m.update(),o.armature=m,o.emit("loaded",{resource:o.resource}),m.state.addListener({start:function(e,t){o.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){o.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){o.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){o.emit("end",{track:e,name:e.animation.name})},event:function(e,t){o.emit("event",e,t)}}),[2]):[2]):(o.addHandler=setTimeout((function(){o.destroied||(void 0===n&&(n=20),--n>0?h.add(t,n):console.log("retry exceed max times",o.resource))}),1e3),[2]):[2]}}))}))},r.prototype.change=function(e){this.remove(e),this.add(e)},r.prototype.remove=function(t){var n,r,a,o;return s(this,void 0,void 0,(function(){var i,s,c,p;return u(this,(function(u){switch(u.label){case 0:return this.increaseAsyncId(t.gameObject.id),i=t.component,clearTimeout(i.addHandler),s=this.armatures[t.gameObject.id],(c=null===(r=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===r?void 0:r.getContainer(t.gameObject.id))&&s&&c.removeChild(s),i.armature?(i.armature.destroy({children:!0}),[4,e.resource.getResource(i.lastResource)]):[3,2];case 1:f((p=u.sent()).name,null===(o=null===(a=p.data)||void 0===a?void 0:a.image)||void 0===o?void 0:o.src),u.label=2;case 2:return i.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE,[2]}}))}))},r.systemName="SpineSystem",r=i([e.decorators.componentObserver({Spine:["resource"]})],r)}(t.Renderer);e.resource.registerResourceType("SPINE"),exports.Spine=c,exports.SpineSystem=h;
@@ -1,8 +1,8 @@
1
1
  /// <reference path="./global.d.ts"/>
2
2
  import { Component } from '@eva/eva.js';
3
3
  import { ComponentChanged } from '@eva/eva.js';
4
+ import { Container } from 'pixi.js';
4
5
  import { ContainerManager } from '@eva/plugin-renderer';
5
- import { DisplayObject } from 'pixi.js';
6
6
  import { Renderer } from '@eva/plugin-renderer';
7
7
  import { RendererManager } from '@eva/plugin-renderer';
8
8
  import { RendererSystem } from '@eva/plugin-renderer';
@@ -11,6 +11,7 @@ import { UpdateParams } from '@eva/eva.js';
11
11
  export declare class Spine extends Component<SpineParams> {
12
12
  static componentName: string;
13
13
  resource: string;
14
+ scale: number;
14
15
  animationName: string;
15
16
  autoPlay: boolean;
16
17
  private _armature;
@@ -35,12 +36,13 @@ export declare class Spine extends Component<SpineParams> {
35
36
  export declare interface SpineParams {
36
37
  resource: string;
37
38
  animationName?: string;
39
+ scale?: number;
38
40
  autoPlay?: boolean;
39
41
  }
40
42
 
41
43
  export declare class SpineSystem extends Renderer {
42
44
  static systemName: string;
43
- armatures: Record<number, DisplayObject>;
45
+ armatures: Record<number, Container>;
44
46
  renderSystem: RendererSystem;
45
47
  rendererManager: RendererManager;
46
48
  containerManager: ContainerManager;
@@ -92,6 +92,7 @@ var Spine = (function (_super) {
92
92
  function Spine() {
93
93
  var _this = _super !== null && _super.apply(this, arguments) || this;
94
94
  _this.resource = '';
95
+ _this.scale = 1;
95
96
  _this.animationName = '';
96
97
  _this.autoPlay = true;
97
98
  _this.waitExecuteInfos = [];
@@ -150,7 +151,7 @@ var Spine = (function (_super) {
150
151
  playType: true,
151
152
  name: name,
152
153
  loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
153
- track: track
154
+ track: track,
154
155
  });
155
156
  }
156
157
  else {
@@ -168,7 +169,7 @@ var Spine = (function (_super) {
168
169
  if (!this.armature) {
169
170
  this.waitExecuteInfos.push({
170
171
  playType: false,
171
- track: track
172
+ track: track,
172
173
  });
173
174
  return;
174
175
  }
@@ -233,6 +234,9 @@ var Spine = (function (_super) {
233
234
  __decorate([
234
235
  type('string')
235
236
  ], Spine.prototype, "resource", void 0);
237
+ __decorate([
238
+ type('number')
239
+ ], Spine.prototype, "scale", void 0);
236
240
  __decorate([
237
241
  type('string')
238
242
  ], Spine.prototype, "animationName", void 0);
@@ -247,7 +251,7 @@ var texCache = {};
247
251
  function cacheImage(data) {
248
252
  var oldImg = data.image;
249
253
  return {
250
- tex: Texture.from(oldImg),
254
+ tex: oldImg instanceof Texture ? oldImg : Texture.from(oldImg),
251
255
  count: 0,
252
256
  };
253
257
  }
@@ -260,14 +264,6 @@ function retainTexture(name, data) {
260
264
  cache.count++;
261
265
  return cache.tex;
262
266
  }
263
- function getTexture(imageSrc, data) {
264
- var cache = texCache[imageSrc];
265
- if (!cache) {
266
- cache = cacheImage(data);
267
- texCache[imageSrc] = cache;
268
- }
269
- return cache.tex;
270
- }
271
267
  function releaseTexture(imageSrc) {
272
268
  if (!imageSrc)
273
269
  return;
@@ -288,38 +284,32 @@ function releaseTexture(imageSrc) {
288
284
 
289
285
  var dataMap = {};
290
286
  function createSpineData(name, data, scale, pixiSpine) {
291
- var spineData = null;
292
- var img = getTexture(data.image.src, data);
293
- new pixiSpine.core.TextureAtlas(data.atlas, function (line, callback) {
294
- callback(img.baseTexture);
295
- }, function (spineAtlas) {
296
- if (spineAtlas) {
297
- var attachmentLoader = new pixiSpine.core.AtlasAttachmentLoader(spineAtlas);
298
- var spineJsonParser = new pixiSpine.core.SkeletonJson(attachmentLoader);
299
- if (scale) {
300
- spineJsonParser.scale = scale;
301
- }
302
- spineData = spineJsonParser.readSkeletonData(data.ske);
303
- }
304
- });
305
- var obj = { spineData: spineData, ref: 0, imageSrc: data.image.src };
287
+ var skeletonAsset = data.ske;
288
+ var atlasAsset = data.atlas;
289
+ var attachmentLoader = new pixiSpine.AtlasAttachmentLoader(atlasAsset);
290
+ var parser = skeletonAsset instanceof Uint8Array
291
+ ? new pixiSpine.SkeletonBinary(attachmentLoader)
292
+ : new pixiSpine.SkeletonJson(attachmentLoader);
293
+ parser.scale = scale || 1;
294
+ var skeletonData = parser.readSkeletonData(skeletonAsset);
295
+ var obj = { spineData: skeletonData, ref: 0, imageSrc: data.image.label };
306
296
  dataMap[name] = obj;
307
297
  return obj;
308
298
  }
309
- function getSpineData(res, pixiSpine) {
299
+ function getSpineData(res, scale, pixiSpine) {
310
300
  return __awaiter(this, void 0, void 0, function () {
311
301
  var data;
312
302
  return __generator(this, function (_a) {
313
303
  data = dataMap[res.name];
314
304
  if (!data) {
315
305
  if (res.complete) {
316
- data = createSpineData(res.name, res.data, res.scale, pixiSpine);
306
+ data = createSpineData(res.name, res.data, scale, pixiSpine);
317
307
  }
318
308
  else if (!data) {
319
309
  return [2];
320
310
  }
321
311
  }
322
- retainTexture(res.data.image.src, res.data);
312
+ retainTexture(res.data.image.label, res.data);
323
313
  data.ref++;
324
314
  return [2, data.spineData];
325
315
  });
@@ -388,7 +378,6 @@ var SpineSystem = (function (_super) {
388
378
  SpineSystem.prototype.update = function (e) {
389
379
  for (var key in this.armatures) {
390
380
  this.armatures[key].update(e.deltaTime * 0.001);
391
- this.armatures[key].updateTransform();
392
381
  }
393
382
  _super.prototype.update.call(this);
394
383
  };
@@ -431,7 +420,7 @@ var SpineSystem = (function (_super) {
431
420
  res = _c.sent();
432
421
  if (!this.validateAsyncId(gameObjectId, asyncId))
433
422
  return [2];
434
- return [4, getSpineData(res, this.pixiSpine)];
423
+ return [4, getSpineData(res, component.scale, this.pixiSpine)];
435
424
  case 2:
436
425
  spineData = _c.sent();
437
426
  if (!this.validateAsyncId(gameObjectId, asyncId))
@@ -459,7 +448,10 @@ var SpineSystem = (function (_super) {
459
448
  return [2];
460
449
  }
461
450
  component.lastResource = component.resource;
462
- armature = new this.pixiSpine.Spine(spineData);
451
+ armature = new this.pixiSpine.Spine({
452
+ skeletonData: spineData,
453
+ autoUpdate: false,
454
+ });
463
455
  this.armatures[changed.gameObject.id] = armature;
464
456
  if (changed.gameObject && changed.gameObject.transform) {
465
457
  tran = changed.gameObject.transform;
@@ -468,7 +460,6 @@ var SpineSystem = (function (_super) {
468
460
  }
469
461
  container.addChildAt(armature, 0);
470
462
  armature.update();
471
- armature.updateTransform();
472
463
  component.armature = armature;
473
464
  component.emit('loaded', { resource: component.resource });
474
465
  armature.state.addListener({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/spine-base",
3
- "version": "1.2.8",
3
+ "version": "2.0.0-beta.1",
4
4
  "description": "@eva/spine-base",
5
5
  "main": "index.js",
6
6
  "module": "dist/spine-base.esm.js",
@@ -18,9 +18,9 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/eva.js": "1.2.8",
22
- "@eva/plugin-renderer": "1.2.8",
21
+ "@eva/eva.js": "2.0.0-beta.1",
22
+ "@eva/plugin-renderer": "2.0.0-beta.1",
23
23
  "@eva/inspector-decorator": "^0.0.5",
24
- "pixi.js": "^4.8.9"
24
+ "pixi.js": "^8.6.3"
25
25
  }
26
26
  }