@eva/plugin-renderer-sprite-animation 1.1.1-fix.2 → 1.1.1-fix.3

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