@eva/spine-base 2.0.0-beta.17 → 2.0.0-beta.19

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,6 +1,6 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- window.EVA = window.EVA || {};
3
- window.EVA.plugin = window.EVA.plugin || {};
2
+ globalThis.EVA = globalThis.EVA || {};
3
+ globalThis.EVA.plugin = globalThis.EVA.plugin || {};
4
4
  var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
5
5
  'use strict';
6
6
  function __decorate(decorators, target, key, desc) {
@@ -440,4 +440,4 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
440
440
  });
441
441
  return exports;
442
442
  }({}, EVA, EVA.plugin.renderer, PIXI);
443
- window.EVA.plugin.spineBase = window.EVA.plugin.spineBase || _EVA_IIFE_spineBase;
443
+ globalThis.EVA.plugin.spineBase = globalThis.EVA.plugin.spineBase || _EVA_IIFE_spineBase;
@@ -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)({}).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";function a(e,t,n,r){var a,i=arguments.length,o=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(o=(i<3?a(o):i>3?a(t,n,o):a(t,n))||o);return i>3&&o&&Object.defineProperty(t,n,o),o}function i(e,t,n,r){return new(n||(n=Promise))((function(a,i){function o(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,s)}c((r=r.apply(e,t||[])).next())}))}function o(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}}class s extends t.Component{constructor(){super(...arguments),this.resource="",this.scale=1,this.animationName="",this.autoPlay=!0,this.waitExecuteInfos=[]}set armature(e){if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);for(const e of this.waitExecuteInfos)if(e.playType){const{name:t,loop:n,track:r}=e;this.play(t,n,r)}else this.stop(e.track);this.waitExecuteInfos=[]}}get armature(){return this._armature}init(e){e&&_extends(this,e)}onDestroy(){this.destroied=!0}play(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)}}stop(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})}addAnimation(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)}}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)}}s.componentName="Spine",a([o("string")],s.prototype,"resource",void 0),a([o("number")],s.prototype,"scale",void 0),a([o("string")],s.prototype,"animationName",void 0),a([o("boolean")],s.prototype,"autoPlay",void 0);let c={};function u(e,t){let n=c[e];return n||(n=function(e){const t=e.image;return{tex:t instanceof r.Texture?t:r.Texture.from(t),count:0}}(t),c[e]=n),n.count++,n.tex}let m={};function d(e,t,n){return i(this,void 0,void 0,(function*(){let r=m[e.name];if(!r)if(e.complete)r=function(e,t,n,r){const a=t.ske,i=t.atlas,o=new r.AtlasAttachmentLoader(i),s=a instanceof Uint8Array?new r.SkeletonBinary(o):new r.SkeletonJson(o);s.scale=n||1;const c={spineData:s.readSkeletonData(a),ref:0,imageSrc:t.image.label};return m[e]=c,c}(e.name,e.data,t,n);else if(!r)return;return u(e.data.image.label,e.data),r.ref++,r.spineData}))}function l(e,t){const n=m[e];n&&(n.ref--,n.ref<=0&&(!function(e){e&&setTimeout((()=>{const t=c[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete c[e]))}),100)}(t),delete m[e]))}let p=class extends n.Renderer{constructor(){super(...arguments),this.armatures={}}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 r in this.armatures){const a=+r;for(let r=0;r<e.length;++r){let i=e[r];if(i.id===a){let e=i.getComponent(s);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:i,component:e,componentName:s.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:i,component:e,componentName:s.componentName}));break}}}setTimeout((()=>{n.forEach((e=>{this.add(e)}))}),1e3)}),!1)}update(e){for(let t in this.armatures)this.armatures[t].update(.001*e.deltaTime);super.update()}componentChanged(e){return i(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 r,a;return i(this,void 0,void 0,(function*(){const i=e.component;clearTimeout(i.addHandler);const o=e.gameObject.id,s=this.increaseAsyncId(o),c=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(o,s))return;const u=yield d(c,i.scale,this.pixiSpine);if(!this.validateAsyncId(o,s))return;if(!u)return void(i.addHandler=setTimeout((()=>{i.destroied||(void 0===n&&(n=20),--n>0?this.add(e,n):console.log("retry exceed max times",i.resource))}),1e3));this.remove(e);const m=null===(a=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===a?void 0:a.getContainer(e.gameObject.id);if(!m)return;i.lastResource=i.resource;const l=new this.pixiSpine.Spine({skeletonData:u,autoUpdate:!1});if(this.armatures[e.gameObject.id]=l,e.gameObject&&e.gameObject.transform){const t=e.gameObject.transform;l.x=t.size.width*t.origin.x,l.y=t.size.height*t.origin.y}m.addChildAt(l,0),l.update(),i.armature=l,i.emit("loaded",{resource:i.resource}),l.state.addListener({start:(e,t)=>{i.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{i.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{i.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{i.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{i.emit("event",e,t)}})}))}change(e){this.remove(e),this.add(e)}remove(e){var n,r,a,o;return i(this,void 0,void 0,(function*(){this.increaseAsyncId(e.gameObject.id);const i=e.component;clearTimeout(i.addHandler);const 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);if(c&&s&&c.removeChild(s),i.armature){i.armature.destroy({children:!0});const e=yield t.resource.getResource(i.lastResource);l(e.name,null===(o=null===(a=e.data)||void 0===a?void 0:a.image)||void 0===o?void 0:o.src)}i.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE}))}};p.systemName="SpineSystem",p=a([t.decorators.componentObserver({Spine:["resource"]})],p);var h=p;return t.resource.registerResourceType("SPINE"),e.Spine=s,e.SpineSystem=h,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 a in n)({}).hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,a){"use strict";function r(e,t,n,a){var r,i=arguments.length,o=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,a);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(o=(i<3?r(o):i>3?r(t,n,o):r(t,n))||o);return i>3&&o&&Object.defineProperty(t,n,o),o}function i(e,t,n,a){return new(n||(n=Promise))((function(r,i){function o(e){try{c(a.next(e))}catch(e){i(e)}}function s(e){try{c(a.throw(e))}catch(e){i(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,s)}c((a=a.apply(e,t||[])).next())}))}function o(e){return function(t,n){var a=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,n);a.key=n,a.type=e}}class s extends t.Component{constructor(){super(...arguments),this.resource="",this.scale=1,this.animationName="",this.autoPlay=!0,this.waitExecuteInfos=[]}set armature(e){if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);for(const e of this.waitExecuteInfos)if(e.playType){const{name:t,loop:n,track:a}=e;this.play(t,n,a)}else this.stop(e.track);this.waitExecuteInfos=[]}}get armature(){return this._armature}init(e){e&&_extends(this,e)}onDestroy(){this.destroied=!0}play(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)}}stop(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})}addAnimation(e,t,n,a){try{this.armature&&(void 0===a&&(a=0),this.armature.state.addAnimation(a,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)}}s.componentName="Spine",r([o("string")],s.prototype,"resource",void 0),r([o("number")],s.prototype,"scale",void 0),r([o("string")],s.prototype,"animationName",void 0),r([o("boolean")],s.prototype,"autoPlay",void 0);let c={};function u(e,t){let n=c[e];return n||(n=function(e){const t=e.image;return{tex:t instanceof a.Texture?t:a.Texture.from(t),count:0}}(t),c[e]=n),n.count++,n.tex}let m={};function l(e,t,n){return i(this,void 0,void 0,(function*(){let a=m[e.name];if(!a)if(e.complete)a=function(e,t,n,a){const r=t.ske,i=t.atlas,o=new a.AtlasAttachmentLoader(i),s=r instanceof Uint8Array?new a.SkeletonBinary(o):new a.SkeletonJson(o);s.scale=n||1;const c={spineData:s.readSkeletonData(r),ref:0,imageSrc:t.image.label};return m[e]=c,c}(e.name,e.data,t,n);else if(!a)return;return u(e.data.image.label,e.data),a.ref++,a.spineData}))}function d(e,t){const n=m[e];n&&(n.ref--,n.ref<=0&&(!function(e){e&&setTimeout((()=>{const t=c[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete c[e]))}),100)}(t),delete m[e]))}let h=class extends n.Renderer{constructor(){super(...arguments),this.armatures={}}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 a in this.armatures){const r=+a;for(let a=0;a<e.length;++a){let i=e[a];if(i.id===r){let e=i.getComponent(s);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:i,component:e,componentName:s.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:i,component:e,componentName:s.componentName}));break}}}setTimeout((()=>{n.forEach((e=>{this.add(e)}))}),1e3)}),!1)}update(e){for(let t in this.armatures)this.armatures[t].update(.001*e.deltaTime);super.update()}componentChanged(e){return i(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 a,r;return i(this,void 0,void 0,(function*(){const i=e.component;clearTimeout(i.addHandler);const o=e.gameObject.id,s=this.increaseAsyncId(o),c=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(o,s))return;const u=yield l(c,i.scale,this.pixiSpine);if(!this.validateAsyncId(o,s))return;if(!u)return void(i.addHandler=setTimeout((()=>{i.destroied||(void 0===n&&(n=20),--n>0?this.add(e,n):console.log("retry exceed max times",i.resource))}),1e3));this.remove(e);const m=null===(r=null===(a=this.renderSystem)||void 0===a?void 0:a.containerManager)||void 0===r?void 0:r.getContainer(e.gameObject.id);if(!m)return;i.lastResource=i.resource;const d=new this.pixiSpine.Spine({skeletonData:u,autoUpdate:!1});if(this.armatures[e.gameObject.id]=d,e.gameObject&&e.gameObject.transform){const t=e.gameObject.transform;d.x=t.size.width*t.origin.x,d.y=t.size.height*t.origin.y}m.addChildAt(d,0),d.update(),i.armature=d,i.emit("loaded",{resource:i.resource}),d.state.addListener({start:(e,t)=>{i.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{i.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{i.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{i.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{i.emit("event",e,t)}})}))}change(e){this.remove(e),this.add(e)}remove(e){var n,a,r,o;return i(this,void 0,void 0,(function*(){this.increaseAsyncId(e.gameObject.id);const i=e.component;clearTimeout(i.addHandler);const s=this.armatures[e.gameObject.id],c=null===(a=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===a?void 0:a.getContainer(e.gameObject.id);if(c&&s&&c.removeChild(s),i.armature){i.armature.destroy({children:!0});const e=yield t.resource.getResource(i.lastResource);d(e.name,null===(o=null===(r=e.data)||void 0===r?void 0:r.image)||void 0===o?void 0:o.src)}i.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE}))}};h.systemName="SpineSystem",h=r([t.decorators.componentObserver({Spine:["resource"]})],h);var p=h;return t.resource.registerResourceType("SPINE"),e.Spine=s,e.SpineSystem=p,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.0.0-beta.17",
3
+ "version": "2.0.0-beta.19",
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.0.0-beta.17",
22
- "@eva/plugin-renderer": "2.0.0-beta.17",
21
+ "@eva/eva.js": "2.0.0-beta.19",
22
+ "@eva/plugin-renderer": "2.0.0-beta.19",
23
23
  "@eva/inspector-decorator": "^0.0.5",
24
24
  "pixi.js": "^8.8.1"
25
25
  }