@eva/spine-base 2.1.0-beta.14 → 2.1.0-beta.15

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,7 +1,8 @@
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
+ var globalThis = typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : Function('return this')();
2
3
  globalThis.EVA = globalThis.EVA || {};
3
4
  globalThis.EVA.plugin = globalThis.EVA.plugin || {};
4
- var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
5
+ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js, inspectorDecorator) {
5
6
  'use strict';
6
7
  function __decorate(decorators, target, key, desc) {
7
8
  var c = arguments.length,
@@ -40,110 +41,6 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
40
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
41
42
  });
42
43
  }
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
- };
47
- function __rest(s, e) {
48
- var t = {};
49
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
50
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
51
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
52
- }
53
- return t;
54
- }
55
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
56
- var e = new Error(message);
57
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
58
- };
59
- class SymbolKeysNotSupportedError extends Error {
60
- constructor() {
61
- super('Symbol keys are not supported yet!');
62
- Object.setPrototypeOf(this, new.target.prototype);
63
- }
64
- }
65
- const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
66
- function transformBasicType(type) {
67
- if (type === String) {
68
- return 'string';
69
- }
70
- if (type === Number) {
71
- return 'number';
72
- }
73
- if (type === Boolean) {
74
- return 'boolean';
75
- }
76
- return 'unknown';
77
- }
78
- function defineLegacyIDEProp(target, propertyKey, patch) {
79
- const constructor = target.constructor;
80
- const current = constructor.IDEProps || {};
81
- current[propertyKey] = _extends(_extends({
82
- key: propertyKey
83
- }, current[propertyKey]), patch);
84
- constructor.IDEProps = current;
85
- }
86
- function defineTypes(target, key, options, returnTypeFunction) {
87
- let type = Reflect.getMetadata('design:type', target, key);
88
- let isArray = type === Array;
89
- const str = transformBasicType(type);
90
- if (str !== 'unknown') {
91
- type = str;
92
- }
93
- if (returnTypeFunction) {
94
- const returnType = returnTypeFunction();
95
- if (Array.isArray(returnType)) {
96
- isArray = true;
97
- type = returnType[0];
98
- } else {
99
- type = returnType;
100
- }
101
- }
102
- const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
103
- const current = properties[key] || {};
104
- const property = _extends(_extends(_extends({}, current), {
105
- type,
106
- isArray: isArray
107
- }), options);
108
- properties[key] = property;
109
- Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
110
- const legacyProperty = __rest(property, ["isArray"]);
111
- defineLegacyIDEProp(target, key, legacyProperty);
112
- }
113
- function type(type) {
114
- return Field({
115
- type
116
- });
117
- }
118
- function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
119
- if (typeof returnTypeFuncOrOptions === 'function') {
120
- return {
121
- returnTypeFunc: returnTypeFuncOrOptions,
122
- options: maybeOptions || {}
123
- };
124
- }
125
- return {
126
- options: returnTypeFuncOrOptions || {}
127
- };
128
- }
129
- function Field(returnTypeFunction, maybeOptions) {
130
- return (target, propertyKey) => {
131
- if (typeof propertyKey === 'symbol') {
132
- throw new SymbolKeysNotSupportedError();
133
- }
134
- const {
135
- options,
136
- returnTypeFunc
137
- } = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
138
- defineTypes(target, propertyKey, options, returnTypeFunc);
139
- };
140
- }
141
- var ExecuteMode;
142
- (function (ExecuteMode) {
143
- ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
144
- ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
145
- ExecuteMode[ExecuteMode["All"] = 6] = "All";
146
- })(ExecuteMode || (ExecuteMode = {}));
147
44
  class Spine extends eva_js.Component {
148
45
  constructor(params) {
149
46
  super(params);
@@ -434,13 +331,13 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
434
331
  }
435
332
  }
436
333
  Spine.componentName = 'Spine';
437
- __decorate([type('string'), __metadata("design:type", String)], Spine.prototype, "resource", void 0);
438
- __decorate([type('number'), __metadata("design:type", Number)], Spine.prototype, "scale", void 0);
439
- __decorate([type('string'), __metadata("design:type", String)], Spine.prototype, "animationName", void 0);
440
- __decorate([type('boolean'), __metadata("design:type", Boolean)], Spine.prototype, "autoPlay", void 0);
441
- __decorate([type('boolean'), __metadata("design:type", Boolean)], Spine.prototype, "keepResource", void 0);
442
- __decorate([type('number'), __metadata("design:type", Number)], Spine.prototype, "timeScale", void 0);
443
- __decorate([type('string'), __metadata("design:type", String)], Spine.prototype, "skin", void 0);
334
+ __decorate([inspectorDecorator.type('string'), __metadata("design:type", String)], Spine.prototype, "resource", void 0);
335
+ __decorate([inspectorDecorator.type('number'), __metadata("design:type", Number)], Spine.prototype, "scale", void 0);
336
+ __decorate([inspectorDecorator.type('string'), __metadata("design:type", String)], Spine.prototype, "animationName", void 0);
337
+ __decorate([inspectorDecorator.type('boolean'), __metadata("design:type", Boolean)], Spine.prototype, "autoPlay", void 0);
338
+ __decorate([inspectorDecorator.type('boolean'), __metadata("design:type", Boolean)], Spine.prototype, "keepResource", void 0);
339
+ __decorate([inspectorDecorator.type('number'), __metadata("design:type", Number)], Spine.prototype, "timeScale", void 0);
340
+ __decorate([inspectorDecorator.type('string'), __metadata("design:type", String)], Spine.prototype, "skin", void 0);
444
341
  let dataMap = {};
445
342
  function resolveImageSrc(image) {
446
343
  var _a, _b, _c, _d, _e;
@@ -742,5 +639,5 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
742
639
  value: true
743
640
  });
744
641
  return exports;
745
- }({}, EVA, EVA.plugin.renderer, PIXI);
642
+ }({}, EVA, EVA.plugin.renderer, PIXI, inspectorDecorator);
746
643
  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 s in n)({}).hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,s){"use strict";function o(e,t,n,s){var o,i=arguments.length,r=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,s);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(i<3?o(r):i>3?o(t,n,r):o(t,n))||r);return i>3&&r&&Object.defineProperty(t,n,r),r}function i(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function r(e,t,n,s){return new(n||(n=Promise))(function(o,i){function r(e){try{l(s.next(e))}catch(e){i(e)}}function a(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,a)}l((s=s.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 l="IDE_PROPERTY_METADATA";function c(e,t,n,s){let o=Reflect.getMetadata("design:type",e,t),i=o===Array;const r=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==r&&(o=r),s){const e=s();Array.isArray(e)?(i=!0,o=e[0]):o=e}const a=Reflect.getMetadata(l,e.constructor)||{},c=_extends(_extends(_extends({},a[t]||{}),{type:o,isArray:i}),n);a[t]=c,Reflect.defineMetadata(l,a,e.constructor);!function(e,t,n){const s=e.constructor,o=s.IDEProps||{};o[t]=_extends(_extends({key:t},o[t]),n),s.IDEProps=o}(e,t,function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}(c,["isArray"]))}function d(e){return t={type:e},(e,s)=>{if("symbol"==typeof s)throw new a;const{options:o,returnTypeFunc:i}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,n);c(e,s,o,i)};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:s}=e;this.play(t,n,s)}else this.stop(e.track);this.waitExecuteInfos=[],this._flushPendingSlotObjects()}}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._destroySlotGameObjects(),this.armature&&!this.armature.destroyed&&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,s,o,i;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===(s=null===(n=this.armature.skeleton.data)||void 0===n?void 0:n.findSkin)||void 0===s?void 0:s.call(n,e))||e;this.armature.skeleton.setSkin(t)}null===(i=(o=this.armature.skeleton).setSlotsToSetupPose)||void 0===i||i.call(o)}}play(e,t,n){try{const s=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,s)):this.waitExecuteInfos.push({playType:!0,name:e,loop:s,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,s){try{this.armature&&(void 0===s&&(s=0),this.armature.state.addAnimation(s,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){this.destroied?console.warn("Spine component has been destroyed, cannot addSlotObject"):t&&!t.destroyed?(this._pendingSlotObjects=this._pendingSlotObjects.filter(e=>e.gameObject!==t),this._detachSlotObject(t),this._pendingSlotObjects.push({slot:e,gameObject:t,options:n}),this._flushPendingSlotObjects()):console.warn("Cannot add a destroyed or missing GameObject to a Spine slot")}_doAddSlotObject(e,t,n,o){const i=new s.Container;i.addChild(n),this.armature.addSlotObject(e,i,o),this._slotGameObjects.set(t,{slot:e,wrapper:i}),this._syncTransformTree(t)}_isSlotAvailable(e){var t,n,s,o;if("number"==typeof e){if(!Number.isInteger(e)||e<0)return!1;const s=null===(n=null===(t=this.armature)||void 0===t?void 0:t.skeleton)||void 0===n?void 0:n.slots;return!Array.isArray(s)||e<s.length}if("string"!=typeof e||0===e.length)return!1;const i=null===(o=null===(s=this.armature)||void 0===s?void 0:s.skeleton)||void 0===o?void 0:o.findSlot;return"function"!=typeof i||Boolean(i.call(this.armature.skeleton,e))}_detachSlotObject(e){const t=this._slotGameObjects.get(e);if(t){this.armature&&!this.armature.destroyed&&this.armature.removeSlotObject(t.wrapper);for(const e of[...t.wrapper.children])t.wrapper.removeChild(e);t.wrapper.destroy({children:!1}),this._slotGameObjects.delete(e)}}_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(this.destroied||0===this._pendingSlotObjects.length)return;if(!this.armature||!this._containerManager)return;const e=[],t=this._pendingSlotObjects;this._pendingSlotObjects=[];for(const n of t){if(n.gameObject.destroyed)continue;if(!this._isSlotAvailable(n.slot)){console.warn(`Spine slot "${n.slot}" does not exist; pending slot object was discarded`);continue}const t=this._containerManager.getContainer(n.gameObject.id);if(t)try{this._doAddSlotObject(n.slot,n.gameObject,t,n.options)}catch(e){console.warn(`Failed to add GameObject to Spine slot "${n.slot}"`,e)}else e.push(n)}this._pendingSlotObjects.push(...e)}removeSlotObject(e){this._pendingSlotObjects=this._pendingSlotObjects.filter(t=>t.gameObject!==e),this._detachSlotObject(e)}_destroySlotGameObjects(){const e=new Set([...this._slotGameObjects.keys(),...this._pendingSlotObjects.map(e=>e.gameObject)]);for(const t of e)this._detachSlotObject(t),t.destroyed||t.destroy();this._slotGameObjects.clear(),this._pendingSlotObjects=[]}}m.componentName="Spine",o([d("string"),i("design:type",String)],m.prototype,"resource",void 0),o([d("number"),i("design:type",Number)],m.prototype,"scale",void 0),o([d("string"),i("design:type",String)],m.prototype,"animationName",void 0),o([d("boolean"),i("design:type",Boolean)],m.prototype,"autoPlay",void 0),o([d("boolean"),i("design:type",Boolean)],m.prototype,"keepResource",void 0),o([d("number"),i("design:type",Number)],m.prototype,"timeScale",void 0),o([d("string"),i("design:type",String)],m.prototype,"skin",void 0);let h={};function p(e,t,n){return r(this,void 0,void 0,function*(){let s=h[e.name];if(!s)if(e.complete)s=function(e,t,n,s){const o=t.ske,i=t.atlas,r=new s.AtlasAttachmentLoader(i),a=o instanceof Uint8Array?new s.SkeletonBinary(r):new s.SkeletonJson(r);a.scale=n||1;const l={spineData:a.readSkeletonData(o),ref:0,imageSrc:(c=t.image,c?"string"==typeof c?c:c.label||(null===(d=c.source)||void 0===d?void 0:d.label)||(null===(m=null===(u=c.source)||void 0===u?void 0:u.resource)||void 0===m?void 0:m.src)||(null===(p=c.source)||void 0===p?void 0:p._sourceOrigin)||c.src||(null===(f=c.baseTexture)||void 0===f?void 0:f.cacheId)||"":"")};var c,d,u,m,p,f;return h[e]=l,l}(e.name,e.data,t,n);else if(!s)return;return s.ref++,s.spineData})}let f=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 s in this.armatures){const o=+s;for(let s=0;s<e.length;++s){let i=e[s];if(i.id===o){let e=i.getComponent(m);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:i,component:e,componentName:m.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:i,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],s=this._spineComponents[t];!n||n.destroyed||(null==s?void 0:s.destroied)?(this.releaseComponentResource(s),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():(this.releaseComponentResource(t),delete this._spineComponents[e])}}componentChanged(e){return r(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 s,o,i;return r(this,void 0,void 0,function*(){const r=e.component;clearTimeout(r.addHandler);const a=e.gameObject.id,l=this.increaseAsyncId(a),c=yield t.resource.getResource(r.resource);if(!this.validateAsyncId(a,l)||r.destroied||e.gameObject.destroyed)return;const d=yield p(c,r.scale,this.pixiSpine);if(!this.validateAsyncId(a,l)||r.destroied||e.gameObject.destroyed)return;if(!d)return void(r.addHandler=setTimeout(()=>{r.destroied||e.gameObject.destroyed||(void 0===n&&(n=20),--n>0?this.add(e,n):console.log("retry exceed max times",r.resource))},1e3));this.remove(e);const u=null===(o=null===(s=this.renderSystem)||void 0===s?void 0:s.containerManager)||void 0===o?void 0:o.getContainer(e.gameObject.id);if(!u||r.destroied||e.gameObject.destroyed)return;r.lastResource=r.resource;const m=new this.pixiSpine.Spine({skeletonData:d,autoUpdate:!1});if(this.armatures[e.gameObject.id]=m,this._spineComponents[e.gameObject.id]=r,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(),r._containerManager=null===(i=this.renderSystem)||void 0===i?void 0:i.containerManager,r.armature=m,r.emit("loaded",{resource:r.resource}),m.state.addListener({start:(e,t)=>{r.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{r.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{r.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{r.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{r.emit("event",e,t)}})})}change(e){this.remove(e),this.add(e)}remove(e){var n,s;return r(this,void 0,void 0,function*(){const o=e.gameObject.id;this.increaseAsyncId(o);const i=e.component;clearTimeout(i.addHandler);const r=this.armatures[o],a=null===(s=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===s?void 0:s.getContainer(o);a&&r&&a.removeChild(r);const l=i.armature;i.armature=null,delete this.armatures[o],delete this._spineComponents[o],l&&(i._destroySlotGameObjects(),l.destroyed||l.destroy({children:!0})),this.releaseComponentResource(i),e.type,t.OBSERVER_TYPE.CHANGE})}onDestroy(){for(const e of Object.keys(this._spineComponents)){const t=this._spineComponents[+e],n=this.armatures[+e];null==t||t._destroySlotGameObjects(),n&&!n.destroyed&&n.destroy({children:!0}),t&&(t.armature=null),this.releaseComponentResource(t)}this.armatures={},this._spineComponents={},this.asyncIdMap={}}releaseComponentResource(e){const n=null==e?void 0:e.lastResource;e&&n&&(e.lastResource="",function(e,n,s=!0){const o=e.name,i=h[o];i&&(i.ref--,i.ref>0||(h[o]===i&&delete h[o],s&&setTimeout(()=>r(this,void 0,void 0,function*(){i.ref<=0&&!h[o]&&t.resource.destroy(o)}),100)))}({name:n},0,!e.keepResource))}};f.systemName="SpineSystem",f=o([t.decorators.componentObserver({Spine:["resource"]})],f);var y=f;return t.resource.registerResourceType("SPINE"),e.Spine=m,e.SpineSystem=y,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 o in n)({}).hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},_extends.apply(null,arguments)}var globalThis="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,o){"use strict";var s=function(e,t){return s=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])},s(e,t)};function r(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}s(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i=function(){return i=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var s in t=arguments[n])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e},i.apply(this,arguments)};function a(e,t,n,o){var s,r=arguments.length,i=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(i=(r<3?s(i):r>3?s(t,n,i):s(t,n))||i);return r>3&&i&&Object.defineProperty(t,n,i),i}function c(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function l(e,t,n,o){return new(n||(n=Promise))(function(s,r){function i(e){try{c(o.next(e))}catch(e){r(e)}}function a(e){try{c(o.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(i,a)}c((o=o.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;var d=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 r(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}r(t,e)}(Error);var u,p="IDE_PROPERTY_METADATA";function h(e,t,n,o){var s=Reflect.getMetadata("design:type",e,t),r=s===Array,a=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(s);if("unknown"!==a&&(s=a),o){var c=o();Array.isArray(c)?(r=!0,s=c[0]):s=c}var l=Reflect.getMetadata(p,e.constructor)||{},d=l[t]||{},u=i(i(i({},d),{type:s,isArray:r}),n);l[t]=u,Reflect.defineMetadata(p,l,e.constructor),u.isArray,function(e,t,n){var o=e.constructor,s=o.IDEProps||{};s[t]=i(i({key:t},s[t]),n),o.IDEProps=s}(e,t,function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(o=Object.getOwnPropertySymbols(e);s<o.length;s++)t.indexOf(o[s])<0&&Object.prototype.propertyIsEnumerable.call(e,o[s])&&(n[o[s]]=e[o[s]])}return n}(u,["isArray"]))}function m(e){return t={type:e},function(e,o){if("symbol"==typeof o)throw new d;var s=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,n);h(e,o,s.options,s.returnTypeFunc)};var t,n}!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(u||(u={}));class f 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:o}=e;this.play(t,n,o)}else this.stop(e.track);this.waitExecuteInfos=[],this._flushPendingSlotObjects()}}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._destroySlotGameObjects(),this.armature&&!this.armature.destroyed&&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,o,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===(o=null===(n=this.armature.skeleton.data)||void 0===n?void 0:n.findSkin)||void 0===o?void 0:o.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 o=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,o)):this.waitExecuteInfos.push({playType:!0,name:e,loop:o,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,o){try{this.armature&&(void 0===o&&(o=0),this.armature.state.addAnimation(o,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){this.destroied?console.warn("Spine component has been destroyed, cannot addSlotObject"):t&&!t.destroyed?(this._pendingSlotObjects=this._pendingSlotObjects.filter(e=>e.gameObject!==t),this._detachSlotObject(t),this._pendingSlotObjects.push({slot:e,gameObject:t,options:n}),this._flushPendingSlotObjects()):console.warn("Cannot add a destroyed or missing GameObject to a Spine slot")}_doAddSlotObject(e,t,n,s){const r=new o.Container;r.addChild(n),this.armature.addSlotObject(e,r,s),this._slotGameObjects.set(t,{slot:e,wrapper:r}),this._syncTransformTree(t)}_isSlotAvailable(e){var t,n,o,s;if("number"==typeof e){if(!Number.isInteger(e)||e<0)return!1;const o=null===(n=null===(t=this.armature)||void 0===t?void 0:t.skeleton)||void 0===n?void 0:n.slots;return!Array.isArray(o)||e<o.length}if("string"!=typeof e||0===e.length)return!1;const r=null===(s=null===(o=this.armature)||void 0===o?void 0:o.skeleton)||void 0===s?void 0:s.findSlot;return"function"!=typeof r||Boolean(r.call(this.armature.skeleton,e))}_detachSlotObject(e){const t=this._slotGameObjects.get(e);if(t){this.armature&&!this.armature.destroyed&&this.armature.removeSlotObject(t.wrapper);for(const e of[...t.wrapper.children])t.wrapper.removeChild(e);t.wrapper.destroy({children:!1}),this._slotGameObjects.delete(e)}}_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(this.destroied||0===this._pendingSlotObjects.length)return;if(!this.armature||!this._containerManager)return;const e=[],t=this._pendingSlotObjects;this._pendingSlotObjects=[];for(const n of t){if(n.gameObject.destroyed)continue;if(!this._isSlotAvailable(n.slot)){console.warn(`Spine slot "${n.slot}" does not exist; pending slot object was discarded`);continue}const t=this._containerManager.getContainer(n.gameObject.id);if(t)try{this._doAddSlotObject(n.slot,n.gameObject,t,n.options)}catch(e){console.warn(`Failed to add GameObject to Spine slot "${n.slot}"`,e)}else e.push(n)}this._pendingSlotObjects.push(...e)}removeSlotObject(e){this._pendingSlotObjects=this._pendingSlotObjects.filter(t=>t.gameObject!==e),this._detachSlotObject(e)}_destroySlotGameObjects(){const e=new Set([...this._slotGameObjects.keys(),...this._pendingSlotObjects.map(e=>e.gameObject)]);for(const t of e)this._detachSlotObject(t),t.destroyed||t.destroy();this._slotGameObjects.clear(),this._pendingSlotObjects=[]}}f.componentName="Spine",a([m("string"),c("design:type",String)],f.prototype,"resource",void 0),a([m("number"),c("design:type",Number)],f.prototype,"scale",void 0),a([m("string"),c("design:type",String)],f.prototype,"animationName",void 0),a([m("boolean"),c("design:type",Boolean)],f.prototype,"autoPlay",void 0),a([m("boolean"),c("design:type",Boolean)],f.prototype,"keepResource",void 0),a([m("number"),c("design:type",Number)],f.prototype,"timeScale",void 0),a([m("string"),c("design:type",String)],f.prototype,"skin",void 0);let y={};function g(e,t,n){return l(this,void 0,void 0,function*(){let o=y[e.name];if(!o)if(e.complete)o=function(e,t,n,o){const s=t.ske,r=t.atlas,i=new o.AtlasAttachmentLoader(r),a=s instanceof Uint8Array?new o.SkeletonBinary(i):new o.SkeletonJson(i);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===(p=null===(u=l.source)||void 0===u?void 0:u.resource)||void 0===p?void 0:p.src)||(null===(h=l.source)||void 0===h?void 0:h._sourceOrigin)||l.src||(null===(m=l.baseTexture)||void 0===m?void 0:m.cacheId)||"":"")};var l,d,u,p,h,m;return y[e]=c,c}(e.name,e.data,t,n);else if(!o)return;return o.ref++,o.spineData})}let v=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 o in this.armatures){const s=+o;for(let o=0;o<e.length;++o){let r=e[o];if(r.id===s){let e=r.getComponent(f);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:r,component:e,componentName:f.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:r,component:e,componentName:f.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],o=this._spineComponents[t];!n||n.destroyed||(null==o?void 0:o.destroied)?(this.releaseComponentResource(o),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():(this.releaseComponentResource(t),delete this._spineComponents[e])}}componentChanged(e){return l(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 o,s,r;return l(this,void 0,void 0,function*(){const i=e.component;clearTimeout(i.addHandler);const a=e.gameObject.id,c=this.increaseAsyncId(a),l=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(a,c)||i.destroied||e.gameObject.destroyed)return;const d=yield g(l,i.scale,this.pixiSpine);if(!this.validateAsyncId(a,c)||i.destroied||e.gameObject.destroyed)return;if(!d)return void(i.addHandler=setTimeout(()=>{i.destroied||e.gameObject.destroyed||(void 0===n&&(n=20),--n>0?this.add(e,n):console.log("retry exceed max times",i.resource))},1e3));this.remove(e);const u=null===(s=null===(o=this.renderSystem)||void 0===o?void 0:o.containerManager)||void 0===s?void 0:s.getContainer(e.gameObject.id);if(!u||i.destroied||e.gameObject.destroyed)return;i.lastResource=i.resource;const p=new this.pixiSpine.Spine({skeletonData:d,autoUpdate:!1});if(this.armatures[e.gameObject.id]=p,this._spineComponents[e.gameObject.id]=i,e.gameObject&&e.gameObject.transform){const t=e.gameObject.transform;p.x=t.size.width*t.origin.x,p.y=t.size.height*t.origin.y}u.addChildAt(p,0),p.update(),i._containerManager=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager,i.armature=p,i.emit("loaded",{resource:i.resource}),p.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,o;return l(this,void 0,void 0,function*(){const s=e.gameObject.id;this.increaseAsyncId(s);const r=e.component;clearTimeout(r.addHandler);const i=this.armatures[s],a=null===(o=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===o?void 0:o.getContainer(s);a&&i&&a.removeChild(i);const c=r.armature;r.armature=null,delete this.armatures[s],delete this._spineComponents[s],c&&(r._destroySlotGameObjects(),c.destroyed||c.destroy({children:!0})),this.releaseComponentResource(r),e.type,t.OBSERVER_TYPE.CHANGE})}onDestroy(){for(const e of Object.keys(this._spineComponents)){const t=this._spineComponents[+e],n=this.armatures[+e];null==t||t._destroySlotGameObjects(),n&&!n.destroyed&&n.destroy({children:!0}),t&&(t.armature=null),this.releaseComponentResource(t)}this.armatures={},this._spineComponents={},this.asyncIdMap={}}releaseComponentResource(e){const n=null==e?void 0:e.lastResource;e&&n&&(e.lastResource="",function(e,n,o=!0){const s=e.name,r=y[s];r&&(r.ref--,r.ref>0||(y[s]===r&&delete y[s],o&&setTimeout(()=>l(this,void 0,void 0,function*(){r.ref<=0&&!y[s]&&t.resource.destroy(s)}),100)))}({name:n},0,!e.keepResource))}};v.systemName="SpineSystem",v=a([t.decorators.componentObserver({Spine:["resource"]})],v);var b=v;return t.resource.registerResourceType("SPINE"),e.Spine=f,e.SpineSystem=b,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.14",
3
+ "version": "2.1.0-beta.15",
4
4
  "description": "@eva/spine-base",
5
5
  "main": "index.js",
6
6
  "module": "dist/spine-base.esm.js",
@@ -18,9 +18,9 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/eva.js": "2.1.0-beta.14",
22
- "@eva/plugin-renderer": "2.1.0-beta.14",
21
+ "@eva/eva.js": "2.1.0-beta.15",
22
+ "@eva/plugin-renderer": "2.1.0-beta.15",
23
23
  "@eva/inspector-decorator": "^2.0.0-beta.0",
24
- "pixi.js": "^8.17.0"
24
+ "pixi.js": "8.19.0"
25
25
  }
26
26
  }