@eva/spine-base 1.2.7-editor.9 → 1.2.8-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
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); }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : 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
2
 
3
3
  window.EVA = window.EVA || {};
4
4
  window.EVA.plugin = window.EVA.plugin || {};
@@ -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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
16
+ if (b.hasOwnProperty(p)) d[p] = b[p];
17
17
  }
18
18
  };
19
19
 
@@ -21,8 +21,6 @@ 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
-
26
24
  _extendStatics(d, b);
27
25
 
28
26
  function __() {
@@ -32,22 +30,6 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
32
30
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
33
31
  }
34
32
 
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
-
51
33
  function __decorate(decorators, target, key, desc) {
52
34
  var c = arguments.length,
53
35
  r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
@@ -58,10 +40,6 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
58
40
  return c > 3 && r && Object.defineProperty(target, key, r), r;
59
41
  }
60
42
 
61
- function __metadata(metadataKey, metadataValue) {
62
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
63
- }
64
-
65
43
  function __awaiter(thisArg, _arguments, P, generator) {
66
44
  function adopt(value) {
67
45
  return value instanceof P ? value : new P(function (resolve) {
@@ -222,123 +200,27 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
222
200
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
223
201
  }
224
202
 
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;
203
+ function getIDEPropsPropertyObj(target, propertyKey) {
204
+ if (!target.constructor.IDEProps) {
205
+ target.constructor.IDEProps = {};
235
206
  }
236
207
 
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';
208
+ if (!target.constructor.IDEProps[propertyKey]) {
209
+ target.constructor.IDEProps[propertyKey] = {};
268
210
  }
269
211
 
270
- return 'unknown';
212
+ var propertyObj = target.constructor.IDEProps[propertyKey];
213
+ return propertyObj;
271
214
  }
272
215
 
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) {
216
+ function type(type) {
315
217
  return function (target, propertyKey) {
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);
218
+ var prop = getIDEPropsPropertyObj(target, propertyKey);
219
+ prop.key = propertyKey;
220
+ prop.type = type;
325
221
  };
326
222
  }
327
223
 
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
-
342
224
  var Spine = function (_super) {
343
225
  __extends(Spine, _super);
344
226
 
@@ -504,47 +386,11 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
504
386
 
505
387
  Spine.componentName = 'Spine';
506
388
 
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;
389
+ __decorate([type('string')], Spine.prototype, "resource", void 0);
538
390
 
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);
391
+ __decorate([type('string')], Spine.prototype, "animationName", void 0);
546
392
 
547
- __decorate([Field(), __metadata("design:type", Boolean)], Spine.prototype, "autoPlay", void 0);
393
+ __decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
548
394
 
549
395
  return Spine;
550
396
  }(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},_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;
1
+ function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)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)t.hasOwnProperty(n)&&(e[n]=t[n])},o(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=p,m={};function f(e){var t=e.image;return{tex:r.Texture.from(t),count:0}}var d={};function h(e,t,n,r){var o=null,a=function(e,t){var n=m[e];return n||(n=f(t),m[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 d[e]=i,i}function y(e,t){return s(this,void 0,void 0,(function(){var n;return u(this,(function(r){if(!(n=d[e.name]))if(e.complete)n=h(e.name,e.data,e.scale,t);else if(!n)return[2];return function(e,t){var n=m[e];n||(n=f(t),m[e]=n),n.count++,n.tex}(e.data.image.src,e.data),n.ref++,[2,n.spineData]}))}))}function v(e,t){var n=d[e];n&&(n.ref--,n.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(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(l);u&&(r.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:l.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:l.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){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 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,y(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:v((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),b=g;return t.resource.registerResourceType("SPINE"),e.Spine=l,e.SpineSystem=b,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);window.EVA.plugin.spineBase=window.EVA.plugin.spineBase||_EVA_IIFE_spineBase;
@@ -0,0 +1,550 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 };
@@ -36,17 +36,6 @@ 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
-
50
39
  function __decorate(decorators, target, key, desc) {
51
40
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
52
41
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -54,10 +43,6 @@ function __decorate(decorators, target, key, desc) {
54
43
  return c > 3 && r && Object.defineProperty(target, key, r), r;
55
44
  }
56
45
 
57
- function __metadata(metadataKey, metadataValue) {
58
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
59
- }
60
-
61
46
  function __awaiter(thisArg, _arguments, P, generator) {
62
47
  return new (P || (P = Promise))(function (resolve, reject) {
63
48
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -106,7 +91,6 @@ function __values(o) {
106
91
  };
107
92
  }
108
93
 
109
- var sleep = function (time) { return new Promise(function (resolve) { return setTimeout(resolve, time); }); };
110
94
  var Spine = (function (_super) {
111
95
  __extends(Spine, _super);
112
96
  function Spine() {
@@ -170,7 +154,7 @@ var Spine = (function (_super) {
170
154
  playType: true,
171
155
  name: name,
172
156
  loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
173
- track: track,
157
+ track: track
174
158
  });
175
159
  }
176
160
  else {
@@ -188,7 +172,7 @@ var Spine = (function (_super) {
188
172
  if (!this.armature) {
189
173
  this.waitExecuteInfos.push({
190
174
  playType: false,
191
- track: track,
175
+ track: track
192
176
  });
193
177
  return;
194
178
  }
@@ -251,42 +235,13 @@ var Spine = (function (_super) {
251
235
  };
252
236
  Spine.componentName = 'Spine';
253
237
  __decorate([
254
- inspectorDecorator.Field({ type: 'resource' }),
255
- __metadata("design:type", String)
238
+ inspectorDecorator.type('string')
256
239
  ], Spine.prototype, "resource", void 0);
257
240
  __decorate([
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)
241
+ inspectorDecorator.type('string')
286
242
  ], Spine.prototype, "animationName", void 0);
287
243
  __decorate([
288
- inspectorDecorator.Field(),
289
- __metadata("design:type", Boolean)
244
+ inspectorDecorator.type('boolean')
290
245
  ], Spine.prototype, "autoPlay", void 0);
291
246
  return Spine;
292
247
  }(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"),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
+ "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])},a(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){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,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,6 +1,6 @@
1
- import { Component, resource, OBSERVER_TYPE, decorators } from '@eva/eva.js';
1
+ import { Component, OBSERVER_TYPE, decorators, resource } from '@eva/eva.js';
2
2
  import { RendererSystem, Renderer } from '@eva/plugin-renderer';
3
- import { Field } from '@eva/inspector-decorator';
3
+ import { type } from '@eva/inspector-decorator';
4
4
  import { Texture } from 'pixi.js';
5
5
 
6
6
  /*! *****************************************************************************
@@ -32,17 +32,6 @@ 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
-
46
35
  function __decorate(decorators, target, key, desc) {
47
36
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
48
37
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -50,10 +39,6 @@ function __decorate(decorators, target, key, desc) {
50
39
  return c > 3 && r && Object.defineProperty(target, key, r), r;
51
40
  }
52
41
 
53
- function __metadata(metadataKey, metadataValue) {
54
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
55
- }
56
-
57
42
  function __awaiter(thisArg, _arguments, P, generator) {
58
43
  return new (P || (P = Promise))(function (resolve, reject) {
59
44
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -102,7 +87,6 @@ function __values(o) {
102
87
  };
103
88
  }
104
89
 
105
- var sleep = function (time) { return new Promise(function (resolve) { return setTimeout(resolve, time); }); };
106
90
  var Spine = (function (_super) {
107
91
  __extends(Spine, _super);
108
92
  function Spine() {
@@ -166,7 +150,7 @@ var Spine = (function (_super) {
166
150
  playType: true,
167
151
  name: name,
168
152
  loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
169
- track: track,
153
+ track: track
170
154
  });
171
155
  }
172
156
  else {
@@ -184,7 +168,7 @@ var Spine = (function (_super) {
184
168
  if (!this.armature) {
185
169
  this.waitExecuteInfos.push({
186
170
  playType: false,
187
- track: track,
171
+ track: track
188
172
  });
189
173
  return;
190
174
  }
@@ -247,42 +231,13 @@ var Spine = (function (_super) {
247
231
  };
248
232
  Spine.componentName = 'Spine';
249
233
  __decorate([
250
- Field({ type: 'resource' }),
251
- __metadata("design:type", String)
234
+ type('string')
252
235
  ], Spine.prototype, "resource", void 0);
253
236
  __decorate([
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)
237
+ type('string')
282
238
  ], Spine.prototype, "animationName", void 0);
283
239
  __decorate([
284
- Field(),
285
- __metadata("design:type", Boolean)
240
+ type('boolean')
286
241
  ], Spine.prototype, "autoPlay", void 0);
287
242
  return Spine;
288
243
  }(Component));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/spine-base",
3
- "version": "1.2.7-editor.9",
3
+ "version": "1.2.8-alpha.0",
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.9",
22
- "@eva/plugin-renderer": "1.2.7-editor.9",
23
- "@eva/inspector-decorator": "0.1.0-alpha.2",
21
+ "@eva/eva.js": "1.2.8-alpha.0",
22
+ "@eva/plugin-renderer": "1.2.8-alpha.0",
23
+ "@eva/inspector-decorator": "^0.0.5",
24
24
  "pixi.js": "^4.8.9"
25
25
  }
26
26
  }