@eva/spine-base 1.2.7-editor.9 → 1.2.7-fix.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.plugin.spineBase.js +33 -322
- package/dist/EVA.plugin.spineBase.min.js +1 -1
- package/dist/miniprogram.js +453 -0
- package/dist/spine-base.cjs.js +5 -50
- package/dist/spine-base.cjs.prod.js +1 -1
- package/dist/spine-base.esm.js +7 -52
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign||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)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},o(e,t)};function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var a=function(){return a=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function c(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(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(a,s)}u((r=r.apply(e,t||[])).next())}))}function p(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var l=function(e){function t(){var t=this.constructor,n=e.call(this,"Symbol keys are not supported yet!")||this;return Object.setPrototypeOf(n,t.prototype),n}return i(t,e),t}(Error);!function(e){function t(){var t=this.constructor,n=e.call(this,"getProperties is not a function!")||this;return Object.setPrototypeOf(n,t.prototype),n}i(t,e)}(Error);var f,m="IDE_PROPERTY_METADATA";function d(e,t,n,r){var o=Reflect.getMetadata("design:type",e,t),i=o===Array,s=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),r){var u=r();Array.isArray(u)?(i=!0,o=u[0]):o=u}var c=Reflect.getMetadata(m,e.constructor)||{};c[t]=a({type:o,isArray:i},n),Reflect.defineMetadata(m,c,e.constructor)}function y(e,t){return function(n,r){if("symbol"==typeof r)throw new l;var o=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(e,t);d(n,r,o.options,o.returnTypeFunc)}}!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(f||(f={}));var h=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.animationName="",t.autoPlay=!0,t.waitExecuteInfos=[],t}return i(n,e),Object.defineProperty(n.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 i=o.value;if(i.playType){var a=i.name,s=i.loop,u=i.track;this.play(a,s,u)}else this.stop(i.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}),n.prototype.init=function(e){e&&_extends(this,e)},n.prototype.onDestroy=function(){this.destroied=!0},n.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)}},n.prototype.stop=function(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})},n.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)}},n.prototype.setMix=function(e,t,n){this.armature&&this.armature.stateData.setMix(e,t,n)},n.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)}},n.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},n.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},n.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},n.componentName="Spine",s([y({type:"resource"}),u("design:type",String)],n.prototype,"resource",void 0),s([y({type:"selector",options:function(e){var n,r,o;return c(this,void 0,void 0,(function(){var i;return p(this,(function(s){switch(s.label){case 0:return[4,(u=0,new Promise((function(e){return setTimeout(e,u)})))];case 1:return s.sent(),e.resource&&t.resource.promiseMap[e.resource]?[4,t.resource.promiseMap[e.resource]]:[2,{}];case 2:return s.sent(),[2,(i=null===(o=null===(r=null===(n=t.resource.resourcesMap[e.resource])||void 0===n?void 0:n.data)||void 0===r?void 0:r.ske)||void 0===o?void 0:o.animations)?Object.keys(i).reduce((function(e,t){var n;return a(a({},e),((n={})[t]=t,n))}),{}):{}]}var u}))}))}}),u("design:type",String)],n.prototype,"animationName",void 0),s([y(),u("design:type",Boolean)],n.prototype,"autoPlay",void 0),n}(t.Component),v=h,g={};function b(e){var t=e.image;return{tex:r.Texture.from(t),count:0}}var E={};function w(e,t,n,r){var o=null,i=function(e,t){var n=g[e];return n||(n=b(t),g[e]=n),n.tex}(t.image.src,t);new r.core.TextureAtlas(t.atlas,(function(e,t){t(i.baseTexture)}),(function(e){if(e){var i=new r.core.AtlasAttachmentLoader(e),a=new r.core.SkeletonJson(i);n&&(a.scale=n),o=a.readSkeletonData(t.ske)}}));var a={spineData:o,ref:0,imageSrc:t.image.src};return E[e]=a,a}function O(e,t){return c(this,void 0,void 0,(function(){var n;return p(this,(function(r){if(!(n=E[e.name]))if(e.complete)n=w(e.name,e.data,e.scale,t);else if(!n)return[2];return function(e,t){var n=g[e];n||(n=b(t),g[e]=n),n.count++,n.tex}(e.data.image.src,e.data),n.ref++,[2,n.spineData]}))}))}function x(e,t){var n=E[e];n&&(n.ref--,n.ref<=0&&(!function(e){e&&setTimeout((function(){var t=g[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete g[e]))}),100)}(t),delete E[e]))}var A=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.armatures={},t}return i(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 i=+o,a=0;a<e.length;++a){var s=e[a];if(s.id===i){var u=s.getComponent(v);u&&(r.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:v.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:v.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 c(this,void 0,void 0,(function(){return p(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 c(this,void 0,void 0,(function(){var i,a,s,u,c,l,f,m,d=this;return p(this,(function(p){switch(p.label){case 0:return i=e.component,clearTimeout(i.addHandler),a=e.gameObject.id,s=this.increaseAsyncId(a),[4,t.resource.getResource(i.resource)];case 1:return u=p.sent(),this.validateAsyncId(a,s)?[4,O(u,this.pixiSpine)]:[2];case 2:return c=p.sent(),this.validateAsyncId(a,s)?c?(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))?(i.lastResource=i.resource,f=new this.pixiSpine.Spine(c),this.armatures[e.gameObject.id]=f,e.gameObject&&e.gameObject.transform&&(m=e.gameObject.transform,f.x=m.size.width*m.origin.x,f.y=m.size.height*m.origin.y),l.addChildAt(f,0),f.update(),f.updateTransform(),i.armature=f,i.emit("loaded",{resource:i.resource}),f.state.addListener({start:function(e,t){i.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){i.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){i.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){i.emit("end",{track:e,name:e.animation.name})},event:function(e,t){i.emit("event",e,t)}}),[2]):[2]):(i.addHandler=setTimeout((function(){i.destroied||(void 0===n&&(n=20),--n>0?d.add(e,n):console.log("retry exceed max times",i.resource))}),1e3),[2]):[2]}}))}))},r.prototype.change=function(e){this.remove(e),this.add(e)},r.prototype.remove=function(e){var n,r,o,i;return c(this,void 0,void 0,(function(){var a,s,u,c;return p(this,(function(p){switch(p.label){case 0:return this.increaseAsyncId(e.gameObject.id),a=e.component,clearTimeout(a.addHandler),s=this.armatures[e.gameObject.id],(u=null===(r=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===r?void 0:r.getContainer(e.gameObject.id))&&s&&u.removeChild(s),a.armature?(a.armature.destroy({children:!0}),[4,t.resource.getResource(a.lastResource)]):[3,2];case 1:x((c=p.sent()).name,null===(i=null===(o=c.data)||void 0===o?void 0:o.image)||void 0===i?void 0:i.src),p.label=2;case 2:return a.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE,[2]}}))}))},r.systemName="SpineSystem",r=s([t.decorators.componentObserver({Spine:["resource"]})],r)}(n.Renderer),S=A;return t.resource.registerResourceType("SPINE"),e.Spine=v,e.SpineSystem=S,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)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;
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
|
|
3
|
+
import { __extends, __values, __decorate, __awaiter, __generator } from 'tslib';
|
|
4
|
+
import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
|
|
5
|
+
import { type } from '@eva/inspector-decorator';
|
|
6
|
+
import { Texture } from '@eva/miniprogram-pixi';
|
|
7
|
+
var Spine = function (_super) {
|
|
8
|
+
__extends(Spine, _super);
|
|
9
|
+
function Spine() {
|
|
10
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
11
|
+
_this.resource = '';
|
|
12
|
+
_this.animationName = '';
|
|
13
|
+
_this.autoPlay = true;
|
|
14
|
+
_this.waitExecuteInfos = [];
|
|
15
|
+
return _this;
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(Spine.prototype, "armature", {
|
|
18
|
+
get: function get() {
|
|
19
|
+
return this._armature;
|
|
20
|
+
},
|
|
21
|
+
set: function set(val) {
|
|
22
|
+
var e_1, _a;
|
|
23
|
+
this._armature = val;
|
|
24
|
+
if (!val) return;
|
|
25
|
+
if (this.autoPlay) {
|
|
26
|
+
this.play(this.animationName);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
for (var _b = __values(this.waitExecuteInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
30
|
+
var info = _c.value;
|
|
31
|
+
if (info.playType) {
|
|
32
|
+
var name_1 = info.name,
|
|
33
|
+
loop = info.loop,
|
|
34
|
+
track = info.track;
|
|
35
|
+
this.play(name_1, loop, track);
|
|
36
|
+
} else {
|
|
37
|
+
this.stop(info.track);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} catch (e_1_1) {
|
|
41
|
+
e_1 = {
|
|
42
|
+
error: e_1_1
|
|
43
|
+
};
|
|
44
|
+
} finally {
|
|
45
|
+
try {
|
|
46
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
47
|
+
} finally {
|
|
48
|
+
if (e_1) throw e_1.error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.waitExecuteInfos = [];
|
|
52
|
+
},
|
|
53
|
+
enumerable: false,
|
|
54
|
+
configurable: true
|
|
55
|
+
});
|
|
56
|
+
Spine.prototype.init = function (obj) {
|
|
57
|
+
if (!obj) return;
|
|
58
|
+
_extends(this, obj);
|
|
59
|
+
};
|
|
60
|
+
Spine.prototype.onDestroy = function () {
|
|
61
|
+
this.destroied = true;
|
|
62
|
+
};
|
|
63
|
+
Spine.prototype.play = function (name, loop, track) {
|
|
64
|
+
try {
|
|
65
|
+
if (name) this.animationName = name;
|
|
66
|
+
if (!this.armature) {
|
|
67
|
+
this.waitExecuteInfos.push({
|
|
68
|
+
playType: true,
|
|
69
|
+
name: name,
|
|
70
|
+
loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
|
|
71
|
+
track: track
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
if (track === undefined) {
|
|
75
|
+
track = 0;
|
|
76
|
+
}
|
|
77
|
+
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
78
|
+
}
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.log(e);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
Spine.prototype.stop = function (track) {
|
|
84
|
+
if (!this.armature) {
|
|
85
|
+
this.waitExecuteInfos.push({
|
|
86
|
+
playType: false,
|
|
87
|
+
track: track
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (track === undefined) {
|
|
92
|
+
track = 0;
|
|
93
|
+
}
|
|
94
|
+
this.armature.state.setEmptyAnimation(track, 0);
|
|
95
|
+
};
|
|
96
|
+
Spine.prototype.addAnimation = function (name, delay, loop, track) {
|
|
97
|
+
try {
|
|
98
|
+
if (!this.armature) {} else {
|
|
99
|
+
if (track === undefined) {
|
|
100
|
+
track = 0;
|
|
101
|
+
}
|
|
102
|
+
this.armature.state.addAnimation(track, name, loop, delay);
|
|
103
|
+
}
|
|
104
|
+
} catch (e) {
|
|
105
|
+
console.log(e);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
Spine.prototype.setMix = function (from, to, duration) {
|
|
109
|
+
if (!this.armature) ;else {
|
|
110
|
+
this.armature.stateData.setMix(from, to, duration);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
Spine.prototype.getAnim = function (track) {
|
|
114
|
+
if (track === void 0) {
|
|
115
|
+
track = 0;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
if (!this.armature) {} else {
|
|
119
|
+
return this.armature.state.tracks[track].animation.name;
|
|
120
|
+
}
|
|
121
|
+
} catch (e) {
|
|
122
|
+
console.log(e);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
Spine.prototype.setDefaultMix = function (duration) {
|
|
126
|
+
if (!this.armature) ;else {
|
|
127
|
+
this.armature.stateData.defaultMix = duration;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
Spine.prototype.setAttachment = function (slotName, attachmentName) {
|
|
131
|
+
if (!this.armature) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
this.armature.skeleton.setAttachment(slotName, attachmentName);
|
|
135
|
+
};
|
|
136
|
+
Spine.prototype.getBone = function (boneName) {
|
|
137
|
+
if (!this.armature) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
return this.armature.skeleton.findBone(boneName);
|
|
141
|
+
};
|
|
142
|
+
Spine.componentName = 'Spine';
|
|
143
|
+
__decorate([type('string')], Spine.prototype, "resource", void 0);
|
|
144
|
+
__decorate([type('string')], Spine.prototype, "animationName", void 0);
|
|
145
|
+
__decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
|
|
146
|
+
return Spine;
|
|
147
|
+
}(Component);
|
|
148
|
+
var Spine$1 = Spine;
|
|
149
|
+
var texCache = {};
|
|
150
|
+
function cacheImage(data) {
|
|
151
|
+
var oldImg = data.image;
|
|
152
|
+
return {
|
|
153
|
+
tex: Texture.from(oldImg),
|
|
154
|
+
count: 0
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function retainTexture(name, data) {
|
|
158
|
+
var cache = texCache[name];
|
|
159
|
+
if (!cache) {
|
|
160
|
+
cache = cacheImage(data);
|
|
161
|
+
texCache[name] = cache;
|
|
162
|
+
}
|
|
163
|
+
cache.count++;
|
|
164
|
+
return cache.tex;
|
|
165
|
+
}
|
|
166
|
+
function getTexture(imageSrc, data) {
|
|
167
|
+
var cache = texCache[imageSrc];
|
|
168
|
+
if (!cache) {
|
|
169
|
+
cache = cacheImage(data);
|
|
170
|
+
texCache[imageSrc] = cache;
|
|
171
|
+
}
|
|
172
|
+
return cache.tex;
|
|
173
|
+
}
|
|
174
|
+
function releaseTexture(imageSrc) {
|
|
175
|
+
if (!imageSrc) return;
|
|
176
|
+
setTimeout(function () {
|
|
177
|
+
var cache = texCache[imageSrc];
|
|
178
|
+
if (cache) {
|
|
179
|
+
cache.count--;
|
|
180
|
+
if (cache.count <= 0) {
|
|
181
|
+
if (cache.tex) {
|
|
182
|
+
cache.tex.destroy(true);
|
|
183
|
+
cache.tex = null;
|
|
184
|
+
}
|
|
185
|
+
delete texCache[imageSrc];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}, 100);
|
|
189
|
+
}
|
|
190
|
+
var dataMap = {};
|
|
191
|
+
function createSpineData(name, data, scale, pixiSpine) {
|
|
192
|
+
var spineData = null;
|
|
193
|
+
var img = getTexture(data.image.src, data);
|
|
194
|
+
new pixiSpine.core.TextureAtlas(data.atlas, function (line, callback) {
|
|
195
|
+
callback(img.baseTexture);
|
|
196
|
+
}, function (spineAtlas) {
|
|
197
|
+
if (spineAtlas) {
|
|
198
|
+
var attachmentLoader = new pixiSpine.core.AtlasAttachmentLoader(spineAtlas);
|
|
199
|
+
var spineJsonParser = new pixiSpine.core.SkeletonJson(attachmentLoader);
|
|
200
|
+
if (scale) {
|
|
201
|
+
spineJsonParser.scale = scale;
|
|
202
|
+
}
|
|
203
|
+
spineData = spineJsonParser.readSkeletonData(data.ske);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
var obj = {
|
|
207
|
+
spineData: spineData,
|
|
208
|
+
ref: 0,
|
|
209
|
+
imageSrc: data.image.src
|
|
210
|
+
};
|
|
211
|
+
dataMap[name] = obj;
|
|
212
|
+
return obj;
|
|
213
|
+
}
|
|
214
|
+
function getSpineData(res, pixiSpine) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
+
var data;
|
|
217
|
+
return __generator(this, function (_a) {
|
|
218
|
+
data = dataMap[res.name];
|
|
219
|
+
if (!data) {
|
|
220
|
+
if (res.complete) {
|
|
221
|
+
data = createSpineData(res.name, res.data, res.scale, pixiSpine);
|
|
222
|
+
} else if (!data) {
|
|
223
|
+
return [2];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
retainTexture(res.data.image.src, res.data);
|
|
227
|
+
data.ref++;
|
|
228
|
+
return [2, data.spineData];
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function releaseSpineData(resourceName, imageSrc) {
|
|
233
|
+
var data = dataMap[resourceName];
|
|
234
|
+
if (!data) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
data.ref--;
|
|
238
|
+
if (data.ref <= 0) {
|
|
239
|
+
releaseTexture(imageSrc);
|
|
240
|
+
delete dataMap[resourceName];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
var MaxRetryCount = 20;
|
|
244
|
+
var SpineSystem = function (_super) {
|
|
245
|
+
__extends(SpineSystem, _super);
|
|
246
|
+
function SpineSystem() {
|
|
247
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
248
|
+
_this.armatures = {};
|
|
249
|
+
return _this;
|
|
250
|
+
}
|
|
251
|
+
SpineSystem.prototype.init = function (_a) {
|
|
252
|
+
var _this = this;
|
|
253
|
+
var pixiSpine = _a.pixiSpine;
|
|
254
|
+
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
255
|
+
this.renderSystem.rendererManager.register(this);
|
|
256
|
+
this.pixiSpine = pixiSpine;
|
|
257
|
+
this.game.canvas.addEventListener('webglcontextrestored', function () {
|
|
258
|
+
var objs = _this.game.gameObjects;
|
|
259
|
+
var toAdd = [];
|
|
260
|
+
for (var k in _this.armatures) {
|
|
261
|
+
var id = +k;
|
|
262
|
+
for (var i = 0; i < objs.length; ++i) {
|
|
263
|
+
var obj = objs[i];
|
|
264
|
+
if (obj.id === id) {
|
|
265
|
+
var sp = obj.getComponent(Spine$1);
|
|
266
|
+
if (sp) {
|
|
267
|
+
_this.remove({
|
|
268
|
+
type: OBSERVER_TYPE.REMOVE,
|
|
269
|
+
gameObject: obj,
|
|
270
|
+
component: sp,
|
|
271
|
+
componentName: Spine$1.componentName
|
|
272
|
+
});
|
|
273
|
+
toAdd.push({
|
|
274
|
+
type: OBSERVER_TYPE.ADD,
|
|
275
|
+
gameObject: obj,
|
|
276
|
+
component: sp,
|
|
277
|
+
componentName: Spine$1.componentName
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
setTimeout(function () {
|
|
285
|
+
toAdd.forEach(function (obj) {
|
|
286
|
+
_this.add(obj);
|
|
287
|
+
});
|
|
288
|
+
}, 1000);
|
|
289
|
+
}, false);
|
|
290
|
+
};
|
|
291
|
+
SpineSystem.prototype.update = function (e) {
|
|
292
|
+
for (var key in this.armatures) {
|
|
293
|
+
this.armatures[key].update(e.deltaTime * 0.001);
|
|
294
|
+
this.armatures[key].updateTransform();
|
|
295
|
+
}
|
|
296
|
+
_super.prototype.update.call(this);
|
|
297
|
+
};
|
|
298
|
+
SpineSystem.prototype.componentChanged = function (changed) {
|
|
299
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
300
|
+
return __generator(this, function (_a) {
|
|
301
|
+
if (changed.componentName === 'Spine') {
|
|
302
|
+
if (changed.type === OBSERVER_TYPE.ADD) {
|
|
303
|
+
this.add(changed);
|
|
304
|
+
} else if (changed.type === OBSERVER_TYPE.CHANGE) {
|
|
305
|
+
switch (changed.prop.prop[0]) {
|
|
306
|
+
case 'resource':
|
|
307
|
+
this.change(changed);
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
} else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
311
|
+
this.remove(changed);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return [2];
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
SpineSystem.prototype.add = function (changed, count) {
|
|
319
|
+
var _a, _b;
|
|
320
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
321
|
+
var component, gameObjectId, asyncId, res, spineData, container, armature, tran;
|
|
322
|
+
var _this = this;
|
|
323
|
+
return __generator(this, function (_c) {
|
|
324
|
+
switch (_c.label) {
|
|
325
|
+
case 0:
|
|
326
|
+
component = changed.component;
|
|
327
|
+
clearTimeout(component.addHandler);
|
|
328
|
+
gameObjectId = changed.gameObject.id;
|
|
329
|
+
asyncId = this.increaseAsyncId(gameObjectId);
|
|
330
|
+
return [4, resource.getResource(component.resource)];
|
|
331
|
+
case 1:
|
|
332
|
+
res = _c.sent();
|
|
333
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
334
|
+
return [4, getSpineData(res, this.pixiSpine)];
|
|
335
|
+
case 2:
|
|
336
|
+
spineData = _c.sent();
|
|
337
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
338
|
+
if (!spineData) {
|
|
339
|
+
component.addHandler = setTimeout(function () {
|
|
340
|
+
if (!component.destroied) {
|
|
341
|
+
if (count === undefined) {
|
|
342
|
+
count = MaxRetryCount;
|
|
343
|
+
}
|
|
344
|
+
count--;
|
|
345
|
+
if (count > 0) {
|
|
346
|
+
_this.add(changed, count);
|
|
347
|
+
} else {
|
|
348
|
+
console.log('retry exceed max times', component.resource);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}, 1000);
|
|
352
|
+
return [2];
|
|
353
|
+
}
|
|
354
|
+
this.remove(changed);
|
|
355
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
356
|
+
if (!container) {
|
|
357
|
+
return [2];
|
|
358
|
+
}
|
|
359
|
+
component.lastResource = component.resource;
|
|
360
|
+
armature = new this.pixiSpine.Spine(spineData);
|
|
361
|
+
this.armatures[changed.gameObject.id] = armature;
|
|
362
|
+
if (changed.gameObject && changed.gameObject.transform) {
|
|
363
|
+
tran = changed.gameObject.transform;
|
|
364
|
+
armature.x = tran.size.width * tran.origin.x;
|
|
365
|
+
armature.y = tran.size.height * tran.origin.y;
|
|
366
|
+
}
|
|
367
|
+
container.addChildAt(armature, 0);
|
|
368
|
+
armature.update();
|
|
369
|
+
armature.updateTransform();
|
|
370
|
+
component.armature = armature;
|
|
371
|
+
component.emit('loaded', {
|
|
372
|
+
resource: component.resource
|
|
373
|
+
});
|
|
374
|
+
armature.state.addListener({
|
|
375
|
+
start: function start(track, event) {
|
|
376
|
+
component.emit('start', {
|
|
377
|
+
track: track,
|
|
378
|
+
name: track.animation.name
|
|
379
|
+
});
|
|
380
|
+
},
|
|
381
|
+
complete: function complete(track, event) {
|
|
382
|
+
component.emit('complete', {
|
|
383
|
+
track: track,
|
|
384
|
+
name: track.animation.name
|
|
385
|
+
});
|
|
386
|
+
},
|
|
387
|
+
interrupt: function interrupt(track, event) {
|
|
388
|
+
component.emit('interrupt', {
|
|
389
|
+
track: track,
|
|
390
|
+
name: track.animation.name
|
|
391
|
+
});
|
|
392
|
+
},
|
|
393
|
+
end: function end(track, event) {
|
|
394
|
+
component.emit('end', {
|
|
395
|
+
track: track,
|
|
396
|
+
name: track.animation.name
|
|
397
|
+
});
|
|
398
|
+
},
|
|
399
|
+
event: function event(track, _event) {
|
|
400
|
+
component.emit('event', track, _event);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
return [2];
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
};
|
|
408
|
+
SpineSystem.prototype.change = function (changed) {
|
|
409
|
+
this.remove(changed);
|
|
410
|
+
this.add(changed);
|
|
411
|
+
};
|
|
412
|
+
SpineSystem.prototype.remove = function (changed) {
|
|
413
|
+
var _a, _b, _c, _d;
|
|
414
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
415
|
+
var component, armature, container, res;
|
|
416
|
+
return __generator(this, function (_e) {
|
|
417
|
+
switch (_e.label) {
|
|
418
|
+
case 0:
|
|
419
|
+
this.increaseAsyncId(changed.gameObject.id);
|
|
420
|
+
component = changed.component;
|
|
421
|
+
clearTimeout(component.addHandler);
|
|
422
|
+
armature = this.armatures[changed.gameObject.id];
|
|
423
|
+
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
424
|
+
if (container && armature) {
|
|
425
|
+
container.removeChild(armature);
|
|
426
|
+
}
|
|
427
|
+
if (!component.armature) return [3, 2];
|
|
428
|
+
component.armature.destroy({
|
|
429
|
+
children: true
|
|
430
|
+
});
|
|
431
|
+
return [4, resource.getResource(component.lastResource)];
|
|
432
|
+
case 1:
|
|
433
|
+
res = _e.sent();
|
|
434
|
+
releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
|
|
435
|
+
_e.label = 2;
|
|
436
|
+
case 2:
|
|
437
|
+
component.armature = null;
|
|
438
|
+
delete this.armatures[changed.gameObject.id];
|
|
439
|
+
if (changed.type === OBSERVER_TYPE.CHANGE) ;
|
|
440
|
+
return [2];
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
SpineSystem.systemName = 'SpineSystem';
|
|
446
|
+
SpineSystem = __decorate([decorators.componentObserver({
|
|
447
|
+
Spine: ['resource']
|
|
448
|
+
})], SpineSystem);
|
|
449
|
+
return SpineSystem;
|
|
450
|
+
}(Renderer);
|
|
451
|
+
var SpineSystem$1 = SpineSystem;
|
|
452
|
+
resource.registerResourceType('SPINE');
|
|
453
|
+
export { Spine$1 as Spine, SpineSystem$1 as SpineSystem };
|
package/dist/spine-base.cjs.js
CHANGED
|
@@ -36,17 +36,6 @@ function __extends(d, b) {
|
|
|
36
36
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
var __assign = function() {
|
|
40
|
-
__assign = Object.assign || function __assign(t) {
|
|
41
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
42
|
-
s = arguments[i];
|
|
43
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
44
|
-
}
|
|
45
|
-
return t;
|
|
46
|
-
};
|
|
47
|
-
return __assign.apply(this, arguments);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
39
|
function __decorate(decorators, target, key, desc) {
|
|
51
40
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
52
41
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -54,10 +43,6 @@ function __decorate(decorators, target, key, desc) {
|
|
|
54
43
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
55
44
|
}
|
|
56
45
|
|
|
57
|
-
function __metadata(metadataKey, metadataValue) {
|
|
58
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
46
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
62
47
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
63
48
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -106,7 +91,6 @@ function __values(o) {
|
|
|
106
91
|
};
|
|
107
92
|
}
|
|
108
93
|
|
|
109
|
-
var sleep = function (time) { return new Promise(function (resolve) { return setTimeout(resolve, time); }); };
|
|
110
94
|
var Spine = (function (_super) {
|
|
111
95
|
__extends(Spine, _super);
|
|
112
96
|
function Spine() {
|
|
@@ -170,7 +154,7 @@ var Spine = (function (_super) {
|
|
|
170
154
|
playType: true,
|
|
171
155
|
name: name,
|
|
172
156
|
loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
|
|
173
|
-
track: track
|
|
157
|
+
track: track
|
|
174
158
|
});
|
|
175
159
|
}
|
|
176
160
|
else {
|
|
@@ -188,7 +172,7 @@ var Spine = (function (_super) {
|
|
|
188
172
|
if (!this.armature) {
|
|
189
173
|
this.waitExecuteInfos.push({
|
|
190
174
|
playType: false,
|
|
191
|
-
track: track
|
|
175
|
+
track: track
|
|
192
176
|
});
|
|
193
177
|
return;
|
|
194
178
|
}
|
|
@@ -251,42 +235,13 @@ var Spine = (function (_super) {
|
|
|
251
235
|
};
|
|
252
236
|
Spine.componentName = 'Spine';
|
|
253
237
|
__decorate([
|
|
254
|
-
inspectorDecorator.
|
|
255
|
-
__metadata("design:type", String)
|
|
238
|
+
inspectorDecorator.type('string')
|
|
256
239
|
], Spine.prototype, "resource", void 0);
|
|
257
240
|
__decorate([
|
|
258
|
-
inspectorDecorator.
|
|
259
|
-
type: 'selector',
|
|
260
|
-
options: function (that) {
|
|
261
|
-
var _a, _b, _c;
|
|
262
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
263
|
-
var animations;
|
|
264
|
-
return __generator(this, function (_d) {
|
|
265
|
-
switch (_d.label) {
|
|
266
|
-
case 0: return [4, sleep(0)];
|
|
267
|
-
case 1:
|
|
268
|
-
_d.sent();
|
|
269
|
-
if (!that.resource || !eva_js.resource.promiseMap[that.resource]) {
|
|
270
|
-
return [2, {}];
|
|
271
|
-
}
|
|
272
|
-
return [4, eva_js.resource.promiseMap[that.resource]];
|
|
273
|
-
case 2:
|
|
274
|
-
_d.sent();
|
|
275
|
-
animations = (_c = (_b = (_a = eva_js.resource.resourcesMap[that.resource]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.ske) === null || _c === void 0 ? void 0 : _c.animations;
|
|
276
|
-
return [2, animations ? Object.keys(animations).reduce(function (prev, key) {
|
|
277
|
-
var _a;
|
|
278
|
-
return (__assign(__assign({}, prev), (_a = {}, _a[key] = key, _a)));
|
|
279
|
-
}, {}) : {}];
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
},
|
|
284
|
-
}),
|
|
285
|
-
__metadata("design:type", String)
|
|
241
|
+
inspectorDecorator.type('string')
|
|
286
242
|
], Spine.prototype, "animationName", void 0);
|
|
287
243
|
__decorate([
|
|
288
|
-
inspectorDecorator.
|
|
289
|
-
__metadata("design:type", Boolean)
|
|
244
|
+
inspectorDecorator.type('boolean')
|
|
290
245
|
], Spine.prototype, "autoPlay", void 0);
|
|
291
246
|
return Spine;
|
|
292
247
|
}(eva_js.Component));
|
|
@@ -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"),
|
|
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;
|