@eva/plugin-renderer-sprite-animation 1.2.7 → 1.2.8-fix.1
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 +4 -4
- package/dist/miniprogram.js +0 -387
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-sprite-animation",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8-fix.1",
|
|
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": "1.2.
|
|
23
|
-
"@eva/renderer-adapter": "1.2.
|
|
24
|
-
"@eva/eva.js": "1.2.
|
|
22
|
+
"@eva/plugin-renderer": "1.2.8-fix.1",
|
|
23
|
+
"@eva/renderer-adapter": "1.2.8-fix.1",
|
|
24
|
+
"@eva/eva.js": "1.2.8-fix.1",
|
|
25
25
|
"pixi.js": "^4.8.7"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/dist/miniprogram.js
DELETED
|
@@ -1,387 +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, __values, __awaiter, __generator } from 'tslib';
|
|
4
|
-
import { Component, resource, RESOURCE_TYPE, OBSERVER_TYPE, decorators } from '@eva/eva.js/dist/miniprogram';
|
|
5
|
-
import { type, step } 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([type('string')], SpriteAnimation.prototype, "resource", void 0);
|
|
129
|
-
|
|
130
|
-
__decorate([type('boolean')], SpriteAnimation.prototype, "autoPlay", void 0);
|
|
131
|
-
|
|
132
|
-
__decorate([type('number'), step(10)], SpriteAnimation.prototype, "speed", void 0);
|
|
133
|
-
|
|
134
|
-
__decorate([type('boolean')], SpriteAnimation.prototype, "forwards", void 0);
|
|
135
|
-
|
|
136
|
-
return SpriteAnimation;
|
|
137
|
-
}(Component);
|
|
138
|
-
|
|
139
|
-
var SpriteAnimation$3 = SpriteAnimation$2;
|
|
140
|
-
var resourceKeySplit = '_s|r|c_';
|
|
141
|
-
resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
|
|
142
|
-
var name = _a.name,
|
|
143
|
-
data = _a.data;
|
|
144
|
-
return new Promise(function (r) {
|
|
145
|
-
var e_1, _a;
|
|
146
|
-
|
|
147
|
-
var textureObj = data.json;
|
|
148
|
-
var texture = BaseTexture.from(data.image);
|
|
149
|
-
var frames = textureObj.frames || {};
|
|
150
|
-
var animations = textureObj.animations || {};
|
|
151
|
-
var newFrames = {};
|
|
152
|
-
|
|
153
|
-
for (var key in frames) {
|
|
154
|
-
var newKey = name + resourceKeySplit + key;
|
|
155
|
-
newFrames[newKey] = frames[key];
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
for (var key in animations) {
|
|
159
|
-
var spriteList = [];
|
|
160
|
-
|
|
161
|
-
if (animations[key] && animations[key].length >= 0) {
|
|
162
|
-
try {
|
|
163
|
-
for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
164
|
-
var spriteName = _c.value;
|
|
165
|
-
var newSpriteName = name + resourceKeySplit + spriteName;
|
|
166
|
-
spriteList.push(newSpriteName);
|
|
167
|
-
}
|
|
168
|
-
} catch (e_1_1) {
|
|
169
|
-
e_1 = {
|
|
170
|
-
error: e_1_1
|
|
171
|
-
};
|
|
172
|
-
} finally {
|
|
173
|
-
try {
|
|
174
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
175
|
-
} finally {
|
|
176
|
-
if (e_1) throw e_1.error;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
animations[key] = spriteList;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
textureObj.frames = newFrames;
|
|
185
|
-
var spriteSheet = new Spritesheet(texture, textureObj);
|
|
186
|
-
spriteSheet.parse(function () {
|
|
187
|
-
var textures = spriteSheet.textures;
|
|
188
|
-
var spriteFrames = [];
|
|
189
|
-
|
|
190
|
-
for (var key in textures) {
|
|
191
|
-
spriteFrames.push(textures[key]);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
r(spriteFrames);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
resource.registerDestroy(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
|
|
199
|
-
var e_2, _b;
|
|
200
|
-
|
|
201
|
-
var instance = _a.instance;
|
|
202
|
-
if (!instance) return;
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
for (var instance_1 = __values(instance), instance_1_1 = instance_1.next(); !instance_1_1.done; instance_1_1 = instance_1.next()) {
|
|
206
|
-
var texture = instance_1_1.value;
|
|
207
|
-
texture.destroy(true);
|
|
208
|
-
}
|
|
209
|
-
} catch (e_2_1) {
|
|
210
|
-
e_2 = {
|
|
211
|
-
error: e_2_1
|
|
212
|
-
};
|
|
213
|
-
} finally {
|
|
214
|
-
try {
|
|
215
|
-
if (instance_1_1 && !instance_1_1.done && (_b = instance_1.return)) _b.call(instance_1);
|
|
216
|
-
} finally {
|
|
217
|
-
if (e_2) throw e_2.error;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
var SpriteAnimation = function (_super) {
|
|
223
|
-
__extends(SpriteAnimation, _super);
|
|
224
|
-
|
|
225
|
-
function SpriteAnimation() {
|
|
226
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
227
|
-
|
|
228
|
-
_this.name = 'SpriteAnimation';
|
|
229
|
-
_this.animates = {};
|
|
230
|
-
_this.autoPlay = {};
|
|
231
|
-
return _this;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
SpriteAnimation.prototype.init = function () {
|
|
235
|
-
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
236
|
-
this.renderSystem.rendererManager.register(this);
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
SpriteAnimation.prototype.rendererUpdate = function (gameObject) {
|
|
240
|
-
var _a = gameObject.transform.size,
|
|
241
|
-
width = _a.width,
|
|
242
|
-
height = _a.height;
|
|
243
|
-
|
|
244
|
-
if (this.animates[gameObject.id]) {
|
|
245
|
-
this.animates[gameObject.id].animatedSprite.width = width;
|
|
246
|
-
this.animates[gameObject.id].animatedSprite.height = height;
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
SpriteAnimation.prototype.componentChanged = function (changed) {
|
|
251
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
252
|
-
var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
|
|
253
|
-
return __generator(this, function (_a) {
|
|
254
|
-
switch (_a.label) {
|
|
255
|
-
case 0:
|
|
256
|
-
gameObjectId = changed.gameObject.id;
|
|
257
|
-
if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
|
|
258
|
-
component = changed.component;
|
|
259
|
-
this.autoPlay[changed.gameObject.id] = component.autoPlay;
|
|
260
|
-
if (!(changed.type === OBSERVER_TYPE.ADD)) return [3, 2];
|
|
261
|
-
asyncId = this.increaseAsyncId(gameObjectId);
|
|
262
|
-
return [4, resource.getResource(component.resource)];
|
|
263
|
-
|
|
264
|
-
case 1:
|
|
265
|
-
frames_1 = _a.sent().instance;
|
|
266
|
-
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
267
|
-
|
|
268
|
-
if (!frames_1) {
|
|
269
|
-
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
this.add({
|
|
273
|
-
frames: frames_1,
|
|
274
|
-
id: changed.gameObject.id,
|
|
275
|
-
component: component
|
|
276
|
-
});
|
|
277
|
-
return [3, 7];
|
|
278
|
-
|
|
279
|
-
case 2:
|
|
280
|
-
if (!(changed.type === OBSERVER_TYPE.CHANGE)) return [3, 6];
|
|
281
|
-
if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
|
|
282
|
-
this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
|
|
283
|
-
return [3, 5];
|
|
284
|
-
|
|
285
|
-
case 3:
|
|
286
|
-
asyncId = this.increaseAsyncId(gameObjectId);
|
|
287
|
-
return [4, resource.getResource(component.resource)];
|
|
288
|
-
|
|
289
|
-
case 4:
|
|
290
|
-
frames_2 = _a.sent().instance;
|
|
291
|
-
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
292
|
-
|
|
293
|
-
if (!frames_2) {
|
|
294
|
-
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
this.change({
|
|
298
|
-
frames: frames_2,
|
|
299
|
-
id: changed.gameObject.id,
|
|
300
|
-
component: component
|
|
301
|
-
});
|
|
302
|
-
_a.label = 5;
|
|
303
|
-
|
|
304
|
-
case 5:
|
|
305
|
-
return [3, 7];
|
|
306
|
-
|
|
307
|
-
case 6:
|
|
308
|
-
if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
309
|
-
this.increaseAsyncId(gameObjectId);
|
|
310
|
-
this.remove(changed.gameObject.id);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
_a.label = 7;
|
|
314
|
-
|
|
315
|
-
case 7:
|
|
316
|
-
return [2];
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
SpriteAnimation.prototype.add = function (_a) {
|
|
323
|
-
var frames = _a.frames,
|
|
324
|
-
id = _a.id,
|
|
325
|
-
component = _a.component;
|
|
326
|
-
var animate = new SpriteAnimation$4({
|
|
327
|
-
frames: frames
|
|
328
|
-
});
|
|
329
|
-
this.animates[id] = animate;
|
|
330
|
-
this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
|
|
331
|
-
|
|
332
|
-
animate.animatedSprite.onComplete = function () {
|
|
333
|
-
component.emit('complete');
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
animate.animatedSprite.onFrameChange = function () {
|
|
337
|
-
component.emit('frameChange');
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
animate.animatedSprite.onLoop = function () {
|
|
341
|
-
component.emit('loop');
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
component.animate = this.animates[id];
|
|
345
|
-
this.animates[id].speed = 1000 / 60 / component.speed;
|
|
346
|
-
|
|
347
|
-
if (this.autoPlay[id]) {
|
|
348
|
-
animate.animatedSprite.play();
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
SpriteAnimation.prototype.change = function (_a) {
|
|
353
|
-
var frames = _a.frames,
|
|
354
|
-
id = _a.id,
|
|
355
|
-
component = _a.component;
|
|
356
|
-
this.remove(id, true);
|
|
357
|
-
this.add({
|
|
358
|
-
frames: frames,
|
|
359
|
-
id: id,
|
|
360
|
-
component: component
|
|
361
|
-
});
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
SpriteAnimation.prototype.remove = function (id, isChange) {
|
|
365
|
-
var animate = this.animates[id];
|
|
366
|
-
if (!animate) return;
|
|
367
|
-
this.autoPlay[id] = animate.animatedSprite.playing;
|
|
368
|
-
this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
|
|
369
|
-
animate.animatedSprite.destroy({
|
|
370
|
-
children: true
|
|
371
|
-
});
|
|
372
|
-
delete this.animates[id];
|
|
373
|
-
|
|
374
|
-
if (!isChange) {
|
|
375
|
-
delete this.autoPlay[id];
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
SpriteAnimation.systemName = 'SpriteAnimation';
|
|
380
|
-
SpriteAnimation = __decorate([decorators.componentObserver({
|
|
381
|
-
SpriteAnimation: ['speed', 'resource']
|
|
382
|
-
})], SpriteAnimation);
|
|
383
|
-
return SpriteAnimation;
|
|
384
|
-
}(Renderer);
|
|
385
|
-
|
|
386
|
-
var SpriteAnimation$1 = SpriteAnimation;
|
|
387
|
-
export { SpriteAnimation$3 as SpriteAnimation, SpriteAnimation$1 as SpriteAnimationSystem };
|