@eva/plugin-renderer-sprite-animation 2.0.0-beta.1 → 2.0.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/dist/EVA.plugin.renderer.spriteAnimation.js +168 -347
- package/dist/EVA.plugin.renderer.spriteAnimation.min.js +1 -1
- package/dist/plugin-renderer-sprite-animation.cjs.js +158 -271
- package/dist/plugin-renderer-sprite-animation.cjs.prod.js +16 -1
- package/dist/plugin-renderer-sprite-animation.esm.js +160 -273
- package/package.json +4 -4
|
@@ -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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
111
|
-
var _this = this;
|
|
55
|
+
init(obj) {
|
|
112
56
|
obj && Object.assign(this, obj);
|
|
113
|
-
this.on('loop',
|
|
114
|
-
if (++
|
|
115
|
-
if (
|
|
116
|
-
|
|
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
|
-
|
|
63
|
+
this.animate.stop();
|
|
120
64
|
}
|
|
121
|
-
|
|
122
|
-
|
|
65
|
+
this.complete = true;
|
|
66
|
+
this.emit('complete');
|
|
123
67
|
}
|
|
124
68
|
});
|
|
125
|
-
}
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
111
|
+
}
|
|
112
|
+
gotoAndStop(frameNumber) {
|
|
174
113
|
this.animate.gotoAndStop(frameNumber);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
211
|
-
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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 (
|
|
225
|
-
|
|
151
|
+
for (const key in animations) {
|
|
152
|
+
const spriteList = [];
|
|
226
153
|
if (animations[key] && animations[key].length >= 0) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
246
|
-
spriteSheet.parse().then(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
for (
|
|
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,
|
|
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
|
-
|
|
262
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
187
|
+
init() {
|
|
285
188
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
286
189
|
this.renderSystem.rendererManager.register(this);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
296
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
asyncId = this.increaseAsyncId(gameObjectId);
|
|
328
|
-
|
|
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
|
|
333
|
-
if (!
|
|
334
|
-
console.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:
|
|
231
|
+
frames: frames,
|
|
338
232
|
id: changed.gameObject.id,
|
|
339
|
-
component
|
|
233
|
+
component,
|
|
340
234
|
});
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
-
|
|
355
|
-
|
|
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 =
|
|
248
|
+
animate.animatedSprite.onComplete = () => {
|
|
360
249
|
component.emit('complete');
|
|
361
250
|
};
|
|
362
|
-
animate.animatedSprite.onFrameChange =
|
|
251
|
+
animate.animatedSprite.onFrameChange = () => {
|
|
363
252
|
component.emit('frameChange');
|
|
364
253
|
};
|
|
365
|
-
animate.animatedSprite.onLoop =
|
|
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
|
-
|
|
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
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
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
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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$
|
|
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"),
|
|
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;
|