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

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