@eva/plugin-renderer-sprite-animation 1.2.7-editor.7 → 1.2.7-editor.8

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