@eva/spine-base 2.0.0-beta.21 → 2.0.0-beta.22
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.
|
@@ -193,21 +193,20 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
193
193
|
return cache.tex;
|
|
194
194
|
}
|
|
195
195
|
function releaseTexture(imageSrc) {
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
if (!imageSrc) return;
|
|
197
|
+
setTimeout(() => {
|
|
198
198
|
const cache = texCache[imageSrc];
|
|
199
199
|
if (cache) {
|
|
200
200
|
cache.count--;
|
|
201
201
|
if (cache.count <= 0) {
|
|
202
202
|
if (cache.tex) {
|
|
203
|
-
yield pixi_js.Assets.unload(imageSrc);
|
|
204
203
|
cache.tex.destroy(true);
|
|
205
204
|
cache.tex = null;
|
|
206
205
|
}
|
|
207
206
|
delete texCache[imageSrc];
|
|
208
207
|
}
|
|
209
208
|
}
|
|
210
|
-
});
|
|
209
|
+
}, 100);
|
|
211
210
|
}
|
|
212
211
|
let dataMap = {};
|
|
213
212
|
function createSpineData(name, data, scale, pixiSpine) {
|
|
@@ -240,28 +239,16 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
240
239
|
return data.spineData;
|
|
241
240
|
});
|
|
242
241
|
}
|
|
243
|
-
function releaseSpineData(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
delete
|
|
252
|
-
|
|
253
|
-
delete resolver._resolverHash[res.src.ske.url];
|
|
254
|
-
const data = dataMap[resourceName];
|
|
255
|
-
if (!data) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
data.ref--;
|
|
259
|
-
if (data.ref <= 0) {
|
|
260
|
-
releaseTexture(imageSrc);
|
|
261
|
-
eva_js.resource.destroy(resourceName);
|
|
262
|
-
delete dataMap[resourceName];
|
|
263
|
-
}
|
|
264
|
-
});
|
|
242
|
+
function releaseSpineData(resourceName, imageSrc) {
|
|
243
|
+
const data = dataMap[resourceName];
|
|
244
|
+
if (!data) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
data.ref--;
|
|
248
|
+
if (data.ref <= 0) {
|
|
249
|
+
releaseTexture(imageSrc);
|
|
250
|
+
delete dataMap[resourceName];
|
|
251
|
+
}
|
|
265
252
|
}
|
|
266
253
|
const MaxRetryCount = 20;
|
|
267
254
|
let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
|
|
@@ -432,8 +419,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
432
419
|
children: true
|
|
433
420
|
});
|
|
434
421
|
const res = yield eva_js.resource.getResource(component.lastResource);
|
|
435
|
-
|
|
436
|
-
yield releaseSpineData(res, imageSrc);
|
|
422
|
+
releaseSpineData(res.name, ((_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));
|
|
437
423
|
}
|
|
438
424
|
component.armature = null;
|
|
439
425
|
delete this.armatures[changed.gameObject.id];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var
|
|
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 i(e,t,n,a){var i,r=arguments.length,o=r<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--)(i=e[s])&&(o=(r<3?i(o):r>3?i(t,n,o):i(t,n))||o);return r>3&&o&&Object.defineProperty(t,n,o),o}function r(e,t,n,a){return new(n||(n=Promise))((function(i,r){function o(e){try{c(a.next(e))}catch(e){r(e)}}function s(e){try{c(a.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(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",i([o("string")],s.prototype,"resource",void 0),i([o("number")],s.prototype,"scale",void 0),i([o("string")],s.prototype,"animationName",void 0),i([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 r(this,void 0,void 0,(function*(){let a=m[e.name];if(!a)if(e.complete)a=function(e,t,n,a){const i=t.ske,r=t.atlas,o=new a.AtlasAttachmentLoader(r),s=i instanceof Uint8Array?new a.SkeletonBinary(o):new a.SkeletonJson(o);s.scale=n||1;const c={spineData:s.readSkeletonData(i),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 i=+a;for(let a=0;a<e.length;++a){let r=e[a];if(r.id===i){let e=r.getComponent(s);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:r,component:e,componentName:s.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:r,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 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 a,i;return r(this,void 0,void 0,(function*(){const r=e.component;clearTimeout(r.addHandler);const o=e.gameObject.id,s=this.increaseAsyncId(o),c=yield t.resource.getResource(r.resource);if(!this.validateAsyncId(o,s))return;const u=yield l(c,r.scale,this.pixiSpine);if(!this.validateAsyncId(o,s))return;if(!u)return void(r.addHandler=setTimeout((()=>{r.destroied||(void 0===n&&(n=20),--n>0?this.add(e,n):console.log("retry exceed max times",r.resource))}),1e3));this.remove(e);const m=null===(i=null===(a=this.renderSystem)||void 0===a?void 0:a.containerManager)||void 0===i?void 0:i.getContainer(e.gameObject.id);if(!m)return;r.lastResource=r.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(),r.armature=d,r.emit("loaded",{resource:r.resource}),d.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,a,i,o,s,c;return r(this,void 0,void 0,(function*(){this.increaseAsyncId(e.gameObject.id);const r=e.component;clearTimeout(r.addHandler);const u=this.armatures[e.gameObject.id],m=null===(a=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===a?void 0:a.getContainer(e.gameObject.id);if(m&&u&&m.removeChild(u),r.armature){r.armature.destroy({children:!0});const e=yield t.resource.getResource(r.lastResource);d(e.name,(null===(o=null===(i=e.data)||void 0===i?void 0:i.image)||void 0===o?void 0:o.src)||(null===(c=null===(s=e.data)||void 0===s?void 0:s.image)||void 0===c?void 0:c.label))}r.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE}))}};h.systemName="SpineSystem",h=i([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/dist/spine-base.cjs.js
CHANGED
|
@@ -196,22 +196,21 @@ function retainTexture(name, data) {
|
|
|
196
196
|
return cache.tex;
|
|
197
197
|
}
|
|
198
198
|
function releaseTexture(imageSrc) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
199
|
+
if (!imageSrc)
|
|
200
|
+
return;
|
|
201
|
+
setTimeout(() => {
|
|
202
202
|
const cache = texCache[imageSrc];
|
|
203
203
|
if (cache) {
|
|
204
204
|
cache.count--;
|
|
205
205
|
if (cache.count <= 0) {
|
|
206
206
|
if (cache.tex) {
|
|
207
|
-
yield pixi_js.Assets.unload(imageSrc);
|
|
208
207
|
cache.tex.destroy(true);
|
|
209
208
|
cache.tex = null;
|
|
210
209
|
}
|
|
211
210
|
delete texCache[imageSrc];
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
|
-
});
|
|
213
|
+
}, 100);
|
|
215
214
|
}
|
|
216
215
|
|
|
217
216
|
let dataMap = {};
|
|
@@ -244,28 +243,16 @@ function getSpineData(res, scale, pixiSpine) {
|
|
|
244
243
|
return data.spineData;
|
|
245
244
|
});
|
|
246
245
|
}
|
|
247
|
-
function releaseSpineData(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
delete
|
|
256
|
-
|
|
257
|
-
delete resolver._resolverHash[res.src.ske.url];
|
|
258
|
-
const data = dataMap[resourceName];
|
|
259
|
-
if (!data) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
data.ref--;
|
|
263
|
-
if (data.ref <= 0) {
|
|
264
|
-
releaseTexture(imageSrc);
|
|
265
|
-
eva_js.resource.destroy(resourceName);
|
|
266
|
-
delete dataMap[resourceName];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
246
|
+
function releaseSpineData(resourceName, imageSrc) {
|
|
247
|
+
const data = dataMap[resourceName];
|
|
248
|
+
if (!data) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
data.ref--;
|
|
252
|
+
if (data.ref <= 0) {
|
|
253
|
+
releaseTexture(imageSrc);
|
|
254
|
+
delete dataMap[resourceName];
|
|
255
|
+
}
|
|
269
256
|
}
|
|
270
257
|
|
|
271
258
|
const MaxRetryCount = 20;
|
|
@@ -424,8 +411,7 @@ let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
|
|
|
424
411
|
if (component.armature) {
|
|
425
412
|
component.armature.destroy({ children: true });
|
|
426
413
|
const res = yield eva_js.resource.getResource(component.lastResource);
|
|
427
|
-
|
|
428
|
-
yield releaseSpineData(res, imageSrc);
|
|
414
|
+
releaseSpineData(res.name, ((_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));
|
|
429
415
|
}
|
|
430
416
|
component.armature = null;
|
|
431
417
|
delete this.armatures[changed.gameObject.id];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),a=require("@eva/inspector-decorator"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),a=require("@eva/inspector-decorator"),i=require("pixi.js");
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -13,4 +13,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
15
|
***************************************************************************** */
|
|
16
|
-
function
|
|
16
|
+
function r(e,t,a,i){var r,n=arguments.length,o=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,a):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,a,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(o=(n<3?r(o):n>3?r(t,a,o):r(t,a))||o);return n>3&&o&&Object.defineProperty(t,a,o),o}function n(e,t,a,i){return new(a||(a=Promise))((function(r,n){function o(e){try{c(i.next(e))}catch(e){n(e)}}function s(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){e.done?r(e.value):new a((function(t){t(e.value)})).then(o,s)}c((i=i.apply(e,t||[])).next())}))}class o extends e.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:a,track:i}=e;this.play(t,a,i)}else this.stop(e.track);this.waitExecuteInfos=[]}}get armature(){return this._armature}init(e){e&&Object.assign(this,e)}onDestroy(){this.destroied=!0}play(e,t,a){try{e&&(this.animationName=e),this.armature?(void 0===a&&(a=0),this.armature.state.setAnimation(a,this.animationName,t)):this.waitExecuteInfos.push({playType:!0,name:e,loop:null!=t?t:this.autoPlay,track:a})}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,a,i){try{this.armature&&(void 0===i&&(i=0),this.armature.state.addAnimation(i,e,a,t))}catch(e){console.log(e)}}setMix(e,t,a){this.armature&&this.armature.state.data.setMix(e,t,a)}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",r([a.type("string")],o.prototype,"resource",void 0),r([a.type("number")],o.prototype,"scale",void 0),r([a.type("string")],o.prototype,"animationName",void 0),r([a.type("boolean")],o.prototype,"autoPlay",void 0);let s={};function c(e,t){let a=s[e];return a||(a=function(e){const t=e.image;return{tex:t instanceof i.Texture?t:i.Texture.from(t),count:0}}(t),s[e]=a),a.count++,a.tex}let m={};function u(e,t,a){return n(this,void 0,void 0,(function*(){let i=m[e.name];if(!i)if(e.complete)i=function(e,t,a,i){const r=t.ske,n=t.atlas,o=new i.AtlasAttachmentLoader(n),s=r instanceof Uint8Array?new i.SkeletonBinary(o):new i.SkeletonJson(o);s.scale=a||1;const c={spineData:s.readSkeletonData(r),ref:0,imageSrc:t.image.label};return m[e]=c,c}(e.name,e.data,t,a);else if(!i)return;return c(e.data.image.label,e.data),i.ref++,i.spineData}))}function d(e,t){const a=m[e];a&&(a.ref--,a.ref<=0&&(!function(e){e&&setTimeout((()=>{const t=s[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete s[e]))}),100)}(t),delete m[e]))}let l=class extends t.Renderer{constructor(){super(...arguments),this.armatures={}}init({pixiSpine:a}){this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=a,this.game.canvas.addEventListener("webglcontextrestored",(()=>{const t=this.game.gameObjects;let a=[];for(let i in this.armatures){const r=+i;for(let i=0;i<t.length;++i){let n=t[i];if(n.id===r){let t=n.getComponent(o);t&&(this.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:n,component:t,componentName:o.componentName}),a.push({type:e.OBSERVER_TYPE.ADD,gameObject:n,component:t,componentName:o.componentName}));break}}}setTimeout((()=>{a.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(t){return n(this,void 0,void 0,(function*(){if("Spine"===t.componentName)if(t.type===e.OBSERVER_TYPE.ADD)this.add(t);else if(t.type===e.OBSERVER_TYPE.CHANGE){if("resource"===t.prop.prop[0])this.change(t)}else t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t)}))}add(t,a){var i,r;return n(this,void 0,void 0,(function*(){const n=t.component;clearTimeout(n.addHandler);const o=t.gameObject.id,s=this.increaseAsyncId(o),c=yield e.resource.getResource(n.resource);if(!this.validateAsyncId(o,s))return;const m=yield u(c,n.scale,this.pixiSpine);if(!this.validateAsyncId(o,s))return;if(!m)return void(n.addHandler=setTimeout((()=>{n.destroied||(void 0===a&&(a=20),--a>0?this.add(t,a):console.log("retry exceed max times",n.resource))}),1e3));this.remove(t);const d=null===(r=null===(i=this.renderSystem)||void 0===i?void 0:i.containerManager)||void 0===r?void 0:r.getContainer(t.gameObject.id);if(!d)return;n.lastResource=n.resource;const l=new this.pixiSpine.Spine({skeletonData:m,autoUpdate:!1});if(this.armatures[t.gameObject.id]=l,t.gameObject&&t.gameObject.transform){const e=t.gameObject.transform;l.x=e.size.width*e.origin.x,l.y=e.size.height*e.origin.y}d.addChildAt(l,0),l.update(),n.armature=l,n.emit("loaded",{resource:n.resource}),l.state.addListener({start:(e,t)=>{n.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{n.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{n.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{n.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{n.emit("event",e,t)}})}))}change(e){this.remove(e),this.add(e)}remove(t){var a,i,r,o,s,c;return n(this,void 0,void 0,(function*(){this.increaseAsyncId(t.gameObject.id);const n=t.component;clearTimeout(n.addHandler);const m=this.armatures[t.gameObject.id],u=null===(i=null===(a=this.renderSystem)||void 0===a?void 0:a.containerManager)||void 0===i?void 0:i.getContainer(t.gameObject.id);if(u&&m&&u.removeChild(m),n.armature){n.armature.destroy({children:!0});const t=yield e.resource.getResource(n.lastResource);d(t.name,(null===(o=null===(r=t.data)||void 0===r?void 0:r.image)||void 0===o?void 0:o.src)||(null===(c=null===(s=t.data)||void 0===s?void 0:s.image)||void 0===c?void 0:c.label))}n.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE}))}};l.systemName="SpineSystem",l=r([e.decorators.componentObserver({Spine:["resource"]})],l);var h=l;e.resource.registerResourceType("SPINE"),exports.Spine=o,exports.SpineSystem=h;
|
package/dist/spine-base.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Component,
|
|
1
|
+
import { Component, OBSERVER_TYPE, decorators, resource } from '@eva/eva.js';
|
|
2
2
|
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
3
3
|
import { type } from '@eva/inspector-decorator';
|
|
4
|
-
import { Texture
|
|
4
|
+
import { Texture } from 'pixi.js';
|
|
5
5
|
|
|
6
6
|
/*! *****************************************************************************
|
|
7
7
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -192,22 +192,21 @@ function retainTexture(name, data) {
|
|
|
192
192
|
return cache.tex;
|
|
193
193
|
}
|
|
194
194
|
function releaseTexture(imageSrc) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
if (!imageSrc)
|
|
196
|
+
return;
|
|
197
|
+
setTimeout(() => {
|
|
198
198
|
const cache = texCache[imageSrc];
|
|
199
199
|
if (cache) {
|
|
200
200
|
cache.count--;
|
|
201
201
|
if (cache.count <= 0) {
|
|
202
202
|
if (cache.tex) {
|
|
203
|
-
yield Assets.unload(imageSrc);
|
|
204
203
|
cache.tex.destroy(true);
|
|
205
204
|
cache.tex = null;
|
|
206
205
|
}
|
|
207
206
|
delete texCache[imageSrc];
|
|
208
207
|
}
|
|
209
208
|
}
|
|
210
|
-
});
|
|
209
|
+
}, 100);
|
|
211
210
|
}
|
|
212
211
|
|
|
213
212
|
let dataMap = {};
|
|
@@ -240,28 +239,16 @@ function getSpineData(res, scale, pixiSpine) {
|
|
|
240
239
|
return data.spineData;
|
|
241
240
|
});
|
|
242
241
|
}
|
|
243
|
-
function releaseSpineData(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
delete
|
|
252
|
-
|
|
253
|
-
delete resolver._resolverHash[res.src.ske.url];
|
|
254
|
-
const data = dataMap[resourceName];
|
|
255
|
-
if (!data) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
data.ref--;
|
|
259
|
-
if (data.ref <= 0) {
|
|
260
|
-
releaseTexture(imageSrc);
|
|
261
|
-
resource.destroy(resourceName);
|
|
262
|
-
delete dataMap[resourceName];
|
|
263
|
-
}
|
|
264
|
-
});
|
|
242
|
+
function releaseSpineData(resourceName, imageSrc) {
|
|
243
|
+
const data = dataMap[resourceName];
|
|
244
|
+
if (!data) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
data.ref--;
|
|
248
|
+
if (data.ref <= 0) {
|
|
249
|
+
releaseTexture(imageSrc);
|
|
250
|
+
delete dataMap[resourceName];
|
|
251
|
+
}
|
|
265
252
|
}
|
|
266
253
|
|
|
267
254
|
const MaxRetryCount = 20;
|
|
@@ -420,8 +407,7 @@ let SpineSystem = class SpineSystem extends Renderer {
|
|
|
420
407
|
if (component.armature) {
|
|
421
408
|
component.armature.destroy({ children: true });
|
|
422
409
|
const res = yield resource.getResource(component.lastResource);
|
|
423
|
-
|
|
424
|
-
yield releaseSpineData(res, imageSrc);
|
|
410
|
+
releaseSpineData(res.name, ((_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));
|
|
425
411
|
}
|
|
426
412
|
component.armature = null;
|
|
427
413
|
delete this.armatures[changed.gameObject.id];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/spine-base",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.22",
|
|
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.
|
|
22
|
-
"@eva/plugin-renderer": "2.0.0-beta.
|
|
21
|
+
"@eva/eva.js": "2.0.0-beta.22",
|
|
22
|
+
"@eva/plugin-renderer": "2.0.0-beta.22",
|
|
23
23
|
"@eva/inspector-decorator": "^0.0.5",
|
|
24
24
|
"pixi.js": "^8.8.1"
|
|
25
25
|
}
|