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

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.
@@ -4,23 +4,6 @@ window.EVA.plugin = window.EVA.plugin || {};
4
4
  window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
5
5
  var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rendererAdapter, pixi_js) {
6
6
  'use strict';
7
- var extendStatics = function (d, b) {
8
- extendStatics = Object.setPrototypeOf || {
9
- __proto__: []
10
- } instanceof Array && function (d, b) {
11
- d.__proto__ = b;
12
- } || function (d, b) {
13
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
14
- };
15
- return extendStatics(d, b);
16
- };
17
- function __extends(d, b) {
18
- extendStatics(d, b);
19
- function __() {
20
- this.constructor = d;
21
- }
22
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
23
- }
24
7
  function __decorate(decorators, target, key, desc) {
25
8
  var c = arguments.length,
26
9
  r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
@@ -55,110 +38,6 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
55
38
  step((generator = generator.apply(thisArg, _arguments || [])).next());
56
39
  });
57
40
  }
58
- function __generator(thisArg, body) {
59
- var _ = {
60
- label: 0,
61
- sent: function () {
62
- if (t[0] & 1) throw t[1];
63
- return t[1];
64
- },
65
- trys: [],
66
- ops: []
67
- },
68
- f,
69
- y,
70
- t,
71
- g;
72
- return g = {
73
- next: verb(0),
74
- "throw": verb(1),
75
- "return": verb(2)
76
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
77
- return this;
78
- }), g;
79
- function verb(n) {
80
- return function (v) {
81
- return step([n, v]);
82
- };
83
- }
84
- function step(op) {
85
- if (f) throw new TypeError("Generator is already executing.");
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];
120
- t = op;
121
- break;
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;
131
- }
132
- op = body.call(thisArg, _);
133
- } catch (e) {
134
- op = [6, e];
135
- y = 0;
136
- } finally {
137
- f = t = 0;
138
- }
139
- if (op[0] & 5) throw op[1];
140
- return {
141
- value: op[0] ? op[1] : void 0,
142
- done: true
143
- };
144
- }
145
- }
146
- function __values(o) {
147
- var s = typeof Symbol === "function" && Symbol.iterator,
148
- m = s && o[s],
149
- i = 0;
150
- if (m) return m.call(o);
151
- if (o && typeof o.length === "number") return {
152
- next: function () {
153
- if (o && i >= o.length) o = void 0;
154
- return {
155
- value: o && o[i++],
156
- done: !o
157
- };
158
- }
159
- };
160
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
161
- }
162
41
  function getIDEPropsPropertyObj(target, propertyKey) {
163
42
  if (!target.constructor.IDEProps) {
164
43
  target.constructor.IDEProps = {};
@@ -182,40 +61,34 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
182
61
  prop.step = step;
183
62
  };
184
63
  }
185
- var SpriteAnimation$2 = function (_super) {
186
- __extends(SpriteAnimation, _super);
187
- function SpriteAnimation() {
188
- var _this = _super !== null && _super.apply(this, arguments) || this;
189
- _this.resource = '';
190
- _this.autoPlay = true;
191
- _this.speed = 100;
192
- _this.forwards = false;
193
- _this.waitPlay = false;
194
- _this.waitStop = false;
195
- _this.times = Infinity;
196
- _this.count = 0;
197
- _this.complete = false;
198
- return _this;
64
+ class SpriteAnimation$2 extends eva_js.Component {
65
+ constructor() {
66
+ super(...arguments);
67
+ this.resource = '';
68
+ this.autoPlay = true;
69
+ this.speed = 100;
70
+ this.forwards = false;
71
+ this.waitPlay = false;
72
+ this.waitStop = false;
73
+ this.times = Infinity;
74
+ this.count = 0;
75
+ this.complete = false;
199
76
  }
200
- SpriteAnimation.prototype.init = function (obj) {
201
- var _this = this;
77
+ init(obj) {
202
78
  obj && _extends(this, obj);
203
- this.on('loop', function () {
204
- if (++_this.count >= _this.times) {
205
- if (_this.forwards) {
206
- _this.gotoAndStop(_this.totalFrames - 1);
79
+ this.on('loop', () => {
80
+ if (++this.count >= this.times) {
81
+ if (this.forwards) {
82
+ this.gotoAndStop(this.totalFrames - 1);
207
83
  } else {
208
- _this.animate.stop();
84
+ this.animate.stop();
209
85
  }
210
- _this.complete = true;
211
- _this.emit('complete');
86
+ this.complete = true;
87
+ this.emit('complete');
212
88
  }
213
89
  });
214
- };
215
- SpriteAnimation.prototype.play = function (times) {
216
- if (times === void 0) {
217
- times = Infinity;
218
- }
90
+ }
91
+ play(times = Infinity) {
219
92
  if (times === 0) {
220
93
  return;
221
94
  }
@@ -230,230 +103,178 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
230
103
  this.count = 0;
231
104
  this.complete = false;
232
105
  }
233
- };
234
- SpriteAnimation.prototype.stop = function () {
106
+ }
107
+ stop() {
235
108
  if (!this.animate) {
236
109
  this.waitStop = true;
237
110
  } else {
238
111
  this.animate.stop();
239
112
  }
240
- };
241
- Object.defineProperty(SpriteAnimation.prototype, "animate", {
242
- get: function () {
243
- return this._animate;
244
- },
245
- set: function (val) {
246
- this._animate = val;
247
- if (this.waitPlay) {
248
- this.waitPlay = false;
249
- this.play(this.times);
250
- }
251
- if (this.waitStop) {
252
- this.waitStop = false;
253
- this.stop();
254
- }
255
- },
256
- enumerable: false,
257
- configurable: true
258
- });
259
- SpriteAnimation.prototype.gotoAndPlay = function (frameNumber) {
113
+ }
114
+ set animate(val) {
115
+ this._animate = val;
116
+ if (this.waitPlay) {
117
+ this.waitPlay = false;
118
+ this.play(this.times);
119
+ }
120
+ if (this.waitStop) {
121
+ this.waitStop = false;
122
+ this.stop();
123
+ }
124
+ }
125
+ get animate() {
126
+ return this._animate;
127
+ }
128
+ gotoAndPlay(frameNumber) {
260
129
  this.animate.gotoAndPlay(frameNumber);
261
- };
262
- SpriteAnimation.prototype.gotoAndStop = function (frameNumber) {
130
+ }
131
+ gotoAndStop(frameNumber) {
263
132
  this.animate.gotoAndStop(frameNumber);
264
- };
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
- });
281
- SpriteAnimation.componentName = 'SpriteAnimation';
282
- __decorate([type('string')], SpriteAnimation.prototype, "resource", void 0);
283
- __decorate([type('boolean')], SpriteAnimation.prototype, "autoPlay", void 0);
284
- __decorate([type('number'), step(10)], SpriteAnimation.prototype, "speed", void 0);
285
- __decorate([type('boolean')], SpriteAnimation.prototype, "forwards", void 0);
286
- return SpriteAnimation;
287
- }(eva_js.Component);
288
- var SpriteAnimation$3 = SpriteAnimation$2;
289
- var resourceKeySplit = '_s|r|c_';
290
- eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
291
- var name = _a.name,
292
- data = _a.data;
293
- return new Promise(function (r) {
294
- var e_1, _a;
295
- var textureObj = data.json.data;
296
- var texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
297
- var frames = textureObj.frames || {};
298
- var animations = textureObj.animations || {};
299
- var newFrames = {};
300
- for (var key in frames) {
301
- var newKey = name + resourceKeySplit + key;
133
+ }
134
+ get currentFrame() {
135
+ var _a, _b;
136
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
137
+ }
138
+ get totalFrames() {
139
+ var _a, _b;
140
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
141
+ }
142
+ }
143
+ SpriteAnimation$2.componentName = 'SpriteAnimation';
144
+ __decorate([type('string')], SpriteAnimation$2.prototype, "resource", void 0);
145
+ __decorate([type('boolean')], SpriteAnimation$2.prototype, "autoPlay", void 0);
146
+ __decorate([type('number'), step(10)], SpriteAnimation$2.prototype, "speed", void 0);
147
+ __decorate([type('boolean')], SpriteAnimation$2.prototype, "forwards", void 0);
148
+ const resourceKeySplit = '_s|r|c_';
149
+ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({
150
+ name,
151
+ data
152
+ }) => {
153
+ return new Promise(r => {
154
+ const textureObj = data.json.data;
155
+ const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
156
+ const frames = textureObj.frames || {};
157
+ const animations = textureObj.animations || {};
158
+ const newFrames = {};
159
+ for (const key in frames) {
160
+ const newKey = name + resourceKeySplit + key;
302
161
  newFrames[newKey] = frames[key];
303
162
  }
304
- for (var key in animations) {
305
- var spriteList = [];
163
+ for (const key in animations) {
164
+ const spriteList = [];
306
165
  if (animations[key] && animations[key].length >= 0) {
307
- try {
308
- for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
309
- var spriteName = _c.value;
310
- var newSpriteName = name + resourceKeySplit + spriteName;
311
- spriteList.push(newSpriteName);
312
- }
313
- } catch (e_1_1) {
314
- e_1 = {
315
- error: e_1_1
316
- };
317
- } finally {
318
- try {
319
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
320
- } finally {
321
- if (e_1) throw e_1.error;
322
- }
166
+ for (const spriteName of animations[key]) {
167
+ const newSpriteName = name + resourceKeySplit + spriteName;
168
+ spriteList.push(newSpriteName);
323
169
  }
324
170
  }
325
171
  animations[key] = spriteList;
326
172
  }
327
173
  textureObj.frames = newFrames;
328
- var spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
329
- spriteSheet.parse().then(function () {
330
- var textures = spriteSheet.textures;
331
- var spriteFrames = [];
332
- for (var key in textures) {
174
+ const spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
175
+ spriteSheet.parse().then(() => {
176
+ const {
177
+ textures
178
+ } = spriteSheet;
179
+ const spriteFrames = [];
180
+ for (const key in textures) {
333
181
  spriteFrames.push(textures[key]);
334
182
  }
335
183
  r(spriteFrames);
336
184
  });
337
185
  });
338
186
  });
339
- eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
340
- var e_2, _b;
341
- var instance = _a.instance;
187
+ eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({
188
+ instance
189
+ }) => {
342
190
  if (!instance) return;
343
- try {
344
- for (var instance_1 = __values(instance), instance_1_1 = instance_1.next(); !instance_1_1.done; instance_1_1 = instance_1.next()) {
345
- var texture = instance_1_1.value;
346
- texture.destroy(true);
347
- }
348
- } catch (e_2_1) {
349
- e_2 = {
350
- error: e_2_1
351
- };
352
- } finally {
353
- try {
354
- if (instance_1_1 && !instance_1_1.done && (_b = instance_1.return)) _b.call(instance_1);
355
- } finally {
356
- if (e_2) throw e_2.error;
357
- }
191
+ for (const texture of instance) {
192
+ texture.destroy(true);
358
193
  }
359
194
  });
360
- var SpriteAnimation = function (_super) {
361
- __extends(SpriteAnimation, _super);
362
- function SpriteAnimation() {
363
- var _this = _super !== null && _super.apply(this, arguments) || this;
364
- _this.name = 'SpriteAnimation';
365
- _this.animates = {};
366
- _this.autoPlay = {};
367
- return _this;
195
+ let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
196
+ constructor() {
197
+ super(...arguments);
198
+ this.name = 'SpriteAnimation';
199
+ this.animates = {};
200
+ this.autoPlay = {};
368
201
  }
369
- SpriteAnimation.prototype.init = function () {
202
+ init() {
370
203
  this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
371
204
  this.renderSystem.rendererManager.register(this);
372
- };
373
- SpriteAnimation.prototype.rendererUpdate = function (gameObject) {
374
- var _a = gameObject.transform.size,
375
- width = _a.width,
376
- height = _a.height;
205
+ }
206
+ rendererUpdate(gameObject) {
207
+ const {
208
+ width,
209
+ height
210
+ } = gameObject.transform.size;
377
211
  if (this.animates[gameObject.id]) {
378
212
  this.animates[gameObject.id].animatedSprite.width = width;
379
213
  this.animates[gameObject.id].animatedSprite.height = height;
380
214
  }
381
- };
382
- SpriteAnimation.prototype.componentChanged = function (changed) {
383
- return __awaiter(this, void 0, void 0, function () {
384
- var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
385
- return __generator(this, function (_a) {
386
- switch (_a.label) {
387
- case 0:
388
- gameObjectId = changed.gameObject.id;
389
- if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
390
- component = changed.component;
391
- this.autoPlay[changed.gameObject.id] = component.autoPlay;
392
- if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 2];
393
- asyncId = this.increaseAsyncId(gameObjectId);
394
- return [4, eva_js.resource.getResource(component.resource)];
395
- case 1:
396
- frames_1 = _a.sent().instance;
397
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
398
- if (!frames_1) {
399
- console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
400
- }
401
- this.add({
402
- frames: frames_1,
403
- id: changed.gameObject.id,
404
- component: component
405
- });
406
- return [3, 7];
407
- case 2:
408
- if (!(changed.type === eva_js.OBSERVER_TYPE.CHANGE)) return [3, 6];
409
- if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
215
+ }
216
+ componentChanged(changed) {
217
+ return __awaiter(this, void 0, void 0, function* () {
218
+ const gameObjectId = changed.gameObject.id;
219
+ if (changed.componentName === 'SpriteAnimation') {
220
+ const component = changed.component;
221
+ this.autoPlay[changed.gameObject.id] = component.autoPlay;
222
+ if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
223
+ const asyncId = this.increaseAsyncId(gameObjectId);
224
+ const {
225
+ instance: frames
226
+ } = yield eva_js.resource.getResource(component.resource);
227
+ if (!this.validateAsyncId(gameObjectId, asyncId)) return;
228
+ if (!frames) {
229
+ console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
230
+ }
231
+ this.add({
232
+ frames: frames,
233
+ id: changed.gameObject.id,
234
+ component
235
+ });
236
+ } else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
237
+ if (changed.prop && changed.prop.prop[0] === 'speed') {
410
238
  this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
411
- return [3, 5];
412
- case 3:
413
- asyncId = this.increaseAsyncId(gameObjectId);
414
- return [4, eva_js.resource.getResource(component.resource)];
415
- case 4:
416
- frames_2 = _a.sent().instance;
417
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
418
- if (!frames_2) {
419
- console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
239
+ } else {
240
+ const asyncId = this.increaseAsyncId(gameObjectId);
241
+ const {
242
+ instance: frames
243
+ } = yield eva_js.resource.getResource(component.resource);
244
+ if (!this.validateAsyncId(gameObjectId, asyncId)) return;
245
+ if (!frames) {
246
+ console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
420
247
  }
421
248
  this.change({
422
- frames: frames_2,
249
+ frames: frames,
423
250
  id: changed.gameObject.id,
424
- component: component
251
+ component
425
252
  });
426
- _a.label = 5;
427
- case 5:
428
- return [3, 7];
429
- case 6:
430
- if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
431
- this.increaseAsyncId(gameObjectId);
432
- this.remove(changed.gameObject.id);
433
- }
434
- _a.label = 7;
435
- case 7:
436
- return [2];
253
+ }
254
+ } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
255
+ this.increaseAsyncId(gameObjectId);
256
+ this.remove(changed.gameObject.id);
437
257
  }
438
- });
258
+ }
439
259
  });
440
- };
441
- SpriteAnimation.prototype.add = function (_a) {
442
- var frames = _a.frames,
443
- id = _a.id,
444
- component = _a.component;
445
- var animate = new rendererAdapter.SpriteAnimation({
446
- frames: frames
260
+ }
261
+ add({
262
+ frames,
263
+ id,
264
+ component
265
+ }) {
266
+ const animate = new rendererAdapter.SpriteAnimation({
267
+ frames
447
268
  });
448
269
  this.animates[id] = animate;
449
270
  this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
450
- animate.animatedSprite.onComplete = function () {
271
+ animate.animatedSprite.onComplete = () => {
451
272
  component.emit('complete');
452
273
  };
453
- animate.animatedSprite.onFrameChange = function () {
274
+ animate.animatedSprite.onFrameChange = () => {
454
275
  component.emit('frameChange');
455
276
  };
456
- animate.animatedSprite.onLoop = function () {
277
+ animate.animatedSprite.onLoop = () => {
457
278
  component.emit('loop');
458
279
  };
459
280
  component.animate = this.animates[id];
@@ -461,20 +282,21 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
461
282
  if (this.autoPlay[id]) {
462
283
  animate.animatedSprite.play();
463
284
  }
464
- };
465
- SpriteAnimation.prototype.change = function (_a) {
466
- var frames = _a.frames,
467
- id = _a.id,
468
- component = _a.component;
285
+ }
286
+ change({
287
+ frames,
288
+ id,
289
+ component
290
+ }) {
469
291
  this.remove(id, true);
470
292
  this.add({
471
- frames: frames,
472
- id: id,
473
- component: component
293
+ frames,
294
+ id,
295
+ component
474
296
  });
475
- };
476
- SpriteAnimation.prototype.remove = function (id, isChange) {
477
- var animate = this.animates[id];
297
+ }
298
+ remove(id, isChange) {
299
+ const animate = this.animates[id];
478
300
  if (!animate) return;
479
301
  this.autoPlay[id] = animate.animatedSprite.playing;
480
302
  this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
@@ -483,15 +305,14 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
483
305
  if (!isChange) {
484
306
  delete this.autoPlay[id];
485
307
  }
486
- };
487
- SpriteAnimation.systemName = 'SpriteAnimation';
488
- SpriteAnimation = __decorate([eva_js.decorators.componentObserver({
489
- SpriteAnimation: ['speed', 'resource']
490
- })], SpriteAnimation);
491
- return SpriteAnimation;
492
- }(pluginRenderer.Renderer);
308
+ }
309
+ };
310
+ SpriteAnimation.systemName = 'SpriteAnimation';
311
+ SpriteAnimation = __decorate([eva_js.decorators.componentObserver({
312
+ SpriteAnimation: ['speed', 'resource']
313
+ })], SpriteAnimation);
493
314
  var SpriteAnimation$1 = SpriteAnimation;
494
- exports.SpriteAnimation = SpriteAnimation$3;
315
+ exports.SpriteAnimation = SpriteAnimation$2;
495
316
  exports.SpriteAnimationSystem = SpriteAnimation$1;
496
317
  Object.defineProperty(exports, '__esModule', {
497
318
  value: true
@@ -1 +1 @@
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;
1
+ function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)({}).hasOwnProperty.call(i,n)&&(e[n]=i[n])}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,i,n,o){"use strict";function r(e,t,i,n){var o,r=arguments.length,s=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(r<3?o(s):r>3?o(t,i,s):o(t,i))||s);return r>3&&s&&Object.defineProperty(t,i,s),s}function s(e,t,i,n){return new(i||(i=Promise))((function(o,r){function s(e){try{c(n.next(e))}catch(e){r(e)}}function a(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function a(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}function c(e){return function(t,i){var n=a(t,i);n.key=i,n.type=e}}class m extends t.Component{constructor(){super(...arguments),this.resource="",this.autoPlay=!0,this.speed=100,this.forwards=!1,this.waitPlay=!1,this.waitStop=!1,this.times=1/0,this.count=0,this.complete=!1}init(e){e&&_extends(this,e),this.on("loop",(()=>{++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):this.animate.stop(),this.complete=!0,this.emit("complete"))}))}play(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)}stop(){this.animate?this.animate.stop():this.waitStop=!0}set animate(e){this._animate=e,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())}get animate(){return this._animate}gotoAndPlay(e){this.animate.gotoAndPlay(e)}gotoAndStop(e){this.animate.gotoAndStop(e)}get currentFrame(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.currentFrame}get totalFrames(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.totalFrames}}m.componentName="SpriteAnimation",r([c("string")],m.prototype,"resource",void 0),r([c("boolean")],m.prototype,"autoPlay",void 0),r([c("number"),function(e){return function(t,i){a(t,i).step=e}}(10)],m.prototype,"speed",void 0),r([c("boolean")],m.prototype,"forwards",void 0);const d="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE_ANIMATION,(({name:e,data:t})=>new Promise((i=>{const n=t.json.data,r=t.image instanceof o.Texture?t.image:o.Texture.from(t.image),s=n.frames||{},a=n.animations||{},c={};for(const t in s){c[e+d+t]=s[t]}for(const t in a){const i=[];if(a[t]&&a[t].length>=0)for(const n of a[t]){const t=e+d+n;i.push(t)}a[t]=i}n.frames=c;const m=new o.Spritesheet(r,n);m.parse().then((()=>{const{textures:e}=m,t=[];for(const i in e)t.push(e[i]);i(t)}))})))),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE_ANIMATION,(({instance:e})=>{if(e)for(const t of e)t.destroy(!0)}));let p=class extends i.Renderer{constructor(){super(...arguments),this.name="SpriteAnimation",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:i}=e.transform.size;this.animates[e.id]&&(this.animates[e.id].animatedSprite.width=t,this.animates[e.id].animatedSprite.height=i)}componentChanged(e){return s(this,void 0,void 0,(function*(){const i=e.gameObject.id;if("SpriteAnimation"===e.componentName){const n=e.component;if(this.autoPlay[e.gameObject.id]=n.autoPlay,e.type===t.OBSERVER_TYPE.ADD){const o=this.increaseAsyncId(i),{instance:r}=yield t.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;r||console.error(`GameObject:${e.gameObject.name}'s Img resource load error`),this.add({frames:r,id:e.gameObject.id,component:n})}else if(e.type===t.OBSERVER_TYPE.CHANGE)if(e.prop&&"speed"===e.prop.prop[0])this.animates[e.gameObject.id].speed=1e3/60/n.speed;else{const o=this.increaseAsyncId(i),{instance:r}=yield t.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;r||console.error(`GameObject:${e.gameObject.name}'s Img resource load error`),this.change({frames:r,id:e.gameObject.id,component:n})}else e.type===t.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(i),this.remove(e.gameObject.id))}}))}add({frames:e,id:t,component:i}){const o=new n.SpriteAnimation({frames:e});this.animates[t]=o,this.containerManager.getContainer(t).addChildAt(o.animatedSprite,0),o.animatedSprite.onComplete=()=>{i.emit("complete")},o.animatedSprite.onFrameChange=()=>{i.emit("frameChange")},o.animatedSprite.onLoop=()=>{i.emit("loop")},i.animate=this.animates[t],this.animates[t].speed=1e3/60/i.speed,this.autoPlay[t]&&o.animatedSprite.play()}change({frames:e,id:t,component:i}){this.remove(t,!0),this.add({frames:e,id:t,component:i})}remove(e,t){const i=this.animates[e];i&&(this.autoPlay[e]=i.animatedSprite.playing,this.containerManager.getContainer(e).removeChild(i.animatedSprite),i.animatedSprite.destroy(),delete this.animates[e],t||delete this.autoPlay[e])}};p.systemName="SpriteAnimation",p=r([t.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],p);var h=p;return e.SpriteAnimation=m,e.SpriteAnimationSystem=h,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;