@eva/spine-base 1.2.7-editor.1 → 1.2.7-editor.10

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.
@@ -13,7 +13,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
13
13
  d.__proto__ = b;
14
14
  } || function (d, b) {
15
15
  for (var p in b) {
16
- if (b.hasOwnProperty(p)) d[p] = b[p];
16
+ if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
17
17
  }
18
18
  };
19
19
 
@@ -21,6 +21,8 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
21
21
  };
22
22
 
23
23
  function __extends(d, b) {
24
+ if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
25
+
24
26
  _extendStatics(d, b);
25
27
 
26
28
  function __() {
@@ -30,6 +32,22 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
30
32
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
31
33
  }
32
34
 
35
+ var _assign = function __assign() {
36
+ _assign = Object.assign || function __assign(t) {
37
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
38
+ s = arguments[i];
39
+
40
+ for (var p in s) {
41
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
42
+ }
43
+ }
44
+
45
+ return t;
46
+ };
47
+
48
+ return _assign.apply(this, arguments);
49
+ };
50
+
33
51
  function __decorate(decorators, target, key, desc) {
34
52
  var c = arguments.length,
35
53
  r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
@@ -40,6 +58,10 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
40
58
  return c > 3 && r && Object.defineProperty(target, key, r), r;
41
59
  }
42
60
 
61
+ function __metadata(metadataKey, metadataValue) {
62
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
63
+ }
64
+
43
65
  function __awaiter(thisArg, _arguments, P, generator) {
44
66
  function adopt(value) {
45
67
  return value instanceof P ? value : new P(function (resolve) {
@@ -200,27 +222,123 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
200
222
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
201
223
  }
202
224
 
203
- function getIDEPropsPropertyObj(target, propertyKey) {
204
- if (!target.constructor.IDEProps) {
205
- target.constructor.IDEProps = {};
225
+ var SymbolKeysNotSupportedError = function (_super) {
226
+ __extends(SymbolKeysNotSupportedError, _super);
227
+
228
+ function SymbolKeysNotSupportedError() {
229
+ var _newTarget = this.constructor;
230
+
231
+ var _this = _super.call(this, 'Symbol keys are not supported yet!') || this;
232
+
233
+ Object.setPrototypeOf(_this, _newTarget.prototype);
234
+ return _this;
206
235
  }
207
236
 
208
- if (!target.constructor.IDEProps[propertyKey]) {
209
- target.constructor.IDEProps[propertyKey] = {};
237
+ return SymbolKeysNotSupportedError;
238
+ }(Error);
239
+
240
+ (function (_super) {
241
+ __extends(StaticGetPropertiesIsNotAFunctionError, _super);
242
+
243
+ function StaticGetPropertiesIsNotAFunctionError() {
244
+ var _newTarget = this.constructor;
245
+
246
+ var _this = _super.call(this, 'getProperties is not a function!') || this;
247
+
248
+ Object.setPrototypeOf(_this, _newTarget.prototype);
249
+ return _this;
250
+ }
251
+
252
+ return StaticGetPropertiesIsNotAFunctionError;
253
+ })(Error);
254
+
255
+ var IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
256
+
257
+ function transformBasicType(type) {
258
+ if (type === String) {
259
+ return 'string';
260
+ }
261
+
262
+ if (type === Number) {
263
+ return 'number';
264
+ }
265
+
266
+ if (type === Boolean) {
267
+ return 'boolean';
210
268
  }
211
269
 
212
- var propertyObj = target.constructor.IDEProps[propertyKey];
213
- return propertyObj;
270
+ return 'unknown';
214
271
  }
215
272
 
216
- function type(type) {
273
+ function defineTypes(target, key, options, returnTypeFunction) {
274
+ var type = Reflect.getMetadata('design:type', target, key);
275
+ var isArray = type === Array;
276
+ var str = transformBasicType(type);
277
+
278
+ if (str !== 'unknown') {
279
+ type = str;
280
+ }
281
+
282
+ if (returnTypeFunction) {
283
+ var returnType = returnTypeFunction();
284
+
285
+ if (Array.isArray(returnType)) {
286
+ isArray = true;
287
+ type = returnType[0];
288
+ } else {
289
+ type = returnType;
290
+ }
291
+ }
292
+
293
+ var properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
294
+ properties[key] = _assign({
295
+ type: type,
296
+ isArray: isArray
297
+ }, options);
298
+ Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
299
+ }
300
+
301
+ function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
302
+ if (typeof returnTypeFuncOrOptions === 'function') {
303
+ return {
304
+ returnTypeFunc: returnTypeFuncOrOptions,
305
+ options: maybeOptions || {}
306
+ };
307
+ }
308
+
309
+ return {
310
+ options: returnTypeFuncOrOptions || {}
311
+ };
312
+ }
313
+
314
+ function Field(returnTypeFunction, maybeOptions) {
217
315
  return function (target, propertyKey) {
218
- var prop = getIDEPropsPropertyObj(target, propertyKey);
219
- prop.key = propertyKey;
220
- prop.type = type;
316
+ if (typeof propertyKey === 'symbol') {
317
+ throw new SymbolKeysNotSupportedError();
318
+ }
319
+
320
+ var _a = getTypeDecoratorParams(returnTypeFunction, maybeOptions),
321
+ options = _a.options,
322
+ returnTypeFunc = _a.returnTypeFunc;
323
+
324
+ defineTypes(target, propertyKey, options, returnTypeFunc);
221
325
  };
222
326
  }
223
327
 
328
+ var ExecuteMode;
329
+
330
+ (function (ExecuteMode) {
331
+ ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
332
+ ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
333
+ ExecuteMode[ExecuteMode["All"] = 6] = "All";
334
+ })(ExecuteMode || (ExecuteMode = {}));
335
+
336
+ var sleep = function sleep(time) {
337
+ return new Promise(function (resolve) {
338
+ return setTimeout(resolve, time);
339
+ });
340
+ };
341
+
224
342
  var Spine = function (_super) {
225
343
  __extends(Spine, _super);
226
344
 
@@ -386,11 +504,47 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
386
504
 
387
505
  Spine.componentName = 'Spine';
388
506
 
389
- __decorate([type('string')], Spine.prototype, "resource", void 0);
507
+ __decorate([Field({
508
+ type: 'resource'
509
+ }), __metadata("design:type", String)], Spine.prototype, "resource", void 0);
510
+
511
+ __decorate([Field({
512
+ type: 'selector',
513
+ options: function options(that) {
514
+ var _a, _b, _c;
515
+
516
+ return __awaiter(this, void 0, void 0, function () {
517
+ var animations;
518
+ return __generator(this, function (_d) {
519
+ switch (_d.label) {
520
+ case 0:
521
+ return [4, sleep(0)];
522
+
523
+ case 1:
524
+ _d.sent();
525
+
526
+ if (!that.resource || !eva_js.resource.promiseMap[that.resource]) {
527
+ return [2, {}];
528
+ }
529
+
530
+ return [4, eva_js.resource.promiseMap[that.resource]];
531
+
532
+ case 2:
533
+ _d.sent();
534
+
535
+ animations = (_c = (_b = (_a = eva_js.resource.resourcesMap[that.resource]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.ske) === null || _c === void 0 ? void 0 : _c.animations;
536
+ return [2, animations ? Object.keys(animations).reduce(function (prev, key) {
537
+ var _a;
390
538
 
391
- __decorate([type('string')], Spine.prototype, "animationName", void 0);
539
+ return _assign(_assign({}, prev), (_a = {}, _a[key] = key, _a));
540
+ }, {}) : {}];
541
+ }
542
+ });
543
+ });
544
+ }
545
+ }), __metadata("design:type", String)], Spine.prototype, "animationName", void 0);
392
546
 
393
- __decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
547
+ __decorate([Field(), __metadata("design:type", Boolean)], Spine.prototype, "autoPlay", void 0);
394
548
 
395
549
  return Spine;
396
550
  }(eva_js.Component);
@@ -1 +1 @@
1
- function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,r){"use strict";var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function a(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function i(e,t,n,r){var o,a=arguments.length,i=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,n,i):o(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i}function s(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function u(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function c(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}}var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.animationName="",t.autoPlay=!0,t.waitExecuteInfos=[],t}return a(t,e),Object.defineProperty(t.prototype,"armature",{get:function(){return this._armature},set:function(e){var t,n;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var r=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.waitExecuteInfos),o=r.next();!o.done;o=r.next()){var a=o.value;if(a.playType){var i=a.name,s=a.loop,u=a.track;this.play(i,s,u)}else this.stop(a.track)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),t.prototype.init=function(e){e&&_extends(this,e)},t.prototype.onDestroy=function(){this.destroied=!0},t.prototype.play=function(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)}},t.prototype.stop=function(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})},t.prototype.addAnimation=function(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)}},t.prototype.setMix=function(e,t,n){this.armature&&this.armature.stateData.setMix(e,t,n)},t.prototype.getAnim=function(e){void 0===e&&(e=0);try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}},t.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},t.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},t.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},t.componentName="Spine",i([c("string")],t.prototype,"resource",void 0),i([c("string")],t.prototype,"animationName",void 0),i([c("boolean")],t.prototype,"autoPlay",void 0),t}(t.Component),l={};function m(e){var t=e.image;return{tex:r.Texture.from(t),count:0}}var f={};function d(e,t,n,r){var o=null,a=function(e,t){var n=l[e];return n||(n=m(t),l[e]=n),n.tex}(t.image.src,t);new r.core.TextureAtlas(t.atlas,(function(e,t){t(a.baseTexture)}),(function(e){if(e){var a=new r.core.AtlasAttachmentLoader(e),i=new r.core.SkeletonJson(a);n&&(i.scale=n),o=i.readSkeletonData(t.ske)}}));var i={spineData:o,ref:0,imageSrc:t.image.src};return f[e]=i,i}function h(e,t){return s(this,void 0,void 0,(function(){var n;return u(this,(function(r){if(!(n=f[e.name]))if(e.complete)n=d(e.name,e.data,e.scale,t);else if(!n)return[2];return function(e,t){var n=l[e];n||(n=m(t),l[e]=n),n.count++,n.tex}(e.data.image.src,e.data),n.ref++,[2,n.spineData]}))}))}function y(e,t){var n=f[e];n&&(n.ref--,n.ref<=0&&(!function(e){e&&setTimeout((function(){var t=l[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete l[e]))}),100)}(t),delete f[e]))}var v=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.armatures={},t}return a(r,e),r.prototype.init=function(e){var r=this,o=e.pixiSpine;this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=o,this.game.canvas.addEventListener("webglcontextrestored",(function(){var e=r.game.gameObjects,n=[];for(var o in r.armatures)for(var a=+o,i=0;i<e.length;++i){var s=e[i];if(s.id===a){var u=s.getComponent(p);u&&(r.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:p.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:p.componentName}));break}}setTimeout((function(){n.forEach((function(e){r.add(e)}))}),1e3)}),!1)},r.prototype.update=function(t){for(var n in this.armatures)this.armatures[n].update(.001*t.deltaTime),this.armatures[n].updateTransform();e.prototype.update.call(this)},r.prototype.componentChanged=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(n){if("Spine"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD)this.add(e);else if(e.type===t.OBSERVER_TYPE.CHANGE)switch(e.prop.prop[0]){case"resource":this.change(e)}else e.type===t.OBSERVER_TYPE.REMOVE&&this.remove(e);return[2]}))}))},r.prototype.add=function(e,n){var r,o;return s(this,void 0,void 0,(function(){var a,i,s,c,p,l,m,f,d=this;return u(this,(function(u){switch(u.label){case 0:return a=e.component,clearTimeout(a.addHandler),i=e.gameObject.id,s=this.increaseAsyncId(i),[4,t.resource.getResource(a.resource)];case 1:return c=u.sent(),this.validateAsyncId(i,s)?[4,h(c,this.pixiSpine)]:[2];case 2:return p=u.sent(),this.validateAsyncId(i,s)?p?(this.remove(e),(l=null===(o=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===o?void 0:o.getContainer(e.gameObject.id))?(a.lastResource=a.resource,m=new this.pixiSpine.Spine(p),this.armatures[e.gameObject.id]=m,e.gameObject&&e.gameObject.transform&&(f=e.gameObject.transform,m.x=f.size.width*f.origin.x,m.y=f.size.height*f.origin.y),l.addChildAt(m,0),m.update(),m.updateTransform(),a.armature=m,a.emit("loaded",{resource:a.resource}),m.state.addListener({start:function(e,t){a.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){a.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){a.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){a.emit("end",{track:e,name:e.animation.name})},event:function(e,t){a.emit("event",e,t)}}),[2]):[2]):(a.addHandler=setTimeout((function(){a.destroied||(void 0===n&&(n=20),--n>0?d.add(e,n):console.log("retry exceed max times",a.resource))}),1e3),[2]):[2]}}))}))},r.prototype.change=function(e){this.remove(e),this.add(e)},r.prototype.remove=function(e){var n,r,o,a;return s(this,void 0,void 0,(function(){var i,s,c,p;return u(this,(function(u){switch(u.label){case 0:return this.increaseAsyncId(e.gameObject.id),i=e.component,clearTimeout(i.addHandler),s=this.armatures[e.gameObject.id],(c=null===(r=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===r?void 0:r.getContainer(e.gameObject.id))&&s&&c.removeChild(s),i.armature?(i.armature.destroy({children:!0}),[4,t.resource.getResource(i.lastResource)]):[3,2];case 1:y((p=u.sent()).name,null===(a=null===(o=p.data)||void 0===o?void 0:o.image)||void 0===a?void 0:a.src),u.label=2;case 2:return i.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE,[2]}}))}))},r.systemName="SpineSystem",r=i([t.decorators.componentObserver({Spine:["resource"]})],r)}(n.Renderer);return t.resource.registerResourceType("SPINE"),e.Spine=p,e.SpineSystem=v,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);window.EVA.plugin.spineBase=window.EVA.plugin.spineBase||_EVA_IIFE_spineBase;
1
+ function _extends(){return _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(this,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,r){"use strict";var o=function(e,t){return o=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])},o(e,t)};function i(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}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var a=function(){return a=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function s(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function c(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))}function p(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var l=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 i(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}i(t,e)}(Error);var f,m="IDE_PROPERTY_METADATA";function d(e,t,n,r){var o=Reflect.getMetadata("design:type",e,t),i=o===Array,s=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),r){var u=r();Array.isArray(u)?(i=!0,o=u[0]):o=u}var c=Reflect.getMetadata(m,e.constructor)||{};c[t]=a({type:o,isArray:i},n),Reflect.defineMetadata(m,c,e.constructor)}function y(e,t){return function(n,r){if("symbol"==typeof r)throw new l;var o=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(e,t);d(n,r,o.options,o.returnTypeFunc)}}!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(f||(f={}));var h=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.animationName="",t.autoPlay=!0,t.waitExecuteInfos=[],t}return i(n,e),Object.defineProperty(n.prototype,"armature",{get:function(){return this._armature},set:function(e){var t,n;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var r=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.waitExecuteInfos),o=r.next();!o.done;o=r.next()){var i=o.value;if(i.playType){var a=i.name,s=i.loop,u=i.track;this.play(a,s,u)}else this.stop(i.track)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),n.prototype.init=function(e){e&&_extends(this,e)},n.prototype.onDestroy=function(){this.destroied=!0},n.prototype.play=function(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)}},n.prototype.stop=function(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})},n.prototype.addAnimation=function(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)}},n.prototype.setMix=function(e,t,n){this.armature&&this.armature.stateData.setMix(e,t,n)},n.prototype.getAnim=function(e){void 0===e&&(e=0);try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}},n.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},n.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},n.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},n.componentName="Spine",s([y({type:"resource"}),u("design:type",String)],n.prototype,"resource",void 0),s([y({type:"selector",options:function(e){var n,r,o;return c(this,void 0,void 0,(function(){var i;return p(this,(function(s){switch(s.label){case 0:return[4,(u=0,new Promise((function(e){return setTimeout(e,u)})))];case 1:return s.sent(),e.resource&&t.resource.promiseMap[e.resource]?[4,t.resource.promiseMap[e.resource]]:[2,{}];case 2:return s.sent(),[2,(i=null===(o=null===(r=null===(n=t.resource.resourcesMap[e.resource])||void 0===n?void 0:n.data)||void 0===r?void 0:r.ske)||void 0===o?void 0:o.animations)?Object.keys(i).reduce((function(e,t){var n;return a(a({},e),((n={})[t]=t,n))}),{}):{}]}var u}))}))}}),u("design:type",String)],n.prototype,"animationName",void 0),s([y(),u("design:type",Boolean)],n.prototype,"autoPlay",void 0),n}(t.Component),v=h,g={};function b(e){var t=e.image;return{tex:r.Texture.from(t),count:0}}var E={};function w(e,t,n,r){var o=null,i=function(e,t){var n=g[e];return n||(n=b(t),g[e]=n),n.tex}(t.image.src,t);new r.core.TextureAtlas(t.atlas,(function(e,t){t(i.baseTexture)}),(function(e){if(e){var i=new r.core.AtlasAttachmentLoader(e),a=new r.core.SkeletonJson(i);n&&(a.scale=n),o=a.readSkeletonData(t.ske)}}));var a={spineData:o,ref:0,imageSrc:t.image.src};return E[e]=a,a}function O(e,t){return c(this,void 0,void 0,(function(){var n;return p(this,(function(r){if(!(n=E[e.name]))if(e.complete)n=w(e.name,e.data,e.scale,t);else if(!n)return[2];return function(e,t){var n=g[e];n||(n=b(t),g[e]=n),n.count++,n.tex}(e.data.image.src,e.data),n.ref++,[2,n.spineData]}))}))}function x(e,t){var n=E[e];n&&(n.ref--,n.ref<=0&&(!function(e){e&&setTimeout((function(){var t=g[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete g[e]))}),100)}(t),delete E[e]))}var A=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.armatures={},t}return i(r,e),r.prototype.init=function(e){var r=this,o=e.pixiSpine;this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=o,this.game.canvas.addEventListener("webglcontextrestored",(function(){var e=r.game.gameObjects,n=[];for(var o in r.armatures)for(var i=+o,a=0;a<e.length;++a){var s=e[a];if(s.id===i){var u=s.getComponent(v);u&&(r.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:v.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:v.componentName}));break}}setTimeout((function(){n.forEach((function(e){r.add(e)}))}),1e3)}),!1)},r.prototype.update=function(t){for(var n in this.armatures)this.armatures[n].update(.001*t.deltaTime),this.armatures[n].updateTransform();e.prototype.update.call(this)},r.prototype.componentChanged=function(e){return c(this,void 0,void 0,(function(){return p(this,(function(n){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);return[2]}))}))},r.prototype.add=function(e,n){var r,o;return c(this,void 0,void 0,(function(){var i,a,s,u,c,l,f,m,d=this;return p(this,(function(p){switch(p.label){case 0:return i=e.component,clearTimeout(i.addHandler),a=e.gameObject.id,s=this.increaseAsyncId(a),[4,t.resource.getResource(i.resource)];case 1:return u=p.sent(),this.validateAsyncId(a,s)?[4,O(u,this.pixiSpine)]:[2];case 2:return c=p.sent(),this.validateAsyncId(a,s)?c?(this.remove(e),(l=null===(o=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===o?void 0:o.getContainer(e.gameObject.id))?(i.lastResource=i.resource,f=new this.pixiSpine.Spine(c),this.armatures[e.gameObject.id]=f,e.gameObject&&e.gameObject.transform&&(m=e.gameObject.transform,f.x=m.size.width*m.origin.x,f.y=m.size.height*m.origin.y),l.addChildAt(f,0),f.update(),f.updateTransform(),i.armature=f,i.emit("loaded",{resource:i.resource}),f.state.addListener({start:function(e,t){i.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){i.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){i.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){i.emit("end",{track:e,name:e.animation.name})},event:function(e,t){i.emit("event",e,t)}}),[2]):[2]):(i.addHandler=setTimeout((function(){i.destroied||(void 0===n&&(n=20),--n>0?d.add(e,n):console.log("retry exceed max times",i.resource))}),1e3),[2]):[2]}}))}))},r.prototype.change=function(e){this.remove(e),this.add(e)},r.prototype.remove=function(e){var n,r,o,i;return c(this,void 0,void 0,(function(){var a,s,u,c;return p(this,(function(p){switch(p.label){case 0:return this.increaseAsyncId(e.gameObject.id),a=e.component,clearTimeout(a.addHandler),s=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))&&s&&u.removeChild(s),a.armature?(a.armature.destroy({children:!0}),[4,t.resource.getResource(a.lastResource)]):[3,2];case 1:x((c=p.sent()).name,null===(i=null===(o=c.data)||void 0===o?void 0:o.image)||void 0===i?void 0:i.src),p.label=2;case 2:return a.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE,[2]}}))}))},r.systemName="SpineSystem",r=s([t.decorators.componentObserver({Spine:["resource"]})],r)}(n.Renderer),S=A;return t.resource.registerResourceType("SPINE"),e.Spine=v,e.SpineSystem=S,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);window.EVA.plugin.spineBase=window.EVA.plugin.spineBase||_EVA_IIFE_spineBase;
@@ -36,6 +36,17 @@ function __extends(d, b) {
36
36
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
37
37
  }
38
38
 
39
+ var __assign = function() {
40
+ __assign = Object.assign || function __assign(t) {
41
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
42
+ s = arguments[i];
43
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
44
+ }
45
+ return t;
46
+ };
47
+ return __assign.apply(this, arguments);
48
+ };
49
+
39
50
  function __decorate(decorators, target, key, desc) {
40
51
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
41
52
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -43,6 +54,10 @@ function __decorate(decorators, target, key, desc) {
43
54
  return c > 3 && r && Object.defineProperty(target, key, r), r;
44
55
  }
45
56
 
57
+ function __metadata(metadataKey, metadataValue) {
58
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
59
+ }
60
+
46
61
  function __awaiter(thisArg, _arguments, P, generator) {
47
62
  return new (P || (P = Promise))(function (resolve, reject) {
48
63
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -91,6 +106,7 @@ function __values(o) {
91
106
  };
92
107
  }
93
108
 
109
+ var sleep = function (time) { return new Promise(function (resolve) { return setTimeout(resolve, time); }); };
94
110
  var Spine = (function (_super) {
95
111
  __extends(Spine, _super);
96
112
  function Spine() {
@@ -154,7 +170,7 @@ var Spine = (function (_super) {
154
170
  playType: true,
155
171
  name: name,
156
172
  loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
157
- track: track
173
+ track: track,
158
174
  });
159
175
  }
160
176
  else {
@@ -172,7 +188,7 @@ var Spine = (function (_super) {
172
188
  if (!this.armature) {
173
189
  this.waitExecuteInfos.push({
174
190
  playType: false,
175
- track: track
191
+ track: track,
176
192
  });
177
193
  return;
178
194
  }
@@ -235,13 +251,42 @@ var Spine = (function (_super) {
235
251
  };
236
252
  Spine.componentName = 'Spine';
237
253
  __decorate([
238
- inspectorDecorator.type('string')
254
+ inspectorDecorator.Field({ type: 'resource' }),
255
+ __metadata("design:type", String)
239
256
  ], Spine.prototype, "resource", void 0);
240
257
  __decorate([
241
- inspectorDecorator.type('string')
258
+ inspectorDecorator.Field({
259
+ type: 'selector',
260
+ options: function (that) {
261
+ var _a, _b, _c;
262
+ return __awaiter(this, void 0, void 0, function () {
263
+ var animations;
264
+ return __generator(this, function (_d) {
265
+ switch (_d.label) {
266
+ case 0: return [4, sleep(0)];
267
+ case 1:
268
+ _d.sent();
269
+ if (!that.resource || !eva_js.resource.promiseMap[that.resource]) {
270
+ return [2, {}];
271
+ }
272
+ return [4, eva_js.resource.promiseMap[that.resource]];
273
+ case 2:
274
+ _d.sent();
275
+ animations = (_c = (_b = (_a = eva_js.resource.resourcesMap[that.resource]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.ske) === null || _c === void 0 ? void 0 : _c.animations;
276
+ return [2, animations ? Object.keys(animations).reduce(function (prev, key) {
277
+ var _a;
278
+ return (__assign(__assign({}, prev), (_a = {}, _a[key] = key, _a)));
279
+ }, {}) : {}];
280
+ }
281
+ });
282
+ });
283
+ },
284
+ }),
285
+ __metadata("design:type", String)
242
286
  ], Spine.prototype, "animationName", void 0);
243
287
  __decorate([
244
- inspectorDecorator.type('boolean')
288
+ inspectorDecorator.Field(),
289
+ __metadata("design:type", Boolean)
245
290
  ], Spine.prototype, "autoPlay", void 0);
246
291
  return Spine;
247
292
  }(eva_js.Component));
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),r=require("@eva/inspector-decorator"),n=require("pixi.js"),a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function o(e,t){function r(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function i(e,t,r,n){var a,o=arguments.length,i=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,r,i):a(t,r))||i);return o>3&&i&&Object.defineProperty(t,r,i),i}function s(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){e.done?a(e.value):new r((function(t){t(e.value)})).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function u(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var c=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.animationName="",t.autoPlay=!0,t.waitExecuteInfos=[],t}return o(t,e),Object.defineProperty(t.prototype,"armature",{get:function(){return this._armature},set:function(e){var t,r;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var n=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(this.waitExecuteInfos),a=n.next();!a.done;a=n.next()){var o=a.value;if(o.playType){var i=o.name,s=o.loop,u=o.track;this.play(i,s,u)}else this.stop(o.track)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),t.prototype.init=function(e){e&&Object.assign(this,e)},t.prototype.onDestroy=function(){this.destroied=!0},t.prototype.play=function(e,t,r){try{e&&(this.animationName=e),this.armature?(void 0===r&&(r=0),this.armature.state.setAnimation(r,this.animationName,t)):this.waitExecuteInfos.push({playType:!0,name:e,loop:null!=t?t:this.autoPlay,track:r})}catch(e){console.log(e)}},t.prototype.stop=function(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})},t.prototype.addAnimation=function(e,t,r,n){try{this.armature&&(void 0===n&&(n=0),this.armature.state.addAnimation(n,e,r,t))}catch(e){console.log(e)}},t.prototype.setMix=function(e,t,r){this.armature&&this.armature.stateData.setMix(e,t,r)},t.prototype.getAnim=function(e){void 0===e&&(e=0);try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}},t.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},t.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},t.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},t.componentName="Spine",i([r.type("string")],t.prototype,"resource",void 0),i([r.type("string")],t.prototype,"animationName",void 0),i([r.type("boolean")],t.prototype,"autoPlay",void 0),t}(e.Component),p={};function l(e){var t=e.image;return{tex:n.Texture.from(t),count:0}}var m={};function f(e,t,r,n){var a=null,o=function(e,t){var r=p[e];return r||(r=l(t),p[e]=r),r.tex}(t.image.src,t);new n.core.TextureAtlas(t.atlas,(function(e,t){t(o.baseTexture)}),(function(e){if(e){var o=new n.core.AtlasAttachmentLoader(e),i=new n.core.SkeletonJson(o);r&&(i.scale=r),a=i.readSkeletonData(t.ske)}}));var i={spineData:a,ref:0,imageSrc:t.image.src};return m[e]=i,i}function d(e,t){return s(this,void 0,void 0,(function(){var r;return u(this,(function(n){if(!(r=m[e.name]))if(e.complete)r=f(e.name,e.data,e.scale,t);else if(!r)return[2];return function(e,t){var r=p[e];r||(r=l(t),p[e]=r),r.count++,r.tex}(e.data.image.src,e.data),r.ref++,[2,r.spineData]}))}))}function h(e,t){var r=m[e];r&&(r.ref--,r.ref<=0&&(!function(e){e&&setTimeout((function(){var t=p[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete p[e]))}),100)}(t),delete m[e]))}var y=function(r){function n(){var e=null!==r&&r.apply(this,arguments)||this;return e.armatures={},e}return o(n,r),n.prototype.init=function(r){var n=this,a=r.pixiSpine;this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=a,this.game.canvas.addEventListener("webglcontextrestored",(function(){var t=n.game.gameObjects,r=[];for(var a in n.armatures)for(var o=+a,i=0;i<t.length;++i){var s=t[i];if(s.id===o){var u=s.getComponent(c);u&&(n.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:c.componentName}),r.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:c.componentName}));break}}setTimeout((function(){r.forEach((function(e){n.add(e)}))}),1e3)}),!1)},n.prototype.update=function(e){for(var t in this.armatures)this.armatures[t].update(.001*e.deltaTime),this.armatures[t].updateTransform();r.prototype.update.call(this)},n.prototype.componentChanged=function(t){return s(this,void 0,void 0,(function(){return u(this,(function(r){if("Spine"===t.componentName)if(t.type===e.OBSERVER_TYPE.ADD)this.add(t);else if(t.type===e.OBSERVER_TYPE.CHANGE)switch(t.prop.prop[0]){case"resource":this.change(t)}else t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t);return[2]}))}))},n.prototype.add=function(t,r){var n,a;return s(this,void 0,void 0,(function(){var o,i,s,c,p,l,m,f,h=this;return u(this,(function(u){switch(u.label){case 0:return o=t.component,clearTimeout(o.addHandler),i=t.gameObject.id,s=this.increaseAsyncId(i),[4,e.resource.getResource(o.resource)];case 1:return c=u.sent(),this.validateAsyncId(i,s)?[4,d(c,this.pixiSpine)]:[2];case 2:return p=u.sent(),this.validateAsyncId(i,s)?p?(this.remove(t),(l=null===(a=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===a?void 0:a.getContainer(t.gameObject.id))?(o.lastResource=o.resource,m=new this.pixiSpine.Spine(p),this.armatures[t.gameObject.id]=m,t.gameObject&&t.gameObject.transform&&(f=t.gameObject.transform,m.x=f.size.width*f.origin.x,m.y=f.size.height*f.origin.y),l.addChildAt(m,0),m.update(),m.updateTransform(),o.armature=m,o.emit("loaded",{resource:o.resource}),m.state.addListener({start:function(e,t){o.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){o.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){o.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){o.emit("end",{track:e,name:e.animation.name})},event:function(e,t){o.emit("event",e,t)}}),[2]):[2]):(o.addHandler=setTimeout((function(){o.destroied||(void 0===r&&(r=20),--r>0?h.add(t,r):console.log("retry exceed max times",o.resource))}),1e3),[2]):[2]}}))}))},n.prototype.change=function(e){this.remove(e),this.add(e)},n.prototype.remove=function(t){var r,n,a,o;return s(this,void 0,void 0,(function(){var i,s,c,p;return u(this,(function(u){switch(u.label){case 0:return this.increaseAsyncId(t.gameObject.id),i=t.component,clearTimeout(i.addHandler),s=this.armatures[t.gameObject.id],(c=null===(n=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===n?void 0:n.getContainer(t.gameObject.id))&&s&&c.removeChild(s),i.armature?(i.armature.destroy({children:!0}),[4,e.resource.getResource(i.lastResource)]):[3,2];case 1:h((p=u.sent()).name,null===(o=null===(a=p.data)||void 0===a?void 0:a.image)||void 0===o?void 0:o.src),u.label=2;case 2:return i.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE,[2]}}))}))},n.systemName="SpineSystem",n=i([e.decorators.componentObserver({Spine:["resource"]})],n)}(t.Renderer);e.resource.registerResourceType("SPINE"),exports.Spine=c,exports.SpineSystem=y;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),r=require("@eva/inspector-decorator"),n=require("pixi.js"),o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},o(e,t)};function a(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var i=function(){return i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},i.apply(this,arguments)};function s(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function c(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{u(n.next(e))}catch(e){a(e)}}function s(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){e.done?o(e.value):new r((function(t){t(e.value)})).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function l(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var p=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.resource="",e.animationName="",e.autoPlay=!0,e.waitExecuteInfos=[],e}return a(n,t),Object.defineProperty(n.prototype,"armature",{get:function(){return this._armature},set:function(e){var t,r;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var n=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(this.waitExecuteInfos),o=n.next();!o.done;o=n.next()){var a=o.value;if(a.playType){var i=a.name,s=a.loop,u=a.track;this.play(i,s,u)}else this.stop(a.track)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),n.prototype.init=function(e){e&&Object.assign(this,e)},n.prototype.onDestroy=function(){this.destroied=!0},n.prototype.play=function(e,t,r){try{e&&(this.animationName=e),this.armature?(void 0===r&&(r=0),this.armature.state.setAnimation(r,this.animationName,t)):this.waitExecuteInfos.push({playType:!0,name:e,loop:null!=t?t:this.autoPlay,track:r})}catch(e){console.log(e)}},n.prototype.stop=function(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})},n.prototype.addAnimation=function(e,t,r,n){try{this.armature&&(void 0===n&&(n=0),this.armature.state.addAnimation(n,e,r,t))}catch(e){console.log(e)}},n.prototype.setMix=function(e,t,r){this.armature&&this.armature.stateData.setMix(e,t,r)},n.prototype.getAnim=function(e){void 0===e&&(e=0);try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}},n.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},n.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},n.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},n.componentName="Spine",s([r.Field({type:"resource"}),u("design:type",String)],n.prototype,"resource",void 0),s([r.Field({type:"selector",options:function(t){var r,n,o;return c(this,void 0,void 0,(function(){var a;return l(this,(function(s){switch(s.label){case 0:return[4,(u=0,new Promise((function(e){return setTimeout(e,u)})))];case 1:return s.sent(),t.resource&&e.resource.promiseMap[t.resource]?[4,e.resource.promiseMap[t.resource]]:[2,{}];case 2:return s.sent(),[2,(a=null===(o=null===(n=null===(r=e.resource.resourcesMap[t.resource])||void 0===r?void 0:r.data)||void 0===n?void 0:n.ske)||void 0===o?void 0:o.animations)?Object.keys(a).reduce((function(e,t){var r;return i(i({},e),((r={})[t]=t,r))}),{}):{}]}var u}))}))}}),u("design:type",String)],n.prototype,"animationName",void 0),s([r.Field(),u("design:type",Boolean)],n.prototype,"autoPlay",void 0),n}(e.Component),m={};function f(e){var t=e.image;return{tex:n.Texture.from(t),count:0}}var d={};function h(e,t,r,n){var o=null,a=function(e,t){var r=m[e];return r||(r=f(t),m[e]=r),r.tex}(t.image.src,t);new n.core.TextureAtlas(t.atlas,(function(e,t){t(a.baseTexture)}),(function(e){if(e){var a=new n.core.AtlasAttachmentLoader(e),i=new n.core.SkeletonJson(a);r&&(i.scale=r),o=i.readSkeletonData(t.ske)}}));var i={spineData:o,ref:0,imageSrc:t.image.src};return d[e]=i,i}function y(e,t){return c(this,void 0,void 0,(function(){var r;return l(this,(function(n){if(!(r=d[e.name]))if(e.complete)r=h(e.name,e.data,e.scale,t);else if(!r)return[2];return function(e,t){var r=m[e];r||(r=f(t),m[e]=r),r.count++,r.tex}(e.data.image.src,e.data),r.ref++,[2,r.spineData]}))}))}function v(e,t){var r=d[e];r&&(r.ref--,r.ref<=0&&(!function(e){e&&setTimeout((function(){var t=m[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete m[e]))}),100)}(t),delete d[e]))}var g=function(r){function n(){var e=null!==r&&r.apply(this,arguments)||this;return e.armatures={},e}return a(n,r),n.prototype.init=function(r){var n=this,o=r.pixiSpine;this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=o,this.game.canvas.addEventListener("webglcontextrestored",(function(){var t=n.game.gameObjects,r=[];for(var o in n.armatures)for(var a=+o,i=0;i<t.length;++i){var s=t[i];if(s.id===a){var u=s.getComponent(p);u&&(n.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:p.componentName}),r.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:p.componentName}));break}}setTimeout((function(){r.forEach((function(e){n.add(e)}))}),1e3)}),!1)},n.prototype.update=function(e){for(var t in this.armatures)this.armatures[t].update(.001*e.deltaTime),this.armatures[t].updateTransform();r.prototype.update.call(this)},n.prototype.componentChanged=function(t){return c(this,void 0,void 0,(function(){return l(this,(function(r){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);return[2]}))}))},n.prototype.add=function(t,r){var n,o;return c(this,void 0,void 0,(function(){var a,i,s,u,c,p,m,f,d=this;return l(this,(function(l){switch(l.label){case 0:return a=t.component,clearTimeout(a.addHandler),i=t.gameObject.id,s=this.increaseAsyncId(i),[4,e.resource.getResource(a.resource)];case 1:return u=l.sent(),this.validateAsyncId(i,s)?[4,y(u,this.pixiSpine)]:[2];case 2:return c=l.sent(),this.validateAsyncId(i,s)?c?(this.remove(t),(p=null===(o=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===o?void 0:o.getContainer(t.gameObject.id))?(a.lastResource=a.resource,m=new this.pixiSpine.Spine(c),this.armatures[t.gameObject.id]=m,t.gameObject&&t.gameObject.transform&&(f=t.gameObject.transform,m.x=f.size.width*f.origin.x,m.y=f.size.height*f.origin.y),p.addChildAt(m,0),m.update(),m.updateTransform(),a.armature=m,a.emit("loaded",{resource:a.resource}),m.state.addListener({start:function(e,t){a.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){a.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){a.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){a.emit("end",{track:e,name:e.animation.name})},event:function(e,t){a.emit("event",e,t)}}),[2]):[2]):(a.addHandler=setTimeout((function(){a.destroied||(void 0===r&&(r=20),--r>0?d.add(t,r):console.log("retry exceed max times",a.resource))}),1e3),[2]):[2]}}))}))},n.prototype.change=function(e){this.remove(e),this.add(e)},n.prototype.remove=function(t){var r,n,o,a;return c(this,void 0,void 0,(function(){var i,s,u,c;return l(this,(function(l){switch(l.label){case 0:return this.increaseAsyncId(t.gameObject.id),i=t.component,clearTimeout(i.addHandler),s=this.armatures[t.gameObject.id],(u=null===(n=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===n?void 0:n.getContainer(t.gameObject.id))&&s&&u.removeChild(s),i.armature?(i.armature.destroy({children:!0}),[4,e.resource.getResource(i.lastResource)]):[3,2];case 1:v((c=l.sent()).name,null===(a=null===(o=c.data)||void 0===o?void 0:o.image)||void 0===a?void 0:a.src),l.label=2;case 2:return i.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE,[2]}}))}))},n.systemName="SpineSystem",n=s([e.decorators.componentObserver({Spine:["resource"]})],n)}(t.Renderer);e.resource.registerResourceType("SPINE"),exports.Spine=p,exports.SpineSystem=g;
@@ -1,6 +1,6 @@
1
- import { Component, OBSERVER_TYPE, decorators, resource } from '@eva/eva.js';
1
+ import { Component, resource, OBSERVER_TYPE, decorators } from '@eva/eva.js';
2
2
  import { RendererSystem, Renderer } from '@eva/plugin-renderer';
3
- import { type } from '@eva/inspector-decorator';
3
+ import { Field } from '@eva/inspector-decorator';
4
4
  import { Texture } from 'pixi.js';
5
5
 
6
6
  /*! *****************************************************************************
@@ -32,6 +32,17 @@ function __extends(d, b) {
32
32
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
33
33
  }
34
34
 
35
+ var __assign = function() {
36
+ __assign = Object.assign || function __assign(t) {
37
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
38
+ s = arguments[i];
39
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
40
+ }
41
+ return t;
42
+ };
43
+ return __assign.apply(this, arguments);
44
+ };
45
+
35
46
  function __decorate(decorators, target, key, desc) {
36
47
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
37
48
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -39,6 +50,10 @@ function __decorate(decorators, target, key, desc) {
39
50
  return c > 3 && r && Object.defineProperty(target, key, r), r;
40
51
  }
41
52
 
53
+ function __metadata(metadataKey, metadataValue) {
54
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
55
+ }
56
+
42
57
  function __awaiter(thisArg, _arguments, P, generator) {
43
58
  return new (P || (P = Promise))(function (resolve, reject) {
44
59
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -87,6 +102,7 @@ function __values(o) {
87
102
  };
88
103
  }
89
104
 
105
+ var sleep = function (time) { return new Promise(function (resolve) { return setTimeout(resolve, time); }); };
90
106
  var Spine = (function (_super) {
91
107
  __extends(Spine, _super);
92
108
  function Spine() {
@@ -150,7 +166,7 @@ var Spine = (function (_super) {
150
166
  playType: true,
151
167
  name: name,
152
168
  loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
153
- track: track
169
+ track: track,
154
170
  });
155
171
  }
156
172
  else {
@@ -168,7 +184,7 @@ var Spine = (function (_super) {
168
184
  if (!this.armature) {
169
185
  this.waitExecuteInfos.push({
170
186
  playType: false,
171
- track: track
187
+ track: track,
172
188
  });
173
189
  return;
174
190
  }
@@ -231,13 +247,42 @@ var Spine = (function (_super) {
231
247
  };
232
248
  Spine.componentName = 'Spine';
233
249
  __decorate([
234
- type('string')
250
+ Field({ type: 'resource' }),
251
+ __metadata("design:type", String)
235
252
  ], Spine.prototype, "resource", void 0);
236
253
  __decorate([
237
- type('string')
254
+ Field({
255
+ type: 'selector',
256
+ options: function (that) {
257
+ var _a, _b, _c;
258
+ return __awaiter(this, void 0, void 0, function () {
259
+ var animations;
260
+ return __generator(this, function (_d) {
261
+ switch (_d.label) {
262
+ case 0: return [4, sleep(0)];
263
+ case 1:
264
+ _d.sent();
265
+ if (!that.resource || !resource.promiseMap[that.resource]) {
266
+ return [2, {}];
267
+ }
268
+ return [4, resource.promiseMap[that.resource]];
269
+ case 2:
270
+ _d.sent();
271
+ animations = (_c = (_b = (_a = resource.resourcesMap[that.resource]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.ske) === null || _c === void 0 ? void 0 : _c.animations;
272
+ return [2, animations ? Object.keys(animations).reduce(function (prev, key) {
273
+ var _a;
274
+ return (__assign(__assign({}, prev), (_a = {}, _a[key] = key, _a)));
275
+ }, {}) : {}];
276
+ }
277
+ });
278
+ });
279
+ },
280
+ }),
281
+ __metadata("design:type", String)
238
282
  ], Spine.prototype, "animationName", void 0);
239
283
  __decorate([
240
- type('boolean')
284
+ Field(),
285
+ __metadata("design:type", Boolean)
241
286
  ], Spine.prototype, "autoPlay", void 0);
242
287
  return Spine;
243
288
  }(Component));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/spine-base",
3
- "version": "1.2.7-editor.1",
3
+ "version": "1.2.7-editor.10",
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": "1.2.7-editor.1",
22
- "@eva/plugin-renderer": "1.2.7-editor.1",
23
- "@eva/inspector-decorator": "0.1.0-alpha.1",
21
+ "@eva/eva.js": "1.2.7-editor.10",
22
+ "@eva/plugin-renderer": "1.2.7-editor.10",
23
+ "@eva/inspector-decorator": "0.1.0-alpha.2",
24
24
  "pixi.js": "^4.8.9"
25
25
  }
26
26
  }
@@ -1,550 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
4
- import { __extends, __values, __decorate, __awaiter, __generator } from 'tslib';
5
- import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
6
- import { type } from '@eva/inspector-decorator';
7
- import { Texture } from '@eva/miniprogram-pixi';
8
-
9
- var Spine = function (_super) {
10
- __extends(Spine, _super);
11
-
12
- function Spine() {
13
- var _this = _super !== null && _super.apply(this, arguments) || this;
14
-
15
- _this.resource = '';
16
- _this.animationName = '';
17
- _this.autoPlay = true;
18
- _this.waitExecuteInfos = [];
19
- return _this;
20
- }
21
-
22
- Object.defineProperty(Spine.prototype, "armature", {
23
- get: function get() {
24
- return this._armature;
25
- },
26
- set: function set(val) {
27
- var e_1, _a;
28
-
29
- this._armature = val;
30
- if (!val) return;
31
-
32
- if (this.autoPlay) {
33
- this.play(this.animationName);
34
- }
35
-
36
- try {
37
- for (var _b = __values(this.waitExecuteInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
38
- var info = _c.value;
39
-
40
- if (info.playType) {
41
- var name_1 = info.name,
42
- loop = info.loop,
43
- track = info.track;
44
- this.play(name_1, loop, track);
45
- } else {
46
- this.stop(info.track);
47
- }
48
- }
49
- } catch (e_1_1) {
50
- e_1 = {
51
- error: e_1_1
52
- };
53
- } finally {
54
- try {
55
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
56
- } finally {
57
- if (e_1) throw e_1.error;
58
- }
59
- }
60
-
61
- this.waitExecuteInfos = [];
62
- },
63
- enumerable: false,
64
- configurable: true
65
- });
66
-
67
- Spine.prototype.init = function (obj) {
68
- if (!obj) return;
69
-
70
- _extends(this, obj);
71
- };
72
-
73
- Spine.prototype.onDestroy = function () {
74
- this.destroied = true;
75
- };
76
-
77
- Spine.prototype.play = function (name, loop, track) {
78
- try {
79
- if (name) this.animationName = name;
80
-
81
- if (!this.armature) {
82
- this.waitExecuteInfos.push({
83
- playType: true,
84
- name: name,
85
- loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
86
- track: track
87
- });
88
- } else {
89
- if (track === undefined) {
90
- track = 0;
91
- }
92
-
93
- this.armature.state.setAnimation(track, this.animationName, loop);
94
- }
95
- } catch (e) {
96
- console.log(e);
97
- }
98
- };
99
-
100
- Spine.prototype.stop = function (track) {
101
- if (!this.armature) {
102
- this.waitExecuteInfos.push({
103
- playType: false,
104
- track: track
105
- });
106
- return;
107
- }
108
-
109
- if (track === undefined) {
110
- track = 0;
111
- }
112
-
113
- this.armature.state.setEmptyAnimation(track, 0);
114
- };
115
-
116
- Spine.prototype.addAnimation = function (name, delay, loop, track) {
117
- try {
118
- if (!this.armature) {} else {
119
- if (track === undefined) {
120
- track = 0;
121
- }
122
-
123
- this.armature.state.addAnimation(track, name, loop, delay);
124
- }
125
- } catch (e) {
126
- console.log(e);
127
- }
128
- };
129
-
130
- Spine.prototype.setMix = function (from, to, duration) {
131
- if (!this.armature) ;else {
132
- this.armature.stateData.setMix(from, to, duration);
133
- }
134
- };
135
-
136
- Spine.prototype.getAnim = function (track) {
137
- if (track === void 0) {
138
- track = 0;
139
- }
140
-
141
- try {
142
- if (!this.armature) {} else {
143
- return this.armature.state.tracks[track].animation.name;
144
- }
145
- } catch (e) {
146
- console.log(e);
147
- }
148
- };
149
-
150
- Spine.prototype.setDefaultMix = function (duration) {
151
- if (!this.armature) ;else {
152
- this.armature.stateData.defaultMix = duration;
153
- }
154
- };
155
-
156
- Spine.prototype.setAttachment = function (slotName, attachmentName) {
157
- if (!this.armature) {
158
- return;
159
- }
160
-
161
- this.armature.skeleton.setAttachment(slotName, attachmentName);
162
- };
163
-
164
- Spine.prototype.getBone = function (boneName) {
165
- if (!this.armature) {
166
- return;
167
- }
168
-
169
- return this.armature.skeleton.findBone(boneName);
170
- };
171
-
172
- Spine.componentName = 'Spine';
173
-
174
- __decorate([type('string')], Spine.prototype, "resource", void 0);
175
-
176
- __decorate([type('string')], Spine.prototype, "animationName", void 0);
177
-
178
- __decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
179
-
180
- return Spine;
181
- }(Component);
182
-
183
- var Spine$1 = Spine;
184
- var texCache = {};
185
-
186
- function cacheImage(data) {
187
- var oldImg = data.image;
188
- return {
189
- tex: Texture.from(oldImg),
190
- count: 0
191
- };
192
- }
193
-
194
- function retainTexture(name, data) {
195
- var cache = texCache[name];
196
-
197
- if (!cache) {
198
- cache = cacheImage(data);
199
- texCache[name] = cache;
200
- }
201
-
202
- cache.count++;
203
- return cache.tex;
204
- }
205
-
206
- function getTexture(imageSrc, data) {
207
- var cache = texCache[imageSrc];
208
-
209
- if (!cache) {
210
- cache = cacheImage(data);
211
- texCache[imageSrc] = cache;
212
- }
213
-
214
- return cache.tex;
215
- }
216
-
217
- function releaseTexture(imageSrc) {
218
- if (!imageSrc) return;
219
- setTimeout(function () {
220
- var cache = texCache[imageSrc];
221
-
222
- if (cache) {
223
- cache.count--;
224
-
225
- if (cache.count <= 0) {
226
- if (cache.tex) {
227
- cache.tex.destroy(true);
228
- cache.tex = null;
229
- }
230
-
231
- delete texCache[imageSrc];
232
- }
233
- }
234
- }, 100);
235
- }
236
-
237
- var dataMap = {};
238
-
239
- function createSpineData(name, data, scale, pixiSpine) {
240
- var spineData = null;
241
- var img = getTexture(data.image.src, data);
242
- new pixiSpine.core.TextureAtlas(data.atlas, function (line, callback) {
243
- callback(img.baseTexture);
244
- }, function (spineAtlas) {
245
- if (spineAtlas) {
246
- var attachmentLoader = new pixiSpine.core.AtlasAttachmentLoader(spineAtlas);
247
- var spineJsonParser = new pixiSpine.core.SkeletonJson(attachmentLoader);
248
-
249
- if (scale) {
250
- spineJsonParser.scale = scale;
251
- }
252
-
253
- spineData = spineJsonParser.readSkeletonData(data.ske);
254
- }
255
- });
256
- var obj = {
257
- spineData: spineData,
258
- ref: 0,
259
- imageSrc: data.image.src
260
- };
261
- dataMap[name] = obj;
262
- return obj;
263
- }
264
-
265
- function getSpineData(res, pixiSpine) {
266
- return __awaiter(this, void 0, void 0, function () {
267
- var data;
268
- return __generator(this, function (_a) {
269
- data = dataMap[res.name];
270
-
271
- if (!data) {
272
- if (res.complete) {
273
- data = createSpineData(res.name, res.data, res.scale, pixiSpine);
274
- } else if (!data) {
275
- return [2];
276
- }
277
- }
278
-
279
- retainTexture(res.data.image.src, res.data);
280
- data.ref++;
281
- return [2, data.spineData];
282
- });
283
- });
284
- }
285
-
286
- function releaseSpineData(resourceName, imageSrc) {
287
- var data = dataMap[resourceName];
288
-
289
- if (!data) {
290
- return;
291
- }
292
-
293
- data.ref--;
294
-
295
- if (data.ref <= 0) {
296
- releaseTexture(imageSrc);
297
- delete dataMap[resourceName];
298
- }
299
- }
300
-
301
- var MaxRetryCount = 20;
302
-
303
- var SpineSystem = function (_super) {
304
- __extends(SpineSystem, _super);
305
-
306
- function SpineSystem() {
307
- var _this = _super !== null && _super.apply(this, arguments) || this;
308
-
309
- _this.armatures = {};
310
- return _this;
311
- }
312
-
313
- SpineSystem.prototype.init = function (_a) {
314
- var _this = this;
315
-
316
- var pixiSpine = _a.pixiSpine;
317
- this.renderSystem = this.game.getSystem(RendererSystem);
318
- this.renderSystem.rendererManager.register(this);
319
- this.pixiSpine = pixiSpine;
320
- this.game.canvas.addEventListener('webglcontextrestored', function () {
321
- var objs = _this.game.gameObjects;
322
- var toAdd = [];
323
-
324
- for (var k in _this.armatures) {
325
- var id = +k;
326
-
327
- for (var i = 0; i < objs.length; ++i) {
328
- var obj = objs[i];
329
-
330
- if (obj.id === id) {
331
- var sp = obj.getComponent(Spine$1);
332
-
333
- if (sp) {
334
- _this.remove({
335
- type: OBSERVER_TYPE.REMOVE,
336
- gameObject: obj,
337
- component: sp,
338
- componentName: Spine$1.componentName
339
- });
340
-
341
- toAdd.push({
342
- type: OBSERVER_TYPE.ADD,
343
- gameObject: obj,
344
- component: sp,
345
- componentName: Spine$1.componentName
346
- });
347
- }
348
-
349
- break;
350
- }
351
- }
352
- }
353
-
354
- setTimeout(function () {
355
- toAdd.forEach(function (obj) {
356
- _this.add(obj);
357
- });
358
- }, 1000);
359
- }, false);
360
- };
361
-
362
- SpineSystem.prototype.update = function (e) {
363
- for (var key in this.armatures) {
364
- this.armatures[key].update(e.deltaTime * 0.001);
365
- this.armatures[key].updateTransform();
366
- }
367
-
368
- _super.prototype.update.call(this);
369
- };
370
-
371
- SpineSystem.prototype.componentChanged = function (changed) {
372
- return __awaiter(this, void 0, void 0, function () {
373
- return __generator(this, function (_a) {
374
- if (changed.componentName === 'Spine') {
375
- if (changed.type === OBSERVER_TYPE.ADD) {
376
- this.add(changed);
377
- } else if (changed.type === OBSERVER_TYPE.CHANGE) {
378
- switch (changed.prop.prop[0]) {
379
- case 'resource':
380
- this.change(changed);
381
- break;
382
- }
383
- } else if (changed.type === OBSERVER_TYPE.REMOVE) {
384
- this.remove(changed);
385
- }
386
- }
387
-
388
- return [2];
389
- });
390
- });
391
- };
392
-
393
- SpineSystem.prototype.add = function (changed, count) {
394
- var _a, _b;
395
-
396
- return __awaiter(this, void 0, void 0, function () {
397
- var component, gameObjectId, asyncId, res, spineData, container, armature, tran;
398
-
399
- var _this = this;
400
-
401
- return __generator(this, function (_c) {
402
- switch (_c.label) {
403
- case 0:
404
- component = changed.component;
405
- clearTimeout(component.addHandler);
406
- gameObjectId = changed.gameObject.id;
407
- asyncId = this.increaseAsyncId(gameObjectId);
408
- return [4, resource.getResource(component.resource)];
409
-
410
- case 1:
411
- res = _c.sent();
412
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
413
- return [4, getSpineData(res, this.pixiSpine)];
414
-
415
- case 2:
416
- spineData = _c.sent();
417
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
418
-
419
- if (!spineData) {
420
- component.addHandler = setTimeout(function () {
421
- if (!component.destroied) {
422
- if (count === undefined) {
423
- count = MaxRetryCount;
424
- }
425
-
426
- count--;
427
-
428
- if (count > 0) {
429
- _this.add(changed, count);
430
- } else {
431
- console.log('retry exceed max times', component.resource);
432
- }
433
- }
434
- }, 1000);
435
- return [2];
436
- }
437
-
438
- this.remove(changed);
439
- container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
440
-
441
- if (!container) {
442
- return [2];
443
- }
444
-
445
- component.lastResource = component.resource;
446
- armature = new this.pixiSpine.Spine(spineData);
447
- this.armatures[changed.gameObject.id] = armature;
448
-
449
- if (changed.gameObject && changed.gameObject.transform) {
450
- tran = changed.gameObject.transform;
451
- armature.x = tran.size.width * tran.origin.x;
452
- armature.y = tran.size.height * tran.origin.y;
453
- }
454
-
455
- container.addChildAt(armature, 0);
456
- armature.update();
457
- armature.updateTransform();
458
- component.armature = armature;
459
- component.emit('loaded', {
460
- resource: component.resource
461
- });
462
- armature.state.addListener({
463
- start: function start(track, event) {
464
- component.emit('start', {
465
- track: track,
466
- name: track.animation.name
467
- });
468
- },
469
- complete: function complete(track, event) {
470
- component.emit('complete', {
471
- track: track,
472
- name: track.animation.name
473
- });
474
- },
475
- interrupt: function interrupt(track, event) {
476
- component.emit('interrupt', {
477
- track: track,
478
- name: track.animation.name
479
- });
480
- },
481
- end: function end(track, event) {
482
- component.emit('end', {
483
- track: track,
484
- name: track.animation.name
485
- });
486
- },
487
- event: function event(track, _event) {
488
- component.emit('event', track, _event);
489
- }
490
- });
491
- return [2];
492
- }
493
- });
494
- });
495
- };
496
-
497
- SpineSystem.prototype.change = function (changed) {
498
- this.remove(changed);
499
- this.add(changed);
500
- };
501
-
502
- SpineSystem.prototype.remove = function (changed) {
503
- var _a, _b, _c, _d;
504
-
505
- return __awaiter(this, void 0, void 0, function () {
506
- var component, armature, container, res;
507
- return __generator(this, function (_e) {
508
- switch (_e.label) {
509
- case 0:
510
- this.increaseAsyncId(changed.gameObject.id);
511
- component = changed.component;
512
- clearTimeout(component.addHandler);
513
- armature = this.armatures[changed.gameObject.id];
514
- container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
515
-
516
- if (container && armature) {
517
- container.removeChild(armature);
518
- }
519
-
520
- if (!component.armature) return [3, 2];
521
- component.armature.destroy({
522
- children: true
523
- });
524
- return [4, resource.getResource(component.lastResource)];
525
-
526
- case 1:
527
- res = _e.sent();
528
- releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
529
- _e.label = 2;
530
-
531
- case 2:
532
- component.armature = null;
533
- delete this.armatures[changed.gameObject.id];
534
- if (changed.type === OBSERVER_TYPE.CHANGE) ;
535
- return [2];
536
- }
537
- });
538
- });
539
- };
540
-
541
- SpineSystem.systemName = 'SpineSystem';
542
- SpineSystem = __decorate([decorators.componentObserver({
543
- Spine: ['resource']
544
- })], SpineSystem);
545
- return SpineSystem;
546
- }(Renderer);
547
-
548
- var SpineSystem$1 = SpineSystem;
549
- resource.registerResourceType('SPINE');
550
- export { Spine$1 as Spine, SpineSystem$1 as SpineSystem };