@eva/plugin-renderer-sprite-animation 2.1.0-beta.1 → 2.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite-animation",
3
- "version": "2.1.0-beta.1",
3
+ "version": "2.1.0-beta.3",
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": "^2.0.0-beta.0",
22
- "@eva/plugin-renderer": "2.1.0-beta.1",
23
- "@eva/renderer-adapter": "2.1.0-beta.1",
24
- "@eva/eva.js": "2.1.0-beta.1",
22
+ "@eva/plugin-renderer": "2.1.0-beta.3",
23
+ "@eva/renderer-adapter": "2.1.0-beta.3",
24
+ "@eva/eva.js": "2.1.0-beta.3",
25
25
  "pixi.js": "^8.17.0"
26
26
  }
27
27
  }
@@ -1,453 +0,0 @@
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
- globalThis.EVA = globalThis.EVA || {};
3
- globalThis.EVA.plugin = globalThis.EVA.plugin || {};
4
- globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
5
- var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rendererAdapter, pixi_js) {
6
- 'use strict';
7
- function __decorate(decorators, target, key, desc) {
8
- var c = arguments.length,
9
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
10
- d;
11
- 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;
12
- return c > 3 && r && Object.defineProperty(target, key, r), r;
13
- }
14
- function __metadata(metadataKey, metadataValue) {
15
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
16
- }
17
- function __awaiter(thisArg, _arguments, P, generator) {
18
- function adopt(value) {
19
- return value instanceof P ? value : new P(function (resolve) {
20
- resolve(value);
21
- });
22
- }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) {
25
- try {
26
- step(generator.next(value));
27
- } catch (e) {
28
- reject(e);
29
- }
30
- }
31
- function rejected(value) {
32
- try {
33
- step(generator["throw"](value));
34
- } catch (e) {
35
- reject(e);
36
- }
37
- }
38
- function step(result) {
39
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
40
- }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- }
44
- function __rest(s, e) {
45
- var t = {};
46
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
47
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
48
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
49
- }
50
- return t;
51
- }
52
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
53
- var e = new Error(message);
54
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
55
- };
56
- class SymbolKeysNotSupportedError extends Error {
57
- constructor() {
58
- super('Symbol keys are not supported yet!');
59
- Object.setPrototypeOf(this, new.target.prototype);
60
- }
61
- }
62
- const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
63
- function transformBasicType(type) {
64
- if (type === String) {
65
- return 'string';
66
- }
67
- if (type === Number) {
68
- return 'number';
69
- }
70
- if (type === Boolean) {
71
- return 'boolean';
72
- }
73
- return 'unknown';
74
- }
75
- function defineLegacyIDEProp(target, propertyKey, patch) {
76
- const constructor = target.constructor;
77
- const current = constructor.IDEProps || {};
78
- current[propertyKey] = _extends(_extends({
79
- key: propertyKey
80
- }, current[propertyKey]), patch);
81
- constructor.IDEProps = current;
82
- }
83
- function defineTypes(target, key, options, returnTypeFunction) {
84
- let type = Reflect.getMetadata('design:type', target, key);
85
- let isArray = type === Array;
86
- const str = transformBasicType(type);
87
- if (str !== 'unknown') {
88
- type = str;
89
- }
90
- if (returnTypeFunction) {
91
- const returnType = returnTypeFunction();
92
- if (Array.isArray(returnType)) {
93
- isArray = true;
94
- type = returnType[0];
95
- } else {
96
- type = returnType;
97
- }
98
- }
99
- const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
100
- const current = properties[key] || {};
101
- const property = _extends(_extends(_extends({}, current), {
102
- type,
103
- isArray: isArray
104
- }), options);
105
- properties[key] = property;
106
- Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
107
- const legacyProperty = __rest(property, ["isArray"]);
108
- defineLegacyIDEProp(target, key, legacyProperty);
109
- }
110
- function type(type) {
111
- return Field({
112
- type
113
- });
114
- }
115
- function step(step) {
116
- return Field({
117
- step
118
- });
119
- }
120
- function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
121
- if (typeof returnTypeFuncOrOptions === 'function') {
122
- return {
123
- returnTypeFunc: returnTypeFuncOrOptions,
124
- options: maybeOptions || {}
125
- };
126
- }
127
- return {
128
- options: returnTypeFuncOrOptions || {}
129
- };
130
- }
131
- function Field(returnTypeFunction, maybeOptions) {
132
- return (target, propertyKey) => {
133
- if (typeof propertyKey === 'symbol') {
134
- throw new SymbolKeysNotSupportedError();
135
- }
136
- const {
137
- options,
138
- returnTypeFunc
139
- } = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
140
- defineTypes(target, propertyKey, options, returnTypeFunc);
141
- };
142
- }
143
- var ExecuteMode;
144
- (function (ExecuteMode) {
145
- ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
146
- ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
147
- ExecuteMode[ExecuteMode["All"] = 6] = "All";
148
- })(ExecuteMode || (ExecuteMode = {}));
149
- class SpriteAnimation$2 extends eva_js.Component {
150
- constructor(params) {
151
- super(params);
152
- this.resource = '';
153
- this.autoPlay = true;
154
- this.speed = 100;
155
- this.forwards = false;
156
- this.animations = {};
157
- this.waitPlay = false;
158
- this.waitLoop = false;
159
- this.waitStop = false;
160
- this.times = Infinity;
161
- this.count = 0;
162
- this.complete = false;
163
- this.listenerBound = false;
164
- this.init(params);
165
- }
166
- init(obj) {
167
- obj && _extends(this, obj);
168
- if (!this.listenerBound) {
169
- this.listenerBound = true;
170
- this.on('loop', () => {
171
- var _a;
172
- if (++this.count >= this.times) {
173
- if (this.forwards) {
174
- this.gotoAndStop(this.totalFrames - 1);
175
- } else {
176
- (_a = this.animate) === null || _a === void 0 ? void 0 : _a.stop();
177
- }
178
- this.complete = true;
179
- this.emit('complete');
180
- }
181
- });
182
- this.on('complete', () => {
183
- var _a;
184
- (_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this);
185
- });
186
- this.on('frameChange', () => {
187
- var _a;
188
- (_a = this.onFrameChange) === null || _a === void 0 ? void 0 : _a.call(this, this.currentFrame);
189
- });
190
- }
191
- }
192
- play(nameOrTimes = Infinity, loop = false) {
193
- let times = typeof nameOrTimes === 'number' ? nameOrTimes : loop ? Infinity : 1;
194
- let startFrame;
195
- if (typeof nameOrTimes === 'string') {
196
- this.currentAnimation = nameOrTimes;
197
- const clip = this.animations[nameOrTimes];
198
- if (clip) {
199
- startFrame = clip.start;
200
- if (clip.speed !== undefined) this.speed = clip.speed;
201
- }
202
- }
203
- if (times === 0) {
204
- return;
205
- }
206
- this.times = times;
207
- if (!this.animate) {
208
- this.waitPlay = true;
209
- this.waitAnimation = typeof nameOrTimes === 'string' ? nameOrTimes : undefined;
210
- this.waitLoop = loop;
211
- } else {
212
- if (this.complete) {
213
- this.gotoAndStop(0);
214
- }
215
- if (startFrame !== undefined) {
216
- this.animate.gotoAndPlay(startFrame);
217
- } else {
218
- this.animate.play();
219
- }
220
- this.count = 0;
221
- this.complete = false;
222
- }
223
- }
224
- stop() {
225
- if (!this.animate) {
226
- this.waitStop = true;
227
- } else {
228
- this.animate.stop();
229
- }
230
- }
231
- set animate(val) {
232
- this._animate = val;
233
- if (this.waitPlay) {
234
- this.waitPlay = false;
235
- const waitAnimation = this.waitAnimation;
236
- this.waitAnimation = undefined;
237
- this.play(waitAnimation !== null && waitAnimation !== void 0 ? waitAnimation : this.times, this.waitLoop);
238
- }
239
- if (this.waitStop) {
240
- this.waitStop = false;
241
- this.stop();
242
- }
243
- }
244
- get animate() {
245
- return this._animate;
246
- }
247
- gotoAndPlay(frameNumber) {
248
- this.animate.gotoAndPlay(frameNumber);
249
- }
250
- gotoAndStop(frameNumber) {
251
- this.animate.gotoAndStop(frameNumber);
252
- }
253
- get currentFrame() {
254
- var _a, _b;
255
- return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
256
- }
257
- get totalFrames() {
258
- var _a, _b;
259
- return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
260
- }
261
- }
262
- SpriteAnimation$2.componentName = 'SpriteAnimation';
263
- __decorate([type('string'), __metadata("design:type", String)], SpriteAnimation$2.prototype, "resource", void 0);
264
- __decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "autoPlay", void 0);
265
- __decorate([type('number'), step(10), __metadata("design:type", Number)], SpriteAnimation$2.prototype, "speed", void 0);
266
- __decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "forwards", void 0);
267
- const resourceKeySplit = '_s|r|c_';
268
- eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({
269
- name,
270
- data
271
- }) => {
272
- return new Promise(r => {
273
- var _a;
274
- const textureObj = data.json.data;
275
- const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
276
- let frames = textureObj.frames || {};
277
- if (Array.isArray(frames)) {
278
- const hashFrames = {};
279
- for (const f of frames) {
280
- const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
281
- if (key) hashFrames[key] = f;
282
- }
283
- frames = hashFrames;
284
- }
285
- const animations = textureObj.animations || {};
286
- const newAnimations = {};
287
- const newFrames = {};
288
- for (const key in frames) {
289
- const newKey = name + resourceKeySplit + key;
290
- newFrames[newKey] = frames[key];
291
- }
292
- for (const key in animations) {
293
- const spriteList = [];
294
- if (animations[key] && animations[key].length >= 0) {
295
- for (const spriteName of animations[key]) {
296
- const newSpriteName = name + resourceKeySplit + spriteName;
297
- spriteList.push(newSpriteName);
298
- }
299
- }
300
- newAnimations[key] = spriteList;
301
- }
302
- const spriteSheet = new pixi_js.Spritesheet(texture, _extends(_extends({}, textureObj), {
303
- frames: newFrames,
304
- animations: newAnimations
305
- }));
306
- spriteSheet.parse().then(() => {
307
- const {
308
- textures
309
- } = spriteSheet;
310
- const spriteFrames = [];
311
- for (const key in textures) {
312
- spriteFrames.push(textures[key]);
313
- }
314
- r(spriteFrames);
315
- });
316
- });
317
- });
318
- eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({
319
- instance
320
- }) => {
321
- if (!instance) return;
322
- for (const texture of instance) {
323
- texture.destroy(true);
324
- }
325
- });
326
- let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
327
- constructor() {
328
- super(...arguments);
329
- this.name = 'SpriteAnimationSystem';
330
- this.animates = {};
331
- this.autoPlay = {};
332
- }
333
- init() {
334
- this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
335
- this.renderSystem.rendererManager.register(this);
336
- }
337
- rendererUpdate(gameObject) {
338
- const {
339
- width,
340
- height
341
- } = gameObject.transform.size;
342
- if (this.animates[gameObject.id]) {
343
- this.animates[gameObject.id].animatedSprite.width = width;
344
- this.animates[gameObject.id].animatedSprite.height = height;
345
- }
346
- }
347
- componentChanged(changed) {
348
- return __awaiter(this, void 0, void 0, function* () {
349
- const gameObjectId = changed.gameObject.id;
350
- if (changed.componentName === 'SpriteAnimation') {
351
- const component = changed.component;
352
- this.autoPlay[changed.gameObject.id] = component.autoPlay;
353
- if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
354
- const asyncId = this.increaseAsyncId(gameObjectId);
355
- const {
356
- instance: frames
357
- } = yield eva_js.resource.getResource(component.resource);
358
- if (!this.validateAsyncId(gameObjectId, asyncId)) return;
359
- if (!frames) {
360
- console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
361
- }
362
- this.add({
363
- frames: frames,
364
- id: changed.gameObject.id,
365
- component
366
- });
367
- } else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
368
- if (changed.prop && changed.prop.prop[0] === 'speed') {
369
- this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
370
- } else {
371
- const asyncId = this.increaseAsyncId(gameObjectId);
372
- const {
373
- instance: frames
374
- } = yield eva_js.resource.getResource(component.resource);
375
- if (!this.validateAsyncId(gameObjectId, asyncId)) return;
376
- if (!frames) {
377
- console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
378
- }
379
- this.change({
380
- frames: frames,
381
- id: changed.gameObject.id,
382
- component
383
- });
384
- }
385
- } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
386
- this.increaseAsyncId(gameObjectId);
387
- this.remove(changed.gameObject.id);
388
- }
389
- }
390
- });
391
- }
392
- add({
393
- frames,
394
- id,
395
- component
396
- }) {
397
- const animate = new rendererAdapter.SpriteAnimation({
398
- frames
399
- });
400
- this.animates[id] = animate;
401
- this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
402
- animate.animatedSprite.onComplete = () => {
403
- component.emit('complete');
404
- };
405
- animate.animatedSprite.onFrameChange = () => {
406
- component.emit('frameChange');
407
- };
408
- animate.animatedSprite.onLoop = () => {
409
- component.emit('loop');
410
- };
411
- component.animate = this.animates[id];
412
- this.animates[id].speed = 1000 / 60 / component.speed;
413
- if (this.autoPlay[id]) {
414
- animate.animatedSprite.play();
415
- }
416
- }
417
- change({
418
- frames,
419
- id,
420
- component
421
- }) {
422
- this.remove(id, true);
423
- this.add({
424
- frames,
425
- id,
426
- component
427
- });
428
- }
429
- remove(id, isChange) {
430
- const animate = this.animates[id];
431
- if (!animate) return;
432
- this.autoPlay[id] = animate.animatedSprite.playing;
433
- this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
434
- animate.animatedSprite.destroy();
435
- delete this.animates[id];
436
- if (!isChange) {
437
- delete this.autoPlay[id];
438
- }
439
- }
440
- };
441
- SpriteAnimation.systemName = 'SpriteAnimationSystem';
442
- SpriteAnimation = __decorate([eva_js.decorators.componentObserver({
443
- SpriteAnimation: ['speed', 'resource']
444
- })], SpriteAnimation);
445
- var SpriteAnimation$1 = SpriteAnimation;
446
- exports.SpriteAnimation = SpriteAnimation$2;
447
- exports.SpriteAnimationSystem = SpriteAnimation$1;
448
- Object.defineProperty(exports, '__esModule', {
449
- value: true
450
- });
451
- return exports;
452
- }({}, EVA, EVA.plugin.renderer, EVA.rendererAdapter, PIXI);
453
- globalThis.EVA.plugin.renderer.spriteAnimation = globalThis.EVA.plugin.renderer.spriteAnimation || _EVA_IIFE_spriteAnimation;
@@ -1 +0,0 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_spriteAnimation=function(t,e,n,i,o){"use strict";function r(t,e,n,i){var o,r=arguments.length,s=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(r<3?o(s):r>3?o(e,n,s):o(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}function s(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function a(t,e,n,i){return new(n||(n=Promise))(function(o,r){function s(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((i=i.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class c extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const p="IDE_PROPERTY_METADATA";function m(t,e,n,i){let o=Reflect.getMetadata("design:type",t,e),r=o===Array;const s=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),i){const t=i();Array.isArray(t)?(r=!0,o=t[0]):o=t}const a=Reflect.getMetadata(p,t.constructor)||{},c=_extends(_extends(_extends({},a[e]||{}),{type:o,isArray:r}),n);a[e]=c,Reflect.defineMetadata(p,a,t.constructor);!function(t,e,n){const i=t.constructor,o=i.IDEProps||{};o[e]=_extends(_extends({key:e},o[e]),n),i.IDEProps=o}(t,e,function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(n[i[o]]=t[i[o]])}return n}(c,["isArray"]))}function d(t){return l({type:t})}function l(t,e){return(n,i)=>{if("symbol"==typeof i)throw new c;const{options:o,returnTypeFunc:r}=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);m(n,i,o,r)}}var h;!function(t){t[t.Edit=2]="Edit",t[t.Game=4]="Game",t[t.All=6]="All"}(h||(h={}));class u extends e.Component{constructor(t){super(t),this.resource="",this.autoPlay=!0,this.speed=100,this.forwards=!1,this.animations={},this.waitPlay=!1,this.waitLoop=!1,this.waitStop=!1,this.times=1/0,this.count=0,this.complete=!1,this.listenerBound=!1,this.init(t)}init(t){t&&_extends(this,t),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var t;++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(t=this.animate)||void 0===t||t.stop(),this.complete=!0,this.emit("complete"))}),this.on("complete",()=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this)}),this.on("frameChange",()=>{var t;null===(t=this.onFrameChange)||void 0===t||t.call(this,this.currentFrame)}))}play(t=1/0,e=!1){let n,i="number"==typeof t?t:e?1/0:1;if("string"==typeof t){this.currentAnimation=t;const e=this.animations[t];e&&(n=e.start,void 0!==e.speed&&(this.speed=e.speed))}0!==i&&(this.times=i,this.animate?(this.complete&&this.gotoAndStop(0),void 0!==n?this.animate.gotoAndPlay(n):this.animate.play(),this.count=0,this.complete=!1):(this.waitPlay=!0,this.waitAnimation="string"==typeof t?t:void 0,this.waitLoop=e))}stop(){this.animate?this.animate.stop():this.waitStop=!0}set animate(t){if(this._animate=t,this.waitPlay){this.waitPlay=!1;const t=this.waitAnimation;this.waitAnimation=void 0,this.play(null!=t?t:this.times,this.waitLoop)}this.waitStop&&(this.waitStop=!1,this.stop())}get animate(){return this._animate}gotoAndPlay(t){this.animate.gotoAndPlay(t)}gotoAndStop(t){this.animate.gotoAndStop(t)}get currentFrame(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.currentFrame}get totalFrames(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.totalFrames}}u.componentName="SpriteAnimation",r([d("string"),s("design:type",String)],u.prototype,"resource",void 0),r([d("boolean"),s("design:type",Boolean)],u.prototype,"autoPlay",void 0),r([d("number"),function(t){return l({step:t})}(10),s("design:type",Number)],u.prototype,"speed",void 0),r([d("boolean"),s("design:type",Boolean)],u.prototype,"forwards",void 0);const f="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,({name:t,data:e})=>new Promise(n=>{var i;const r=e.json.data,s=e.image instanceof o.Texture?e.image:o.Texture.from(e.image);let a=r.frames||{};if(Array.isArray(a)){const t={};for(const e of a){const n=null!==(i=e.filename)&&void 0!==i?i:e.name;n&&(t[n]=e)}a=t}const c=r.animations||{},p={},m={};for(const e in a){m[t+f+e]=a[e]}for(const e in c){const n=[];if(c[e]&&c[e].length>=0)for(const i of c[e]){const e=t+f+i;n.push(e)}p[e]=n}const d=new o.Spritesheet(s,_extends(_extends({},r),{frames:m,animations:p}));d.parse().then(()=>{const{textures:t}=d,e=[];for(const n in t)e.push(t[n]);n(e)})})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,({instance:t})=>{if(t)for(const e of t)e.destroy(!0)});let y=class extends n.Renderer{constructor(){super(...arguments),this.name="SpriteAnimationSystem",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(t){const{width:e,height:n}=t.transform.size;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=e,this.animates[t.id].animatedSprite.height=n)}componentChanged(t){return a(this,void 0,void 0,function*(){const n=t.gameObject.id;if("SpriteAnimation"===t.componentName){const i=t.component;if(this.autoPlay[t.gameObject.id]=i.autoPlay,t.type===e.OBSERVER_TYPE.ADD){const o=this.increaseAsyncId(n),{instance:r}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;r||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.add({frames:r,id:t.gameObject.id,component:i})}else if(t.type===e.OBSERVER_TYPE.CHANGE)if(t.prop&&"speed"===t.prop.prop[0])this.animates[t.gameObject.id].speed=1e3/60/i.speed;else{const o=this.increaseAsyncId(n),{instance:r}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;r||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.change({frames:r,id:t.gameObject.id,component:i})}else t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(n),this.remove(t.gameObject.id))}})}add({frames:t,id:e,component:n}){const o=new i.SpriteAnimation({frames:t});this.animates[e]=o,this.containerManager.getContainer(e).addChildAt(o.animatedSprite,0),o.animatedSprite.onComplete=()=>{n.emit("complete")},o.animatedSprite.onFrameChange=()=>{n.emit("frameChange")},o.animatedSprite.onLoop=()=>{n.emit("loop")},n.animate=this.animates[e],this.animates[e].speed=1e3/60/n.speed,this.autoPlay[e]&&o.animatedSprite.play()}change({frames:t,id:e,component:n}){this.remove(e,!0),this.add({frames:t,id:e,component:n})}remove(t,e){const n=this.animates[t];n&&(this.autoPlay[t]=n.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(n.animatedSprite),n.animatedSprite.destroy(),delete this.animates[t],e||delete this.autoPlay[t])}};y.systemName="SpriteAnimationSystem",y=r([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],y);var g=y;return t.SpriteAnimation=u,t.SpriteAnimationSystem=g,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);globalThis.EVA.plugin.renderer.spriteAnimation=globalThis.EVA.plugin.renderer.spriteAnimation||_EVA_IIFE_spriteAnimation;