@eva/spine-base 2.0.1-beta.9 → 2.0.2-beta.0

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.
@@ -61,6 +61,9 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
61
61
  this.scale = 1;
62
62
  this.animationName = '';
63
63
  this.autoPlay = true;
64
+ this.keepResource = false;
65
+ this._slotGameObjects = new Map();
66
+ this._pendingSlotObjects = [];
64
67
  this.waitExecuteInfos = [];
65
68
  }
66
69
  set armature(val) {
@@ -170,12 +173,98 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
170
173
  }
171
174
  return this.armature.skeleton.findBone(boneName);
172
175
  }
176
+ addSlotObject(slot, gameObject, options) {
177
+ if (!this.armature) {
178
+ console.warn('Spine armature is not ready, cannot addSlotObject');
179
+ return;
180
+ }
181
+ if (!this._containerManager) {
182
+ console.warn('ContainerManager is not available');
183
+ return;
184
+ }
185
+ const container = this._containerManager.getContainer(gameObject.id);
186
+ if (!container) {
187
+ this._pendingSlotObjects.push({
188
+ slot,
189
+ gameObject,
190
+ options
191
+ });
192
+ return;
193
+ }
194
+ this._doAddSlotObject(slot, gameObject, container, options);
195
+ }
196
+ _doAddSlotObject(slot, gameObject, container, options) {
197
+ const wrapper = new pixi_js.Container();
198
+ wrapper.addChild(container);
199
+ this.armature.addSlotObject(slot, wrapper, options);
200
+ this._slotGameObjects.set(gameObject, {
201
+ slot,
202
+ wrapper
203
+ });
204
+ this._syncTransformTree(gameObject);
205
+ }
206
+ _syncTransformTree(gameObject) {
207
+ var _a;
208
+ if (!this._containerManager) return;
209
+ this._containerManager.updateTransform({
210
+ name: gameObject.id,
211
+ transform: gameObject.transform
212
+ });
213
+ if ((_a = gameObject.transform) === null || _a === void 0 ? void 0 : _a.children) {
214
+ for (const childTransform of gameObject.transform.children) {
215
+ if (childTransform.gameObject) {
216
+ this._syncTransformTree(childTransform.gameObject);
217
+ }
218
+ }
219
+ }
220
+ }
221
+ _flushPendingSlotObjects() {
222
+ if (this._pendingSlotObjects.length === 0) return;
223
+ if (!this.armature || !this._containerManager) return;
224
+ const still = [];
225
+ for (const pending of this._pendingSlotObjects) {
226
+ const container = this._containerManager.getContainer(pending.gameObject.id);
227
+ if (container) {
228
+ this._doAddSlotObject(pending.slot, pending.gameObject, container, pending.options);
229
+ } else {
230
+ still.push(pending);
231
+ }
232
+ }
233
+ this._pendingSlotObjects = still;
234
+ }
235
+ removeSlotObject(gameObject) {
236
+ this._pendingSlotObjects = this._pendingSlotObjects.filter(p => p.gameObject !== gameObject);
237
+ const entry = this._slotGameObjects.get(gameObject);
238
+ if (entry && this.armature) {
239
+ this.armature.removeSlotObject(entry.wrapper);
240
+ entry.wrapper.destroy({
241
+ children: false
242
+ });
243
+ }
244
+ this._slotGameObjects.delete(gameObject);
245
+ }
246
+ _destroySlotGameObjects() {
247
+ for (const [gameObject, entry] of this._slotGameObjects) {
248
+ if (!gameObject.destroyed) {
249
+ if (this.armature) {
250
+ this.armature.removeSlotObject(entry.wrapper);
251
+ }
252
+ entry.wrapper.destroy({
253
+ children: false
254
+ });
255
+ gameObject.destroy();
256
+ }
257
+ }
258
+ this._slotGameObjects.clear();
259
+ this._pendingSlotObjects = [];
260
+ }
173
261
  }
174
262
  Spine.componentName = 'Spine';
175
263
  __decorate([type('string')], Spine.prototype, "resource", void 0);
176
264
  __decorate([type('number')], Spine.prototype, "scale", void 0);
177
265
  __decorate([type('string')], Spine.prototype, "animationName", void 0);
178
266
  __decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
267
+ __decorate([type('boolean')], Spine.prototype, "keepResource", void 0);
179
268
  let dataMap = {};
180
269
  function createSpineData(name, data, scale, pixiSpine) {
181
270
  const skeletonAsset = data.ske;
@@ -215,14 +304,6 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
215
304
  data.ref--;
216
305
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
217
306
  if (data.ref <= 0) {
218
- yield pixi_js.Assets.unload([res.src.image.url, res.src.atlas.url, res.src.ske.url]);
219
- const resolver = pixi_js.Assets.resolver;
220
- delete resolver._assetMap[res.src.image.url];
221
- delete resolver._assetMap[res.src.atlas.url];
222
- delete resolver._assetMap[res.src.ske.url];
223
- delete resolver._resolverHash[res.src.image.url];
224
- delete resolver._resolverHash[res.src.atlas.url];
225
- delete resolver._resolverHash[res.src.ske.url];
226
307
  eva_js.resource.destroy(resourceName);
227
308
  delete dataMap[resourceName];
228
309
  }
@@ -233,6 +314,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
233
314
  constructor() {
234
315
  super(...arguments);
235
316
  this.armatures = {};
317
+ this._spineComponents = {};
236
318
  }
237
319
  init({
238
320
  pixiSpine
@@ -278,6 +360,9 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
278
360
  for (let key in this.armatures) {
279
361
  this.armatures[key].update(e.deltaTime * 0.001);
280
362
  }
363
+ for (let key in this._spineComponents) {
364
+ this._spineComponents[key]._flushPendingSlotObjects();
365
+ }
281
366
  super.update();
282
367
  }
283
368
  componentChanged(changed) {
@@ -298,7 +383,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
298
383
  });
299
384
  }
300
385
  add(changed, count) {
301
- var _a, _b;
386
+ var _a, _b, _c;
302
387
  return __awaiter(this, void 0, void 0, function* () {
303
388
  const component = changed.component;
304
389
  clearTimeout(component.addHandler);
@@ -335,6 +420,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
335
420
  autoUpdate: false
336
421
  });
337
422
  this.armatures[changed.gameObject.id] = armature;
423
+ this._spineComponents[changed.gameObject.id] = component;
338
424
  if (changed.gameObject && changed.gameObject.transform) {
339
425
  const tran = changed.gameObject.transform;
340
426
  armature.x = tran.size.width * tran.origin.x;
@@ -342,6 +428,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
342
428
  }
343
429
  container.addChildAt(armature, 0);
344
430
  armature.update();
431
+ component._containerManager = (_c = this.renderSystem) === null || _c === void 0 ? void 0 : _c.containerManager;
345
432
  component.armature = armature;
346
433
  component.emit('loaded', {
347
434
  resource: component.resource
@@ -393,15 +480,19 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
393
480
  container.removeChild(armature);
394
481
  }
395
482
  if (component.armature) {
483
+ component._destroySlotGameObjects();
396
484
  component.armature.destroy({
397
485
  children: true
398
486
  });
399
- const res = yield eva_js.resource.getResource(component.lastResource);
400
- ((_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src) || ((_f = (_e = res.data) === null || _e === void 0 ? void 0 : _e.image) === null || _f === void 0 ? void 0 : _f.label);
401
- releaseSpineData(res);
487
+ if (!component.keepResource) {
488
+ const res = yield eva_js.resource.getResource(component.lastResource);
489
+ ((_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src) || ((_f = (_e = res.data) === null || _e === void 0 ? void 0 : _e.image) === null || _f === void 0 ? void 0 : _f.label);
490
+ releaseSpineData(res);
491
+ }
402
492
  }
403
493
  component.armature = null;
404
494
  delete this.armatures[changed.gameObject.id];
495
+ delete this._spineComponents[changed.gameObject.id];
405
496
  if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) ;
406
497
  });
407
498
  }
@@ -1 +1 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)({}).hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,r,a){"use strict";function n(e,t,r,a){var n,i=arguments.length,s=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,a);else for(var o=e.length-1;o>=0;o--)(n=e[o])&&(s=(i<3?n(s):i>3?n(t,r,s):n(t,r))||s);return i>3&&s&&Object.defineProperty(t,r,s),s}function i(e,t,r,a){return new(r||(r=Promise))((function(n,i){function s(e){try{c(a.next(e))}catch(e){i(e)}}function o(e){try{c(a.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,o)}c((a=a.apply(e,t||[])).next())}))}function s(e){return function(t,r){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,r);a.key=r,a.type=e}}class o 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:r,track:a}=e;this.play(t,r,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,r){try{const a=null!=t?t:this.autoPlay;e&&(this.animationName=e),this.armature?(void 0===r&&(r=0),this.armature.state.setAnimation(r,this.animationName,a)):this.waitExecuteInfos.push({playType:!0,name:e,loop:a,track:r})}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,r,a){try{this.armature&&(void 0===a&&(a=0),this.armature.state.addAnimation(a,e,r,t))}catch(e){console.log(e)}}setMix(e,t,r){this.armature&&this.armature.state.data.setMix(e,t,r)}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)}}o.componentName="Spine",n([s("string")],o.prototype,"resource",void 0),n([s("number")],o.prototype,"scale",void 0),n([s("string")],o.prototype,"animationName",void 0),n([s("boolean")],o.prototype,"autoPlay",void 0);let c={};function u(e,t,r){return i(this,void 0,void 0,(function*(){let a=c[e.name];if(!a)if(e.complete)a=function(e,t,r,a){const n=t.ske,i=t.atlas,s=new a.AtlasAttachmentLoader(i),o=n instanceof Uint8Array?new a.SkeletonBinary(s):new a.SkeletonJson(s);o.scale=r||1;const u={spineData:o.readSkeletonData(n),ref:0,imageSrc:t.image.label};return c[e]=u,u}(e.name,e.data,t,r);else if(!a)return;return a.ref++,a.spineData}))}let l=class extends r.Renderer{constructor(){super(...arguments),this.armatures={}}init({pixiSpine:e}){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=e,this.game.canvas.addEventListener("webglcontextrestored",(()=>{const e=this.game.gameObjects;let r=[];for(let a in this.armatures){const n=+a;for(let a=0;a<e.length;++a){let i=e[a];if(i.id===n){let e=i.getComponent(o);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:i,component:e,componentName:o.componentName}),r.push({type:t.OBSERVER_TYPE.ADD,gameObject:i,component:e,componentName:o.componentName}));break}}}setTimeout((()=>{r.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,r){var a,n;return i(this,void 0,void 0,(function*(){const i=e.component;clearTimeout(i.addHandler);const s=e.gameObject.id,o=this.increaseAsyncId(s),c=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(s,o))return;const l=yield u(c,i.scale,this.pixiSpine);if(!this.validateAsyncId(s,o))return;if(!l)return void(i.addHandler=setTimeout((()=>{i.destroied||(void 0===r&&(r=20),--r>0?this.add(e,r):console.log("retry exceed max times",i.resource))}),1e3));this.remove(e);const m=null===(n=null===(a=this.renderSystem)||void 0===a?void 0:a.containerManager)||void 0===n?void 0:n.getContainer(e.gameObject.id);if(!m)return;i.lastResource=i.resource;const d=new this.pixiSpine.Spine({skeletonData:l,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 r,n,s,o,u,l;return i(this,void 0,void 0,(function*(){this.increaseAsyncId(e.gameObject.id);const m=e.component;clearTimeout(m.addHandler);const d=this.armatures[e.gameObject.id],h=null===(n=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===n?void 0:n.getContainer(e.gameObject.id);if(h&&d&&h.removeChild(d),m.armature){m.armature.destroy({children:!0});const e=yield t.resource.getResource(m.lastResource);(null===(o=null===(s=e.data)||void 0===s?void 0:s.image)||void 0===o?void 0:o.src)||null===(l=null===(u=e.data)||void 0===u?void 0:u.image)||void 0===l||l.label,function(e){const r=e.name,n=c[r];n&&(n.ref--,setTimeout((()=>i(this,void 0,void 0,(function*(){if(n.ref<=0){yield a.Assets.unload([e.src.image.url,e.src.atlas.url,e.src.ske.url]);const n=a.Assets.resolver;delete n._assetMap[e.src.image.url],delete n._assetMap[e.src.atlas.url],delete n._assetMap[e.src.ske.url],delete n._resolverHash[e.src.image.url],delete n._resolverHash[e.src.atlas.url],delete n._resolverHash[e.src.ske.url],t.resource.destroy(r),delete c[r]}}))),100))}(e)}m.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE}))}};l.systemName="SpineSystem",l=n([t.decorators.componentObserver({Spine:["resource"]})],l);var m=l;return t.resource.registerResourceType("SPINE"),e.Spine=o,e.SpineSystem=m,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 r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.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.keepResource=!1,this._slotGameObjects=new Map,this._pendingSlotObjects=[],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{const r=null!=t?t:this.autoPlay;e&&(this.animationName=e),this.armature?(void 0===n&&(n=0),this.armature.state.setAnimation(n,this.animationName,r)):this.waitExecuteInfos.push({playType:!0,name:e,loop:r,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)}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 r=this._containerManager.getContainer(t.id);r?this._doAddSlotObject(e,t,r,n):this._pendingSlotObjects.push({slot:e,gameObject:t,options:n})}_doAddSlotObject(e,t,n,a){const i=new r.Container;i.addChild(n),this.armature.addSlotObject(e,i,a),this._slotGameObjects.set(t,{slot:e,wrapper:i}),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=[]}}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),a([o("boolean")],s.prototype,"keepResource",void 0);let c={};function d(e,t,n){return i(this,void 0,void 0,function*(){let r=c[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 d={spineData:s.readSkeletonData(a),ref:0,imageSrc:t.image.label};return c[e]=d,d}(e.name,e.data,t,n);else if(!r)return;return r.ref++,r.spineData})}let m=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 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);for(let e in this._spineComponents)this._spineComponents[e]._flushPendingSlotObjects();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,o;return i(this,void 0,void 0,function*(){const i=e.component;clearTimeout(i.addHandler);const s=e.gameObject.id,c=this.increaseAsyncId(s),m=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(s,c))return;const l=yield d(m,i.scale,this.pixiSpine);if(!this.validateAsyncId(s,c))return;if(!l)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 u=null===(a=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===a?void 0:a.getContainer(e.gameObject.id);if(!u)return;i.lastResource=i.resource;const h=new this.pixiSpine.Spine({skeletonData:l,autoUpdate:!1});if(this.armatures[e.gameObject.id]=h,this._spineComponents[e.gameObject.id]=i,e.gameObject&&e.gameObject.transform){const t=e.gameObject.transform;h.x=t.size.width*t.origin.x,h.y=t.size.height*t.origin.y}u.addChildAt(h,0),h.update(),i._containerManager=null===(o=this.renderSystem)||void 0===o?void 0:o.containerManager,i.armature=h,i.emit("loaded",{resource:i.resource}),h.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,s,d;return i(this,void 0,void 0,function*(){this.increaseAsyncId(e.gameObject.id);const m=e.component;clearTimeout(m.addHandler);const l=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);if(u&&l&&u.removeChild(l),m.armature&&(m._destroySlotGameObjects(),m.armature.destroy({children:!0}),!m.keepResource)){const e=yield t.resource.getResource(m.lastResource);(null===(o=null===(a=e.data)||void 0===a?void 0:a.image)||void 0===o?void 0:o.src)||null===(d=null===(s=e.data)||void 0===s?void 0:s.image)||void 0===d||d.label,function(e){const n=e.name,r=c[n];r&&(r.ref--,setTimeout(()=>i(this,void 0,void 0,function*(){r.ref<=0&&(t.resource.destroy(n),delete c[n])}),100))}(e)}m.armature=null,delete this.armatures[e.gameObject.id],delete this._spineComponents[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE})}};m.systemName="SpineSystem",m=a([t.decorators.componentObserver({Spine:["resource"]})],m);var l=m;return t.resource.registerResourceType("SPINE"),e.Spine=s,e.SpineSystem=l,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.spineBase=globalThis.EVA.plugin.spineBase||_EVA_IIFE_spineBase;