@eva/spine-base 2.0.0-beta.1 → 2.0.0-beta.3

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.
@@ -3,23 +3,6 @@ window.EVA = window.EVA || {};
3
3
  window.EVA.plugin = window.EVA.plugin || {};
4
4
  var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
5
5
  'use strict';
6
- var extendStatics = function (d, b) {
7
- extendStatics = Object.setPrototypeOf || {
8
- __proto__: []
9
- } instanceof Array && function (d, b) {
10
- d.__proto__ = b;
11
- } || function (d, b) {
12
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
13
- };
14
- return extendStatics(d, b);
15
- };
16
- function __extends(d, b) {
17
- extendStatics(d, b);
18
- function __() {
19
- this.constructor = d;
20
- }
21
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22
- }
23
6
  function __decorate(decorators, target, key, desc) {
24
7
  var c = arguments.length,
25
8
  r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
@@ -54,110 +37,6 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
54
37
  step((generator = generator.apply(thisArg, _arguments || [])).next());
55
38
  });
56
39
  }
57
- function __generator(thisArg, body) {
58
- var _ = {
59
- label: 0,
60
- sent: function () {
61
- if (t[0] & 1) throw t[1];
62
- return t[1];
63
- },
64
- trys: [],
65
- ops: []
66
- },
67
- f,
68
- y,
69
- t,
70
- g;
71
- return g = {
72
- next: verb(0),
73
- "throw": verb(1),
74
- "return": verb(2)
75
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
76
- return this;
77
- }), g;
78
- function verb(n) {
79
- return function (v) {
80
- return step([n, v]);
81
- };
82
- }
83
- function step(op) {
84
- if (f) throw new TypeError("Generator is already executing.");
85
- while (_) try {
86
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
87
- if (y = 0, t) op = [op[0] & 2, t.value];
88
- switch (op[0]) {
89
- case 0:
90
- case 1:
91
- t = op;
92
- break;
93
- case 4:
94
- _.label++;
95
- return {
96
- value: op[1],
97
- done: false
98
- };
99
- case 5:
100
- _.label++;
101
- y = op[1];
102
- op = [0];
103
- continue;
104
- case 7:
105
- op = _.ops.pop();
106
- _.trys.pop();
107
- continue;
108
- default:
109
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
110
- _ = 0;
111
- continue;
112
- }
113
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
114
- _.label = op[1];
115
- break;
116
- }
117
- if (op[0] === 6 && _.label < t[1]) {
118
- _.label = t[1];
119
- t = op;
120
- break;
121
- }
122
- if (t && _.label < t[2]) {
123
- _.label = t[2];
124
- _.ops.push(op);
125
- break;
126
- }
127
- if (t[2]) _.ops.pop();
128
- _.trys.pop();
129
- continue;
130
- }
131
- op = body.call(thisArg, _);
132
- } catch (e) {
133
- op = [6, e];
134
- y = 0;
135
- } finally {
136
- f = t = 0;
137
- }
138
- if (op[0] & 5) throw op[1];
139
- return {
140
- value: op[0] ? op[1] : void 0,
141
- done: true
142
- };
143
- }
144
- }
145
- function __values(o) {
146
- var s = typeof Symbol === "function" && Symbol.iterator,
147
- m = s && o[s],
148
- i = 0;
149
- if (m) return m.call(o);
150
- if (o && typeof o.length === "number") return {
151
- next: function () {
152
- if (o && i >= o.length) o = void 0;
153
- return {
154
- value: o && o[i++],
155
- done: !o
156
- };
157
- }
158
- };
159
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
160
- }
161
40
  function getIDEPropsPropertyObj(target, propertyKey) {
162
41
  if (!target.constructor.IDEProps) {
163
42
  target.constructor.IDEProps = {};
@@ -175,72 +54,54 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
175
54
  prop.type = type;
176
55
  };
177
56
  }
178
- var Spine = function (_super) {
179
- __extends(Spine, _super);
180
- function Spine() {
181
- var _this = _super !== null && _super.apply(this, arguments) || this;
182
- _this.resource = '';
183
- _this.scale = 1;
184
- _this.animationName = '';
185
- _this.autoPlay = true;
186
- _this.waitExecuteInfos = [];
187
- return _this;
57
+ class Spine extends eva_js.Component {
58
+ constructor() {
59
+ super(...arguments);
60
+ this.resource = '';
61
+ this.scale = 1;
62
+ this.animationName = '';
63
+ this.autoPlay = true;
64
+ this.waitExecuteInfos = [];
188
65
  }
189
- Object.defineProperty(Spine.prototype, "armature", {
190
- get: function () {
191
- return this._armature;
192
- },
193
- set: function (val) {
194
- var e_1, _a;
195
- this._armature = val;
196
- if (!val) return;
197
- if (this.autoPlay) {
198
- this.play(this.animationName);
199
- }
200
- try {
201
- for (var _b = __values(this.waitExecuteInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
202
- var info = _c.value;
203
- if (info.playType) {
204
- var name_1 = info.name,
205
- loop = info.loop,
206
- track = info.track;
207
- this.play(name_1, loop, track);
208
- } else {
209
- this.stop(info.track);
210
- }
211
- }
212
- } catch (e_1_1) {
213
- e_1 = {
214
- error: e_1_1
215
- };
216
- } finally {
217
- try {
218
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
219
- } finally {
220
- if (e_1) throw e_1.error;
221
- }
66
+ set armature(val) {
67
+ this._armature = val;
68
+ if (!val) return;
69
+ if (this.autoPlay) {
70
+ this.play(this.animationName);
71
+ }
72
+ for (const info of this.waitExecuteInfos) {
73
+ if (info.playType) {
74
+ const {
75
+ name,
76
+ loop,
77
+ track
78
+ } = info;
79
+ this.play(name, loop, track);
80
+ } else {
81
+ this.stop(info.track);
222
82
  }
223
- this.waitExecuteInfos = [];
224
- },
225
- enumerable: false,
226
- configurable: true
227
- });
228
- Spine.prototype.init = function (obj) {
83
+ }
84
+ this.waitExecuteInfos = [];
85
+ }
86
+ get armature() {
87
+ return this._armature;
88
+ }
89
+ init(obj) {
229
90
  if (!obj) return;
230
91
  _extends(this, obj);
231
- };
232
- Spine.prototype.onDestroy = function () {
92
+ }
93
+ onDestroy() {
233
94
  this.destroied = true;
234
- };
235
- Spine.prototype.play = function (name, loop, track) {
95
+ }
96
+ play(name, loop, track) {
236
97
  try {
237
98
  if (name) this.animationName = name;
238
99
  if (!this.armature) {
239
100
  this.waitExecuteInfos.push({
240
101
  playType: true,
241
- name: name,
102
+ name,
242
103
  loop: loop !== null && loop !== void 0 ? loop : this.autoPlay,
243
- track: track
104
+ track
244
105
  });
245
106
  } else {
246
107
  if (track === undefined) {
@@ -251,12 +112,12 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
251
112
  } catch (e) {
252
113
  console.log(e);
253
114
  }
254
- };
255
- Spine.prototype.stop = function (track) {
115
+ }
116
+ stop(track) {
256
117
  if (!this.armature) {
257
118
  this.waitExecuteInfos.push({
258
119
  playType: false,
259
- track: track
120
+ track
260
121
  });
261
122
  return;
262
123
  }
@@ -264,8 +125,8 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
264
125
  track = 0;
265
126
  }
266
127
  this.armature.state.setEmptyAnimation(track, 0);
267
- };
268
- Spine.prototype.addAnimation = function (name, delay, loop, track) {
128
+ }
129
+ addAnimation(name, delay, loop, track) {
269
130
  try {
270
131
  if (!this.armature) {} else {
271
132
  if (track === undefined) {
@@ -276,16 +137,13 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
276
137
  } catch (e) {
277
138
  console.log(e);
278
139
  }
279
- };
280
- Spine.prototype.setMix = function (from, to, duration) {
140
+ }
141
+ setMix(from, to, duration) {
281
142
  if (!this.armature) ;else {
282
143
  this.armature.stateData.setMix(from, to, duration);
283
144
  }
284
- };
285
- Spine.prototype.getAnim = function (track) {
286
- if (track === void 0) {
287
- track = 0;
288
- }
145
+ }
146
+ getAnim(track = 0) {
289
147
  try {
290
148
  if (!this.armature) {} else {
291
149
  return this.armature.state.tracks[track].animation.name;
@@ -293,42 +151,40 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
293
151
  } catch (e) {
294
152
  console.log(e);
295
153
  }
296
- };
297
- Spine.prototype.setDefaultMix = function (duration) {
154
+ }
155
+ setDefaultMix(duration) {
298
156
  if (!this.armature) ;else {
299
157
  this.armature.stateData.defaultMix = duration;
300
158
  }
301
- };
302
- Spine.prototype.setAttachment = function (slotName, attachmentName) {
159
+ }
160
+ setAttachment(slotName, attachmentName) {
303
161
  if (!this.armature) {
304
162
  return;
305
163
  }
306
164
  this.armature.skeleton.setAttachment(slotName, attachmentName);
307
- };
308
- Spine.prototype.getBone = function (boneName) {
165
+ }
166
+ getBone(boneName) {
309
167
  if (!this.armature) {
310
168
  return;
311
169
  }
312
170
  return this.armature.skeleton.findBone(boneName);
313
- };
314
- Spine.componentName = 'Spine';
315
- __decorate([type('string')], Spine.prototype, "resource", void 0);
316
- __decorate([type('number')], Spine.prototype, "scale", void 0);
317
- __decorate([type('string')], Spine.prototype, "animationName", void 0);
318
- __decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
319
- return Spine;
320
- }(eva_js.Component);
321
- var Spine$1 = Spine;
322
- var texCache = {};
171
+ }
172
+ }
173
+ Spine.componentName = 'Spine';
174
+ __decorate([type('string')], Spine.prototype, "resource", void 0);
175
+ __decorate([type('number')], Spine.prototype, "scale", void 0);
176
+ __decorate([type('string')], Spine.prototype, "animationName", void 0);
177
+ __decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
178
+ let texCache = {};
323
179
  function cacheImage(data) {
324
- var oldImg = data.image;
180
+ const oldImg = data.image;
325
181
  return {
326
182
  tex: oldImg instanceof pixi_js.Texture ? oldImg : pixi_js.Texture.from(oldImg),
327
183
  count: 0
328
184
  };
329
185
  }
330
186
  function retainTexture(name, data) {
331
- var cache = texCache[name];
187
+ let cache = texCache[name];
332
188
  if (!cache) {
333
189
  cache = cacheImage(data);
334
190
  texCache[name] = cache;
@@ -338,8 +194,8 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
338
194
  }
339
195
  function releaseTexture(imageSrc) {
340
196
  if (!imageSrc) return;
341
- setTimeout(function () {
342
- var cache = texCache[imageSrc];
197
+ setTimeout(() => {
198
+ const cache = texCache[imageSrc];
343
199
  if (cache) {
344
200
  cache.count--;
345
201
  if (cache.count <= 0) {
@@ -352,15 +208,15 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
352
208
  }
353
209
  }, 100);
354
210
  }
355
- var dataMap = {};
211
+ let dataMap = {};
356
212
  function createSpineData(name, data, scale, pixiSpine) {
357
- var skeletonAsset = data.ske;
358
- var atlasAsset = data.atlas;
359
- var attachmentLoader = new pixiSpine.AtlasAttachmentLoader(atlasAsset);
360
- var parser = skeletonAsset instanceof Uint8Array ? new pixiSpine.SkeletonBinary(attachmentLoader) : new pixiSpine.SkeletonJson(attachmentLoader);
213
+ const skeletonAsset = data.ske;
214
+ const atlasAsset = data.atlas;
215
+ const attachmentLoader = new pixiSpine.AtlasAttachmentLoader(atlasAsset);
216
+ const parser = skeletonAsset instanceof Uint8Array ? new pixiSpine.SkeletonBinary(attachmentLoader) : new pixiSpine.SkeletonJson(attachmentLoader);
361
217
  parser.scale = scale || 1;
362
- var skeletonData = parser.readSkeletonData(skeletonAsset);
363
- var obj = {
218
+ const skeletonData = parser.readSkeletonData(skeletonAsset);
219
+ const obj = {
364
220
  spineData: skeletonData,
365
221
  ref: 0,
366
222
  imageSrc: data.image.label
@@ -369,25 +225,22 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
369
225
  return obj;
370
226
  }
371
227
  function getSpineData(res, scale, pixiSpine) {
372
- return __awaiter(this, void 0, void 0, function () {
373
- var data;
374
- return __generator(this, function (_a) {
375
- data = dataMap[res.name];
376
- if (!data) {
377
- if (res.complete) {
378
- data = createSpineData(res.name, res.data, scale, pixiSpine);
379
- } else if (!data) {
380
- return [2];
381
- }
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ let data = dataMap[res.name];
230
+ if (!data) {
231
+ if (res.complete) {
232
+ data = createSpineData(res.name, res.data, scale, pixiSpine);
233
+ } else if (!data) {
234
+ return;
382
235
  }
383
- retainTexture(res.data.image.label, res.data);
384
- data.ref++;
385
- return [2, data.spineData];
386
- });
236
+ }
237
+ retainTexture(res.data.image.label, res.data);
238
+ data.ref++;
239
+ return data.spineData;
387
240
  });
388
241
  }
389
242
  function releaseSpineData(resourceName, imageSrc) {
390
- var data = dataMap[resourceName];
243
+ const data = dataMap[resourceName];
391
244
  if (!data) {
392
245
  return;
393
246
  }
@@ -397,218 +250,190 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
397
250
  delete dataMap[resourceName];
398
251
  }
399
252
  }
400
- var MaxRetryCount = 20;
401
- var SpineSystem = function (_super) {
402
- __extends(SpineSystem, _super);
403
- function SpineSystem() {
404
- var _this = _super !== null && _super.apply(this, arguments) || this;
405
- _this.armatures = {};
406
- return _this;
253
+ const MaxRetryCount = 20;
254
+ let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
255
+ constructor() {
256
+ super(...arguments);
257
+ this.armatures = {};
407
258
  }
408
- SpineSystem.prototype.init = function (_a) {
409
- var _this = this;
410
- var pixiSpine = _a.pixiSpine;
259
+ init({
260
+ pixiSpine
261
+ }) {
411
262
  this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
412
263
  this.renderSystem.rendererManager.register(this);
413
264
  this.pixiSpine = pixiSpine;
414
- this.game.canvas.addEventListener('webglcontextrestored', function () {
415
- var objs = _this.game.gameObjects;
416
- var toAdd = [];
417
- for (var k in _this.armatures) {
418
- var id = +k;
419
- for (var i = 0; i < objs.length; ++i) {
420
- var obj = objs[i];
265
+ this.game.canvas.addEventListener('webglcontextrestored', () => {
266
+ const objs = this.game.gameObjects;
267
+ let toAdd = [];
268
+ for (let k in this.armatures) {
269
+ const id = +k;
270
+ for (let i = 0; i < objs.length; ++i) {
271
+ let obj = objs[i];
421
272
  if (obj.id === id) {
422
- var sp = obj.getComponent(Spine$1);
273
+ let sp = obj.getComponent(Spine);
423
274
  if (sp) {
424
- _this.remove({
275
+ this.remove({
425
276
  type: eva_js.OBSERVER_TYPE.REMOVE,
426
277
  gameObject: obj,
427
278
  component: sp,
428
- componentName: Spine$1.componentName
279
+ componentName: Spine.componentName
429
280
  });
430
281
  toAdd.push({
431
282
  type: eva_js.OBSERVER_TYPE.ADD,
432
283
  gameObject: obj,
433
284
  component: sp,
434
- componentName: Spine$1.componentName
285
+ componentName: Spine.componentName
435
286
  });
436
287
  }
437
288
  break;
438
289
  }
439
290
  }
440
291
  }
441
- setTimeout(function () {
442
- toAdd.forEach(function (obj) {
443
- _this.add(obj);
292
+ setTimeout(() => {
293
+ toAdd.forEach(obj => {
294
+ this.add(obj);
444
295
  });
445
296
  }, 1000);
446
297
  }, false);
447
- };
448
- SpineSystem.prototype.update = function (e) {
449
- for (var key in this.armatures) {
298
+ }
299
+ update(e) {
300
+ for (let key in this.armatures) {
450
301
  this.armatures[key].update(e.deltaTime * 0.001);
451
302
  }
452
- _super.prototype.update.call(this);
453
- };
454
- SpineSystem.prototype.componentChanged = function (changed) {
455
- return __awaiter(this, void 0, void 0, function () {
456
- return __generator(this, function (_a) {
457
- if (changed.componentName === 'Spine') {
458
- if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
459
- this.add(changed);
460
- } else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
461
- switch (changed.prop.prop[0]) {
462
- case 'resource':
463
- this.change(changed);
464
- break;
465
- }
466
- } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
467
- this.remove(changed);
303
+ super.update();
304
+ }
305
+ componentChanged(changed) {
306
+ return __awaiter(this, void 0, void 0, function* () {
307
+ if (changed.componentName === 'Spine') {
308
+ if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
309
+ this.add(changed);
310
+ } else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
311
+ switch (changed.prop.prop[0]) {
312
+ case 'resource':
313
+ this.change(changed);
314
+ break;
468
315
  }
316
+ } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
317
+ this.remove(changed);
469
318
  }
470
- return [2];
471
- });
319
+ }
472
320
  });
473
- };
474
- SpineSystem.prototype.add = function (changed, count) {
321
+ }
322
+ add(changed, count) {
475
323
  var _a, _b;
476
- return __awaiter(this, void 0, void 0, function () {
477
- var component, gameObjectId, asyncId, res, spineData, container, armature, tran;
478
- var _this = this;
479
- return __generator(this, function (_c) {
480
- switch (_c.label) {
481
- case 0:
482
- component = changed.component;
483
- clearTimeout(component.addHandler);
484
- gameObjectId = changed.gameObject.id;
485
- asyncId = this.increaseAsyncId(gameObjectId);
486
- return [4, eva_js.resource.getResource(component.resource)];
487
- case 1:
488
- res = _c.sent();
489
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
490
- return [4, getSpineData(res, component.scale, this.pixiSpine)];
491
- case 2:
492
- spineData = _c.sent();
493
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
494
- if (!spineData) {
495
- component.addHandler = setTimeout(function () {
496
- if (!component.destroied) {
497
- if (count === undefined) {
498
- count = MaxRetryCount;
499
- }
500
- count--;
501
- if (count > 0) {
502
- _this.add(changed, count);
503
- } else {
504
- console.log('retry exceed max times', component.resource);
505
- }
506
- }
507
- }, 1000);
508
- return [2];
509
- }
510
- this.remove(changed);
511
- container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
512
- if (!container) {
513
- return [2];
324
+ return __awaiter(this, void 0, void 0, function* () {
325
+ const component = changed.component;
326
+ clearTimeout(component.addHandler);
327
+ const gameObjectId = changed.gameObject.id;
328
+ const asyncId = this.increaseAsyncId(gameObjectId);
329
+ const res = yield eva_js.resource.getResource(component.resource);
330
+ if (!this.validateAsyncId(gameObjectId, asyncId)) return;
331
+ const spineData = yield getSpineData(res, component.scale, this.pixiSpine);
332
+ if (!this.validateAsyncId(gameObjectId, asyncId)) return;
333
+ if (!spineData) {
334
+ component.addHandler = setTimeout(() => {
335
+ if (!component.destroied) {
336
+ if (count === undefined) {
337
+ count = MaxRetryCount;
514
338
  }
515
- component.lastResource = component.resource;
516
- armature = new this.pixiSpine.Spine({
517
- skeletonData: spineData,
518
- autoUpdate: false
519
- });
520
- this.armatures[changed.gameObject.id] = armature;
521
- if (changed.gameObject && changed.gameObject.transform) {
522
- tran = changed.gameObject.transform;
523
- armature.x = tran.size.width * tran.origin.x;
524
- armature.y = tran.size.height * tran.origin.y;
339
+ count--;
340
+ if (count > 0) {
341
+ this.add(changed, count);
342
+ } else {
343
+ console.log('retry exceed max times', component.resource);
525
344
  }
526
- container.addChildAt(armature, 0);
527
- armature.update();
528
- component.armature = armature;
529
- component.emit('loaded', {
530
- resource: component.resource
531
- });
532
- armature.state.addListener({
533
- start: function (track, event) {
534
- component.emit('start', {
535
- track: track,
536
- name: track.animation.name
537
- });
538
- },
539
- complete: function (track, event) {
540
- component.emit('complete', {
541
- track: track,
542
- name: track.animation.name
543
- });
544
- },
545
- interrupt: function (track, event) {
546
- component.emit('interrupt', {
547
- track: track,
548
- name: track.animation.name
549
- });
550
- },
551
- end: function (track, event) {
552
- component.emit('end', {
553
- track: track,
554
- name: track.animation.name
555
- });
556
- },
557
- event: function (track, event) {
558
- component.emit('event', track, event);
559
- }
560
- });
561
- return [2];
345
+ }
346
+ }, 1000);
347
+ return;
348
+ }
349
+ this.remove(changed);
350
+ const container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
351
+ if (!container) {
352
+ return;
353
+ }
354
+ component.lastResource = component.resource;
355
+ const armature = new this.pixiSpine.Spine({
356
+ skeletonData: spineData,
357
+ autoUpdate: false
358
+ });
359
+ this.armatures[changed.gameObject.id] = armature;
360
+ if (changed.gameObject && changed.gameObject.transform) {
361
+ const tran = changed.gameObject.transform;
362
+ armature.x = tran.size.width * tran.origin.x;
363
+ armature.y = tran.size.height * tran.origin.y;
364
+ }
365
+ container.addChildAt(armature, 0);
366
+ armature.update();
367
+ component.armature = armature;
368
+ component.emit('loaded', {
369
+ resource: component.resource
370
+ });
371
+ armature.state.addListener({
372
+ start: (track, event) => {
373
+ component.emit('start', {
374
+ track,
375
+ name: track.animation.name
376
+ });
377
+ },
378
+ complete: (track, event) => {
379
+ component.emit('complete', {
380
+ track,
381
+ name: track.animation.name
382
+ });
383
+ },
384
+ interrupt: (track, event) => {
385
+ component.emit('interrupt', {
386
+ track,
387
+ name: track.animation.name
388
+ });
389
+ },
390
+ end: (track, event) => {
391
+ component.emit('end', {
392
+ track,
393
+ name: track.animation.name
394
+ });
395
+ },
396
+ event: (track, event) => {
397
+ component.emit('event', track, event);
562
398
  }
563
399
  });
564
400
  });
565
- };
566
- SpineSystem.prototype.change = function (changed) {
401
+ }
402
+ change(changed) {
567
403
  this.remove(changed);
568
404
  this.add(changed);
569
- };
570
- SpineSystem.prototype.remove = function (changed) {
405
+ }
406
+ remove(changed) {
571
407
  var _a, _b, _c, _d;
572
- return __awaiter(this, void 0, void 0, function () {
573
- var component, armature, container, res;
574
- return __generator(this, function (_e) {
575
- switch (_e.label) {
576
- case 0:
577
- this.increaseAsyncId(changed.gameObject.id);
578
- component = changed.component;
579
- clearTimeout(component.addHandler);
580
- armature = this.armatures[changed.gameObject.id];
581
- container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
582
- if (container && armature) {
583
- container.removeChild(armature);
584
- }
585
- if (!component.armature) return [3, 2];
586
- component.armature.destroy({
587
- children: true
588
- });
589
- return [4, eva_js.resource.getResource(component.lastResource)];
590
- case 1:
591
- res = _e.sent();
592
- releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
593
- _e.label = 2;
594
- case 2:
595
- component.armature = null;
596
- delete this.armatures[changed.gameObject.id];
597
- if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) ;
598
- return [2];
599
- }
600
- });
408
+ return __awaiter(this, void 0, void 0, function* () {
409
+ this.increaseAsyncId(changed.gameObject.id);
410
+ const component = changed.component;
411
+ clearTimeout(component.addHandler);
412
+ const armature = this.armatures[changed.gameObject.id];
413
+ const container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
414
+ if (container && armature) {
415
+ container.removeChild(armature);
416
+ }
417
+ if (component.armature) {
418
+ component.armature.destroy({
419
+ children: true
420
+ });
421
+ const res = yield eva_js.resource.getResource(component.lastResource);
422
+ releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
423
+ }
424
+ component.armature = null;
425
+ delete this.armatures[changed.gameObject.id];
426
+ if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) ;
601
427
  });
602
- };
603
- SpineSystem.systemName = 'SpineSystem';
604
- SpineSystem = __decorate([eva_js.decorators.componentObserver({
605
- Spine: ['resource']
606
- })], SpineSystem);
607
- return SpineSystem;
608
- }(pluginRenderer.Renderer);
428
+ }
429
+ };
430
+ SpineSystem.systemName = 'SpineSystem';
431
+ SpineSystem = __decorate([eva_js.decorators.componentObserver({
432
+ Spine: ['resource']
433
+ })], SpineSystem);
609
434
  var SpineSystem$1 = SpineSystem;
610
435
  eva_js.resource.registerResourceType('SPINE');
611
- exports.Spine = Spine$1;
436
+ exports.Spine = Spine;
612
437
  exports.SpineSystem = SpineSystem$1;
613
438
  Object.defineProperty(exports, '__esModule', {
614
439
  value: true