@eva/spine-base 2.1.0-beta.2 → 2.1.0-beta.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.
|
@@ -40,6 +40,10 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
40
40
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
44
|
+
var e = new Error(message);
|
|
45
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
|
+
};
|
|
43
47
|
function __rest(s, e) {
|
|
44
48
|
var t = {};
|
|
45
49
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
@@ -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 i in n)({}).hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,i){"use strict";function s(e,t,n,i){var s,r=arguments.length,o=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(o=(r<3?s(o):r>3?s(t,n,o):s(t,n))||o);return r>3&&o&&Object.defineProperty(t,n,o),o}function r(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function o(e,t,n,i){return new(n||(n=Promise))(function(s,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function a(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,a)}c((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class a extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const c="IDE_PROPERTY_METADATA";function l(e,t,n,i){let s=Reflect.getMetadata("design:type",e,t),r=s===Array;const o=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(s);if("unknown"!==o&&(s=o),i){const e=i();Array.isArray(e)?(r=!0,s=e[0]):s=e}const a=Reflect.getMetadata(c,e.constructor)||{},l=_extends(_extends(_extends({},a[t]||{}),{type:s,isArray:r}),n);a[t]=l,Reflect.defineMetadata(c,a,e.constructor);!function(e,t,n){const i=e.constructor,s=i.IDEProps||{};s[t]=_extends(_extends({key:t},s[t]),n),i.IDEProps=s}(e,t,function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(i=Object.getOwnPropertySymbols(e);s<i.length;s++)t.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(e,i[s])&&(n[i[s]]=e[i[s]])}return n}(l,["isArray"]))}function d(e){return t={type:e},(e,i)=>{if("symbol"==typeof i)throw new a;const{options:s,returnTypeFunc:r}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,n);l(e,i,s,r)};var t,n}var u;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(u||(u={}));class m extends t.Component{constructor(e){super(e),this.resource="",this.scale=1,this.animationName="",this.autoPlay=!0,this.keepResource=!1,this.timeScale=1,this.skin="",this._slotGameObjects=new Map,this._pendingSlotObjects=[],this.waitExecuteInfos=[],this.listenerBound=!1,this.paused=!1,this.init(e)}set armature(e){if(this._armature=e,e){this.applyTimeScale(),this.skin&&this.setSkin(this.skin),this.autoPlay&&this.play(this.animationName);for(const e of this.waitExecuteInfos)if(e.playType){const{name:t,loop:n,track:i}=e;this.play(t,n,i)}else this.stop(e.track);this.waitExecuteInfos=[]}}get armature(){return this._armature}init(e){e&&_extends(this,e),this.listenerBound||(this.listenerBound=!0,this.on("start",e=>{var t;null===(t=this.onStart)||void 0===t||t.call(this,e)}),this.on("complete",e=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this,e)}),this.on("event",(e,t)=>{var n;null===(n=this.onEvent)||void 0===n||n.call(this,e,t)}))}onDestroy(){this.destroied=!0}load(){return this.armature}destroy(){this.onDestroy(),this.armature&&!this.armature.destroyed&&(this._destroySlotGameObjects(),this.armature.destroy({children:!0})),this.armature=null}pause(){this.paused=!0,this.applyTimeScale()}resume(){this.paused=!1,this.applyTimeScale()}setSkin(e){var t,n,i,s,r;if(this.skin=e,null===(t=this.armature)||void 0===t?void 0:t.skeleton){if(this.armature.skeleton.setSkinByName)this.armature.skeleton.setSkinByName(e);else if(this.armature.skeleton.setSkin){const t=(null===(i=null===(n=this.armature.skeleton.data)||void 0===n?void 0:n.findSkin)||void 0===i?void 0:i.call(n,e))||e;this.armature.skeleton.setSkin(t)}null===(r=(s=this.armature.skeleton).setSlotsToSetupPose)||void 0===r||r.call(s)}}play(e,t,n){try{const i=null!=t?t:this.autoPlay;e&&(this.animationName=e),this.armature?(void 0===n&&(n=0),this.applyTimeScale(),this.armature.state.setAnimation(n,this.animationName,i)):this.waitExecuteInfos.push({playType:!0,name:e,loop:i,track:n})}catch(e){console.log(e)}}stop(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})}applyTimeScale(){var e;(null===(e=this.armature)||void 0===e?void 0:e.state)&&(this.armature.state.timeScale=this.paused?0:this.timeScale)}addAnimation(e,t,n,i){try{this.armature&&(void 0===i&&(i=0),this.armature.state.addAnimation(i,e,n,t))}catch(e){console.log(e)}}setMix(e,t,n){this.armature&&this.armature.state.data.setMix(e,t,n)}getAnim(e=0){try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}}setDefaultMix(e){this.armature&&(this.armature.state.data.defaultMix=e)}setAttachment(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)}getBone(e){if(this.armature)return this.armature.skeleton.findBone(e)}addSlotObject(e,t,n){if(!this.armature)return void console.warn("Spine armature is not ready, cannot addSlotObject");if(!this._containerManager)return void console.warn("ContainerManager is not available");const i=this._containerManager.getContainer(t.id);i?this._doAddSlotObject(e,t,i,n):this._pendingSlotObjects.push({slot:e,gameObject:t,options:n})}_doAddSlotObject(e,t,n,s){const r=new i.Container;r.addChild(n),this.armature.addSlotObject(e,r,s),this._slotGameObjects.set(t,{slot:e,wrapper:r}),this._syncTransformTree(t)}_syncTransformTree(e){var t;if(this._containerManager&&(this._containerManager.updateTransform({name:e.id,transform:e.transform}),null===(t=e.transform)||void 0===t?void 0:t.children))for(const t of e.transform.children)t.gameObject&&this._syncTransformTree(t.gameObject)}_flushPendingSlotObjects(){if(0===this._pendingSlotObjects.length)return;if(!this.armature||!this._containerManager)return;const e=[];for(const t of this._pendingSlotObjects){const n=this._containerManager.getContainer(t.gameObject.id);n?this._doAddSlotObject(t.slot,t.gameObject,n,t.options):e.push(t)}this._pendingSlotObjects=e}removeSlotObject(e){this._pendingSlotObjects=this._pendingSlotObjects.filter(t=>t.gameObject!==e);const t=this._slotGameObjects.get(e);t&&this.armature&&(this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1})),this._slotGameObjects.delete(e)}_destroySlotGameObjects(){for(const[e,t]of this._slotGameObjects)e.destroyed||(this.armature&&this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1}),e.destroy());this._slotGameObjects.clear(),this._pendingSlotObjects=[]}}m.componentName="Spine",s([d("string"),r("design:type",String)],m.prototype,"resource",void 0),s([d("number"),r("design:type",Number)],m.prototype,"scale",void 0),s([d("string"),r("design:type",String)],m.prototype,"animationName",void 0),s([d("boolean"),r("design:type",Boolean)],m.prototype,"autoPlay",void 0),s([d("boolean"),r("design:type",Boolean)],m.prototype,"keepResource",void 0),s([d("number"),r("design:type",Number)],m.prototype,"timeScale",void 0),s([d("string"),r("design:type",String)],m.prototype,"skin",void 0);let p={};function h(e,t,n){return o(this,void 0,void 0,function*(){let i=p[e.name];if(!i)if(e.complete)i=function(e,t,n,i){const s=t.ske,r=t.atlas,o=new i.AtlasAttachmentLoader(r),a=s instanceof Uint8Array?new i.SkeletonBinary(o):new i.SkeletonJson(o);a.scale=n||1;const c={spineData:a.readSkeletonData(s),ref:0,imageSrc:(l=t.image,l?"string"==typeof l?l:l.label||(null===(d=l.source)||void 0===d?void 0:d.label)||(null===(m=null===(u=l.source)||void 0===u?void 0:u.resource)||void 0===m?void 0:m.src)||(null===(h=l.source)||void 0===h?void 0:h._sourceOrigin)||l.src||(null===(y=l.baseTexture)||void 0===y?void 0:y.cacheId)||"":"")};var l,d,u,m,h,y;return p[e]=c,c}(e.name,e.data,t,n);else if(!i)return;return i.ref++,i.spineData})}let y=class extends n.Renderer{constructor(){super(...arguments),this.armatures={},this._spineComponents={}}init({pixiSpine:e}){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=e,this.game.canvas.addEventListener("webglcontextrestored",()=>{const e=this.game.gameObjects;let n=[];for(let i in this.armatures){const s=+i;for(let i=0;i<e.length;++i){let r=e[i];if(r.id===s){let e=r.getComponent(m);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:r,component:e,componentName:m.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:r,component:e,componentName:m.componentName}));break}}}setTimeout(()=>{n.forEach(e=>{this.add(e)})},1e3)},!1)}update(e){super.update();for(let t in this.armatures){const n=this.armatures[t],i=this._spineComponents[t];!n||n.destroyed||(null==i?void 0:i.destroied)?(delete this.armatures[t],delete this._spineComponents[t]):n.update(.001*e.deltaTime)}for(let e in this._spineComponents){const t=this._spineComponents[e];t&&!t.destroied?t._flushPendingSlotObjects():delete this._spineComponents[e]}}componentChanged(e){return o(this,void 0,void 0,function*(){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)})}add(e,n){var i,s,r;return o(this,void 0,void 0,function*(){const o=e.component;clearTimeout(o.addHandler);const a=e.gameObject.id,c=this.increaseAsyncId(a),l=yield t.resource.getResource(o.resource);if(!this.validateAsyncId(a,c)||o.destroied||e.gameObject.destroyed)return;const d=yield h(l,o.scale,this.pixiSpine);if(!this.validateAsyncId(a,c)||o.destroied||e.gameObject.destroyed)return;if(!d)return void(o.addHandler=setTimeout(()=>{o.destroied||e.gameObject.destroyed||(void 0===n&&(n=20),--n>0?this.add(e,n):console.log("retry exceed max times",o.resource))},1e3));this.remove(e);const u=null===(s=null===(i=this.renderSystem)||void 0===i?void 0:i.containerManager)||void 0===s?void 0:s.getContainer(e.gameObject.id);if(!u||o.destroied||e.gameObject.destroyed)return;o.lastResource=o.resource;const m=new this.pixiSpine.Spine({skeletonData:d,autoUpdate:!1});if(this.armatures[e.gameObject.id]=m,this._spineComponents[e.gameObject.id]=o,e.gameObject&&e.gameObject.transform){const t=e.gameObject.transform;m.x=t.size.width*t.origin.x,m.y=t.size.height*t.origin.y}u.addChildAt(m,0),m.update(),o._containerManager=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager,o.armature=m,o.emit("loaded",{resource:o.resource}),m.state.addListener({start:(e,t)=>{o.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{o.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{o.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{o.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{o.emit("event",e,t)}})})}change(e){this.remove(e),this.add(e)}remove(e){var n,i,s,r,a,c;return o(this,void 0,void 0,function*(){const l=e.gameObject.id;this.increaseAsyncId(l);const d=e.component;clearTimeout(d.addHandler);const u=this.armatures[l],m=null===(i=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===i?void 0:i.getContainer(l);m&&u&&m.removeChild(u);const h=d.armature;if(d.armature=null,delete this.armatures[l],delete this._spineComponents[l],h&&(d._destroySlotGameObjects(),h.destroyed||h.destroy({children:!0}),!d.keepResource&&d.lastResource))try{const e=yield t.resource.getResource(d.lastResource);(null===(r=null===(s=e.data)||void 0===s?void 0:s.image)||void 0===r?void 0:r.src)||(null===(c=null===(a=e.data)||void 0===a?void 0:a.image)||void 0===c||c.label);!function(e){const n=e.name,i=p[n];i&&(i.ref--,setTimeout(()=>o(this,void 0,void 0,function*(){i.ref<=0&&(t.resource.destroy(n),delete p[n])}),100))}(e)}catch(e){console.warn("Failed to release Spine resource",d.lastResource,e)}e.type,t.OBSERVER_TYPE.CHANGE})}};y.systemName="SpineSystem",y=s([t.decorators.componentObserver({Spine:["resource"]})],y);var f=y;return t.resource.registerResourceType("SPINE"),e.Spine=m,e.SpineSystem=f,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.spineBase=globalThis.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 i in n)({}).hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,i){"use strict";function r(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function o(e,t,n,i){return new(n||(n=Promise))(function(r,s){function o(e){try{c(i.next(e))}catch(e){s(e)}}function a(e){try{c(i.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,a)}c((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;class a extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const c="IDE_PROPERTY_METADATA";function l(e,t,n,i){let r=Reflect.getMetadata("design:type",e,t),s=r===Array;const o=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(r);if("unknown"!==o&&(r=o),i){const e=i();Array.isArray(e)?(s=!0,r=e[0]):r=e}const a=Reflect.getMetadata(c,e.constructor)||{},l=_extends(_extends(_extends({},a[t]||{}),{type:r,isArray:s}),n);a[t]=l,Reflect.defineMetadata(c,a,e.constructor);!function(e,t,n){const i=e.constructor,r=i.IDEProps||{};r[t]=_extends(_extends({key:t},r[t]),n),i.IDEProps=r}(e,t,function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(l,["isArray"]))}function d(e){return t={type:e},(e,i)=>{if("symbol"==typeof i)throw new a;const{options:r,returnTypeFunc:s}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,n);l(e,i,r,s)};var t,n}var u;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(u||(u={}));class m extends t.Component{constructor(e){super(e),this.resource="",this.scale=1,this.animationName="",this.autoPlay=!0,this.keepResource=!1,this.timeScale=1,this.skin="",this._slotGameObjects=new Map,this._pendingSlotObjects=[],this.waitExecuteInfos=[],this.listenerBound=!1,this.paused=!1,this.init(e)}set armature(e){if(this._armature=e,e){this.applyTimeScale(),this.skin&&this.setSkin(this.skin),this.autoPlay&&this.play(this.animationName);for(const e of this.waitExecuteInfos)if(e.playType){const{name:t,loop:n,track:i}=e;this.play(t,n,i)}else this.stop(e.track);this.waitExecuteInfos=[]}}get armature(){return this._armature}init(e){e&&_extends(this,e),this.listenerBound||(this.listenerBound=!0,this.on("start",e=>{var t;null===(t=this.onStart)||void 0===t||t.call(this,e)}),this.on("complete",e=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this,e)}),this.on("event",(e,t)=>{var n;null===(n=this.onEvent)||void 0===n||n.call(this,e,t)}))}onDestroy(){this.destroied=!0}load(){return this.armature}destroy(){this.onDestroy(),this.armature&&!this.armature.destroyed&&(this._destroySlotGameObjects(),this.armature.destroy({children:!0})),this.armature=null}pause(){this.paused=!0,this.applyTimeScale()}resume(){this.paused=!1,this.applyTimeScale()}setSkin(e){var t,n,i,r,s;if(this.skin=e,null===(t=this.armature)||void 0===t?void 0:t.skeleton){if(this.armature.skeleton.setSkinByName)this.armature.skeleton.setSkinByName(e);else if(this.armature.skeleton.setSkin){const t=(null===(i=null===(n=this.armature.skeleton.data)||void 0===n?void 0:n.findSkin)||void 0===i?void 0:i.call(n,e))||e;this.armature.skeleton.setSkin(t)}null===(s=(r=this.armature.skeleton).setSlotsToSetupPose)||void 0===s||s.call(r)}}play(e,t,n){try{const i=null!=t?t:this.autoPlay;e&&(this.animationName=e),this.armature?(void 0===n&&(n=0),this.applyTimeScale(),this.armature.state.setAnimation(n,this.animationName,i)):this.waitExecuteInfos.push({playType:!0,name:e,loop:i,track:n})}catch(e){console.log(e)}}stop(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})}applyTimeScale(){var e;(null===(e=this.armature)||void 0===e?void 0:e.state)&&(this.armature.state.timeScale=this.paused?0:this.timeScale)}addAnimation(e,t,n,i){try{this.armature&&(void 0===i&&(i=0),this.armature.state.addAnimation(i,e,n,t))}catch(e){console.log(e)}}setMix(e,t,n){this.armature&&this.armature.state.data.setMix(e,t,n)}getAnim(e=0){try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}}setDefaultMix(e){this.armature&&(this.armature.state.data.defaultMix=e)}setAttachment(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)}getBone(e){if(this.armature)return this.armature.skeleton.findBone(e)}addSlotObject(e,t,n){if(!this.armature)return void console.warn("Spine armature is not ready, cannot addSlotObject");if(!this._containerManager)return void console.warn("ContainerManager is not available");const i=this._containerManager.getContainer(t.id);i?this._doAddSlotObject(e,t,i,n):this._pendingSlotObjects.push({slot:e,gameObject:t,options:n})}_doAddSlotObject(e,t,n,r){const s=new i.Container;s.addChild(n),this.armature.addSlotObject(e,s,r),this._slotGameObjects.set(t,{slot:e,wrapper:s}),this._syncTransformTree(t)}_syncTransformTree(e){var t;if(this._containerManager&&(this._containerManager.updateTransform({name:e.id,transform:e.transform}),null===(t=e.transform)||void 0===t?void 0:t.children))for(const t of e.transform.children)t.gameObject&&this._syncTransformTree(t.gameObject)}_flushPendingSlotObjects(){if(0===this._pendingSlotObjects.length)return;if(!this.armature||!this._containerManager)return;const e=[];for(const t of this._pendingSlotObjects){const n=this._containerManager.getContainer(t.gameObject.id);n?this._doAddSlotObject(t.slot,t.gameObject,n,t.options):e.push(t)}this._pendingSlotObjects=e}removeSlotObject(e){this._pendingSlotObjects=this._pendingSlotObjects.filter(t=>t.gameObject!==e);const t=this._slotGameObjects.get(e);t&&this.armature&&(this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1})),this._slotGameObjects.delete(e)}_destroySlotGameObjects(){for(const[e,t]of this._slotGameObjects)e.destroyed||(this.armature&&this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1}),e.destroy());this._slotGameObjects.clear(),this._pendingSlotObjects=[]}}m.componentName="Spine",r([d("string"),s("design:type",String)],m.prototype,"resource",void 0),r([d("number"),s("design:type",Number)],m.prototype,"scale",void 0),r([d("string"),s("design:type",String)],m.prototype,"animationName",void 0),r([d("boolean"),s("design:type",Boolean)],m.prototype,"autoPlay",void 0),r([d("boolean"),s("design:type",Boolean)],m.prototype,"keepResource",void 0),r([d("number"),s("design:type",Number)],m.prototype,"timeScale",void 0),r([d("string"),s("design:type",String)],m.prototype,"skin",void 0);let p={};function h(e,t,n){return o(this,void 0,void 0,function*(){let i=p[e.name];if(!i)if(e.complete)i=function(e,t,n,i){const r=t.ske,s=t.atlas,o=new i.AtlasAttachmentLoader(s),a=r instanceof Uint8Array?new i.SkeletonBinary(o):new i.SkeletonJson(o);a.scale=n||1;const c={spineData:a.readSkeletonData(r),ref:0,imageSrc:(l=t.image,l?"string"==typeof l?l:l.label||(null===(d=l.source)||void 0===d?void 0:d.label)||(null===(m=null===(u=l.source)||void 0===u?void 0:u.resource)||void 0===m?void 0:m.src)||(null===(h=l.source)||void 0===h?void 0:h._sourceOrigin)||l.src||(null===(y=l.baseTexture)||void 0===y?void 0:y.cacheId)||"":"")};var l,d,u,m,h,y;return p[e]=c,c}(e.name,e.data,t,n);else if(!i)return;return i.ref++,i.spineData})}let y=class extends n.Renderer{constructor(){super(...arguments),this.armatures={},this._spineComponents={}}init({pixiSpine:e}){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=e,this.game.canvas.addEventListener("webglcontextrestored",()=>{const e=this.game.gameObjects;let n=[];for(let i in this.armatures){const r=+i;for(let i=0;i<e.length;++i){let s=e[i];if(s.id===r){let e=s.getComponent(m);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:s,component:e,componentName:m.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:s,component:e,componentName:m.componentName}));break}}}setTimeout(()=>{n.forEach(e=>{this.add(e)})},1e3)},!1)}update(e){super.update();for(let t in this.armatures){const n=this.armatures[t],i=this._spineComponents[t];!n||n.destroyed||(null==i?void 0:i.destroied)?(delete this.armatures[t],delete this._spineComponents[t]):n.update(.001*e.deltaTime)}for(let e in this._spineComponents){const t=this._spineComponents[e];t&&!t.destroied?t._flushPendingSlotObjects():delete this._spineComponents[e]}}componentChanged(e){return o(this,void 0,void 0,function*(){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)})}add(e,n){var i,r,s;return o(this,void 0,void 0,function*(){const o=e.component;clearTimeout(o.addHandler);const a=e.gameObject.id,c=this.increaseAsyncId(a),l=yield t.resource.getResource(o.resource);if(!this.validateAsyncId(a,c)||o.destroied||e.gameObject.destroyed)return;const d=yield h(l,o.scale,this.pixiSpine);if(!this.validateAsyncId(a,c)||o.destroied||e.gameObject.destroyed)return;if(!d)return void(o.addHandler=setTimeout(()=>{o.destroied||e.gameObject.destroyed||(void 0===n&&(n=20),--n>0?this.add(e,n):console.log("retry exceed max times",o.resource))},1e3));this.remove(e);const u=null===(r=null===(i=this.renderSystem)||void 0===i?void 0:i.containerManager)||void 0===r?void 0:r.getContainer(e.gameObject.id);if(!u||o.destroied||e.gameObject.destroyed)return;o.lastResource=o.resource;const m=new this.pixiSpine.Spine({skeletonData:d,autoUpdate:!1});if(this.armatures[e.gameObject.id]=m,this._spineComponents[e.gameObject.id]=o,e.gameObject&&e.gameObject.transform){const t=e.gameObject.transform;m.x=t.size.width*t.origin.x,m.y=t.size.height*t.origin.y}u.addChildAt(m,0),m.update(),o._containerManager=null===(s=this.renderSystem)||void 0===s?void 0:s.containerManager,o.armature=m,o.emit("loaded",{resource:o.resource}),m.state.addListener({start:(e,t)=>{o.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{o.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{o.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{o.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{o.emit("event",e,t)}})})}change(e){this.remove(e),this.add(e)}remove(e){var n,i,r,s,a,c;return o(this,void 0,void 0,function*(){const l=e.gameObject.id;this.increaseAsyncId(l);const d=e.component;clearTimeout(d.addHandler);const u=this.armatures[l],m=null===(i=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===i?void 0:i.getContainer(l);m&&u&&m.removeChild(u);const h=d.armature;if(d.armature=null,delete this.armatures[l],delete this._spineComponents[l],h&&(d._destroySlotGameObjects(),h.destroyed||h.destroy({children:!0}),!d.keepResource&&d.lastResource))try{const e=yield t.resource.getResource(d.lastResource);(null===(s=null===(r=e.data)||void 0===r?void 0:r.image)||void 0===s?void 0:s.src)||(null===(c=null===(a=e.data)||void 0===a?void 0:a.image)||void 0===c||c.label);!function(e){const n=e.name,i=p[n];i&&(i.ref--,setTimeout(()=>o(this,void 0,void 0,function*(){i.ref<=0&&(t.resource.destroy(n),delete p[n])}),100))}(e)}catch(e){console.warn("Failed to release Spine resource",d.lastResource,e)}e.type,t.OBSERVER_TYPE.CHANGE})}};y.systemName="SpineSystem",y=r([t.decorators.componentObserver({Spine:["resource"]})],y);var f=y;return t.resource.registerResourceType("SPINE"),e.Spine=m,e.SpineSystem=f,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.spineBase=globalThis.EVA.plugin.spineBase||_EVA_IIFE_spineBase;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/spine-base",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.4",
|
|
4
4
|
"description": "@eva/spine-base",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/spine-base.esm.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "2.1.0-beta.
|
|
22
|
-
"@eva/plugin-renderer": "2.1.0-beta.
|
|
21
|
+
"@eva/eva.js": "2.1.0-beta.4",
|
|
22
|
+
"@eva/plugin-renderer": "2.1.0-beta.4",
|
|
23
23
|
"@eva/inspector-decorator": "^2.0.0-beta.0",
|
|
24
24
|
"pixi.js": "^8.17.0"
|
|
25
25
|
}
|