@eva/spine-base 2.0.1-beta.0 → 2.0.1-beta.2
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.
|
@@ -93,14 +93,15 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
93
93
|
onDestroy() {
|
|
94
94
|
this.destroied = true;
|
|
95
95
|
}
|
|
96
|
-
play(name,
|
|
96
|
+
play(name, loopAnimation, track) {
|
|
97
97
|
try {
|
|
98
|
+
const loop = loopAnimation !== null && loopAnimation !== void 0 ? loopAnimation : this.autoPlay;
|
|
98
99
|
if (name) this.animationName = name;
|
|
99
100
|
if (!this.armature) {
|
|
100
101
|
this.waitExecuteInfos.push({
|
|
101
102
|
playType: true,
|
|
102
103
|
name,
|
|
103
|
-
loop
|
|
104
|
+
loop,
|
|
104
105
|
track
|
|
105
106
|
});
|
|
106
107
|
} else {
|
|
@@ -175,40 +176,6 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
175
176
|
__decorate([type('number')], Spine.prototype, "scale", void 0);
|
|
176
177
|
__decorate([type('string')], Spine.prototype, "animationName", void 0);
|
|
177
178
|
__decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
|
|
178
|
-
let texCache = {};
|
|
179
|
-
function cacheImage(data) {
|
|
180
|
-
const oldImg = data.image;
|
|
181
|
-
return {
|
|
182
|
-
tex: oldImg instanceof pixi_js.Texture ? oldImg : pixi_js.Texture.from(oldImg),
|
|
183
|
-
count: 0
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function retainTexture(name, data) {
|
|
187
|
-
let cache = texCache[name];
|
|
188
|
-
if (!cache) {
|
|
189
|
-
cache = cacheImage(data);
|
|
190
|
-
texCache[name] = cache;
|
|
191
|
-
}
|
|
192
|
-
cache.count++;
|
|
193
|
-
return cache.tex;
|
|
194
|
-
}
|
|
195
|
-
function releaseTexture(imageSrc) {
|
|
196
|
-
if (!imageSrc) return;
|
|
197
|
-
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
const cache = texCache[imageSrc];
|
|
199
|
-
if (cache) {
|
|
200
|
-
cache.count--;
|
|
201
|
-
if (cache.count <= 0) {
|
|
202
|
-
if (cache.tex) {
|
|
203
|
-
yield pixi_js.Assets.unload(imageSrc);
|
|
204
|
-
cache.tex.destroy(true);
|
|
205
|
-
cache.tex = null;
|
|
206
|
-
}
|
|
207
|
-
delete texCache[imageSrc];
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}), 100);
|
|
211
|
-
}
|
|
212
179
|
let dataMap = {};
|
|
213
180
|
function createSpineData(name, data, scale, pixiSpine) {
|
|
214
181
|
const skeletonAsset = data.ske;
|
|
@@ -235,33 +202,31 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
235
202
|
return;
|
|
236
203
|
}
|
|
237
204
|
}
|
|
238
|
-
retainTexture(res.data.image.label, res.data);
|
|
239
205
|
data.ref++;
|
|
240
206
|
return data.spineData;
|
|
241
207
|
});
|
|
242
208
|
}
|
|
243
|
-
function releaseSpineData(res,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
delete resolver._resolverHash[res.src.image.url];
|
|
252
|
-
delete resolver._resolverHash[res.src.atlas.url];
|
|
253
|
-
delete resolver._resolverHash[res.src.ske.url];
|
|
254
|
-
const data = dataMap[resourceName];
|
|
255
|
-
if (!data) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
data.ref--;
|
|
209
|
+
function releaseSpineData(res, _imageSrc) {
|
|
210
|
+
const resourceName = res.name;
|
|
211
|
+
const data = dataMap[resourceName];
|
|
212
|
+
if (!data) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
data.ref--;
|
|
216
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
259
217
|
if (data.ref <= 0) {
|
|
260
|
-
|
|
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];
|
|
261
226
|
eva_js.resource.destroy(resourceName);
|
|
262
227
|
delete dataMap[resourceName];
|
|
263
228
|
}
|
|
264
|
-
});
|
|
229
|
+
}), 100);
|
|
265
230
|
}
|
|
266
231
|
const MaxRetryCount = 20;
|
|
267
232
|
let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
|
|
@@ -432,8 +397,8 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
432
397
|
children: true
|
|
433
398
|
});
|
|
434
399
|
const res = yield eva_js.resource.getResource(component.lastResource);
|
|
435
|
-
|
|
436
|
-
|
|
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);
|
|
437
402
|
}
|
|
438
403
|
component.armature = null;
|
|
439
404
|
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 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{e&&(this.animationName=e),this.armature?(void 0===r&&(r=0),this.armature.state.setAnimation(r,this.animationName,
|
|
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;
|
package/dist/spine-base.cjs.js
CHANGED
|
@@ -76,15 +76,16 @@ class Spine extends eva_js.Component {
|
|
|
76
76
|
onDestroy() {
|
|
77
77
|
this.destroied = true;
|
|
78
78
|
}
|
|
79
|
-
play(name,
|
|
79
|
+
play(name, loopAnimation, track) {
|
|
80
80
|
try {
|
|
81
|
+
const loop = loopAnimation !== null && loopAnimation !== void 0 ? loopAnimation : this.autoPlay;
|
|
81
82
|
if (name)
|
|
82
83
|
this.animationName = name;
|
|
83
84
|
if (!this.armature) {
|
|
84
85
|
this.waitExecuteInfos.push({
|
|
85
86
|
playType: true,
|
|
86
87
|
name,
|
|
87
|
-
loop
|
|
88
|
+
loop,
|
|
88
89
|
track,
|
|
89
90
|
});
|
|
90
91
|
}
|
|
@@ -178,42 +179,6 @@ __decorate([
|
|
|
178
179
|
inspectorDecorator.type('boolean')
|
|
179
180
|
], Spine.prototype, "autoPlay", void 0);
|
|
180
181
|
|
|
181
|
-
let texCache = {};
|
|
182
|
-
function cacheImage(data) {
|
|
183
|
-
const oldImg = data.image;
|
|
184
|
-
return {
|
|
185
|
-
tex: oldImg instanceof pixi_js.Texture ? oldImg : pixi_js.Texture.from(oldImg),
|
|
186
|
-
count: 0,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function retainTexture(name, data) {
|
|
190
|
-
let cache = texCache[name];
|
|
191
|
-
if (!cache) {
|
|
192
|
-
cache = cacheImage(data);
|
|
193
|
-
texCache[name] = cache;
|
|
194
|
-
}
|
|
195
|
-
cache.count++;
|
|
196
|
-
return cache.tex;
|
|
197
|
-
}
|
|
198
|
-
function releaseTexture(imageSrc) {
|
|
199
|
-
if (!imageSrc)
|
|
200
|
-
return;
|
|
201
|
-
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
202
|
-
const cache = texCache[imageSrc];
|
|
203
|
-
if (cache) {
|
|
204
|
-
cache.count--;
|
|
205
|
-
if (cache.count <= 0) {
|
|
206
|
-
if (cache.tex) {
|
|
207
|
-
yield pixi_js.Assets.unload(imageSrc);
|
|
208
|
-
cache.tex.destroy(true);
|
|
209
|
-
cache.tex = null;
|
|
210
|
-
}
|
|
211
|
-
delete texCache[imageSrc];
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}), 100);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
182
|
let dataMap = {};
|
|
218
183
|
function createSpineData(name, data, scale, pixiSpine) {
|
|
219
184
|
const skeletonAsset = data.ske;
|
|
@@ -239,33 +204,31 @@ function getSpineData(res, scale, pixiSpine) {
|
|
|
239
204
|
return;
|
|
240
205
|
}
|
|
241
206
|
}
|
|
242
|
-
retainTexture(res.data.image.label, res.data);
|
|
243
207
|
data.ref++;
|
|
244
208
|
return data.spineData;
|
|
245
209
|
});
|
|
246
210
|
}
|
|
247
|
-
function releaseSpineData(res,
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
delete resolver._resolverHash[res.src.image.url];
|
|
256
|
-
delete resolver._resolverHash[res.src.atlas.url];
|
|
257
|
-
delete resolver._resolverHash[res.src.ske.url];
|
|
258
|
-
const data = dataMap[resourceName];
|
|
259
|
-
if (!data) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
data.ref--;
|
|
211
|
+
function releaseSpineData(res, _imageSrc) {
|
|
212
|
+
const resourceName = res.name;
|
|
213
|
+
const data = dataMap[resourceName];
|
|
214
|
+
if (!data) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
data.ref--;
|
|
218
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
263
219
|
if (data.ref <= 0) {
|
|
264
|
-
|
|
220
|
+
yield pixi_js.Assets.unload([res.src.image.url, res.src.atlas.url, res.src.ske.url]);
|
|
221
|
+
const resolver = pixi_js.Assets.resolver;
|
|
222
|
+
delete resolver._assetMap[res.src.image.url];
|
|
223
|
+
delete resolver._assetMap[res.src.atlas.url];
|
|
224
|
+
delete resolver._assetMap[res.src.ske.url];
|
|
225
|
+
delete resolver._resolverHash[res.src.image.url];
|
|
226
|
+
delete resolver._resolverHash[res.src.atlas.url];
|
|
227
|
+
delete resolver._resolverHash[res.src.ske.url];
|
|
265
228
|
eva_js.resource.destroy(resourceName);
|
|
266
229
|
delete dataMap[resourceName];
|
|
267
230
|
}
|
|
268
|
-
});
|
|
231
|
+
}), 100);
|
|
269
232
|
}
|
|
270
233
|
|
|
271
234
|
const MaxRetryCount = 20;
|
|
@@ -424,8 +387,8 @@ let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
|
|
|
424
387
|
if (component.armature) {
|
|
425
388
|
component.armature.destroy({ children: true });
|
|
426
389
|
const res = yield eva_js.resource.getResource(component.lastResource);
|
|
427
|
-
|
|
428
|
-
|
|
390
|
+
((_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);
|
|
391
|
+
releaseSpineData(res);
|
|
429
392
|
}
|
|
430
393
|
component.armature = null;
|
|
431
394
|
delete this.armatures[changed.gameObject.id];
|
|
@@ -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 i(e,t,a,r){var i,
|
|
16
|
+
function i(e,t,a,r){var i,s=arguments.length,n=s<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,a,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(n=(s<3?i(n):s>3?i(t,a,n):i(t,a))||n);return s>3&&n&&Object.defineProperty(t,a,n),n}function s(e,t,a,r){return new(a||(a=Promise))((function(i,s){function n(e){try{c(r.next(e))}catch(e){s(e)}}function o(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){e.done?i(e.value):new a((function(t){t(e.value)})).then(n,o)}c((r=r.apply(e,t||[])).next())}))}class n 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:r}=e;this.play(t,a,r)}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{const r=null!=t?t:this.autoPlay;e&&(this.animationName=e),this.armature?(void 0===a&&(a=0),this.armature.state.setAnimation(a,this.animationName,r)):this.waitExecuteInfos.push({playType:!0,name:e,loop:r,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,r){try{this.armature&&(void 0===r&&(r=0),this.armature.state.addAnimation(r,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)}}n.componentName="Spine",i([a.type("string")],n.prototype,"resource",void 0),i([a.type("number")],n.prototype,"scale",void 0),i([a.type("string")],n.prototype,"animationName",void 0),i([a.type("boolean")],n.prototype,"autoPlay",void 0);let o={};function c(e,t,a){return s(this,void 0,void 0,(function*(){let r=o[e.name];if(!r)if(e.complete)r=function(e,t,a,r){const i=t.ske,s=t.atlas,n=new r.AtlasAttachmentLoader(s),c=i instanceof Uint8Array?new r.SkeletonBinary(n):new r.SkeletonJson(n);c.scale=a||1;const m={spineData:c.readSkeletonData(i),ref:0,imageSrc:t.image.label};return o[e]=m,m}(e.name,e.data,t,a);else if(!r)return;return r.ref++,r.spineData}))}let m=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 r in this.armatures){const i=+r;for(let r=0;r<t.length;++r){let s=t[r];if(s.id===i){let t=s.getComponent(n);t&&(this.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:t,componentName:n.componentName}),a.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:t,componentName:n.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 s(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 r,i;return s(this,void 0,void 0,(function*(){const s=t.component;clearTimeout(s.addHandler);const n=t.gameObject.id,o=this.increaseAsyncId(n),m=yield e.resource.getResource(s.resource);if(!this.validateAsyncId(n,o))return;const u=yield c(m,s.scale,this.pixiSpine);if(!this.validateAsyncId(n,o))return;if(!u)return void(s.addHandler=setTimeout((()=>{s.destroied||(void 0===a&&(a=20),--a>0?this.add(t,a):console.log("retry exceed max times",s.resource))}),1e3));this.remove(t);const d=null===(i=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===i?void 0:i.getContainer(t.gameObject.id);if(!d)return;s.lastResource=s.resource;const l=new this.pixiSpine.Spine({skeletonData:u,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(),s.armature=l,s.emit("loaded",{resource:s.resource}),l.state.addListener({start:(e,t)=>{s.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{s.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{s.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{s.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{s.emit("event",e,t)}})}))}change(e){this.remove(e),this.add(e)}remove(t){var a,i,n,c,m,u;return s(this,void 0,void 0,(function*(){this.increaseAsyncId(t.gameObject.id);const d=t.component;clearTimeout(d.addHandler);const l=this.armatures[t.gameObject.id],h=null===(i=null===(a=this.renderSystem)||void 0===a?void 0:a.containerManager)||void 0===i?void 0:i.getContainer(t.gameObject.id);if(h&&l&&h.removeChild(l),d.armature){d.armature.destroy({children:!0});const t=yield e.resource.getResource(d.lastResource);(null===(c=null===(n=t.data)||void 0===n?void 0:n.image)||void 0===c?void 0:c.src)||null===(u=null===(m=t.data)||void 0===m?void 0:m.image)||void 0===u||u.label,function(t){const a=t.name,i=o[a];i&&(i.ref--,setTimeout((()=>s(this,void 0,void 0,(function*(){if(i.ref<=0){yield r.Assets.unload([t.src.image.url,t.src.atlas.url,t.src.ske.url]);const i=r.Assets.resolver;delete i._assetMap[t.src.image.url],delete i._assetMap[t.src.atlas.url],delete i._assetMap[t.src.ske.url],delete i._resolverHash[t.src.image.url],delete i._resolverHash[t.src.atlas.url],delete i._resolverHash[t.src.ske.url],e.resource.destroy(a),delete o[a]}}))),100))}(t)}d.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE}))}};m.systemName="SpineSystem",m=i([e.decorators.componentObserver({Spine:["resource"]})],m);var u=m;e.resource.registerResourceType("SPINE"),exports.Spine=n,exports.SpineSystem=u;
|
package/dist/spine-base.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare class Spine extends Component<SpineParams> {
|
|
|
23
23
|
lastResource: string;
|
|
24
24
|
init(obj?: SpineParams): void;
|
|
25
25
|
onDestroy(): void;
|
|
26
|
-
play(name?: string,
|
|
26
|
+
play(name?: string, loopAnimation?: boolean, track?: number): void;
|
|
27
27
|
stop(track?: number): void;
|
|
28
28
|
addAnimation(name?: string, delay?: number, loop?: boolean, track?: number): void;
|
|
29
29
|
setMix(from: string, to: string, duration: number): void;
|
package/dist/spine-base.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Component, resource, OBSERVER_TYPE, decorators } from '@eva/eva.js';
|
|
2
2
|
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
3
3
|
import { type } from '@eva/inspector-decorator';
|
|
4
|
-
import {
|
|
4
|
+
import { Assets } from 'pixi.js';
|
|
5
5
|
|
|
6
6
|
/*! *****************************************************************************
|
|
7
7
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -72,15 +72,16 @@ class Spine extends Component {
|
|
|
72
72
|
onDestroy() {
|
|
73
73
|
this.destroied = true;
|
|
74
74
|
}
|
|
75
|
-
play(name,
|
|
75
|
+
play(name, loopAnimation, track) {
|
|
76
76
|
try {
|
|
77
|
+
const loop = loopAnimation !== null && loopAnimation !== void 0 ? loopAnimation : this.autoPlay;
|
|
77
78
|
if (name)
|
|
78
79
|
this.animationName = name;
|
|
79
80
|
if (!this.armature) {
|
|
80
81
|
this.waitExecuteInfos.push({
|
|
81
82
|
playType: true,
|
|
82
83
|
name,
|
|
83
|
-
loop
|
|
84
|
+
loop,
|
|
84
85
|
track,
|
|
85
86
|
});
|
|
86
87
|
}
|
|
@@ -174,42 +175,6 @@ __decorate([
|
|
|
174
175
|
type('boolean')
|
|
175
176
|
], Spine.prototype, "autoPlay", void 0);
|
|
176
177
|
|
|
177
|
-
let texCache = {};
|
|
178
|
-
function cacheImage(data) {
|
|
179
|
-
const oldImg = data.image;
|
|
180
|
-
return {
|
|
181
|
-
tex: oldImg instanceof Texture ? oldImg : Texture.from(oldImg),
|
|
182
|
-
count: 0,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function retainTexture(name, data) {
|
|
186
|
-
let cache = texCache[name];
|
|
187
|
-
if (!cache) {
|
|
188
|
-
cache = cacheImage(data);
|
|
189
|
-
texCache[name] = cache;
|
|
190
|
-
}
|
|
191
|
-
cache.count++;
|
|
192
|
-
return cache.tex;
|
|
193
|
-
}
|
|
194
|
-
function releaseTexture(imageSrc) {
|
|
195
|
-
if (!imageSrc)
|
|
196
|
-
return;
|
|
197
|
-
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
const cache = texCache[imageSrc];
|
|
199
|
-
if (cache) {
|
|
200
|
-
cache.count--;
|
|
201
|
-
if (cache.count <= 0) {
|
|
202
|
-
if (cache.tex) {
|
|
203
|
-
yield Assets.unload(imageSrc);
|
|
204
|
-
cache.tex.destroy(true);
|
|
205
|
-
cache.tex = null;
|
|
206
|
-
}
|
|
207
|
-
delete texCache[imageSrc];
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}), 100);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
178
|
let dataMap = {};
|
|
214
179
|
function createSpineData(name, data, scale, pixiSpine) {
|
|
215
180
|
const skeletonAsset = data.ske;
|
|
@@ -235,33 +200,31 @@ function getSpineData(res, scale, pixiSpine) {
|
|
|
235
200
|
return;
|
|
236
201
|
}
|
|
237
202
|
}
|
|
238
|
-
retainTexture(res.data.image.label, res.data);
|
|
239
203
|
data.ref++;
|
|
240
204
|
return data.spineData;
|
|
241
205
|
});
|
|
242
206
|
}
|
|
243
|
-
function releaseSpineData(res,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
delete resolver._resolverHash[res.src.image.url];
|
|
252
|
-
delete resolver._resolverHash[res.src.atlas.url];
|
|
253
|
-
delete resolver._resolverHash[res.src.ske.url];
|
|
254
|
-
const data = dataMap[resourceName];
|
|
255
|
-
if (!data) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
data.ref--;
|
|
207
|
+
function releaseSpineData(res, _imageSrc) {
|
|
208
|
+
const resourceName = res.name;
|
|
209
|
+
const data = dataMap[resourceName];
|
|
210
|
+
if (!data) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
data.ref--;
|
|
214
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
259
215
|
if (data.ref <= 0) {
|
|
260
|
-
|
|
216
|
+
yield Assets.unload([res.src.image.url, res.src.atlas.url, res.src.ske.url]);
|
|
217
|
+
const resolver = Assets.resolver;
|
|
218
|
+
delete resolver._assetMap[res.src.image.url];
|
|
219
|
+
delete resolver._assetMap[res.src.atlas.url];
|
|
220
|
+
delete resolver._assetMap[res.src.ske.url];
|
|
221
|
+
delete resolver._resolverHash[res.src.image.url];
|
|
222
|
+
delete resolver._resolverHash[res.src.atlas.url];
|
|
223
|
+
delete resolver._resolverHash[res.src.ske.url];
|
|
261
224
|
resource.destroy(resourceName);
|
|
262
225
|
delete dataMap[resourceName];
|
|
263
226
|
}
|
|
264
|
-
});
|
|
227
|
+
}), 100);
|
|
265
228
|
}
|
|
266
229
|
|
|
267
230
|
const MaxRetryCount = 20;
|
|
@@ -420,8 +383,8 @@ let SpineSystem = class SpineSystem extends Renderer {
|
|
|
420
383
|
if (component.armature) {
|
|
421
384
|
component.armature.destroy({ children: true });
|
|
422
385
|
const res = yield resource.getResource(component.lastResource);
|
|
423
|
-
|
|
424
|
-
|
|
386
|
+
((_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);
|
|
387
|
+
releaseSpineData(res);
|
|
425
388
|
}
|
|
426
389
|
component.armature = null;
|
|
427
390
|
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.1-beta.
|
|
3
|
+
"version": "2.0.1-beta.2",
|
|
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.1-beta.
|
|
22
|
-
"@eva/plugin-renderer": "2.0.1-beta.
|
|
21
|
+
"@eva/eva.js": "2.0.1-beta.2",
|
|
22
|
+
"@eva/plugin-renderer": "2.0.1-beta.2",
|
|
23
23
|
"@eva/inspector-decorator": "^0.0.5",
|
|
24
24
|
"pixi.js": "^8.8.1"
|
|
25
25
|
}
|