@eva/plugin-renderer-sprite-animation 2.0.2 → 2.1.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.
- package/dist/EVA.plugin.renderer.spriteAnimation.js +214 -39
- package/dist/EVA.plugin.renderer.spriteAnimation.min.js +1 -1
- package/dist/plugin-renderer-sprite-animation.cjs.js +135 -24
- package/dist/plugin-renderer-sprite-animation.cjs.prod.js +1 -1
- package/dist/plugin-renderer-sprite-animation.d.ts +29 -1
- package/dist/plugin-renderer-sprite-animation.esm.js +135 -24
- package/package.json +5 -5
|
@@ -11,6 +11,9 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
11
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
12
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
13
|
}
|
|
14
|
+
function __metadata(metadataKey, metadataValue) {
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
16
|
+
}
|
|
14
17
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
15
18
|
function adopt(value) {
|
|
16
19
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -38,70 +41,231 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
38
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
|
-
function
|
|
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]];
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
|
|
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);
|
|
47
64
|
}
|
|
48
|
-
|
|
49
|
-
|
|
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);
|
|
50
113
|
}
|
|
51
114
|
function type(type) {
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
prop.type = type;
|
|
56
|
-
};
|
|
115
|
+
return Field({
|
|
116
|
+
type
|
|
117
|
+
});
|
|
57
118
|
}
|
|
58
119
|
function step(step) {
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
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);
|
|
62
145
|
};
|
|
63
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 = {}));
|
|
64
153
|
class SpriteAnimation$2 extends eva_js.Component {
|
|
65
|
-
constructor() {
|
|
66
|
-
super(
|
|
154
|
+
constructor(params) {
|
|
155
|
+
super(params);
|
|
67
156
|
this.resource = '';
|
|
68
157
|
this.autoPlay = true;
|
|
69
158
|
this.speed = 100;
|
|
70
159
|
this.forwards = false;
|
|
160
|
+
this.animations = {};
|
|
71
161
|
this.waitPlay = false;
|
|
162
|
+
this.waitLoop = false;
|
|
72
163
|
this.waitStop = false;
|
|
73
164
|
this.times = Infinity;
|
|
74
165
|
this.count = 0;
|
|
75
166
|
this.complete = false;
|
|
167
|
+
this.activeClipLoop = false;
|
|
168
|
+
this.listenerBound = false;
|
|
169
|
+
this.init(params);
|
|
76
170
|
}
|
|
77
171
|
init(obj) {
|
|
78
172
|
obj && _extends(this, obj);
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
173
|
+
if (!this.listenerBound) {
|
|
174
|
+
this.listenerBound = true;
|
|
175
|
+
this.on('loop', () => {
|
|
176
|
+
var _a;
|
|
177
|
+
if (this.complete) return;
|
|
178
|
+
if (this.activeClip) {
|
|
179
|
+
if (this.activeClipLoop) {
|
|
180
|
+
this.animate.gotoAndPlay(this.activeClip.start);
|
|
181
|
+
} else {
|
|
182
|
+
this.animate.gotoAndStop(this.activeClip.end);
|
|
183
|
+
this.finish();
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
85
186
|
}
|
|
86
|
-
this.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
187
|
+
if (++this.count >= this.times) {
|
|
188
|
+
if (this.forwards) {
|
|
189
|
+
this.gotoAndStop(this.totalFrames - 1);
|
|
190
|
+
} else {
|
|
191
|
+
(_a = this.animate) === null || _a === void 0 ? void 0 : _a.stop();
|
|
192
|
+
}
|
|
193
|
+
this.finish();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
this.on('complete', () => {
|
|
197
|
+
var _a;
|
|
198
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
199
|
+
});
|
|
200
|
+
this.on('frameChange', () => {
|
|
201
|
+
var _a;
|
|
202
|
+
const frame = this.currentFrame;
|
|
203
|
+
(_a = this.onFrameChange) === null || _a === void 0 ? void 0 : _a.call(this, frame);
|
|
204
|
+
if (!this.complete && this.activeClip && frame >= this.activeClip.end) {
|
|
205
|
+
if (this.activeClipLoop) {
|
|
206
|
+
this.animate.gotoAndPlay(this.activeClip.start);
|
|
207
|
+
} else {
|
|
208
|
+
this.animate.stop();
|
|
209
|
+
if (frame > this.activeClip.end) {
|
|
210
|
+
this.animate.gotoAndStop(this.activeClip.end);
|
|
211
|
+
}
|
|
212
|
+
this.finish();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
finish() {
|
|
219
|
+
if (this.complete) return;
|
|
220
|
+
this.complete = true;
|
|
221
|
+
this.emit('complete');
|
|
90
222
|
}
|
|
91
|
-
|
|
223
|
+
_handleRendererComplete() {
|
|
224
|
+
this.finish();
|
|
225
|
+
}
|
|
226
|
+
isValidClip(clip) {
|
|
227
|
+
return Number.isInteger(clip.start) && Number.isInteger(clip.end) && clip.start >= 0 && clip.start <= clip.end && clip.end < this.totalFrames;
|
|
228
|
+
}
|
|
229
|
+
play(nameOrTimes = Infinity, loop = false) {
|
|
230
|
+
const times = typeof nameOrTimes === 'number' ? nameOrTimes : loop ? Infinity : 1;
|
|
231
|
+
let startFrame;
|
|
232
|
+
if (typeof nameOrTimes === 'string') {
|
|
233
|
+
this.currentAnimation = nameOrTimes;
|
|
234
|
+
this.activeClip = undefined;
|
|
235
|
+
this.activeClipLoop = false;
|
|
236
|
+
const clip = this.animations[nameOrTimes];
|
|
237
|
+
if (clip) {
|
|
238
|
+
startFrame = clip.start;
|
|
239
|
+
if (this.animate && this.isValidClip(clip)) {
|
|
240
|
+
this.activeClip = clip;
|
|
241
|
+
this.activeClipLoop = loop;
|
|
242
|
+
}
|
|
243
|
+
if (clip.speed !== undefined) this.speed = clip.speed;
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
this.currentAnimation = undefined;
|
|
247
|
+
this.activeClip = undefined;
|
|
248
|
+
this.activeClipLoop = false;
|
|
249
|
+
}
|
|
92
250
|
if (times === 0) {
|
|
93
251
|
return;
|
|
94
252
|
}
|
|
95
253
|
this.times = times;
|
|
96
254
|
if (!this.animate) {
|
|
97
255
|
this.waitPlay = true;
|
|
256
|
+
this.waitAnimation = typeof nameOrTimes === 'string' ? nameOrTimes : undefined;
|
|
257
|
+
this.waitLoop = loop;
|
|
98
258
|
} else {
|
|
99
|
-
if (this.complete) {
|
|
259
|
+
if (this.complete && startFrame === undefined) {
|
|
100
260
|
this.gotoAndStop(0);
|
|
101
261
|
}
|
|
102
|
-
this.animate.play();
|
|
103
262
|
this.count = 0;
|
|
104
263
|
this.complete = false;
|
|
264
|
+
if (startFrame !== undefined) {
|
|
265
|
+
this.animate.gotoAndPlay(startFrame);
|
|
266
|
+
} else {
|
|
267
|
+
this.animate.play();
|
|
268
|
+
}
|
|
105
269
|
}
|
|
106
270
|
}
|
|
107
271
|
stop() {
|
|
@@ -115,7 +279,9 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
115
279
|
this._animate = val;
|
|
116
280
|
if (this.waitPlay) {
|
|
117
281
|
this.waitPlay = false;
|
|
118
|
-
this.
|
|
282
|
+
const waitAnimation = this.waitAnimation;
|
|
283
|
+
this.waitAnimation = undefined;
|
|
284
|
+
this.play(waitAnimation !== null && waitAnimation !== void 0 ? waitAnimation : this.times, this.waitLoop);
|
|
119
285
|
}
|
|
120
286
|
if (this.waitStop) {
|
|
121
287
|
this.waitStop = false;
|
|
@@ -141,19 +307,28 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
141
307
|
}
|
|
142
308
|
}
|
|
143
309
|
SpriteAnimation$2.componentName = 'SpriteAnimation';
|
|
144
|
-
__decorate([type('string')], SpriteAnimation$2.prototype, "resource", void 0);
|
|
145
|
-
__decorate([type('boolean')], SpriteAnimation$2.prototype, "autoPlay", void 0);
|
|
146
|
-
__decorate([type('number'), step(10)], SpriteAnimation$2.prototype, "speed", void 0);
|
|
147
|
-
__decorate([type('boolean')], SpriteAnimation$2.prototype, "forwards", void 0);
|
|
310
|
+
__decorate([type('string'), __metadata("design:type", String)], SpriteAnimation$2.prototype, "resource", void 0);
|
|
311
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "autoPlay", void 0);
|
|
312
|
+
__decorate([type('number'), step(10), __metadata("design:type", Number)], SpriteAnimation$2.prototype, "speed", void 0);
|
|
313
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "forwards", void 0);
|
|
148
314
|
const resourceKeySplit = '_s|r|c_';
|
|
149
315
|
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({
|
|
150
316
|
name,
|
|
151
317
|
data
|
|
152
318
|
}) => {
|
|
153
319
|
return new Promise(r => {
|
|
320
|
+
var _a;
|
|
154
321
|
const textureObj = data.json.data;
|
|
155
322
|
const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
|
|
156
|
-
|
|
323
|
+
let frames = textureObj.frames || {};
|
|
324
|
+
if (Array.isArray(frames)) {
|
|
325
|
+
const hashFrames = {};
|
|
326
|
+
for (const f of frames) {
|
|
327
|
+
const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
|
|
328
|
+
if (key) hashFrames[key] = f;
|
|
329
|
+
}
|
|
330
|
+
frames = hashFrames;
|
|
331
|
+
}
|
|
157
332
|
const animations = textureObj.animations || {};
|
|
158
333
|
const newAnimations = {};
|
|
159
334
|
const newFrames = {};
|
|
@@ -198,7 +373,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
198
373
|
let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
199
374
|
constructor() {
|
|
200
375
|
super(...arguments);
|
|
201
|
-
this.name = '
|
|
376
|
+
this.name = 'SpriteAnimationSystem';
|
|
202
377
|
this.animates = {};
|
|
203
378
|
this.autoPlay = {};
|
|
204
379
|
}
|
|
@@ -272,7 +447,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
272
447
|
this.animates[id] = animate;
|
|
273
448
|
this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
|
|
274
449
|
animate.animatedSprite.onComplete = () => {
|
|
275
|
-
component.
|
|
450
|
+
component._handleRendererComplete();
|
|
276
451
|
};
|
|
277
452
|
animate.animatedSprite.onFrameChange = () => {
|
|
278
453
|
component.emit('frameChange');
|
|
@@ -310,7 +485,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
310
485
|
}
|
|
311
486
|
}
|
|
312
487
|
};
|
|
313
|
-
SpriteAnimation.systemName = '
|
|
488
|
+
SpriteAnimation.systemName = 'SpriteAnimationSystem';
|
|
314
489
|
SpriteAnimation = __decorate([eva_js.decorators.componentObserver({
|
|
315
490
|
SpriteAnimation: ['speed', 'resource']
|
|
316
491
|
})], SpriteAnimation);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)({}).hasOwnProperty.call(i,n)&&(t[n]=i[n])}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,i,n,o){"use strict";function s(t,e,i,n){var o,s=arguments.length,a=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var r=t.length-1;r>=0;r--)(o=t[r])&&(a=(s<3?o(a):s>3?o(e,i,a):o(e,i))||a);return s>3&&a&&Object.defineProperty(e,i,a),a}function a(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function r(t,e,i,n){return new(i||(i=Promise))(function(o,s){function a(t){try{p(n.next(t))}catch(t){s(t)}}function r(t){try{p(n.throw(t))}catch(t){s(t)}}function p(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(a,r)}p((n=n.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;class p extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const c="IDE_PROPERTY_METADATA";function l(t,e,i,n){let o=Reflect.getMetadata("design:type",t,e),s=o===Array;const a=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==a&&(o=a),n){const t=n();Array.isArray(t)?(s=!0,o=t[0]):o=t}const r=Reflect.getMetadata(c,t.constructor)||{},p=_extends(_extends(_extends({},r[e]||{}),{type:o,isArray:s}),i);r[e]=p,Reflect.defineMetadata(c,r,t.constructor);!function(t,e,i){const n=t.constructor,o=n.IDEProps||{};o[e]=_extends(_extends({key:e},o[e]),i),n.IDEProps=o}(t,e,function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(i[n[o]]=t[n[o]])}return i}(p,["isArray"]))}function d(t){return h({type:t})}function h(t,e){return(i,n)=>{if("symbol"==typeof n)throw new p;const{options:o,returnTypeFunc:s}=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);l(i,n,o,s)}}var m;!function(t){t[t.Edit=2]="Edit",t[t.Game=4]="Game",t[t.All=6]="All"}(m||(m={}));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.activeClipLoop=!1,this.listenerBound=!1,this.init(t)}init(t){t&&_extends(this,t),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var t;this.complete||(this.activeClip?this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.gotoAndStop(this.activeClip.end),this.finish()):++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(t=this.animate)||void 0===t||t.stop(),this.finish()))}),this.on("complete",()=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this)}),this.on("frameChange",()=>{var t;const e=this.currentFrame;null===(t=this.onFrameChange)||void 0===t||t.call(this,e),!this.complete&&this.activeClip&&e>=this.activeClip.end&&(this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.stop(),e>this.activeClip.end&&this.animate.gotoAndStop(this.activeClip.end),this.finish()))}))}finish(){this.complete||(this.complete=!0,this.emit("complete"))}_handleRendererComplete(){this.finish()}isValidClip(t){return Number.isInteger(t.start)&&Number.isInteger(t.end)&&t.start>=0&&t.start<=t.end&&t.end<this.totalFrames}play(t=1/0,e=!1){const i="number"==typeof t?t:e?1/0:1;let n;if("string"==typeof t){this.currentAnimation=t,this.activeClip=void 0,this.activeClipLoop=!1;const i=this.animations[t];i&&(n=i.start,this.animate&&this.isValidClip(i)&&(this.activeClip=i,this.activeClipLoop=e),void 0!==i.speed&&(this.speed=i.speed))}else this.currentAnimation=void 0,this.activeClip=void 0,this.activeClipLoop=!1;0!==i&&(this.times=i,this.animate?(this.complete&&void 0===n&&this.gotoAndStop(0),this.count=0,this.complete=!1,void 0!==n?this.animate.gotoAndPlay(n):this.animate.play()):(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",s([d("string"),a("design:type",String)],u.prototype,"resource",void 0),s([d("boolean"),a("design:type",Boolean)],u.prototype,"autoPlay",void 0),s([d("number"),function(t){return h({step:t})}(10),a("design:type",Number)],u.prototype,"speed",void 0),s([d("boolean"),a("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(i=>{var n;const s=e.json.data,a=e.image instanceof o.Texture?e.image:o.Texture.from(e.image);let r=s.frames||{};if(Array.isArray(r)){const t={};for(const e of r){const i=null!==(n=e.filename)&&void 0!==n?n:e.name;i&&(t[i]=e)}r=t}const p=s.animations||{},c={},l={};for(const e in r){l[t+f+e]=r[e]}for(const e in p){const i=[];if(p[e]&&p[e].length>=0)for(const n of p[e]){const e=t+f+n;i.push(e)}c[e]=i}const d=new o.Spritesheet(a,_extends(_extends({},s),{frames:l,animations:c}));d.parse().then(()=>{const{textures:t}=d,e=[];for(const i in t)e.push(t[i]);i(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 i.Renderer{constructor(){super(...arguments),this.name="SpriteAnimationSystem",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(t){const{width:e,height:i}=t.transform.size;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=e,this.animates[t.id].animatedSprite.height=i)}componentChanged(t){return r(this,void 0,void 0,function*(){const i=t.gameObject.id;if("SpriteAnimation"===t.componentName){const n=t.component;if(this.autoPlay[t.gameObject.id]=n.autoPlay,t.type===e.OBSERVER_TYPE.ADD){const o=this.increaseAsyncId(i),{instance:s}=yield e.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;s||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.add({frames:s,id:t.gameObject.id,component:n})}else if(t.type===e.OBSERVER_TYPE.CHANGE)if(t.prop&&"speed"===t.prop.prop[0])this.animates[t.gameObject.id].speed=1e3/60/n.speed;else{const o=this.increaseAsyncId(i),{instance:s}=yield e.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;s||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.change({frames:s,id:t.gameObject.id,component:n})}else t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(i),this.remove(t.gameObject.id))}})}add({frames:t,id:e,component:i}){const o=new n.SpriteAnimation({frames:t});this.animates[e]=o,this.containerManager.getContainer(e).addChildAt(o.animatedSprite,0),o.animatedSprite.onComplete=()=>{i._handleRendererComplete()},o.animatedSprite.onFrameChange=()=>{i.emit("frameChange")},o.animatedSprite.onLoop=()=>{i.emit("loop")},i.animate=this.animates[e],this.animates[e].speed=1e3/60/i.speed,this.autoPlay[e]&&o.animatedSprite.play()}change({frames:t,id:e,component:i}){this.remove(e,!0),this.add({frames:t,id:e,component:i})}remove(t,e){const i=this.animates[t];i&&(this.autoPlay[t]=i.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(i.animatedSprite),i.animatedSprite.destroy(),delete this.animates[t],e||delete this.autoPlay[t])}};y.systemName="SpriteAnimationSystem",y=s([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;
|
|
@@ -30,6 +30,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
30
30
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function __metadata(metadataKey, metadataValue) {
|
|
34
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
34
38
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
35
39
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -84,8 +88,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
84
88
|
* ```
|
|
85
89
|
*/
|
|
86
90
|
class SpriteAnimation$2 extends eva_js.Component {
|
|
87
|
-
constructor() {
|
|
88
|
-
super(
|
|
91
|
+
constructor(params) {
|
|
92
|
+
super(params);
|
|
89
93
|
/** 帧动画资源名称 */
|
|
90
94
|
this.resource = '';
|
|
91
95
|
/** 是否自动播放 */
|
|
@@ -94,8 +98,11 @@ class SpriteAnimation$2 extends eva_js.Component {
|
|
|
94
98
|
this.speed = 100;
|
|
95
99
|
/** 是否在最后一帧停止(forwards 模式) */
|
|
96
100
|
this.forwards = false;
|
|
101
|
+
/** 命名动画片段,供编辑器和脚本按动作名播放 */
|
|
102
|
+
this.animations = {};
|
|
97
103
|
/** 等待播放标志(资源加载前调用 play) */
|
|
98
104
|
this.waitPlay = false;
|
|
105
|
+
this.waitLoop = false;
|
|
99
106
|
/** 等待停止标志 */
|
|
100
107
|
this.waitStop = false;
|
|
101
108
|
/** 播放次数 */
|
|
@@ -104,6 +111,10 @@ class SpriteAnimation$2 extends eva_js.Component {
|
|
|
104
111
|
this.count = 0;
|
|
105
112
|
/** 是否播放完成 */
|
|
106
113
|
this.complete = false;
|
|
114
|
+
/** 当前命名动画是否循环 */
|
|
115
|
+
this.activeClipLoop = false;
|
|
116
|
+
this.listenerBound = false;
|
|
117
|
+
this.init(params);
|
|
107
118
|
}
|
|
108
119
|
/**
|
|
109
120
|
* 初始化组件
|
|
@@ -115,34 +126,117 @@ class SpriteAnimation$2 extends eva_js.Component {
|
|
|
115
126
|
*/
|
|
116
127
|
init(obj) {
|
|
117
128
|
obj && Object.assign(this, obj);
|
|
118
|
-
this.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
129
|
+
if (!this.listenerBound) {
|
|
130
|
+
this.listenerBound = true;
|
|
131
|
+
this.on('loop', () => {
|
|
132
|
+
var _a;
|
|
133
|
+
if (this.complete)
|
|
134
|
+
return;
|
|
135
|
+
if (this.activeClip) {
|
|
136
|
+
if (this.activeClipLoop) {
|
|
137
|
+
this.animate.gotoAndPlay(this.activeClip.start);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
this.animate.gotoAndStop(this.activeClip.end);
|
|
141
|
+
this.finish();
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
122
144
|
}
|
|
123
|
-
|
|
124
|
-
this.
|
|
145
|
+
if (++this.count >= this.times) {
|
|
146
|
+
if (this.forwards) {
|
|
147
|
+
this.gotoAndStop(this.totalFrames - 1);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
(_a = this.animate) === null || _a === void 0 ? void 0 : _a.stop();
|
|
151
|
+
}
|
|
152
|
+
this.finish();
|
|
125
153
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
154
|
+
});
|
|
155
|
+
this.on('complete', () => {
|
|
156
|
+
var _a;
|
|
157
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
158
|
+
});
|
|
159
|
+
this.on('frameChange', () => {
|
|
160
|
+
var _a;
|
|
161
|
+
const frame = this.currentFrame;
|
|
162
|
+
(_a = this.onFrameChange) === null || _a === void 0 ? void 0 : _a.call(this, frame);
|
|
163
|
+
if (!this.complete && this.activeClip && frame >= this.activeClip.end) {
|
|
164
|
+
if (this.activeClipLoop) {
|
|
165
|
+
this.animate.gotoAndPlay(this.activeClip.start);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
this.animate.stop();
|
|
169
|
+
if (frame > this.activeClip.end) {
|
|
170
|
+
this.animate.gotoAndStop(this.activeClip.end);
|
|
171
|
+
}
|
|
172
|
+
this.finish();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
finish() {
|
|
179
|
+
if (this.complete)
|
|
180
|
+
return;
|
|
181
|
+
this.complete = true;
|
|
182
|
+
this.emit('complete');
|
|
130
183
|
}
|
|
131
|
-
|
|
184
|
+
/** @internal Renderer event entry point; keeps late renderer callbacks idempotent. */
|
|
185
|
+
_handleRendererComplete() {
|
|
186
|
+
this.finish();
|
|
187
|
+
}
|
|
188
|
+
isValidClip(clip) {
|
|
189
|
+
return (Number.isInteger(clip.start) &&
|
|
190
|
+
Number.isInteger(clip.end) &&
|
|
191
|
+
clip.start >= 0 &&
|
|
192
|
+
clip.start <= clip.end &&
|
|
193
|
+
clip.end < this.totalFrames);
|
|
194
|
+
}
|
|
195
|
+
play(nameOrTimes = Infinity, loop = false) {
|
|
196
|
+
const times = typeof nameOrTimes === 'number' ? nameOrTimes : loop ? Infinity : 1;
|
|
197
|
+
let startFrame;
|
|
198
|
+
if (typeof nameOrTimes === 'string') {
|
|
199
|
+
this.currentAnimation = nameOrTimes;
|
|
200
|
+
this.activeClip = undefined;
|
|
201
|
+
this.activeClipLoop = false;
|
|
202
|
+
const clip = this.animations[nameOrTimes];
|
|
203
|
+
if (clip) {
|
|
204
|
+
startFrame = clip.start;
|
|
205
|
+
// Invalid ranges keep the legacy start-only/full-timeline behavior instead of throwing.
|
|
206
|
+
if (this.animate && this.isValidClip(clip)) {
|
|
207
|
+
this.activeClip = clip;
|
|
208
|
+
this.activeClipLoop = loop;
|
|
209
|
+
}
|
|
210
|
+
if (clip.speed !== undefined)
|
|
211
|
+
this.speed = clip.speed;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
this.currentAnimation = undefined;
|
|
216
|
+
this.activeClip = undefined;
|
|
217
|
+
this.activeClipLoop = false;
|
|
218
|
+
}
|
|
132
219
|
if (times === 0) {
|
|
133
220
|
return;
|
|
134
221
|
}
|
|
135
222
|
this.times = times;
|
|
136
223
|
if (!this.animate) {
|
|
137
224
|
this.waitPlay = true;
|
|
225
|
+
this.waitAnimation = typeof nameOrTimes === 'string' ? nameOrTimes : undefined;
|
|
226
|
+
this.waitLoop = loop;
|
|
138
227
|
}
|
|
139
228
|
else {
|
|
140
|
-
if (this.complete) {
|
|
229
|
+
if (this.complete && startFrame === undefined) {
|
|
141
230
|
this.gotoAndStop(0);
|
|
142
231
|
}
|
|
143
|
-
this.animate.play();
|
|
144
232
|
this.count = 0;
|
|
145
233
|
this.complete = false;
|
|
234
|
+
if (startFrame !== undefined) {
|
|
235
|
+
this.animate.gotoAndPlay(startFrame);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
this.animate.play();
|
|
239
|
+
}
|
|
146
240
|
}
|
|
147
241
|
}
|
|
148
242
|
stop() {
|
|
@@ -157,7 +251,9 @@ class SpriteAnimation$2 extends eva_js.Component {
|
|
|
157
251
|
this._animate = val;
|
|
158
252
|
if (this.waitPlay) {
|
|
159
253
|
this.waitPlay = false;
|
|
160
|
-
this.
|
|
254
|
+
const waitAnimation = this.waitAnimation;
|
|
255
|
+
this.waitAnimation = undefined;
|
|
256
|
+
this.play(waitAnimation !== null && waitAnimation !== void 0 ? waitAnimation : this.times, this.waitLoop);
|
|
161
257
|
}
|
|
162
258
|
if (this.waitStop) {
|
|
163
259
|
this.waitStop = false;
|
|
@@ -185,25 +281,40 @@ class SpriteAnimation$2 extends eva_js.Component {
|
|
|
185
281
|
/** 组件名称 */
|
|
186
282
|
SpriteAnimation$2.componentName = 'SpriteAnimation';
|
|
187
283
|
__decorate([
|
|
188
|
-
inspectorDecorator.type('string')
|
|
284
|
+
inspectorDecorator.type('string'),
|
|
285
|
+
__metadata("design:type", String)
|
|
189
286
|
], SpriteAnimation$2.prototype, "resource", void 0);
|
|
190
287
|
__decorate([
|
|
191
|
-
inspectorDecorator.type('boolean')
|
|
288
|
+
inspectorDecorator.type('boolean'),
|
|
289
|
+
__metadata("design:type", Boolean)
|
|
192
290
|
], SpriteAnimation$2.prototype, "autoPlay", void 0);
|
|
193
291
|
__decorate([
|
|
194
292
|
inspectorDecorator.type('number'),
|
|
195
|
-
inspectorDecorator.step(10)
|
|
293
|
+
inspectorDecorator.step(10),
|
|
294
|
+
__metadata("design:type", Number)
|
|
196
295
|
], SpriteAnimation$2.prototype, "speed", void 0);
|
|
197
296
|
__decorate([
|
|
198
|
-
inspectorDecorator.type('boolean')
|
|
297
|
+
inspectorDecorator.type('boolean'),
|
|
298
|
+
__metadata("design:type", Boolean)
|
|
199
299
|
], SpriteAnimation$2.prototype, "forwards", void 0);
|
|
200
300
|
|
|
201
301
|
const resourceKeySplit = '_s|r|c_';
|
|
202
302
|
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({ name, data }) => {
|
|
203
303
|
return new Promise(r => {
|
|
304
|
+
var _a;
|
|
204
305
|
const textureObj = data.json.data;
|
|
205
306
|
const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
|
|
206
|
-
|
|
307
|
+
// Normalize Phaser JSONArray (`frames: [...]`) to PixiJS-compatible hash (`frames: {name: {...}}`).
|
|
308
|
+
let frames = textureObj.frames || {};
|
|
309
|
+
if (Array.isArray(frames)) {
|
|
310
|
+
const hashFrames = {};
|
|
311
|
+
for (const f of frames) {
|
|
312
|
+
const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
|
|
313
|
+
if (key)
|
|
314
|
+
hashFrames[key] = f;
|
|
315
|
+
}
|
|
316
|
+
frames = hashFrames;
|
|
317
|
+
}
|
|
207
318
|
const animations = textureObj.animations || {};
|
|
208
319
|
const newAnimations = {};
|
|
209
320
|
const newFrames = {};
|
|
@@ -242,7 +353,7 @@ eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({ instan
|
|
|
242
353
|
let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
243
354
|
constructor() {
|
|
244
355
|
super(...arguments);
|
|
245
|
-
this.name = '
|
|
356
|
+
this.name = 'SpriteAnimationSystem';
|
|
246
357
|
this.animates = {};
|
|
247
358
|
this.autoPlay = {};
|
|
248
359
|
}
|
|
@@ -308,7 +419,7 @@ let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
|
308
419
|
this.animates[id] = animate;
|
|
309
420
|
this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
|
|
310
421
|
animate.animatedSprite.onComplete = () => {
|
|
311
|
-
component.
|
|
422
|
+
component._handleRendererComplete();
|
|
312
423
|
};
|
|
313
424
|
animate.animatedSprite.onFrameChange = () => {
|
|
314
425
|
component.emit('frameChange');
|
|
@@ -339,7 +450,7 @@ let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
|
339
450
|
}
|
|
340
451
|
}
|
|
341
452
|
};
|
|
342
|
-
SpriteAnimation.systemName = '
|
|
453
|
+
SpriteAnimation.systemName = 'SpriteAnimationSystem';
|
|
343
454
|
SpriteAnimation = __decorate([
|
|
344
455
|
eva_js.decorators.componentObserver({
|
|
345
456
|
SpriteAnimation: ['speed', 'resource'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=require("@eva/inspector-decorator"),i=require("@eva/plugin-renderer"),s=require("@eva/renderer-adapter"),n=require("pixi.js");function a(t,e,i,s){var n,a=arguments.length,o=a<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var r=t.length-1;r>=0;r--)(n=t[r])&&(o=(a<3?n(o):a>3?n(e,i,o):n(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}function o(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function r(t,e,i,s){return new(i||(i=Promise))(function(n,a){function o(t){try{h(s.next(t))}catch(t){a(t)}}function r(t){try{h(s.throw(t))}catch(t){a(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,r)}h((s=s.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class h extends t.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.activeClipLoop=!1,this.listenerBound=!1,this.init(t)}init(t){t&&Object.assign(this,t),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var t;this.complete||(this.activeClip?this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.gotoAndStop(this.activeClip.end),this.finish()):++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(t=this.animate)||void 0===t||t.stop(),this.finish()))}),this.on("complete",()=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this)}),this.on("frameChange",()=>{var t;const e=this.currentFrame;null===(t=this.onFrameChange)||void 0===t||t.call(this,e),!this.complete&&this.activeClip&&e>=this.activeClip.end&&(this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.stop(),e>this.activeClip.end&&this.animate.gotoAndStop(this.activeClip.end),this.finish()))}))}finish(){this.complete||(this.complete=!0,this.emit("complete"))}_handleRendererComplete(){this.finish()}isValidClip(t){return Number.isInteger(t.start)&&Number.isInteger(t.end)&&t.start>=0&&t.start<=t.end&&t.end<this.totalFrames}play(t=1/0,e=!1){const i="number"==typeof t?t:e?1/0:1;let s;if("string"==typeof t){this.currentAnimation=t,this.activeClip=void 0,this.activeClipLoop=!1;const i=this.animations[t];i&&(s=i.start,this.animate&&this.isValidClip(i)&&(this.activeClip=i,this.activeClipLoop=e),void 0!==i.speed&&(this.speed=i.speed))}else this.currentAnimation=void 0,this.activeClip=void 0,this.activeClipLoop=!1;0!==i&&(this.times=i,this.animate?(this.complete&&void 0===s&&this.gotoAndStop(0),this.count=0,this.complete=!1,void 0!==s?this.animate.gotoAndPlay(s):this.animate.play()):(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}}h.componentName="SpriteAnimation",a([e.type("string"),o("design:type",String)],h.prototype,"resource",void 0),a([e.type("boolean"),o("design:type",Boolean)],h.prototype,"autoPlay",void 0),a([e.type("number"),e.step(10),o("design:type",Number)],h.prototype,"speed",void 0),a([e.type("boolean"),o("design:type",Boolean)],h.prototype,"forwards",void 0);const p="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE_ANIMATION,({name:t,data:e})=>new Promise(i=>{var s;const a=e.json.data,o=e.image instanceof n.Texture?e.image:n.Texture.from(e.image);let r=a.frames||{};if(Array.isArray(r)){const t={};for(const e of r){const i=null!==(s=e.filename)&&void 0!==s?s:e.name;i&&(t[i]=e)}r=t}const h=a.animations||{},c={},m={};for(const e in r){m[t+p+e]=r[e]}for(const e in h){const i=[];if(h[e]&&h[e].length>=0)for(const s of h[e]){const e=t+p+s;i.push(e)}c[e]=i}const d=new n.Spritesheet(o,Object.assign(Object.assign({},a),{frames:m,animations:c}));d.parse().then(()=>{const{textures:t}=d,e=[];for(const i in t)e.push(t[i]);i(e)})})),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE_ANIMATION,({instance:t})=>{if(t)for(const e of t)e.destroy(!0)});let c=class extends i.Renderer{constructor(){super(...arguments),this.name="SpriteAnimationSystem",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(t){const{width:e,height:i}=t.transform.size;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=e,this.animates[t.id].animatedSprite.height=i)}componentChanged(e){return r(this,void 0,void 0,function*(){const i=e.gameObject.id;if("SpriteAnimation"===e.componentName){const s=e.component;if(this.autoPlay[e.gameObject.id]=s.autoPlay,e.type===t.OBSERVER_TYPE.ADD){const n=this.increaseAsyncId(i),{instance:a}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(i,n))return;a||console.error(`GameObject:${e.gameObject.name}'s Img resource load error`),this.add({frames:a,id:e.gameObject.id,component:s})}else if(e.type===t.OBSERVER_TYPE.CHANGE)if(e.prop&&"speed"===e.prop.prop[0])this.animates[e.gameObject.id].speed=1e3/60/s.speed;else{const n=this.increaseAsyncId(i),{instance:a}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(i,n))return;a||console.error(`GameObject:${e.gameObject.name}'s Img resource load error`),this.change({frames:a,id:e.gameObject.id,component:s})}else e.type===t.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(i),this.remove(e.gameObject.id))}})}add({frames:t,id:e,component:i}){const n=new s.SpriteAnimation({frames:t});this.animates[e]=n,this.containerManager.getContainer(e).addChildAt(n.animatedSprite,0),n.animatedSprite.onComplete=()=>{i._handleRendererComplete()},n.animatedSprite.onFrameChange=()=>{i.emit("frameChange")},n.animatedSprite.onLoop=()=>{i.emit("loop")},i.animate=this.animates[e],this.animates[e].speed=1e3/60/i.speed,this.autoPlay[e]&&n.animatedSprite.play()}change({frames:t,id:e,component:i}){this.remove(e,!0),this.add({frames:t,id:e,component:i})}remove(t,e){const i=this.animates[t];i&&(this.autoPlay[t]=i.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(i.animatedSprite),i.animatedSprite.destroy(),delete this.animates[t],e||delete this.autoPlay[t])}};c.systemName="SpriteAnimationSystem",c=a([t.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],c);var m=c;exports.SpriteAnimation=h,exports.SpriteAnimationSystem=m;
|
|
@@ -56,10 +56,20 @@ export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
|
|
|
56
56
|
speed: number;
|
|
57
57
|
/** 是否在最后一帧停止(forwards 模式) */
|
|
58
58
|
forwards: boolean;
|
|
59
|
+
/** 命名动画片段,供编辑器和脚本按动作名播放 */
|
|
60
|
+
animations: Record<string, SpriteAnimationClip>;
|
|
61
|
+
/** 当前正在播放或等待播放的动画名 */
|
|
62
|
+
currentAnimation?: string;
|
|
63
|
+
/** 动画完成事件回调 */
|
|
64
|
+
onComplete?: () => void;
|
|
65
|
+
/** 帧变化事件回调 */
|
|
66
|
+
onFrameChange?: (frame?: number) => void;
|
|
59
67
|
/** 动画引擎实例 */
|
|
60
68
|
_animate: SpriteAnimation_2;
|
|
61
69
|
/** 等待播放标志(资源加载前调用 play) */
|
|
62
70
|
private waitPlay;
|
|
71
|
+
private waitAnimation?;
|
|
72
|
+
private waitLoop;
|
|
63
73
|
/** 等待停止标志 */
|
|
64
74
|
private waitStop;
|
|
65
75
|
/** 播放次数 */
|
|
@@ -68,6 +78,12 @@ export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
|
|
|
68
78
|
private count;
|
|
69
79
|
/** 是否播放完成 */
|
|
70
80
|
private complete;
|
|
81
|
+
/** 当前命名动画的闭区间边界 */
|
|
82
|
+
private activeClip?;
|
|
83
|
+
/** 当前命名动画是否循环 */
|
|
84
|
+
private activeClipLoop;
|
|
85
|
+
private listenerBound;
|
|
86
|
+
constructor(params?: SpriteAnimationParams);
|
|
71
87
|
/**
|
|
72
88
|
* 初始化组件
|
|
73
89
|
* @param obj - 初始化参数
|
|
@@ -77,7 +93,10 @@ export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
|
|
|
77
93
|
* @param obj.forwards - 是否停在最后一帧
|
|
78
94
|
*/
|
|
79
95
|
init(obj?: SpriteAnimationParams): void;
|
|
80
|
-
|
|
96
|
+
private finish;
|
|
97
|
+
/* Excluded from this release type: _handleRendererComplete */
|
|
98
|
+
private isValidClip;
|
|
99
|
+
play(nameOrTimes?: string | number, loop?: boolean): void;
|
|
81
100
|
stop(): void;
|
|
82
101
|
set animate(val: SpriteAnimation_2);
|
|
83
102
|
get animate(): SpriteAnimation_2;
|
|
@@ -87,12 +106,21 @@ export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
|
|
|
87
106
|
get totalFrames(): number;
|
|
88
107
|
}
|
|
89
108
|
|
|
109
|
+
declare interface SpriteAnimationClip {
|
|
110
|
+
start: number;
|
|
111
|
+
end: number;
|
|
112
|
+
speed?: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
90
115
|
export declare interface SpriteAnimationParams {
|
|
91
116
|
resource: string;
|
|
92
117
|
autoPlay?: boolean;
|
|
93
118
|
speed?: number;
|
|
94
119
|
/** Stop at last frame */
|
|
95
120
|
forwards?: boolean;
|
|
121
|
+
animations?: Record<string, SpriteAnimationClip>;
|
|
122
|
+
onComplete?: () => void;
|
|
123
|
+
onFrameChange?: (frame?: number) => void;
|
|
96
124
|
}
|
|
97
125
|
|
|
98
126
|
export declare class SpriteAnimationSystem extends Renderer {
|
|
@@ -26,6 +26,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
26
26
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
function __metadata(metadataKey, metadataValue) {
|
|
30
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
30
34
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
35
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -80,8 +84,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
80
84
|
* ```
|
|
81
85
|
*/
|
|
82
86
|
class SpriteAnimation$2 extends Component {
|
|
83
|
-
constructor() {
|
|
84
|
-
super(
|
|
87
|
+
constructor(params) {
|
|
88
|
+
super(params);
|
|
85
89
|
/** 帧动画资源名称 */
|
|
86
90
|
this.resource = '';
|
|
87
91
|
/** 是否自动播放 */
|
|
@@ -90,8 +94,11 @@ class SpriteAnimation$2 extends Component {
|
|
|
90
94
|
this.speed = 100;
|
|
91
95
|
/** 是否在最后一帧停止(forwards 模式) */
|
|
92
96
|
this.forwards = false;
|
|
97
|
+
/** 命名动画片段,供编辑器和脚本按动作名播放 */
|
|
98
|
+
this.animations = {};
|
|
93
99
|
/** 等待播放标志(资源加载前调用 play) */
|
|
94
100
|
this.waitPlay = false;
|
|
101
|
+
this.waitLoop = false;
|
|
95
102
|
/** 等待停止标志 */
|
|
96
103
|
this.waitStop = false;
|
|
97
104
|
/** 播放次数 */
|
|
@@ -100,6 +107,10 @@ class SpriteAnimation$2 extends Component {
|
|
|
100
107
|
this.count = 0;
|
|
101
108
|
/** 是否播放完成 */
|
|
102
109
|
this.complete = false;
|
|
110
|
+
/** 当前命名动画是否循环 */
|
|
111
|
+
this.activeClipLoop = false;
|
|
112
|
+
this.listenerBound = false;
|
|
113
|
+
this.init(params);
|
|
103
114
|
}
|
|
104
115
|
/**
|
|
105
116
|
* 初始化组件
|
|
@@ -111,34 +122,117 @@ class SpriteAnimation$2 extends Component {
|
|
|
111
122
|
*/
|
|
112
123
|
init(obj) {
|
|
113
124
|
obj && Object.assign(this, obj);
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
if (!this.listenerBound) {
|
|
126
|
+
this.listenerBound = true;
|
|
127
|
+
this.on('loop', () => {
|
|
128
|
+
var _a;
|
|
129
|
+
if (this.complete)
|
|
130
|
+
return;
|
|
131
|
+
if (this.activeClip) {
|
|
132
|
+
if (this.activeClipLoop) {
|
|
133
|
+
this.animate.gotoAndPlay(this.activeClip.start);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
this.animate.gotoAndStop(this.activeClip.end);
|
|
137
|
+
this.finish();
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
118
140
|
}
|
|
119
|
-
|
|
120
|
-
this.
|
|
141
|
+
if (++this.count >= this.times) {
|
|
142
|
+
if (this.forwards) {
|
|
143
|
+
this.gotoAndStop(this.totalFrames - 1);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
(_a = this.animate) === null || _a === void 0 ? void 0 : _a.stop();
|
|
147
|
+
}
|
|
148
|
+
this.finish();
|
|
121
149
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
150
|
+
});
|
|
151
|
+
this.on('complete', () => {
|
|
152
|
+
var _a;
|
|
153
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
154
|
+
});
|
|
155
|
+
this.on('frameChange', () => {
|
|
156
|
+
var _a;
|
|
157
|
+
const frame = this.currentFrame;
|
|
158
|
+
(_a = this.onFrameChange) === null || _a === void 0 ? void 0 : _a.call(this, frame);
|
|
159
|
+
if (!this.complete && this.activeClip && frame >= this.activeClip.end) {
|
|
160
|
+
if (this.activeClipLoop) {
|
|
161
|
+
this.animate.gotoAndPlay(this.activeClip.start);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
this.animate.stop();
|
|
165
|
+
if (frame > this.activeClip.end) {
|
|
166
|
+
this.animate.gotoAndStop(this.activeClip.end);
|
|
167
|
+
}
|
|
168
|
+
this.finish();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
finish() {
|
|
175
|
+
if (this.complete)
|
|
176
|
+
return;
|
|
177
|
+
this.complete = true;
|
|
178
|
+
this.emit('complete');
|
|
126
179
|
}
|
|
127
|
-
|
|
180
|
+
/** @internal Renderer event entry point; keeps late renderer callbacks idempotent. */
|
|
181
|
+
_handleRendererComplete() {
|
|
182
|
+
this.finish();
|
|
183
|
+
}
|
|
184
|
+
isValidClip(clip) {
|
|
185
|
+
return (Number.isInteger(clip.start) &&
|
|
186
|
+
Number.isInteger(clip.end) &&
|
|
187
|
+
clip.start >= 0 &&
|
|
188
|
+
clip.start <= clip.end &&
|
|
189
|
+
clip.end < this.totalFrames);
|
|
190
|
+
}
|
|
191
|
+
play(nameOrTimes = Infinity, loop = false) {
|
|
192
|
+
const times = typeof nameOrTimes === 'number' ? nameOrTimes : loop ? Infinity : 1;
|
|
193
|
+
let startFrame;
|
|
194
|
+
if (typeof nameOrTimes === 'string') {
|
|
195
|
+
this.currentAnimation = nameOrTimes;
|
|
196
|
+
this.activeClip = undefined;
|
|
197
|
+
this.activeClipLoop = false;
|
|
198
|
+
const clip = this.animations[nameOrTimes];
|
|
199
|
+
if (clip) {
|
|
200
|
+
startFrame = clip.start;
|
|
201
|
+
// Invalid ranges keep the legacy start-only/full-timeline behavior instead of throwing.
|
|
202
|
+
if (this.animate && this.isValidClip(clip)) {
|
|
203
|
+
this.activeClip = clip;
|
|
204
|
+
this.activeClipLoop = loop;
|
|
205
|
+
}
|
|
206
|
+
if (clip.speed !== undefined)
|
|
207
|
+
this.speed = clip.speed;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
this.currentAnimation = undefined;
|
|
212
|
+
this.activeClip = undefined;
|
|
213
|
+
this.activeClipLoop = false;
|
|
214
|
+
}
|
|
128
215
|
if (times === 0) {
|
|
129
216
|
return;
|
|
130
217
|
}
|
|
131
218
|
this.times = times;
|
|
132
219
|
if (!this.animate) {
|
|
133
220
|
this.waitPlay = true;
|
|
221
|
+
this.waitAnimation = typeof nameOrTimes === 'string' ? nameOrTimes : undefined;
|
|
222
|
+
this.waitLoop = loop;
|
|
134
223
|
}
|
|
135
224
|
else {
|
|
136
|
-
if (this.complete) {
|
|
225
|
+
if (this.complete && startFrame === undefined) {
|
|
137
226
|
this.gotoAndStop(0);
|
|
138
227
|
}
|
|
139
|
-
this.animate.play();
|
|
140
228
|
this.count = 0;
|
|
141
229
|
this.complete = false;
|
|
230
|
+
if (startFrame !== undefined) {
|
|
231
|
+
this.animate.gotoAndPlay(startFrame);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.animate.play();
|
|
235
|
+
}
|
|
142
236
|
}
|
|
143
237
|
}
|
|
144
238
|
stop() {
|
|
@@ -153,7 +247,9 @@ class SpriteAnimation$2 extends Component {
|
|
|
153
247
|
this._animate = val;
|
|
154
248
|
if (this.waitPlay) {
|
|
155
249
|
this.waitPlay = false;
|
|
156
|
-
this.
|
|
250
|
+
const waitAnimation = this.waitAnimation;
|
|
251
|
+
this.waitAnimation = undefined;
|
|
252
|
+
this.play(waitAnimation !== null && waitAnimation !== void 0 ? waitAnimation : this.times, this.waitLoop);
|
|
157
253
|
}
|
|
158
254
|
if (this.waitStop) {
|
|
159
255
|
this.waitStop = false;
|
|
@@ -181,25 +277,40 @@ class SpriteAnimation$2 extends Component {
|
|
|
181
277
|
/** 组件名称 */
|
|
182
278
|
SpriteAnimation$2.componentName = 'SpriteAnimation';
|
|
183
279
|
__decorate([
|
|
184
|
-
type('string')
|
|
280
|
+
type('string'),
|
|
281
|
+
__metadata("design:type", String)
|
|
185
282
|
], SpriteAnimation$2.prototype, "resource", void 0);
|
|
186
283
|
__decorate([
|
|
187
|
-
type('boolean')
|
|
284
|
+
type('boolean'),
|
|
285
|
+
__metadata("design:type", Boolean)
|
|
188
286
|
], SpriteAnimation$2.prototype, "autoPlay", void 0);
|
|
189
287
|
__decorate([
|
|
190
288
|
type('number'),
|
|
191
|
-
step(10)
|
|
289
|
+
step(10),
|
|
290
|
+
__metadata("design:type", Number)
|
|
192
291
|
], SpriteAnimation$2.prototype, "speed", void 0);
|
|
193
292
|
__decorate([
|
|
194
|
-
type('boolean')
|
|
293
|
+
type('boolean'),
|
|
294
|
+
__metadata("design:type", Boolean)
|
|
195
295
|
], SpriteAnimation$2.prototype, "forwards", void 0);
|
|
196
296
|
|
|
197
297
|
const resourceKeySplit = '_s|r|c_';
|
|
198
298
|
resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, ({ name, data }) => {
|
|
199
299
|
return new Promise(r => {
|
|
300
|
+
var _a;
|
|
200
301
|
const textureObj = data.json.data;
|
|
201
302
|
const texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
|
|
202
|
-
|
|
303
|
+
// Normalize Phaser JSONArray (`frames: [...]`) to PixiJS-compatible hash (`frames: {name: {...}}`).
|
|
304
|
+
let frames = textureObj.frames || {};
|
|
305
|
+
if (Array.isArray(frames)) {
|
|
306
|
+
const hashFrames = {};
|
|
307
|
+
for (const f of frames) {
|
|
308
|
+
const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
|
|
309
|
+
if (key)
|
|
310
|
+
hashFrames[key] = f;
|
|
311
|
+
}
|
|
312
|
+
frames = hashFrames;
|
|
313
|
+
}
|
|
203
314
|
const animations = textureObj.animations || {};
|
|
204
315
|
const newAnimations = {};
|
|
205
316
|
const newFrames = {};
|
|
@@ -238,7 +349,7 @@ resource.registerDestroy(RESOURCE_TYPE.SPRITE_ANIMATION, ({ instance }) => {
|
|
|
238
349
|
let SpriteAnimation = class SpriteAnimation extends Renderer {
|
|
239
350
|
constructor() {
|
|
240
351
|
super(...arguments);
|
|
241
|
-
this.name = '
|
|
352
|
+
this.name = 'SpriteAnimationSystem';
|
|
242
353
|
this.animates = {};
|
|
243
354
|
this.autoPlay = {};
|
|
244
355
|
}
|
|
@@ -304,7 +415,7 @@ let SpriteAnimation = class SpriteAnimation extends Renderer {
|
|
|
304
415
|
this.animates[id] = animate;
|
|
305
416
|
this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
|
|
306
417
|
animate.animatedSprite.onComplete = () => {
|
|
307
|
-
component.
|
|
418
|
+
component._handleRendererComplete();
|
|
308
419
|
};
|
|
309
420
|
animate.animatedSprite.onFrameChange = () => {
|
|
310
421
|
component.emit('frameChange');
|
|
@@ -335,7 +446,7 @@ let SpriteAnimation = class SpriteAnimation extends Renderer {
|
|
|
335
446
|
}
|
|
336
447
|
}
|
|
337
448
|
};
|
|
338
|
-
SpriteAnimation.systemName = '
|
|
449
|
+
SpriteAnimation.systemName = 'SpriteAnimationSystem';
|
|
339
450
|
SpriteAnimation = __decorate([
|
|
340
451
|
decorators.componentObserver({
|
|
341
452
|
SpriteAnimation: ['speed', 'resource'],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-sprite-animation",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-beta.10",
|
|
4
4
|
"description": "@eva/plugin-renderer-sprite-animation",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-sprite-animation.esm.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/inspector-decorator": "^0.0.
|
|
22
|
-
"@eva/plugin-renderer": "2.0.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.
|
|
24
|
-
"@eva/eva.js": "2.0.
|
|
21
|
+
"@eva/inspector-decorator": "^2.0.0-beta.0",
|
|
22
|
+
"@eva/plugin-renderer": "2.1.0-beta.10",
|
|
23
|
+
"@eva/renderer-adapter": "2.1.0-beta.10",
|
|
24
|
+
"@eva/eva.js": "2.1.0-beta.10",
|
|
25
25
|
"pixi.js": "^8.17.0"
|
|
26
26
|
}
|
|
27
27
|
}
|