@eva/plugin-renderer-sprite-animation 1.3.0-alpha.1 → 2.0.0-beta.1

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,53 +1,39 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- this.EVA = this.EVA || {};
4
- this.EVA.plugin = this.EVA.plugin || {};
5
- this.EVA.plugin.renderer = this.EVA.plugin.renderer || {};
6
-
7
- this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRenderer, rendererAdapter, pixi_js) {
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ window.EVA = window.EVA || {};
3
+ window.EVA.plugin = window.EVA.plugin || {};
4
+ window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
5
+ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rendererAdapter, pixi_js) {
8
6
  'use strict';
9
-
10
- var _extendStatics = function extendStatics(d, b) {
11
- _extendStatics = Object.setPrototypeOf || {
7
+ var extendStatics = function (d, b) {
8
+ extendStatics = Object.setPrototypeOf || {
12
9
  __proto__: []
13
10
  } instanceof Array && function (d, b) {
14
11
  d.__proto__ = b;
15
12
  } || function (d, b) {
16
- for (var p in b) {
17
- if (b.hasOwnProperty(p)) d[p] = b[p];
18
- }
13
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
19
14
  };
20
-
21
- return _extendStatics(d, b);
15
+ return extendStatics(d, b);
22
16
  };
23
-
24
17
  function __extends(d, b) {
25
- _extendStatics(d, b);
26
-
18
+ extendStatics(d, b);
27
19
  function __() {
28
20
  this.constructor = d;
29
21
  }
30
-
31
22
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
23
  }
33
-
34
24
  function __decorate(decorators, target, key, desc) {
35
25
  var c = arguments.length,
36
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
37
- d;
38
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
39
- if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
40
- }
26
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
27
+ d;
28
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
41
29
  return c > 3 && r && Object.defineProperty(target, key, r), r;
42
30
  }
43
-
44
31
  function __awaiter(thisArg, _arguments, P, generator) {
45
32
  function adopt(value) {
46
33
  return value instanceof P ? value : new P(function (resolve) {
47
34
  resolve(value);
48
35
  });
49
36
  }
50
-
51
37
  return new (P || (P = Promise))(function (resolve, reject) {
52
38
  function fulfilled(value) {
53
39
  try {
@@ -56,7 +42,6 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
56
42
  reject(e);
57
43
  }
58
44
  }
59
-
60
45
  function rejected(value) {
61
46
  try {
62
47
  step(generator["throw"](value));
@@ -64,29 +49,26 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
64
49
  reject(e);
65
50
  }
66
51
  }
67
-
68
52
  function step(result) {
69
53
  result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
70
54
  }
71
-
72
55
  step((generator = generator.apply(thisArg, _arguments || [])).next());
73
56
  });
74
57
  }
75
-
76
58
  function __generator(thisArg, body) {
77
59
  var _ = {
78
- label: 0,
79
- sent: function sent() {
80
- if (t[0] & 1) throw t[1];
81
- return t[1];
60
+ label: 0,
61
+ sent: function () {
62
+ if (t[0] & 1) throw t[1];
63
+ return t[1];
64
+ },
65
+ trys: [],
66
+ ops: []
82
67
  },
83
- trys: [],
84
- ops: []
85
- },
86
- f,
87
- y,
88
- t,
89
- g;
68
+ f,
69
+ y,
70
+ t,
71
+ g;
90
72
  return g = {
91
73
  next: verb(0),
92
74
  "throw": verb(1),
@@ -94,88 +76,66 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
94
76
  }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
95
77
  return this;
96
78
  }), g;
97
-
98
79
  function verb(n) {
99
80
  return function (v) {
100
81
  return step([n, v]);
101
82
  };
102
83
  }
103
-
104
84
  function step(op) {
105
85
  if (f) throw new TypeError("Generator is already executing.");
106
-
107
- while (_) {
108
- try {
109
- 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;
110
- if (y = 0, t) op = [op[0] & 2, t.value];
111
-
112
- switch (op[0]) {
113
- case 0:
114
- case 1:
86
+ while (_) try {
87
+ 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;
88
+ if (y = 0, t) op = [op[0] & 2, t.value];
89
+ switch (op[0]) {
90
+ case 0:
91
+ case 1:
92
+ t = op;
93
+ break;
94
+ case 4:
95
+ _.label++;
96
+ return {
97
+ value: op[1],
98
+ done: false
99
+ };
100
+ case 5:
101
+ _.label++;
102
+ y = op[1];
103
+ op = [0];
104
+ continue;
105
+ case 7:
106
+ op = _.ops.pop();
107
+ _.trys.pop();
108
+ continue;
109
+ default:
110
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
111
+ _ = 0;
112
+ continue;
113
+ }
114
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
115
+ _.label = op[1];
116
+ break;
117
+ }
118
+ if (op[0] === 6 && _.label < t[1]) {
119
+ _.label = t[1];
115
120
  t = op;
116
121
  break;
117
-
118
- case 4:
119
- _.label++;
120
- return {
121
- value: op[1],
122
- done: false
123
- };
124
-
125
- case 5:
126
- _.label++;
127
- y = op[1];
128
- op = [0];
129
- continue;
130
-
131
- case 7:
132
- op = _.ops.pop();
133
-
134
- _.trys.pop();
135
-
136
- continue;
137
-
138
- default:
139
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
140
- _ = 0;
141
- continue;
142
- }
143
-
144
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
145
- _.label = op[1];
146
- break;
147
- }
148
-
149
- if (op[0] === 6 && _.label < t[1]) {
150
- _.label = t[1];
151
- t = op;
152
- break;
153
- }
154
-
155
- if (t && _.label < t[2]) {
156
- _.label = t[2];
157
-
158
- _.ops.push(op);
159
-
160
- break;
161
- }
162
-
163
- if (t[2]) _.ops.pop();
164
-
165
- _.trys.pop();
166
-
167
- continue;
168
- }
169
-
170
- op = body.call(thisArg, _);
171
- } catch (e) {
172
- op = [6, e];
173
- y = 0;
174
- } finally {
175
- f = t = 0;
122
+ }
123
+ if (t && _.label < t[2]) {
124
+ _.label = t[2];
125
+ _.ops.push(op);
126
+ break;
127
+ }
128
+ if (t[2]) _.ops.pop();
129
+ _.trys.pop();
130
+ continue;
176
131
  }
132
+ op = body.call(thisArg, _);
133
+ } catch (e) {
134
+ op = [6, e];
135
+ y = 0;
136
+ } finally {
137
+ f = t = 0;
177
138
  }
178
-
179
139
  if (op[0] & 5) throw op[1];
180
140
  return {
181
141
  value: op[0] ? op[1] : void 0,
@@ -183,14 +143,13 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
183
143
  };
184
144
  }
185
145
  }
186
-
187
146
  function __values(o) {
188
147
  var s = typeof Symbol === "function" && Symbol.iterator,
189
- m = s && o[s],
190
- i = 0;
148
+ m = s && o[s],
149
+ i = 0;
191
150
  if (m) return m.call(o);
192
151
  if (o && typeof o.length === "number") return {
193
- next: function next() {
152
+ next: function () {
194
153
  if (o && i >= o.length) o = void 0;
195
154
  return {
196
155
  value: o && o[i++],
@@ -200,20 +159,16 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
200
159
  };
201
160
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
202
161
  }
203
-
204
162
  function getIDEPropsPropertyObj(target, propertyKey) {
205
163
  if (!target.constructor.IDEProps) {
206
164
  target.constructor.IDEProps = {};
207
165
  }
208
-
209
166
  if (!target.constructor.IDEProps[propertyKey]) {
210
167
  target.constructor.IDEProps[propertyKey] = {};
211
168
  }
212
-
213
169
  var propertyObj = target.constructor.IDEProps[propertyKey];
214
170
  return propertyObj;
215
171
  }
216
-
217
172
  function type(type) {
218
173
  return function (target, propertyKey) {
219
174
  var prop = getIDEPropsPropertyObj(target, propertyKey);
@@ -221,62 +176,61 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
221
176
  prop.type = type;
222
177
  };
223
178
  }
224
-
225
179
  function step(step) {
226
180
  return function (target, propertyKey) {
227
181
  var prop = getIDEPropsPropertyObj(target, propertyKey);
228
182
  prop.step = step;
229
183
  };
230
184
  }
231
-
232
185
  var SpriteAnimation$2 = function (_super) {
233
186
  __extends(SpriteAnimation, _super);
234
-
235
187
  function SpriteAnimation() {
236
188
  var _this = _super !== null && _super.apply(this, arguments) || this;
237
-
238
189
  _this.resource = '';
239
190
  _this.autoPlay = true;
240
191
  _this.speed = 100;
192
+ _this.forwards = false;
241
193
  _this.waitPlay = false;
242
194
  _this.waitStop = false;
243
195
  _this.times = Infinity;
244
196
  _this.count = 0;
197
+ _this.complete = false;
245
198
  return _this;
246
199
  }
247
-
248
200
  SpriteAnimation.prototype.init = function (obj) {
249
201
  var _this = this;
250
-
251
202
  obj && _extends(this, obj);
252
203
  this.on('loop', function () {
253
204
  if (++_this.count >= _this.times) {
254
- _this.animate.stop();
255
-
205
+ if (_this.forwards) {
206
+ _this.gotoAndStop(_this.totalFrames - 1);
207
+ } else {
208
+ _this.animate.stop();
209
+ }
210
+ _this.complete = true;
256
211
  _this.emit('complete');
257
212
  }
258
213
  });
259
214
  };
260
-
261
215
  SpriteAnimation.prototype.play = function (times) {
262
216
  if (times === void 0) {
263
217
  times = Infinity;
264
218
  }
265
-
266
219
  if (times === 0) {
267
220
  return;
268
221
  }
269
-
270
222
  this.times = times;
271
-
272
223
  if (!this.animate) {
273
224
  this.waitPlay = true;
274
225
  } else {
226
+ if (this.complete) {
227
+ this.gotoAndStop(0);
228
+ }
275
229
  this.animate.play();
276
230
  this.count = 0;
231
+ this.complete = false;
277
232
  }
278
233
  };
279
-
280
234
  SpriteAnimation.prototype.stop = function () {
281
235
  if (!this.animate) {
282
236
  this.waitStop = true;
@@ -284,19 +238,16 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
284
238
  this.animate.stop();
285
239
  }
286
240
  };
287
-
288
241
  Object.defineProperty(SpriteAnimation.prototype, "animate", {
289
- get: function get() {
242
+ get: function () {
290
243
  return this._animate;
291
244
  },
292
- set: function set(val) {
245
+ set: function (val) {
293
246
  this._animate = val;
294
-
295
247
  if (this.waitPlay) {
296
248
  this.waitPlay = false;
297
249
  this.play(this.times);
298
250
  }
299
-
300
251
  if (this.waitStop) {
301
252
  this.waitStop = false;
302
253
  this.stop();
@@ -305,48 +256,53 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
305
256
  enumerable: false,
306
257
  configurable: true
307
258
  });
308
-
309
259
  SpriteAnimation.prototype.gotoAndPlay = function (frameNumber) {
310
260
  this.animate.gotoAndPlay(frameNumber);
311
261
  };
312
-
313
262
  SpriteAnimation.prototype.gotoAndStop = function (frameNumber) {
314
263
  this.animate.gotoAndStop(frameNumber);
315
264
  };
316
-
265
+ Object.defineProperty(SpriteAnimation.prototype, "currentFrame", {
266
+ get: function () {
267
+ var _a, _b;
268
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
269
+ },
270
+ enumerable: false,
271
+ configurable: true
272
+ });
273
+ Object.defineProperty(SpriteAnimation.prototype, "totalFrames", {
274
+ get: function () {
275
+ var _a, _b;
276
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
277
+ },
278
+ enumerable: false,
279
+ configurable: true
280
+ });
317
281
  SpriteAnimation.componentName = 'SpriteAnimation';
318
-
319
282
  __decorate([type('string')], SpriteAnimation.prototype, "resource", void 0);
320
-
321
283
  __decorate([type('boolean')], SpriteAnimation.prototype, "autoPlay", void 0);
322
-
323
284
  __decorate([type('number'), step(10)], SpriteAnimation.prototype, "speed", void 0);
324
-
285
+ __decorate([type('boolean')], SpriteAnimation.prototype, "forwards", void 0);
325
286
  return SpriteAnimation;
326
287
  }(eva_js.Component);
327
-
328
288
  var SpriteAnimation$3 = SpriteAnimation$2;
329
289
  var resourceKeySplit = '_s|r|c_';
330
290
  eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
331
291
  var name = _a.name,
332
- data = _a.data;
292
+ data = _a.data;
333
293
  return new Promise(function (r) {
334
294
  var e_1, _a;
335
-
336
- var textureObj = data.json;
337
- var texture = pixi_js.BaseTexture.from(data.image);
295
+ var textureObj = data.json.data;
296
+ var texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
338
297
  var frames = textureObj.frames || {};
339
298
  var animations = textureObj.animations || {};
340
299
  var newFrames = {};
341
-
342
300
  for (var key in frames) {
343
301
  var newKey = name + resourceKeySplit + key;
344
302
  newFrames[newKey] = frames[key];
345
303
  }
346
-
347
304
  for (var key in animations) {
348
305
  var spriteList = [];
349
-
350
306
  if (animations[key] && animations[key].length >= 0) {
351
307
  try {
352
308
  for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -366,30 +322,24 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
366
322
  }
367
323
  }
368
324
  }
369
-
370
325
  animations[key] = spriteList;
371
326
  }
372
-
373
327
  textureObj.frames = newFrames;
374
328
  var spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
375
- spriteSheet.parse(function () {
329
+ spriteSheet.parse().then(function () {
376
330
  var textures = spriteSheet.textures;
377
331
  var spriteFrames = [];
378
-
379
332
  for (var key in textures) {
380
333
  spriteFrames.push(textures[key]);
381
334
  }
382
-
383
335
  r(spriteFrames);
384
336
  });
385
337
  });
386
338
  });
387
339
  eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
388
340
  var e_2, _b;
389
-
390
341
  var instance = _a.instance;
391
342
  if (!instance) return;
392
-
393
343
  try {
394
344
  for (var instance_1 = __values(instance), instance_1_1 = instance_1.next(); !instance_1_1.done; instance_1_1 = instance_1.next()) {
395
345
  var texture = instance_1_1.value;
@@ -407,135 +357,115 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
407
357
  }
408
358
  }
409
359
  });
410
-
411
360
  var SpriteAnimation = function (_super) {
412
361
  __extends(SpriteAnimation, _super);
413
-
414
362
  function SpriteAnimation() {
415
363
  var _this = _super !== null && _super.apply(this, arguments) || this;
416
-
417
364
  _this.name = 'SpriteAnimation';
418
365
  _this.animates = {};
419
366
  _this.autoPlay = {};
420
367
  return _this;
421
368
  }
422
-
423
369
  SpriteAnimation.prototype.init = function () {
424
370
  this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
425
371
  this.renderSystem.rendererManager.register(this);
426
372
  };
427
-
428
373
  SpriteAnimation.prototype.rendererUpdate = function (gameObject) {
429
374
  var _a = gameObject.transform.size,
430
- width = _a.width,
431
- height = _a.height;
432
-
375
+ width = _a.width,
376
+ height = _a.height;
433
377
  if (this.animates[gameObject.id]) {
434
378
  this.animates[gameObject.id].animatedSprite.width = width;
435
379
  this.animates[gameObject.id].animatedSprite.height = height;
436
380
  }
437
381
  };
438
-
439
382
  SpriteAnimation.prototype.componentChanged = function (changed) {
440
383
  return __awaiter(this, void 0, void 0, function () {
441
- var component, frames_1, frames_2;
384
+ var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
442
385
  return __generator(this, function (_a) {
443
386
  switch (_a.label) {
444
387
  case 0:
388
+ gameObjectId = changed.gameObject.id;
445
389
  if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
446
390
  component = changed.component;
447
391
  this.autoPlay[changed.gameObject.id] = component.autoPlay;
448
392
  if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 2];
393
+ asyncId = this.increaseAsyncId(gameObjectId);
449
394
  return [4, eva_js.resource.getResource(component.resource)];
450
-
451
395
  case 1:
452
396
  frames_1 = _a.sent().instance;
453
-
397
+ if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
454
398
  if (!frames_1) {
455
399
  console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
456
400
  }
457
-
458
401
  this.add({
459
402
  frames: frames_1,
460
403
  id: changed.gameObject.id,
461
404
  component: component
462
405
  });
463
406
  return [3, 7];
464
-
465
407
  case 2:
466
408
  if (!(changed.type === eva_js.OBSERVER_TYPE.CHANGE)) return [3, 6];
467
409
  if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
468
410
  this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
469
411
  return [3, 5];
470
-
471
412
  case 3:
413
+ asyncId = this.increaseAsyncId(gameObjectId);
472
414
  return [4, eva_js.resource.getResource(component.resource)];
473
-
474
415
  case 4:
475
416
  frames_2 = _a.sent().instance;
476
-
417
+ if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
477
418
  if (!frames_2) {
478
419
  console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
479
420
  }
480
-
481
421
  this.change({
482
422
  frames: frames_2,
483
423
  id: changed.gameObject.id,
484
424
  component: component
485
425
  });
486
426
  _a.label = 5;
487
-
488
427
  case 5:
489
428
  return [3, 7];
490
-
491
429
  case 6:
492
430
  if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
431
+ this.increaseAsyncId(gameObjectId);
493
432
  this.remove(changed.gameObject.id);
494
433
  }
495
-
496
434
  _a.label = 7;
497
-
498
435
  case 7:
499
436
  return [2];
500
437
  }
501
438
  });
502
439
  });
503
440
  };
504
-
505
441
  SpriteAnimation.prototype.add = function (_a) {
506
442
  var frames = _a.frames,
507
- id = _a.id,
508
- component = _a.component;
443
+ id = _a.id,
444
+ component = _a.component;
509
445
  var animate = new rendererAdapter.SpriteAnimation({
510
446
  frames: frames
511
447
  });
512
448
  this.animates[id] = animate;
513
449
  this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
514
-
515
450
  animate.animatedSprite.onComplete = function () {
516
451
  component.emit('complete');
517
452
  };
518
-
519
453
  animate.animatedSprite.onFrameChange = function () {
520
454
  component.emit('frameChange');
521
455
  };
522
-
523
456
  animate.animatedSprite.onLoop = function () {
524
457
  component.emit('loop');
525
458
  };
526
-
527
459
  component.animate = this.animates[id];
528
460
  this.animates[id].speed = 1000 / 60 / component.speed;
529
-
530
461
  if (this.autoPlay[id]) {
531
462
  animate.animatedSprite.play();
532
463
  }
533
464
  };
534
-
535
465
  SpriteAnimation.prototype.change = function (_a) {
536
466
  var frames = _a.frames,
537
- id = _a.id,
538
- component = _a.component;
467
+ id = _a.id,
468
+ component = _a.component;
539
469
  this.remove(id, true);
540
470
  this.add({
541
471
  frames: frames,
@@ -543,28 +473,23 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
543
473
  component: component
544
474
  });
545
475
  };
546
-
547
476
  SpriteAnimation.prototype.remove = function (id, isChange) {
548
477
  var animate = this.animates[id];
478
+ if (!animate) return;
549
479
  this.autoPlay[id] = animate.animatedSprite.playing;
550
480
  this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
551
- animate.animatedSprite.destroy({
552
- children: true
553
- });
481
+ animate.animatedSprite.destroy();
554
482
  delete this.animates[id];
555
-
556
483
  if (!isChange) {
557
484
  delete this.autoPlay[id];
558
485
  }
559
486
  };
560
-
561
487
  SpriteAnimation.systemName = 'SpriteAnimation';
562
488
  SpriteAnimation = __decorate([eva_js.decorators.componentObserver({
563
489
  SpriteAnimation: ['speed', 'resource']
564
490
  })], SpriteAnimation);
565
491
  return SpriteAnimation;
566
492
  }(pluginRenderer.Renderer);
567
-
568
493
  var SpriteAnimation$1 = SpriteAnimation;
569
494
  exports.SpriteAnimation = SpriteAnimation$3;
570
495
  exports.SpriteAnimationSystem = SpriteAnimation$1;
@@ -573,3 +498,4 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
573
498
  });
574
499
  return exports;
575
500
  }({}, EVA, EVA.plugin.renderer, EVA.rendererAdapter, PIXI);
501
+ window.EVA.plugin.renderer.spriteAnimation = window.EVA.plugin.renderer.spriteAnimation || _EVA_IIFE_spriteAnimation;
@@ -1 +1 @@
1
- function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}this.EVA=this.EVA||{},this.EVA.plugin=this.EVA.plugin||{},this.EVA.plugin.renderer=this.EVA.plugin.renderer||{},this.EVA.plugin.renderer.spriteAnimation=function(e,t,n,r,o){"use strict";var i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function a(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}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 c(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((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])}}}function u(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.")}function l(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}function f(e){return function(t,n){var r=l(t,n);r.key=n,r.type=e}}function m(e){return function(t,n){l(t,n).step=e}}var h=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.autoPlay=!0,t.speed=100,t.waitPlay=!1,t.waitStop=!1,t.times=1/0,t.count=0,t}return a(t,e),t.prototype.init=function(e){var t=this;e&&_extends(this,e),this.on("loop",(function(){++t.count>=t.times&&(t.animate.stop(),t.emit("complete"))}))},t.prototype.play=function(e){void 0===e&&(e=1/0),0!==e&&(this.times=e,this.animate?(this.animate.play(),this.count=0):this.waitPlay=!0)},t.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(t.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),t.prototype.gotoAndPlay=function(e){this.animate.gotoAndPlay(e)},t.prototype.gotoAndStop=function(e){this.animate.gotoAndStop(e)},t.componentName="SpriteAnimation",s([f("string")],t.prototype,"resource",void 0),s([f("boolean")],t.prototype,"autoPlay",void 0),s([f("number"),m(10)],t.prototype,"speed",void 0),t}(t.Component),d="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t=e.name,n=e.data;return new Promise((function(e){var r,i,a=n.json,s=o.BaseTexture.from(n.image),c=a.frames||{},p=a.animations||{},l={};for(var f in c){l[t+d+f]=c[f]}for(var f in p){var m=[];if(p[f]&&p[f].length>=0)try{for(var h=(r=void 0,u(p[f])),y=h.next();!y.done;y=h.next()){var v=y.value,g=t+d+v;m.push(g)}}catch(e){r={error:e}}finally{try{y&&!y.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}p[f]=m}a.frames=l;var b=new o.Spritesheet(s,a);b.parse((function(){var t=b.textures,n=[];for(var r in t)n.push(t[r]);e(n)}))}))})),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t,n,r=e.instance;if(r)try{for(var o=u(r),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}}));var y=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="SpriteAnimation",t.animates={},t.autoPlay={},t}return a(o,e),o.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(e){var t=e.transform.size,n=t.width,r=t.height;this.animates[e.id]&&(this.animates[e.id].animatedSprite.width=n,this.animates[e.id].animatedSprite.height=r)},o.prototype.componentChanged=function(e){return c(this,void 0,void 0,(function(){var n,r,o;return p(this,(function(i){switch(i.label){case 0:return"SpriteAnimation"!==e.componentName?[3,7]:(n=e.component,this.autoPlay[e.gameObject.id]=n.autoPlay,e.type!==t.OBSERVER_TYPE.ADD?[3,2]:[4,t.resource.getResource(n.resource)]);case 1:return(r=i.sent().instance)||console.error("GameObject:"+e.gameObject.name+"'s Img resource load error"),this.add({frames:r,id:e.gameObject.id,component:n}),[3,7];case 2:return e.type!==t.OBSERVER_TYPE.CHANGE?[3,6]:e.prop&&"speed"===e.prop.prop[0]?(this.animates[e.gameObject.id].speed=1e3/60/n.speed,[3,5]):[3,3];case 3:return[4,t.resource.getResource(n.resource)];case 4:(o=i.sent().instance)||console.error("GameObject:"+e.gameObject.name+"'s Img resource load error"),this.change({frames:o,id:e.gameObject.id,component:n}),i.label=5;case 5:return[3,7];case 6:e.type===t.OBSERVER_TYPE.REMOVE&&this.remove(e.gameObject.id),i.label=7;case 7:return[2]}}))}))},o.prototype.add=function(e){var t=e.frames,n=e.id,o=e.component,i=new r.SpriteAnimation({frames:t});this.animates[n]=i,this.containerManager.getContainer(n).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[n],this.animates[n].speed=1e3/60/o.speed,this.autoPlay[n]&&i.animatedSprite.play()},o.prototype.change=function(e){var t=e.frames,n=e.id,r=e.component;this.remove(n,!0),this.add({frames:t,id:n,component:r})},o.prototype.remove=function(e,t){var n=this.animates[e];this.autoPlay[e]=n.animatedSprite.playing,this.containerManager.getContainer(e).removeChild(n.animatedSprite),n.animatedSprite.destroy({children:!0}),delete this.animates[e],t||delete this.autoPlay[e]},o.systemName="SpriteAnimation",o=s([t.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(n.Renderer);return e.SpriteAnimation=h,e.SpriteAnimationSystem=y,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);
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)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(null,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_spriteAnimation=function(e,t,n,r,o){"use strict";var i=function(e,t){return i=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])},i(e,t)};function a(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}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 c(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((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])}}}function u(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.")}function l(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}function d(e){return function(t,n){var r=l(t,n);r.key=n,r.type=e}}function m(e){return function(t,n){l(t,n).step=e}}var f=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.autoPlay=!0,t.speed=100,t.forwards=!1,t.waitPlay=!1,t.waitStop=!1,t.times=1/0,t.count=0,t.complete=!1,t}return a(t,e),t.prototype.init=function(e){var t=this;e&&_extends(this,e),this.on("loop",(function(){++t.count>=t.times&&(t.forwards?t.gotoAndStop(t.totalFrames-1):t.animate.stop(),t.complete=!0,t.emit("complete"))}))},t.prototype.play=function(e){void 0===e&&(e=1/0),0!==e&&(this.times=e,this.animate?(this.complete&&this.gotoAndStop(0),this.animate.play(),this.count=0,this.complete=!1):this.waitPlay=!0)},t.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(t.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),t.prototype.gotoAndPlay=function(e){this.animate.gotoAndPlay(e)},t.prototype.gotoAndStop=function(e){this.animate.gotoAndStop(e)},Object.defineProperty(t.prototype,"currentFrame",{get:function(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.currentFrame},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"totalFrames",{get:function(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.totalFrames},enumerable:!1,configurable:!0}),t.componentName="SpriteAnimation",s([d("string")],t.prototype,"resource",void 0),s([d("boolean")],t.prototype,"autoPlay",void 0),s([d("number"),m(10)],t.prototype,"speed",void 0),s([d("boolean")],t.prototype,"forwards",void 0),t}(t.Component),h=f,y="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t=e.name,n=e.data;return new Promise((function(e){var r,i,a=n.json.data,s=n.image instanceof o.Texture?n.image:o.Texture.from(n.image),c=a.frames||{},p=a.animations||{},l={};for(var d in c){l[t+y+d]=c[d]}for(var d in p){var m=[];if(p[d]&&p[d].length>=0)try{for(var f=(r=void 0,u(p[d])),h=f.next();!h.done;h=f.next()){var v=h.value,g=t+y+v;m.push(g)}}catch(e){r={error:e}}finally{try{h&&!h.done&&(i=f.return)&&i.call(f)}finally{if(r)throw r.error}}p[d]=m}a.frames=l;var b=new o.Spritesheet(s,a);b.parse().then((function(){var t=b.textures,n=[];for(var r in t)n.push(t[r]);e(n)}))}))})),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t,n,r=e.instance;if(r)try{for(var o=u(r),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}}));var v=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="SpriteAnimation",t.animates={},t.autoPlay={},t}return a(o,e),o.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(e){var t=e.transform.size,n=t.width,r=t.height;this.animates[e.id]&&(this.animates[e.id].animatedSprite.width=n,this.animates[e.id].animatedSprite.height=r)},o.prototype.componentChanged=function(e){return c(this,void 0,void 0,(function(){var n,r,o,i,a;return p(this,(function(s){switch(s.label){case 0:return n=e.gameObject.id,"SpriteAnimation"!==e.componentName?[3,7]:(r=e.component,this.autoPlay[e.gameObject.id]=r.autoPlay,e.type!==t.OBSERVER_TYPE.ADD?[3,2]:(i=this.increaseAsyncId(n),[4,t.resource.getResource(r.resource)]));case 1:return o=s.sent().instance,this.validateAsyncId(n,i)?(o||console.error("GameObject:"+e.gameObject.name+"'s Img resource load error"),this.add({frames:o,id:e.gameObject.id,component:r}),[3,7]):[2];case 2:return e.type!==t.OBSERVER_TYPE.CHANGE?[3,6]:e.prop&&"speed"===e.prop.prop[0]?(this.animates[e.gameObject.id].speed=1e3/60/r.speed,[3,5]):[3,3];case 3:return i=this.increaseAsyncId(n),[4,t.resource.getResource(r.resource)];case 4:if(a=s.sent().instance,!this.validateAsyncId(n,i))return[2];a||console.error("GameObject:"+e.gameObject.name+"'s Img resource load error"),this.change({frames:a,id:e.gameObject.id,component:r}),s.label=5;case 5:return[3,7];case 6:e.type===t.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(n),this.remove(e.gameObject.id)),s.label=7;case 7:return[2]}}))}))},o.prototype.add=function(e){var t=e.frames,n=e.id,o=e.component,i=new r.SpriteAnimation({frames:t});this.animates[n]=i,this.containerManager.getContainer(n).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[n],this.animates[n].speed=1e3/60/o.speed,this.autoPlay[n]&&i.animatedSprite.play()},o.prototype.change=function(e){var t=e.frames,n=e.id,r=e.component;this.remove(n,!0),this.add({frames:t,id:n,component:r})},o.prototype.remove=function(e,t){var n=this.animates[e];n&&(this.autoPlay[e]=n.animatedSprite.playing,this.containerManager.getContainer(e).removeChild(n.animatedSprite),n.animatedSprite.destroy(),delete this.animates[e],t||delete this.autoPlay[e])},o.systemName="SpriteAnimation",o=s([t.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(n.Renderer),g=v;return e.SpriteAnimation=h,e.SpriteAnimationSystem=g,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);window.EVA.plugin.renderer.spriteAnimation=window.EVA.plugin.renderer.spriteAnimation||_EVA_IIFE_spriteAnimation;
@@ -99,10 +99,12 @@ var SpriteAnimation$2 = (function (_super) {
99
99
  _this.resource = '';
100
100
  _this.autoPlay = true;
101
101
  _this.speed = 100;
102
+ _this.forwards = false;
102
103
  _this.waitPlay = false;
103
104
  _this.waitStop = false;
104
105
  _this.times = Infinity;
105
106
  _this.count = 0;
107
+ _this.complete = false;
106
108
  return _this;
107
109
  }
108
110
  SpriteAnimation.prototype.init = function (obj) {
@@ -110,7 +112,13 @@ var SpriteAnimation$2 = (function (_super) {
110
112
  obj && Object.assign(this, obj);
111
113
  this.on('loop', function () {
112
114
  if (++_this.count >= _this.times) {
113
- _this.animate.stop();
115
+ if (_this.forwards) {
116
+ _this.gotoAndStop(_this.totalFrames - 1);
117
+ }
118
+ else {
119
+ _this.animate.stop();
120
+ }
121
+ _this.complete = true;
114
122
  _this.emit('complete');
115
123
  }
116
124
  });
@@ -125,8 +133,12 @@ var SpriteAnimation$2 = (function (_super) {
125
133
  this.waitPlay = true;
126
134
  }
127
135
  else {
136
+ if (this.complete) {
137
+ this.gotoAndStop(0);
138
+ }
128
139
  this.animate.play();
129
140
  this.count = 0;
141
+ this.complete = false;
130
142
  }
131
143
  };
132
144
  SpriteAnimation.prototype.stop = function () {
@@ -161,6 +173,22 @@ var SpriteAnimation$2 = (function (_super) {
161
173
  SpriteAnimation.prototype.gotoAndStop = function (frameNumber) {
162
174
  this.animate.gotoAndStop(frameNumber);
163
175
  };
176
+ Object.defineProperty(SpriteAnimation.prototype, "currentFrame", {
177
+ get: function () {
178
+ var _a, _b;
179
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
180
+ },
181
+ enumerable: false,
182
+ configurable: true
183
+ });
184
+ Object.defineProperty(SpriteAnimation.prototype, "totalFrames", {
185
+ get: function () {
186
+ var _a, _b;
187
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
188
+ },
189
+ enumerable: false,
190
+ configurable: true
191
+ });
164
192
  SpriteAnimation.componentName = 'SpriteAnimation';
165
193
  __decorate([
166
194
  inspectorDecorator.type('string')
@@ -172,6 +200,9 @@ var SpriteAnimation$2 = (function (_super) {
172
200
  inspectorDecorator.type('number'),
173
201
  inspectorDecorator.step(10)
174
202
  ], SpriteAnimation.prototype, "speed", void 0);
203
+ __decorate([
204
+ inspectorDecorator.type('boolean')
205
+ ], SpriteAnimation.prototype, "forwards", void 0);
175
206
  return SpriteAnimation;
176
207
  }(eva_js.Component));
177
208
  var SpriteAnimation$3 = SpriteAnimation$2;
@@ -181,8 +212,8 @@ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, function
181
212
  var name = _a.name, data = _a.data;
182
213
  return new Promise(function (r) {
183
214
  var e_1, _a;
184
- var textureObj = data.json;
185
- var texture = pixi_js.BaseTexture.from(data.image);
215
+ var textureObj = data.json.data;
216
+ var texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
186
217
  var frames = textureObj.frames || {};
187
218
  var animations = textureObj.animations || {};
188
219
  var newFrames = {};
@@ -212,7 +243,7 @@ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, function
212
243
  }
213
244
  textureObj.frames = newFrames;
214
245
  var spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
215
- spriteSheet.parse(function () {
246
+ spriteSheet.parse().then(function () {
216
247
  var textures = spriteSheet.textures;
217
248
  var spriteFrames = [];
218
249
  for (var key in textures) {
@@ -263,17 +294,21 @@ var SpriteAnimation = (function (_super) {
263
294
  };
264
295
  SpriteAnimation.prototype.componentChanged = function (changed) {
265
296
  return __awaiter(this, void 0, void 0, function () {
266
- var component, frames_1, frames_2;
297
+ var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
267
298
  return __generator(this, function (_a) {
268
299
  switch (_a.label) {
269
300
  case 0:
301
+ gameObjectId = changed.gameObject.id;
270
302
  if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
271
303
  component = changed.component;
272
304
  this.autoPlay[changed.gameObject.id] = component.autoPlay;
273
305
  if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 2];
306
+ asyncId = this.increaseAsyncId(gameObjectId);
274
307
  return [4, eva_js.resource.getResource(component.resource)];
275
308
  case 1:
276
309
  frames_1 = (_a.sent()).instance;
310
+ if (!this.validateAsyncId(gameObjectId, asyncId))
311
+ return [2];
277
312
  if (!frames_1) {
278
313
  console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
279
314
  }
@@ -288,9 +323,13 @@ var SpriteAnimation = (function (_super) {
288
323
  if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
289
324
  this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
290
325
  return [3, 5];
291
- case 3: return [4, eva_js.resource.getResource(component.resource)];
326
+ case 3:
327
+ asyncId = this.increaseAsyncId(gameObjectId);
328
+ return [4, eva_js.resource.getResource(component.resource)];
292
329
  case 4:
293
330
  frames_2 = (_a.sent()).instance;
331
+ if (!this.validateAsyncId(gameObjectId, asyncId))
332
+ return [2];
294
333
  if (!frames_2) {
295
334
  console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
296
335
  }
@@ -303,6 +342,7 @@ var SpriteAnimation = (function (_super) {
303
342
  case 5: return [3, 7];
304
343
  case 6:
305
344
  if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
345
+ this.increaseAsyncId(gameObjectId);
306
346
  this.remove(changed.gameObject.id);
307
347
  }
308
348
  _a.label = 7;
@@ -338,9 +378,11 @@ var SpriteAnimation = (function (_super) {
338
378
  };
339
379
  SpriteAnimation.prototype.remove = function (id, isChange) {
340
380
  var animate = this.animates[id];
381
+ if (!animate)
382
+ return;
341
383
  this.autoPlay[id] = animate.animatedSprite.playing;
342
384
  this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
343
- animate.animatedSprite.destroy({ children: true });
385
+ animate.animatedSprite.destroy();
344
386
  delete this.animates[id];
345
387
  if (!isChange) {
346
388
  delete this.autoPlay[id];
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),n=require("@eva/plugin-renderer"),r=require("@eva/renderer-adapter"),o=require("pixi.js"),i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function a(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}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 c(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])}}}function p(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}var u=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.autoPlay=!0,t.speed=100,t.waitPlay=!1,t.waitStop=!1,t.times=1/0,t.count=0,t}return a(n,e),n.prototype.init=function(e){var t=this;e&&Object.assign(this,e),this.on("loop",(function(){++t.count>=t.times&&(t.animate.stop(),t.emit("complete"))}))},n.prototype.play=function(e){void 0===e&&(e=1/0),0!==e&&(this.times=e,this.animate?(this.animate.play(),this.count=0):this.waitPlay=!0)},n.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(n.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),n.prototype.gotoAndPlay=function(e){this.animate.gotoAndPlay(e)},n.prototype.gotoAndStop=function(e){this.animate.gotoAndStop(e)},n.componentName="SpriteAnimation",s([t.type("string")],n.prototype,"resource",void 0),s([t.type("boolean")],n.prototype,"autoPlay",void 0),s([t.type("number"),t.step(10)],n.prototype,"speed",void 0),n}(e.Component);e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t=e.name,n=e.data;return new Promise((function(e){var r,i,a=n.json,s=o.BaseTexture.from(n.image),c=a.frames||{},u=a.animations||{},l={};for(var m in c){l[t+"_s|r|c_"+m]=c[m]}for(var m in u){var f=[];if(u[m]&&u[m].length>=0)try{for(var h=(r=void 0,p(u[m])),d=h.next();!d.done;d=h.next()){var y=d.value,v=t+"_s|r|c_"+y;f.push(v)}}catch(e){r={error:e}}finally{try{d&&!d.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}u[m]=f}a.frames=l;var g=new o.Spritesheet(s,a);g.parse((function(){var t=g.textures,n=[];for(var r in t)n.push(t[r]);e(n)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t,n,r=e.instance;if(r)try{for(var o=p(r),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}}));var l=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="SpriteAnimation",e.animates={},e.autoPlay={},e}return a(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(e){var t=e.transform.size,n=t.width,r=t.height;this.animates[e.id]&&(this.animates[e.id].animatedSprite.width=n,this.animates[e.id].animatedSprite.height=r)},o.prototype.componentChanged=function(t){return n=this,r=void 0,i=function(){var n,r,o;return c(this,(function(i){switch(i.label){case 0:return"SpriteAnimation"!==t.componentName?[3,7]:(n=t.component,this.autoPlay[t.gameObject.id]=n.autoPlay,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:[4,e.resource.getResource(n.resource)]);case 1:return(r=i.sent().instance)||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.add({frames:r,id:t.gameObject.id,component:n}),[3,7];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,6]:t.prop&&"speed"===t.prop.prop[0]?(this.animates[t.gameObject.id].speed=1e3/60/n.speed,[3,5]):[3,3];case 3:return[4,e.resource.getResource(n.resource)];case 4:(o=i.sent().instance)||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.change({frames:o,id:t.gameObject.id,component:n}),i.label=5;case 5:return[3,7];case 6:t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t.gameObject.id),i.label=7;case 7:return[2]}}))},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{c(i.next(e))}catch(e){t(e)}}function s(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){t.done?e(t.value):new o((function(e){e(t.value)})).then(a,s)}c((i=i.apply(n,r||[])).next())}));var n,r,o,i},o.prototype.add=function(e){var t=e.frames,n=e.id,o=e.component,i=new r.SpriteAnimation({frames:t});this.animates[n]=i,this.containerManager.getContainer(n).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[n],this.animates[n].speed=1e3/60/o.speed,this.autoPlay[n]&&i.animatedSprite.play()},o.prototype.change=function(e){var t=e.frames,n=e.id,r=e.component;this.remove(n,!0),this.add({frames:t,id:n,component:r})},o.prototype.remove=function(e,t){var n=this.animates[e];this.autoPlay[e]=n.animatedSprite.playing,this.containerManager.getContainer(e).removeChild(n.animatedSprite),n.animatedSprite.destroy({children:!0}),delete this.animates[e],t||delete this.autoPlay[e]},o.systemName="SpriteAnimation",o=s([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(n.Renderer);exports.SpriteAnimation=u,exports.SpriteAnimationSystem=l;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),n=require("@eva/renderer-adapter"),o=require("pixi.js"),i=function(e,t){return i=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])},i(e,t)};function a(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function s(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function c(e,t){var r,n,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(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=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++,n=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],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function p(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}}}}var u=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.autoPlay=!0,t.speed=100,t.forwards=!1,t.waitPlay=!1,t.waitStop=!1,t.times=1/0,t.count=0,t.complete=!1,t}return a(r,e),r.prototype.init=function(e){var t=this;e&&Object.assign(this,e),this.on("loop",(function(){++t.count>=t.times&&(t.forwards?t.gotoAndStop(t.totalFrames-1):t.animate.stop(),t.complete=!0,t.emit("complete"))}))},r.prototype.play=function(e){void 0===e&&(e=1/0),0!==e&&(this.times=e,this.animate?(this.complete&&this.gotoAndStop(0),this.animate.play(),this.count=0,this.complete=!1):this.waitPlay=!0)},r.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(r.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),r.prototype.gotoAndPlay=function(e){this.animate.gotoAndPlay(e)},r.prototype.gotoAndStop=function(e){this.animate.gotoAndStop(e)},Object.defineProperty(r.prototype,"currentFrame",{get:function(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.currentFrame},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"totalFrames",{get:function(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.totalFrames},enumerable:!1,configurable:!0}),r.componentName="SpriteAnimation",s([t.type("string")],r.prototype,"resource",void 0),s([t.type("boolean")],r.prototype,"autoPlay",void 0),s([t.type("number"),t.step(10)],r.prototype,"speed",void 0),s([t.type("boolean")],r.prototype,"forwards",void 0),r}(e.Component),l=u,m="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t=e.name,r=e.data;return new Promise((function(e){var n,i,a=r.json.data,s=r.image instanceof o.Texture?r.image:o.Texture.from(r.image),c=a.frames||{},u=a.animations||{},l={};for(var d in c){l[t+m+d]=c[d]}for(var d in u){var f=[];if(u[d]&&u[d].length>=0)try{for(var h=(n=void 0,p(u[d])),y=h.next();!y.done;y=h.next()){var v=y.value,g=t+m+v;f.push(g)}}catch(e){n={error:e}}finally{try{y&&!y.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}u[d]=f}a.frames=l;var b=new o.Spritesheet(s,a);b.parse().then((function(){var t=b.textures,r=[];for(var n in t)r.push(t[n]);e(r)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t,r,n=e.instance;if(n)try{for(var o=p(n),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}}));var d=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="SpriteAnimation",e.animates={},e.autoPlay={},e}return a(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(e){var t=e.transform.size,r=t.width,n=t.height;this.animates[e.id]&&(this.animates[e.id].animatedSprite.width=r,this.animates[e.id].animatedSprite.height=n)},o.prototype.componentChanged=function(t){return r=this,n=void 0,i=function(){var r,n,o,i,a;return c(this,(function(s){switch(s.label){case 0:return r=t.gameObject.id,"SpriteAnimation"!==t.componentName?[3,7]:(n=t.component,this.autoPlay[t.gameObject.id]=n.autoPlay,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:(i=this.increaseAsyncId(r),[4,e.resource.getResource(n.resource)]));case 1:return o=s.sent().instance,this.validateAsyncId(r,i)?(o||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.add({frames:o,id:t.gameObject.id,component:n}),[3,7]):[2];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,6]:t.prop&&"speed"===t.prop.prop[0]?(this.animates[t.gameObject.id].speed=1e3/60/n.speed,[3,5]):[3,3];case 3:return i=this.increaseAsyncId(r),[4,e.resource.getResource(n.resource)];case 4:if(a=s.sent().instance,!this.validateAsyncId(r,i))return[2];a||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.change({frames:a,id:t.gameObject.id,component:n}),s.label=5;case 5:return[3,7];case 6:t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(r),this.remove(t.gameObject.id)),s.label=7;case 7:return[2]}}))},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{c(i.next(e))}catch(e){t(e)}}function s(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){t.done?e(t.value):new o((function(e){e(t.value)})).then(a,s)}c((i=i.apply(r,n||[])).next())}));var r,n,o,i},o.prototype.add=function(e){var t=e.frames,r=e.id,o=e.component,i=new n.SpriteAnimation({frames:t});this.animates[r]=i,this.containerManager.getContainer(r).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[r],this.animates[r].speed=1e3/60/o.speed,this.autoPlay[r]&&i.animatedSprite.play()},o.prototype.change=function(e){var t=e.frames,r=e.id,n=e.component;this.remove(r,!0),this.add({frames:t,id:r,component:n})},o.prototype.remove=function(e,t){var r=this.animates[e];r&&(this.autoPlay[e]=r.animatedSprite.playing,this.containerManager.getContainer(e).removeChild(r.animatedSprite),r.animatedSprite.destroy(),delete this.animates[e],t||delete this.autoPlay[e])},o.systemName="SpriteAnimation",o=s([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(r.Renderer);exports.SpriteAnimation=l,exports.SpriteAnimationSystem=d;
@@ -12,11 +12,13 @@ export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
12
12
  resource: string;
13
13
  autoPlay: boolean;
14
14
  speed: number;
15
+ forwards: boolean;
15
16
  _animate: SpriteAnimation_2;
16
17
  private waitPlay;
17
18
  private waitStop;
18
19
  private times;
19
20
  private count;
21
+ private complete;
20
22
  init(obj?: SpriteAnimationParams): void;
21
23
  play(times?: number): void;
22
24
  stop(): void;
@@ -24,12 +26,15 @@ export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
24
26
  get animate(): SpriteAnimation_2;
25
27
  gotoAndPlay(frameNumber: any): void;
26
28
  gotoAndStop(frameNumber: any): void;
29
+ get currentFrame(): number;
30
+ get totalFrames(): number;
27
31
  }
28
32
 
29
33
  export declare interface SpriteAnimationParams {
30
34
  resource: string;
31
- autoPlay: boolean;
32
- speed: number;
35
+ autoPlay?: boolean;
36
+ speed?: number;
37
+ forwards?: boolean;
33
38
  }
34
39
 
35
40
  export declare class SpriteAnimationSystem extends Renderer {
@@ -2,7 +2,7 @@ import { Component, resource, RESOURCE_TYPE, decorators, OBSERVER_TYPE } from '@
2
2
  import { type, step } from '@eva/inspector-decorator';
3
3
  import { RendererSystem, Renderer } from '@eva/plugin-renderer';
4
4
  import { SpriteAnimation as SpriteAnimation$4 } from '@eva/renderer-adapter';
5
- import { BaseTexture, Spritesheet } from 'pixi.js';
5
+ import { Texture, Spritesheet } from 'pixi.js';
6
6
 
7
7
  /*! *****************************************************************************
8
8
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -95,10 +95,12 @@ var SpriteAnimation$2 = (function (_super) {
95
95
  _this.resource = '';
96
96
  _this.autoPlay = true;
97
97
  _this.speed = 100;
98
+ _this.forwards = false;
98
99
  _this.waitPlay = false;
99
100
  _this.waitStop = false;
100
101
  _this.times = Infinity;
101
102
  _this.count = 0;
103
+ _this.complete = false;
102
104
  return _this;
103
105
  }
104
106
  SpriteAnimation.prototype.init = function (obj) {
@@ -106,7 +108,13 @@ var SpriteAnimation$2 = (function (_super) {
106
108
  obj && Object.assign(this, obj);
107
109
  this.on('loop', function () {
108
110
  if (++_this.count >= _this.times) {
109
- _this.animate.stop();
111
+ if (_this.forwards) {
112
+ _this.gotoAndStop(_this.totalFrames - 1);
113
+ }
114
+ else {
115
+ _this.animate.stop();
116
+ }
117
+ _this.complete = true;
110
118
  _this.emit('complete');
111
119
  }
112
120
  });
@@ -121,8 +129,12 @@ var SpriteAnimation$2 = (function (_super) {
121
129
  this.waitPlay = true;
122
130
  }
123
131
  else {
132
+ if (this.complete) {
133
+ this.gotoAndStop(0);
134
+ }
124
135
  this.animate.play();
125
136
  this.count = 0;
137
+ this.complete = false;
126
138
  }
127
139
  };
128
140
  SpriteAnimation.prototype.stop = function () {
@@ -157,6 +169,22 @@ var SpriteAnimation$2 = (function (_super) {
157
169
  SpriteAnimation.prototype.gotoAndStop = function (frameNumber) {
158
170
  this.animate.gotoAndStop(frameNumber);
159
171
  };
172
+ Object.defineProperty(SpriteAnimation.prototype, "currentFrame", {
173
+ get: function () {
174
+ var _a, _b;
175
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
176
+ },
177
+ enumerable: false,
178
+ configurable: true
179
+ });
180
+ Object.defineProperty(SpriteAnimation.prototype, "totalFrames", {
181
+ get: function () {
182
+ var _a, _b;
183
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
184
+ },
185
+ enumerable: false,
186
+ configurable: true
187
+ });
160
188
  SpriteAnimation.componentName = 'SpriteAnimation';
161
189
  __decorate([
162
190
  type('string')
@@ -168,6 +196,9 @@ var SpriteAnimation$2 = (function (_super) {
168
196
  type('number'),
169
197
  step(10)
170
198
  ], SpriteAnimation.prototype, "speed", void 0);
199
+ __decorate([
200
+ type('boolean')
201
+ ], SpriteAnimation.prototype, "forwards", void 0);
171
202
  return SpriteAnimation;
172
203
  }(Component));
173
204
  var SpriteAnimation$3 = SpriteAnimation$2;
@@ -177,8 +208,8 @@ resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
177
208
  var name = _a.name, data = _a.data;
178
209
  return new Promise(function (r) {
179
210
  var e_1, _a;
180
- var textureObj = data.json;
181
- var texture = BaseTexture.from(data.image);
211
+ var textureObj = data.json.data;
212
+ var texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
182
213
  var frames = textureObj.frames || {};
183
214
  var animations = textureObj.animations || {};
184
215
  var newFrames = {};
@@ -208,7 +239,7 @@ resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
208
239
  }
209
240
  textureObj.frames = newFrames;
210
241
  var spriteSheet = new Spritesheet(texture, textureObj);
211
- spriteSheet.parse(function () {
242
+ spriteSheet.parse().then(function () {
212
243
  var textures = spriteSheet.textures;
213
244
  var spriteFrames = [];
214
245
  for (var key in textures) {
@@ -259,17 +290,21 @@ var SpriteAnimation = (function (_super) {
259
290
  };
260
291
  SpriteAnimation.prototype.componentChanged = function (changed) {
261
292
  return __awaiter(this, void 0, void 0, function () {
262
- var component, frames_1, frames_2;
293
+ var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
263
294
  return __generator(this, function (_a) {
264
295
  switch (_a.label) {
265
296
  case 0:
297
+ gameObjectId = changed.gameObject.id;
266
298
  if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
267
299
  component = changed.component;
268
300
  this.autoPlay[changed.gameObject.id] = component.autoPlay;
269
301
  if (!(changed.type === OBSERVER_TYPE.ADD)) return [3, 2];
302
+ asyncId = this.increaseAsyncId(gameObjectId);
270
303
  return [4, resource.getResource(component.resource)];
271
304
  case 1:
272
305
  frames_1 = (_a.sent()).instance;
306
+ if (!this.validateAsyncId(gameObjectId, asyncId))
307
+ return [2];
273
308
  if (!frames_1) {
274
309
  console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
275
310
  }
@@ -284,9 +319,13 @@ var SpriteAnimation = (function (_super) {
284
319
  if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
285
320
  this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
286
321
  return [3, 5];
287
- case 3: return [4, resource.getResource(component.resource)];
322
+ case 3:
323
+ asyncId = this.increaseAsyncId(gameObjectId);
324
+ return [4, resource.getResource(component.resource)];
288
325
  case 4:
289
326
  frames_2 = (_a.sent()).instance;
327
+ if (!this.validateAsyncId(gameObjectId, asyncId))
328
+ return [2];
290
329
  if (!frames_2) {
291
330
  console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
292
331
  }
@@ -299,6 +338,7 @@ var SpriteAnimation = (function (_super) {
299
338
  case 5: return [3, 7];
300
339
  case 6:
301
340
  if (changed.type === OBSERVER_TYPE.REMOVE) {
341
+ this.increaseAsyncId(gameObjectId);
302
342
  this.remove(changed.gameObject.id);
303
343
  }
304
344
  _a.label = 7;
@@ -334,9 +374,11 @@ var SpriteAnimation = (function (_super) {
334
374
  };
335
375
  SpriteAnimation.prototype.remove = function (id, isChange) {
336
376
  var animate = this.animates[id];
377
+ if (!animate)
378
+ return;
337
379
  this.autoPlay[id] = animate.animatedSprite.playing;
338
380
  this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
339
- animate.animatedSprite.destroy({ children: true });
381
+ animate.animatedSprite.destroy();
340
382
  delete this.animates[id];
341
383
  if (!isChange) {
342
384
  delete this.autoPlay[id];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite-animation",
3
- "version": "1.3.0-alpha.1",
3
+ "version": "2.0.0-beta.1",
4
4
  "description": "@eva/plugin-renderer-sprite-animation",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-sprite-animation.esm.js",
@@ -19,9 +19,9 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "^0.0.5",
22
- "@eva/plugin-renderer": "1.3.0-alpha.1",
23
- "@eva/renderer-adapter": "1.3.0-alpha.1",
24
- "@eva/eva.js": "1.3.0-alpha.1",
25
- "pixi.js": "^4.8.7"
22
+ "@eva/plugin-renderer": "2.0.0-beta.1",
23
+ "@eva/renderer-adapter": "2.0.0-beta.1",
24
+ "@eva/eva.js": "2.0.0-beta.1",
25
+ "pixi.js": "^8.6.3"
26
26
  }
27
27
  }