@eva/plugin-renderer-sprite-animation 2.1.0-beta.3 → 2.1.0-beta.5
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 +457 -0
- package/dist/EVA.plugin.renderer.spriteAnimation.min.js +1 -0
- package/dist/plugin-renderer-sprite-animation.cjs.js +407 -0
- package/dist/plugin-renderer-sprite-animation.cjs.prod.js +1 -0
- package/dist/plugin-renderer-sprite-animation.d.ts +147 -0
- package/dist/plugin-renderer-sprite-animation.esm.js +402 -0
- package/package.json +4 -4
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
globalThis.EVA = globalThis.EVA || {};
|
|
3
|
+
globalThis.EVA.plugin = globalThis.EVA.plugin || {};
|
|
4
|
+
globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
|
|
5
|
+
var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rendererAdapter, pixi_js) {
|
|
6
|
+
'use strict';
|
|
7
|
+
function __decorate(decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length,
|
|
9
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
10
|
+
d;
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
12
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
+
}
|
|
14
|
+
function __metadata(metadataKey, metadataValue) {
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
16
|
+
}
|
|
17
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) {
|
|
19
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
20
|
+
resolve(value);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) {
|
|
25
|
+
try {
|
|
26
|
+
step(generator.next(value));
|
|
27
|
+
} catch (e) {
|
|
28
|
+
reject(e);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function rejected(value) {
|
|
32
|
+
try {
|
|
33
|
+
step(generator["throw"](value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function step(result) {
|
|
39
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
40
|
+
}
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
45
|
+
var e = new Error(message);
|
|
46
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
47
|
+
};
|
|
48
|
+
function __rest(s, e) {
|
|
49
|
+
var t = {};
|
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
51
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
52
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
53
|
+
}
|
|
54
|
+
return t;
|
|
55
|
+
}
|
|
56
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
57
|
+
var e = new Error(message);
|
|
58
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
59
|
+
};
|
|
60
|
+
class SymbolKeysNotSupportedError extends Error {
|
|
61
|
+
constructor() {
|
|
62
|
+
super('Symbol keys are not supported yet!');
|
|
63
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
|
|
67
|
+
function transformBasicType(type) {
|
|
68
|
+
if (type === String) {
|
|
69
|
+
return 'string';
|
|
70
|
+
}
|
|
71
|
+
if (type === Number) {
|
|
72
|
+
return 'number';
|
|
73
|
+
}
|
|
74
|
+
if (type === Boolean) {
|
|
75
|
+
return 'boolean';
|
|
76
|
+
}
|
|
77
|
+
return 'unknown';
|
|
78
|
+
}
|
|
79
|
+
function defineLegacyIDEProp(target, propertyKey, patch) {
|
|
80
|
+
const constructor = target.constructor;
|
|
81
|
+
const current = constructor.IDEProps || {};
|
|
82
|
+
current[propertyKey] = _extends(_extends({
|
|
83
|
+
key: propertyKey
|
|
84
|
+
}, current[propertyKey]), patch);
|
|
85
|
+
constructor.IDEProps = current;
|
|
86
|
+
}
|
|
87
|
+
function defineTypes(target, key, options, returnTypeFunction) {
|
|
88
|
+
let type = Reflect.getMetadata('design:type', target, key);
|
|
89
|
+
let isArray = type === Array;
|
|
90
|
+
const str = transformBasicType(type);
|
|
91
|
+
if (str !== 'unknown') {
|
|
92
|
+
type = str;
|
|
93
|
+
}
|
|
94
|
+
if (returnTypeFunction) {
|
|
95
|
+
const returnType = returnTypeFunction();
|
|
96
|
+
if (Array.isArray(returnType)) {
|
|
97
|
+
isArray = true;
|
|
98
|
+
type = returnType[0];
|
|
99
|
+
} else {
|
|
100
|
+
type = returnType;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
|
|
104
|
+
const current = properties[key] || {};
|
|
105
|
+
const property = _extends(_extends(_extends({}, current), {
|
|
106
|
+
type,
|
|
107
|
+
isArray: isArray
|
|
108
|
+
}), options);
|
|
109
|
+
properties[key] = property;
|
|
110
|
+
Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
|
|
111
|
+
const legacyProperty = __rest(property, ["isArray"]);
|
|
112
|
+
defineLegacyIDEProp(target, key, legacyProperty);
|
|
113
|
+
}
|
|
114
|
+
function type(type) {
|
|
115
|
+
return Field({
|
|
116
|
+
type
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function step(step) {
|
|
120
|
+
return Field({
|
|
121
|
+
step
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
|
|
125
|
+
if (typeof returnTypeFuncOrOptions === 'function') {
|
|
126
|
+
return {
|
|
127
|
+
returnTypeFunc: returnTypeFuncOrOptions,
|
|
128
|
+
options: maybeOptions || {}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
options: returnTypeFuncOrOptions || {}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function Field(returnTypeFunction, maybeOptions) {
|
|
136
|
+
return (target, propertyKey) => {
|
|
137
|
+
if (typeof propertyKey === 'symbol') {
|
|
138
|
+
throw new SymbolKeysNotSupportedError();
|
|
139
|
+
}
|
|
140
|
+
const {
|
|
141
|
+
options,
|
|
142
|
+
returnTypeFunc
|
|
143
|
+
} = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
|
|
144
|
+
defineTypes(target, propertyKey, options, returnTypeFunc);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
var ExecuteMode;
|
|
148
|
+
(function (ExecuteMode) {
|
|
149
|
+
ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
|
|
150
|
+
ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
|
|
151
|
+
ExecuteMode[ExecuteMode["All"] = 6] = "All";
|
|
152
|
+
})(ExecuteMode || (ExecuteMode = {}));
|
|
153
|
+
class SpriteAnimation$2 extends eva_js.Component {
|
|
154
|
+
constructor(params) {
|
|
155
|
+
super(params);
|
|
156
|
+
this.resource = '';
|
|
157
|
+
this.autoPlay = true;
|
|
158
|
+
this.speed = 100;
|
|
159
|
+
this.forwards = false;
|
|
160
|
+
this.animations = {};
|
|
161
|
+
this.waitPlay = false;
|
|
162
|
+
this.waitLoop = false;
|
|
163
|
+
this.waitStop = false;
|
|
164
|
+
this.times = Infinity;
|
|
165
|
+
this.count = 0;
|
|
166
|
+
this.complete = false;
|
|
167
|
+
this.listenerBound = false;
|
|
168
|
+
this.init(params);
|
|
169
|
+
}
|
|
170
|
+
init(obj) {
|
|
171
|
+
obj && _extends(this, obj);
|
|
172
|
+
if (!this.listenerBound) {
|
|
173
|
+
this.listenerBound = true;
|
|
174
|
+
this.on('loop', () => {
|
|
175
|
+
var _a;
|
|
176
|
+
if (++this.count >= this.times) {
|
|
177
|
+
if (this.forwards) {
|
|
178
|
+
this.gotoAndStop(this.totalFrames - 1);
|
|
179
|
+
} else {
|
|
180
|
+
(_a = this.animate) === null || _a === void 0 ? void 0 : _a.stop();
|
|
181
|
+
}
|
|
182
|
+
this.complete = true;
|
|
183
|
+
this.emit('complete');
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
this.on('complete', () => {
|
|
187
|
+
var _a;
|
|
188
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
189
|
+
});
|
|
190
|
+
this.on('frameChange', () => {
|
|
191
|
+
var _a;
|
|
192
|
+
(_a = this.onFrameChange) === null || _a === void 0 ? void 0 : _a.call(this, this.currentFrame);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
play(nameOrTimes = Infinity, loop = false) {
|
|
197
|
+
let times = typeof nameOrTimes === 'number' ? nameOrTimes : loop ? Infinity : 1;
|
|
198
|
+
let startFrame;
|
|
199
|
+
if (typeof nameOrTimes === 'string') {
|
|
200
|
+
this.currentAnimation = nameOrTimes;
|
|
201
|
+
const clip = this.animations[nameOrTimes];
|
|
202
|
+
if (clip) {
|
|
203
|
+
startFrame = clip.start;
|
|
204
|
+
if (clip.speed !== undefined) this.speed = clip.speed;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (times === 0) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
this.times = times;
|
|
211
|
+
if (!this.animate) {
|
|
212
|
+
this.waitPlay = true;
|
|
213
|
+
this.waitAnimation = typeof nameOrTimes === 'string' ? nameOrTimes : undefined;
|
|
214
|
+
this.waitLoop = loop;
|
|
215
|
+
} else {
|
|
216
|
+
if (this.complete) {
|
|
217
|
+
this.gotoAndStop(0);
|
|
218
|
+
}
|
|
219
|
+
if (startFrame !== undefined) {
|
|
220
|
+
this.animate.gotoAndPlay(startFrame);
|
|
221
|
+
} else {
|
|
222
|
+
this.animate.play();
|
|
223
|
+
}
|
|
224
|
+
this.count = 0;
|
|
225
|
+
this.complete = false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
stop() {
|
|
229
|
+
if (!this.animate) {
|
|
230
|
+
this.waitStop = true;
|
|
231
|
+
} else {
|
|
232
|
+
this.animate.stop();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
set animate(val) {
|
|
236
|
+
this._animate = val;
|
|
237
|
+
if (this.waitPlay) {
|
|
238
|
+
this.waitPlay = false;
|
|
239
|
+
const waitAnimation = this.waitAnimation;
|
|
240
|
+
this.waitAnimation = undefined;
|
|
241
|
+
this.play(waitAnimation !== null && waitAnimation !== void 0 ? waitAnimation : this.times, this.waitLoop);
|
|
242
|
+
}
|
|
243
|
+
if (this.waitStop) {
|
|
244
|
+
this.waitStop = false;
|
|
245
|
+
this.stop();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
get animate() {
|
|
249
|
+
return this._animate;
|
|
250
|
+
}
|
|
251
|
+
gotoAndPlay(frameNumber) {
|
|
252
|
+
this.animate.gotoAndPlay(frameNumber);
|
|
253
|
+
}
|
|
254
|
+
gotoAndStop(frameNumber) {
|
|
255
|
+
this.animate.gotoAndStop(frameNumber);
|
|
256
|
+
}
|
|
257
|
+
get currentFrame() {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
|
|
260
|
+
}
|
|
261
|
+
get totalFrames() {
|
|
262
|
+
var _a, _b;
|
|
263
|
+
return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
SpriteAnimation$2.componentName = 'SpriteAnimation';
|
|
267
|
+
__decorate([type('string'), __metadata("design:type", String)], SpriteAnimation$2.prototype, "resource", void 0);
|
|
268
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "autoPlay", void 0);
|
|
269
|
+
__decorate([type('number'), step(10), __metadata("design:type", Number)], SpriteAnimation$2.prototype, "speed", void 0);
|
|
270
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "forwards", void 0);
|
|
271
|
+
const resourceKeySplit = '_s|r|c_';
|
|
272
|
+
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({
|
|
273
|
+
name,
|
|
274
|
+
data
|
|
275
|
+
}) => {
|
|
276
|
+
return new Promise(r => {
|
|
277
|
+
var _a;
|
|
278
|
+
const textureObj = data.json.data;
|
|
279
|
+
const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
|
|
280
|
+
let frames = textureObj.frames || {};
|
|
281
|
+
if (Array.isArray(frames)) {
|
|
282
|
+
const hashFrames = {};
|
|
283
|
+
for (const f of frames) {
|
|
284
|
+
const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
|
|
285
|
+
if (key) hashFrames[key] = f;
|
|
286
|
+
}
|
|
287
|
+
frames = hashFrames;
|
|
288
|
+
}
|
|
289
|
+
const animations = textureObj.animations || {};
|
|
290
|
+
const newAnimations = {};
|
|
291
|
+
const newFrames = {};
|
|
292
|
+
for (const key in frames) {
|
|
293
|
+
const newKey = name + resourceKeySplit + key;
|
|
294
|
+
newFrames[newKey] = frames[key];
|
|
295
|
+
}
|
|
296
|
+
for (const key in animations) {
|
|
297
|
+
const spriteList = [];
|
|
298
|
+
if (animations[key] && animations[key].length >= 0) {
|
|
299
|
+
for (const spriteName of animations[key]) {
|
|
300
|
+
const newSpriteName = name + resourceKeySplit + spriteName;
|
|
301
|
+
spriteList.push(newSpriteName);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
newAnimations[key] = spriteList;
|
|
305
|
+
}
|
|
306
|
+
const spriteSheet = new pixi_js.Spritesheet(texture, _extends(_extends({}, textureObj), {
|
|
307
|
+
frames: newFrames,
|
|
308
|
+
animations: newAnimations
|
|
309
|
+
}));
|
|
310
|
+
spriteSheet.parse().then(() => {
|
|
311
|
+
const {
|
|
312
|
+
textures
|
|
313
|
+
} = spriteSheet;
|
|
314
|
+
const spriteFrames = [];
|
|
315
|
+
for (const key in textures) {
|
|
316
|
+
spriteFrames.push(textures[key]);
|
|
317
|
+
}
|
|
318
|
+
r(spriteFrames);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({
|
|
323
|
+
instance
|
|
324
|
+
}) => {
|
|
325
|
+
if (!instance) return;
|
|
326
|
+
for (const texture of instance) {
|
|
327
|
+
texture.destroy(true);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
331
|
+
constructor() {
|
|
332
|
+
super(...arguments);
|
|
333
|
+
this.name = 'SpriteAnimationSystem';
|
|
334
|
+
this.animates = {};
|
|
335
|
+
this.autoPlay = {};
|
|
336
|
+
}
|
|
337
|
+
init() {
|
|
338
|
+
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
339
|
+
this.renderSystem.rendererManager.register(this);
|
|
340
|
+
}
|
|
341
|
+
rendererUpdate(gameObject) {
|
|
342
|
+
const {
|
|
343
|
+
width,
|
|
344
|
+
height
|
|
345
|
+
} = gameObject.transform.size;
|
|
346
|
+
if (this.animates[gameObject.id]) {
|
|
347
|
+
this.animates[gameObject.id].animatedSprite.width = width;
|
|
348
|
+
this.animates[gameObject.id].animatedSprite.height = height;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
componentChanged(changed) {
|
|
352
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
353
|
+
const gameObjectId = changed.gameObject.id;
|
|
354
|
+
if (changed.componentName === 'SpriteAnimation') {
|
|
355
|
+
const component = changed.component;
|
|
356
|
+
this.autoPlay[changed.gameObject.id] = component.autoPlay;
|
|
357
|
+
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
358
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
359
|
+
const {
|
|
360
|
+
instance: frames
|
|
361
|
+
} = yield eva_js.resource.getResource(component.resource);
|
|
362
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return;
|
|
363
|
+
if (!frames) {
|
|
364
|
+
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
365
|
+
}
|
|
366
|
+
this.add({
|
|
367
|
+
frames: frames,
|
|
368
|
+
id: changed.gameObject.id,
|
|
369
|
+
component
|
|
370
|
+
});
|
|
371
|
+
} else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
|
|
372
|
+
if (changed.prop && changed.prop.prop[0] === 'speed') {
|
|
373
|
+
this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
|
|
374
|
+
} else {
|
|
375
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
376
|
+
const {
|
|
377
|
+
instance: frames
|
|
378
|
+
} = yield eva_js.resource.getResource(component.resource);
|
|
379
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return;
|
|
380
|
+
if (!frames) {
|
|
381
|
+
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
382
|
+
}
|
|
383
|
+
this.change({
|
|
384
|
+
frames: frames,
|
|
385
|
+
id: changed.gameObject.id,
|
|
386
|
+
component
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
} else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
390
|
+
this.increaseAsyncId(gameObjectId);
|
|
391
|
+
this.remove(changed.gameObject.id);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
add({
|
|
397
|
+
frames,
|
|
398
|
+
id,
|
|
399
|
+
component
|
|
400
|
+
}) {
|
|
401
|
+
const animate = new rendererAdapter.SpriteAnimation({
|
|
402
|
+
frames
|
|
403
|
+
});
|
|
404
|
+
this.animates[id] = animate;
|
|
405
|
+
this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
|
|
406
|
+
animate.animatedSprite.onComplete = () => {
|
|
407
|
+
component.emit('complete');
|
|
408
|
+
};
|
|
409
|
+
animate.animatedSprite.onFrameChange = () => {
|
|
410
|
+
component.emit('frameChange');
|
|
411
|
+
};
|
|
412
|
+
animate.animatedSprite.onLoop = () => {
|
|
413
|
+
component.emit('loop');
|
|
414
|
+
};
|
|
415
|
+
component.animate = this.animates[id];
|
|
416
|
+
this.animates[id].speed = 1000 / 60 / component.speed;
|
|
417
|
+
if (this.autoPlay[id]) {
|
|
418
|
+
animate.animatedSprite.play();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
change({
|
|
422
|
+
frames,
|
|
423
|
+
id,
|
|
424
|
+
component
|
|
425
|
+
}) {
|
|
426
|
+
this.remove(id, true);
|
|
427
|
+
this.add({
|
|
428
|
+
frames,
|
|
429
|
+
id,
|
|
430
|
+
component
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
remove(id, isChange) {
|
|
434
|
+
const animate = this.animates[id];
|
|
435
|
+
if (!animate) return;
|
|
436
|
+
this.autoPlay[id] = animate.animatedSprite.playing;
|
|
437
|
+
this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
|
|
438
|
+
animate.animatedSprite.destroy();
|
|
439
|
+
delete this.animates[id];
|
|
440
|
+
if (!isChange) {
|
|
441
|
+
delete this.autoPlay[id];
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
SpriteAnimation.systemName = 'SpriteAnimationSystem';
|
|
446
|
+
SpriteAnimation = __decorate([eva_js.decorators.componentObserver({
|
|
447
|
+
SpriteAnimation: ['speed', 'resource']
|
|
448
|
+
})], SpriteAnimation);
|
|
449
|
+
var SpriteAnimation$1 = SpriteAnimation;
|
|
450
|
+
exports.SpriteAnimation = SpriteAnimation$2;
|
|
451
|
+
exports.SpriteAnimationSystem = SpriteAnimation$1;
|
|
452
|
+
Object.defineProperty(exports, '__esModule', {
|
|
453
|
+
value: true
|
|
454
|
+
});
|
|
455
|
+
return exports;
|
|
456
|
+
}({}, EVA, EVA.plugin.renderer, EVA.rendererAdapter, PIXI);
|
|
457
|
+
globalThis.EVA.plugin.renderer.spriteAnimation = globalThis.EVA.plugin.renderer.spriteAnimation || _EVA_IIFE_spriteAnimation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_spriteAnimation=function(t,e,n,i,o){"use strict";function r(t,e,n,i){var o,r=arguments.length,s=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(r<3?o(s):r>3?o(e,n,s):o(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}function s(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function a(t,e,n,i){return new(n||(n=Promise))(function(o,r){function s(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((i=i.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;class c extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const p="IDE_PROPERTY_METADATA";function d(t,e,n,i){let o=Reflect.getMetadata("design:type",t,e),r=o===Array;const s=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),i){const t=i();Array.isArray(t)?(r=!0,o=t[0]):o=t}const a=Reflect.getMetadata(p,t.constructor)||{},c=_extends(_extends(_extends({},a[e]||{}),{type:o,isArray:r}),n);a[e]=c,Reflect.defineMetadata(p,a,t.constructor);!function(t,e,n){const i=t.constructor,o=i.IDEProps||{};o[e]=_extends(_extends({key:e},o[e]),n),i.IDEProps=o}(t,e,function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(n[i[o]]=t[i[o]])}return n}(c,["isArray"]))}function m(t){return l({type:t})}function l(t,e){return(n,i)=>{if("symbol"==typeof i)throw new c;const{options:o,returnTypeFunc:r}=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);d(n,i,o,r)}}var h;!function(t){t[t.Edit=2]="Edit",t[t.Game=4]="Game",t[t.All=6]="All"}(h||(h={}));class u extends e.Component{constructor(t){super(t),this.resource="",this.autoPlay=!0,this.speed=100,this.forwards=!1,this.animations={},this.waitPlay=!1,this.waitLoop=!1,this.waitStop=!1,this.times=1/0,this.count=0,this.complete=!1,this.listenerBound=!1,this.init(t)}init(t){t&&_extends(this,t),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var t;++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(t=this.animate)||void 0===t||t.stop(),this.complete=!0,this.emit("complete"))}),this.on("complete",()=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this)}),this.on("frameChange",()=>{var t;null===(t=this.onFrameChange)||void 0===t||t.call(this,this.currentFrame)}))}play(t=1/0,e=!1){let n,i="number"==typeof t?t:e?1/0:1;if("string"==typeof t){this.currentAnimation=t;const e=this.animations[t];e&&(n=e.start,void 0!==e.speed&&(this.speed=e.speed))}0!==i&&(this.times=i,this.animate?(this.complete&&this.gotoAndStop(0),void 0!==n?this.animate.gotoAndPlay(n):this.animate.play(),this.count=0,this.complete=!1):(this.waitPlay=!0,this.waitAnimation="string"==typeof t?t:void 0,this.waitLoop=e))}stop(){this.animate?this.animate.stop():this.waitStop=!0}set animate(t){if(this._animate=t,this.waitPlay){this.waitPlay=!1;const t=this.waitAnimation;this.waitAnimation=void 0,this.play(null!=t?t:this.times,this.waitLoop)}this.waitStop&&(this.waitStop=!1,this.stop())}get animate(){return this._animate}gotoAndPlay(t){this.animate.gotoAndPlay(t)}gotoAndStop(t){this.animate.gotoAndStop(t)}get currentFrame(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.currentFrame}get totalFrames(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.totalFrames}}u.componentName="SpriteAnimation",r([m("string"),s("design:type",String)],u.prototype,"resource",void 0),r([m("boolean"),s("design:type",Boolean)],u.prototype,"autoPlay",void 0),r([m("number"),function(t){return l({step:t})}(10),s("design:type",Number)],u.prototype,"speed",void 0),r([m("boolean"),s("design:type",Boolean)],u.prototype,"forwards",void 0);const f="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,({name:t,data:e})=>new Promise(n=>{var i;const r=e.json.data,s=e.image instanceof o.Texture?e.image:o.Texture.from(e.image);let a=r.frames||{};if(Array.isArray(a)){const t={};for(const e of a){const n=null!==(i=e.filename)&&void 0!==i?i:e.name;n&&(t[n]=e)}a=t}const c=r.animations||{},p={},d={};for(const e in a){d[t+f+e]=a[e]}for(const e in c){const n=[];if(c[e]&&c[e].length>=0)for(const i of c[e]){const e=t+f+i;n.push(e)}p[e]=n}const m=new o.Spritesheet(s,_extends(_extends({},r),{frames:d,animations:p}));m.parse().then(()=>{const{textures:t}=m,e=[];for(const n in t)e.push(t[n]);n(e)})})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,({instance:t})=>{if(t)for(const e of t)e.destroy(!0)});let y=class extends n.Renderer{constructor(){super(...arguments),this.name="SpriteAnimationSystem",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(t){const{width:e,height:n}=t.transform.size;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=e,this.animates[t.id].animatedSprite.height=n)}componentChanged(t){return a(this,void 0,void 0,function*(){const n=t.gameObject.id;if("SpriteAnimation"===t.componentName){const i=t.component;if(this.autoPlay[t.gameObject.id]=i.autoPlay,t.type===e.OBSERVER_TYPE.ADD){const o=this.increaseAsyncId(n),{instance:r}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;r||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.add({frames:r,id:t.gameObject.id,component:i})}else if(t.type===e.OBSERVER_TYPE.CHANGE)if(t.prop&&"speed"===t.prop.prop[0])this.animates[t.gameObject.id].speed=1e3/60/i.speed;else{const o=this.increaseAsyncId(n),{instance:r}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;r||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.change({frames:r,id:t.gameObject.id,component:i})}else t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(n),this.remove(t.gameObject.id))}})}add({frames:t,id:e,component:n}){const o=new i.SpriteAnimation({frames:t});this.animates[e]=o,this.containerManager.getContainer(e).addChildAt(o.animatedSprite,0),o.animatedSprite.onComplete=()=>{n.emit("complete")},o.animatedSprite.onFrameChange=()=>{n.emit("frameChange")},o.animatedSprite.onLoop=()=>{n.emit("loop")},n.animate=this.animates[e],this.animates[e].speed=1e3/60/n.speed,this.autoPlay[e]&&o.animatedSprite.play()}change({frames:t,id:e,component:n}){this.remove(e,!0),this.add({frames:t,id:e,component:n})}remove(t,e){const n=this.animates[t];n&&(this.autoPlay[t]=n.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(n.animatedSprite),n.animatedSprite.destroy(),delete this.animates[t],e||delete this.autoPlay[t])}};y.systemName="SpriteAnimationSystem",y=r([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],y);var g=y;return t.SpriteAnimation=u,t.SpriteAnimationSystem=g,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);globalThis.EVA.plugin.renderer.spriteAnimation=globalThis.EVA.plugin.renderer.spriteAnimation||_EVA_IIFE_spriteAnimation;
|