@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.
@@ -1,7 +1,7 @@
1
1
  import { Component, resource, RESOURCE_TYPE, decorators, OBSERVER_TYPE } from '@eva/eva.js';
2
2
  import { type, step } from '@eva/inspector-decorator';
3
- import { RendererSystem, Renderer } from '@eva/plugin-renderer';
4
- import { SpriteAnimation as SpriteAnimation$4 } from '@eva/renderer-adapter';
3
+ import { Renderer, RendererSystem } from '@eva/plugin-renderer';
4
+ import { SpriteAnimation as SpriteAnimation$3 } from '@eva/renderer-adapter';
5
5
  import { Texture, Spritesheet } from 'pixi.js';
6
6
 
7
7
  /*! *****************************************************************************
@@ -18,20 +18,6 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
18
18
  See the Apache Version 2.0 License for specific language governing permissions
19
19
  and limitations under the License.
20
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
21
 
36
22
  function __decorate(decorators, target, key, desc) {
37
23
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -47,80 +33,37 @@ function __awaiter(thisArg, _arguments, P, generator) {
47
33
  function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
48
34
  step((generator = generator.apply(thisArg, _arguments || [])).next());
49
35
  });
50
- }
51
-
52
- function __generator(thisArg, body) {
53
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
54
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
55
- function verb(n) { return function (v) { return step([n, v]); }; }
56
- function step(op) {
57
- if (f) throw new TypeError("Generator is already executing.");
58
- while (_) try {
59
- 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;
60
- if (y = 0, t) op = [op[0] & 2, t.value];
61
- switch (op[0]) {
62
- case 0: case 1: t = op; break;
63
- case 4: _.label++; return { value: op[1], done: false };
64
- case 5: _.label++; y = op[1]; op = [0]; continue;
65
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
66
- default:
67
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
68
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
69
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
70
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
71
- if (t[2]) _.ops.pop();
72
- _.trys.pop(); continue;
73
- }
74
- op = body.call(thisArg, _);
75
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
76
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
77
- }
78
- }
79
-
80
- function __values(o) {
81
- var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
82
- if (m) return m.call(o);
83
- return {
84
- next: function () {
85
- if (o && i >= o.length) o = void 0;
86
- return { value: o && o[i++], done: !o };
87
- }
88
- };
89
36
  }
90
37
 
91
- var SpriteAnimation$2 = (function (_super) {
92
- __extends(SpriteAnimation, _super);
93
- function SpriteAnimation() {
94
- var _this = _super !== null && _super.apply(this, arguments) || this;
95
- _this.resource = '';
96
- _this.autoPlay = true;
97
- _this.speed = 100;
98
- _this.forwards = false;
99
- _this.waitPlay = false;
100
- _this.waitStop = false;
101
- _this.times = Infinity;
102
- _this.count = 0;
103
- _this.complete = false;
104
- return _this;
38
+ class SpriteAnimation$2 extends Component {
39
+ constructor() {
40
+ super(...arguments);
41
+ this.resource = '';
42
+ this.autoPlay = true;
43
+ this.speed = 100;
44
+ this.forwards = false;
45
+ this.waitPlay = false;
46
+ this.waitStop = false;
47
+ this.times = Infinity;
48
+ this.count = 0;
49
+ this.complete = false;
105
50
  }
106
- SpriteAnimation.prototype.init = function (obj) {
107
- var _this = this;
51
+ init(obj) {
108
52
  obj && Object.assign(this, obj);
109
- this.on('loop', function () {
110
- if (++_this.count >= _this.times) {
111
- if (_this.forwards) {
112
- _this.gotoAndStop(_this.totalFrames - 1);
53
+ this.on('loop', () => {
54
+ if (++this.count >= this.times) {
55
+ if (this.forwards) {
56
+ this.gotoAndStop(this.totalFrames - 1);
113
57
  }
114
58
  else {
115
- _this.animate.stop();
59
+ this.animate.stop();
116
60
  }
117
- _this.complete = true;
118
- _this.emit('complete');
61
+ this.complete = true;
62
+ this.emit('complete');
119
63
  }
120
64
  });
121
- };
122
- SpriteAnimation.prototype.play = function (times) {
123
- if (times === void 0) { times = Infinity; }
65
+ }
66
+ play(times = Infinity) {
124
67
  if (times === 0) {
125
68
  return;
126
69
  }
@@ -136,229 +79,175 @@ var SpriteAnimation$2 = (function (_super) {
136
79
  this.count = 0;
137
80
  this.complete = false;
138
81
  }
139
- };
140
- SpriteAnimation.prototype.stop = function () {
82
+ }
83
+ stop() {
141
84
  if (!this.animate) {
142
85
  this.waitStop = true;
143
86
  }
144
87
  else {
145
88
  this.animate.stop();
146
89
  }
147
- };
148
- Object.defineProperty(SpriteAnimation.prototype, "animate", {
149
- get: function () {
150
- return this._animate;
151
- },
152
- set: function (val) {
153
- this._animate = val;
154
- if (this.waitPlay) {
155
- this.waitPlay = false;
156
- this.play(this.times);
157
- }
158
- if (this.waitStop) {
159
- this.waitStop = false;
160
- this.stop();
161
- }
162
- },
163
- enumerable: false,
164
- configurable: true
165
- });
166
- SpriteAnimation.prototype.gotoAndPlay = function (frameNumber) {
90
+ }
91
+ set animate(val) {
92
+ this._animate = val;
93
+ if (this.waitPlay) {
94
+ this.waitPlay = false;
95
+ this.play(this.times);
96
+ }
97
+ if (this.waitStop) {
98
+ this.waitStop = false;
99
+ this.stop();
100
+ }
101
+ }
102
+ get animate() {
103
+ return this._animate;
104
+ }
105
+ gotoAndPlay(frameNumber) {
167
106
  this.animate.gotoAndPlay(frameNumber);
168
- };
169
- SpriteAnimation.prototype.gotoAndStop = function (frameNumber) {
107
+ }
108
+ gotoAndStop(frameNumber) {
170
109
  this.animate.gotoAndStop(frameNumber);
171
- };
172
- Object.defineProperty(SpriteAnimation.prototype, "currentFrame", {
173
- get: function () {
174
- var _a, _b;
175
- return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
176
- },
177
- enumerable: false,
178
- configurable: true
179
- });
180
- Object.defineProperty(SpriteAnimation.prototype, "totalFrames", {
181
- get: function () {
182
- var _a, _b;
183
- return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
184
- },
185
- enumerable: false,
186
- configurable: true
187
- });
188
- SpriteAnimation.componentName = 'SpriteAnimation';
189
- __decorate([
190
- type('string')
191
- ], SpriteAnimation.prototype, "resource", void 0);
192
- __decorate([
193
- type('boolean')
194
- ], SpriteAnimation.prototype, "autoPlay", void 0);
195
- __decorate([
196
- type('number'),
197
- step(10)
198
- ], SpriteAnimation.prototype, "speed", void 0);
199
- __decorate([
200
- type('boolean')
201
- ], SpriteAnimation.prototype, "forwards", void 0);
202
- return SpriteAnimation;
203
- }(Component));
204
- var SpriteAnimation$3 = SpriteAnimation$2;
110
+ }
111
+ get currentFrame() {
112
+ var _a, _b;
113
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
114
+ }
115
+ get totalFrames() {
116
+ var _a, _b;
117
+ return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
118
+ }
119
+ }
120
+ SpriteAnimation$2.componentName = 'SpriteAnimation';
121
+ __decorate([
122
+ type('string')
123
+ ], SpriteAnimation$2.prototype, "resource", void 0);
124
+ __decorate([
125
+ type('boolean')
126
+ ], SpriteAnimation$2.prototype, "autoPlay", void 0);
127
+ __decorate([
128
+ type('number'),
129
+ step(10)
130
+ ], SpriteAnimation$2.prototype, "speed", void 0);
131
+ __decorate([
132
+ type('boolean')
133
+ ], SpriteAnimation$2.prototype, "forwards", void 0);
205
134
 
206
- var resourceKeySplit = '_s|r|c_';
207
- resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
208
- var name = _a.name, data = _a.data;
209
- return new Promise(function (r) {
210
- var e_1, _a;
211
- var textureObj = data.json.data;
212
- var texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
213
- var frames = textureObj.frames || {};
214
- var animations = textureObj.animations || {};
215
- var newFrames = {};
216
- for (var key in frames) {
217
- var newKey = name + resourceKeySplit + key;
135
+ const resourceKeySplit = '_s|r|c_';
136
+ resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, ({ name, data }) => {
137
+ return new Promise(r => {
138
+ const textureObj = data.json.data;
139
+ const texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
140
+ const frames = textureObj.frames || {};
141
+ const animations = textureObj.animations || {};
142
+ const newFrames = {};
143
+ for (const key in frames) {
144
+ const newKey = name + resourceKeySplit + key;
218
145
  newFrames[newKey] = frames[key];
219
146
  }
220
- for (var key in animations) {
221
- var spriteList = [];
147
+ for (const key in animations) {
148
+ const spriteList = [];
222
149
  if (animations[key] && animations[key].length >= 0) {
223
- try {
224
- for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
225
- var spriteName = _c.value;
226
- var newSpriteName = name + resourceKeySplit + spriteName;
227
- spriteList.push(newSpriteName);
228
- }
229
- }
230
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
231
- finally {
232
- try {
233
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
234
- }
235
- finally { if (e_1) throw e_1.error; }
150
+ for (const spriteName of animations[key]) {
151
+ const newSpriteName = name + resourceKeySplit + spriteName;
152
+ spriteList.push(newSpriteName);
236
153
  }
237
154
  }
238
155
  animations[key] = spriteList;
239
156
  }
240
157
  textureObj.frames = newFrames;
241
- var spriteSheet = new Spritesheet(texture, textureObj);
242
- spriteSheet.parse().then(function () {
243
- var textures = spriteSheet.textures;
244
- var spriteFrames = [];
245
- for (var key in textures) {
158
+ const spriteSheet = new Spritesheet(texture, textureObj);
159
+ spriteSheet.parse().then(() => {
160
+ const { textures } = spriteSheet;
161
+ const spriteFrames = [];
162
+ for (const key in textures) {
246
163
  spriteFrames.push(textures[key]);
247
164
  }
248
165
  r(spriteFrames);
249
166
  });
250
167
  });
251
168
  });
252
- resource.registerDestroy(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
253
- var e_2, _b;
254
- var instance = _a.instance;
169
+ resource.registerDestroy(RESOURCE_TYPE.SPRITE_ANIMATION, ({ instance }) => {
255
170
  if (!instance)
256
171
  return;
257
- try {
258
- for (var instance_1 = __values(instance), instance_1_1 = instance_1.next(); !instance_1_1.done; instance_1_1 = instance_1.next()) {
259
- var texture = instance_1_1.value;
260
- texture.destroy(true);
261
- }
262
- }
263
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
264
- finally {
265
- try {
266
- if (instance_1_1 && !instance_1_1.done && (_b = instance_1.return)) _b.call(instance_1);
267
- }
268
- finally { if (e_2) throw e_2.error; }
172
+ for (const texture of instance) {
173
+ texture.destroy(true);
269
174
  }
270
175
  });
271
- var SpriteAnimation = (function (_super) {
272
- __extends(SpriteAnimation, _super);
273
- function SpriteAnimation() {
274
- var _this = _super !== null && _super.apply(this, arguments) || this;
275
- _this.name = 'SpriteAnimation';
276
- _this.animates = {};
277
- _this.autoPlay = {};
278
- return _this;
176
+ let SpriteAnimation = class SpriteAnimation extends Renderer {
177
+ constructor() {
178
+ super(...arguments);
179
+ this.name = 'SpriteAnimation';
180
+ this.animates = {};
181
+ this.autoPlay = {};
279
182
  }
280
- SpriteAnimation.prototype.init = function () {
183
+ init() {
281
184
  this.renderSystem = this.game.getSystem(RendererSystem);
282
185
  this.renderSystem.rendererManager.register(this);
283
- };
284
- SpriteAnimation.prototype.rendererUpdate = function (gameObject) {
285
- var _a = gameObject.transform.size, width = _a.width, height = _a.height;
186
+ }
187
+ rendererUpdate(gameObject) {
188
+ const { width, height } = gameObject.transform.size;
286
189
  if (this.animates[gameObject.id]) {
287
190
  this.animates[gameObject.id].animatedSprite.width = width;
288
191
  this.animates[gameObject.id].animatedSprite.height = height;
289
192
  }
290
- };
291
- SpriteAnimation.prototype.componentChanged = function (changed) {
292
- return __awaiter(this, void 0, void 0, function () {
293
- var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
294
- return __generator(this, function (_a) {
295
- switch (_a.label) {
296
- case 0:
297
- gameObjectId = changed.gameObject.id;
298
- if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
299
- component = changed.component;
300
- this.autoPlay[changed.gameObject.id] = component.autoPlay;
301
- if (!(changed.type === OBSERVER_TYPE.ADD)) return [3, 2];
302
- asyncId = this.increaseAsyncId(gameObjectId);
303
- return [4, resource.getResource(component.resource)];
304
- case 1:
305
- frames_1 = (_a.sent()).instance;
306
- if (!this.validateAsyncId(gameObjectId, asyncId))
307
- return [2];
308
- if (!frames_1) {
309
- console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
310
- }
311
- this.add({
312
- frames: frames_1,
313
- id: changed.gameObject.id,
314
- component: component,
315
- });
316
- return [3, 7];
317
- case 2:
318
- if (!(changed.type === OBSERVER_TYPE.CHANGE)) return [3, 6];
319
- if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
193
+ }
194
+ componentChanged(changed) {
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ const gameObjectId = changed.gameObject.id;
197
+ if (changed.componentName === 'SpriteAnimation') {
198
+ const component = changed.component;
199
+ this.autoPlay[changed.gameObject.id] = component.autoPlay;
200
+ if (changed.type === OBSERVER_TYPE.ADD) {
201
+ const asyncId = this.increaseAsyncId(gameObjectId);
202
+ const { instance: frames } = yield resource.getResource(component.resource);
203
+ if (!this.validateAsyncId(gameObjectId, asyncId))
204
+ return;
205
+ if (!frames) {
206
+ console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
207
+ }
208
+ this.add({
209
+ frames: frames,
210
+ id: changed.gameObject.id,
211
+ component,
212
+ });
213
+ }
214
+ else if (changed.type === OBSERVER_TYPE.CHANGE) {
215
+ if (changed.prop && changed.prop.prop[0] === 'speed') {
320
216
  this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
321
- return [3, 5];
322
- case 3:
323
- asyncId = this.increaseAsyncId(gameObjectId);
324
- return [4, resource.getResource(component.resource)];
325
- case 4:
326
- frames_2 = (_a.sent()).instance;
217
+ }
218
+ else {
219
+ const asyncId = this.increaseAsyncId(gameObjectId);
220
+ const { instance: frames } = yield resource.getResource(component.resource);
327
221
  if (!this.validateAsyncId(gameObjectId, asyncId))
328
- return [2];
329
- if (!frames_2) {
330
- console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
222
+ return;
223
+ if (!frames) {
224
+ console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
331
225
  }
332
226
  this.change({
333
- frames: frames_2,
227
+ frames: frames,
334
228
  id: changed.gameObject.id,
335
- component: component,
229
+ component,
336
230
  });
337
- _a.label = 5;
338
- case 5: return [3, 7];
339
- case 6:
340
- if (changed.type === OBSERVER_TYPE.REMOVE) {
341
- this.increaseAsyncId(gameObjectId);
342
- this.remove(changed.gameObject.id);
343
- }
344
- _a.label = 7;
345
- case 7: return [2];
231
+ }
232
+ }
233
+ else if (changed.type === OBSERVER_TYPE.REMOVE) {
234
+ this.increaseAsyncId(gameObjectId);
235
+ this.remove(changed.gameObject.id);
346
236
  }
347
- });
237
+ }
348
238
  });
349
- };
350
- SpriteAnimation.prototype.add = function (_a) {
351
- var frames = _a.frames, id = _a.id, component = _a.component;
352
- var animate = new SpriteAnimation$4({ frames: frames });
239
+ }
240
+ add({ frames, id, component }) {
241
+ const animate = new SpriteAnimation$3({ frames });
353
242
  this.animates[id] = animate;
354
243
  this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
355
- animate.animatedSprite.onComplete = function () {
244
+ animate.animatedSprite.onComplete = () => {
356
245
  component.emit('complete');
357
246
  };
358
- animate.animatedSprite.onFrameChange = function () {
247
+ animate.animatedSprite.onFrameChange = () => {
359
248
  component.emit('frameChange');
360
249
  };
361
- animate.animatedSprite.onLoop = function () {
250
+ animate.animatedSprite.onLoop = () => {
362
251
  component.emit('loop');
363
252
  };
364
253
  component.animate = this.animates[id];
@@ -366,14 +255,13 @@ var SpriteAnimation = (function (_super) {
366
255
  if (this.autoPlay[id]) {
367
256
  animate.animatedSprite.play();
368
257
  }
369
- };
370
- SpriteAnimation.prototype.change = function (_a) {
371
- var frames = _a.frames, id = _a.id, component = _a.component;
258
+ }
259
+ change({ frames, id, component }) {
372
260
  this.remove(id, true);
373
- this.add({ frames: frames, id: id, component: component });
374
- };
375
- SpriteAnimation.prototype.remove = function (id, isChange) {
376
- var animate = this.animates[id];
261
+ this.add({ frames, id, component });
262
+ }
263
+ remove(id, isChange) {
264
+ const animate = this.animates[id];
377
265
  if (!animate)
378
266
  return;
379
267
  this.autoPlay[id] = animate.animatedSprite.playing;
@@ -383,15 +271,14 @@ var SpriteAnimation = (function (_super) {
383
271
  if (!isChange) {
384
272
  delete this.autoPlay[id];
385
273
  }
386
- };
387
- SpriteAnimation.systemName = 'SpriteAnimation';
388
- SpriteAnimation = __decorate([
389
- decorators.componentObserver({
390
- SpriteAnimation: ['speed', 'resource'],
391
- })
392
- ], SpriteAnimation);
393
- return SpriteAnimation;
394
- }(Renderer));
274
+ }
275
+ };
276
+ SpriteAnimation.systemName = 'SpriteAnimation';
277
+ SpriteAnimation = __decorate([
278
+ decorators.componentObserver({
279
+ SpriteAnimation: ['speed', 'resource'],
280
+ })
281
+ ], SpriteAnimation);
395
282
  var SpriteAnimation$1 = SpriteAnimation;
396
283
 
397
- export { SpriteAnimation$3 as SpriteAnimation, SpriteAnimation$1 as SpriteAnimationSystem };
284
+ export { SpriteAnimation$2 as SpriteAnimation, SpriteAnimation$1 as SpriteAnimationSystem };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite-animation",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.11",
4
4
  "description": "@eva/plugin-renderer-sprite-animation",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-sprite-animation.esm.js",
@@ -19,9 +19,9 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "^0.0.5",
22
- "@eva/plugin-renderer": "2.0.0-beta.1",
23
- "@eva/renderer-adapter": "2.0.0-beta.1",
24
- "@eva/eva.js": "2.0.0-beta.1",
25
- "pixi.js": "^8.6.3"
22
+ "@eva/plugin-renderer": "2.0.0-beta.11",
23
+ "@eva/renderer-adapter": "2.0.0-beta.11",
24
+ "@eva/eva.js": "2.0.0-beta.11",
25
+ "pixi.js": "^8.6.5"
26
26
  }
27
27
  }