@eva/plugin-renderer-sprite-animation 2.0.2 → 2.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.plugin.renderer.spriteAnimation.js +165 -37
- package/dist/EVA.plugin.renderer.spriteAnimation.min.js +1 -1
- package/dist/plugin-renderer-sprite-animation.cjs.js +79 -23
- package/dist/plugin-renderer-sprite-animation.cjs.prod.js +1 -1
- package/dist/plugin-renderer-sprite-animation.d.ts +22 -1
- package/dist/plugin-renderer-sprite-animation.esm.js +79 -23
- 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,68 +41,182 @@ 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
|
+
function __rest(s, e) {
|
|
45
|
+
var t = {};
|
|
46
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
47
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
48
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
49
|
+
}
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
53
|
+
var e = new Error(message);
|
|
54
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
55
|
+
};
|
|
56
|
+
class SymbolKeysNotSupportedError extends Error {
|
|
57
|
+
constructor() {
|
|
58
|
+
super('Symbol keys are not supported yet!');
|
|
59
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
|
|
63
|
+
function transformBasicType(type) {
|
|
64
|
+
if (type === String) {
|
|
65
|
+
return 'string';
|
|
66
|
+
}
|
|
67
|
+
if (type === Number) {
|
|
68
|
+
return 'number';
|
|
69
|
+
}
|
|
70
|
+
if (type === Boolean) {
|
|
71
|
+
return 'boolean';
|
|
72
|
+
}
|
|
73
|
+
return 'unknown';
|
|
74
|
+
}
|
|
75
|
+
function defineLegacyIDEProp(target, propertyKey, patch) {
|
|
76
|
+
const constructor = target.constructor;
|
|
77
|
+
const current = constructor.IDEProps || {};
|
|
78
|
+
current[propertyKey] = _extends(_extends({
|
|
79
|
+
key: propertyKey
|
|
80
|
+
}, current[propertyKey]), patch);
|
|
81
|
+
constructor.IDEProps = current;
|
|
82
|
+
}
|
|
83
|
+
function defineTypes(target, key, options, returnTypeFunction) {
|
|
84
|
+
let type = Reflect.getMetadata('design:type', target, key);
|
|
85
|
+
let isArray = type === Array;
|
|
86
|
+
const str = transformBasicType(type);
|
|
87
|
+
if (str !== 'unknown') {
|
|
88
|
+
type = str;
|
|
44
89
|
}
|
|
45
|
-
if (
|
|
46
|
-
|
|
90
|
+
if (returnTypeFunction) {
|
|
91
|
+
const returnType = returnTypeFunction();
|
|
92
|
+
if (Array.isArray(returnType)) {
|
|
93
|
+
isArray = true;
|
|
94
|
+
type = returnType[0];
|
|
95
|
+
} else {
|
|
96
|
+
type = returnType;
|
|
97
|
+
}
|
|
47
98
|
}
|
|
48
|
-
|
|
49
|
-
|
|
99
|
+
const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
|
|
100
|
+
const current = properties[key] || {};
|
|
101
|
+
const property = _extends(_extends(_extends({}, current), {
|
|
102
|
+
type,
|
|
103
|
+
isArray: isArray
|
|
104
|
+
}), options);
|
|
105
|
+
properties[key] = property;
|
|
106
|
+
Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
|
|
107
|
+
const legacyProperty = __rest(property, ["isArray"]);
|
|
108
|
+
defineLegacyIDEProp(target, key, legacyProperty);
|
|
50
109
|
}
|
|
51
110
|
function type(type) {
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
prop.type = type;
|
|
56
|
-
};
|
|
111
|
+
return Field({
|
|
112
|
+
type
|
|
113
|
+
});
|
|
57
114
|
}
|
|
58
115
|
function step(step) {
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
116
|
+
return Field({
|
|
117
|
+
step
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
|
|
121
|
+
if (typeof returnTypeFuncOrOptions === 'function') {
|
|
122
|
+
return {
|
|
123
|
+
returnTypeFunc: returnTypeFuncOrOptions,
|
|
124
|
+
options: maybeOptions || {}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
options: returnTypeFuncOrOptions || {}
|
|
62
129
|
};
|
|
63
130
|
}
|
|
131
|
+
function Field(returnTypeFunction, maybeOptions) {
|
|
132
|
+
return (target, propertyKey) => {
|
|
133
|
+
if (typeof propertyKey === 'symbol') {
|
|
134
|
+
throw new SymbolKeysNotSupportedError();
|
|
135
|
+
}
|
|
136
|
+
const {
|
|
137
|
+
options,
|
|
138
|
+
returnTypeFunc
|
|
139
|
+
} = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
|
|
140
|
+
defineTypes(target, propertyKey, options, returnTypeFunc);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
var ExecuteMode;
|
|
144
|
+
(function (ExecuteMode) {
|
|
145
|
+
ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
|
|
146
|
+
ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
|
|
147
|
+
ExecuteMode[ExecuteMode["All"] = 6] = "All";
|
|
148
|
+
})(ExecuteMode || (ExecuteMode = {}));
|
|
64
149
|
class SpriteAnimation$2 extends eva_js.Component {
|
|
65
|
-
constructor() {
|
|
66
|
-
super(
|
|
150
|
+
constructor(params) {
|
|
151
|
+
super(params);
|
|
67
152
|
this.resource = '';
|
|
68
153
|
this.autoPlay = true;
|
|
69
154
|
this.speed = 100;
|
|
70
155
|
this.forwards = false;
|
|
156
|
+
this.animations = {};
|
|
71
157
|
this.waitPlay = false;
|
|
158
|
+
this.waitLoop = false;
|
|
72
159
|
this.waitStop = false;
|
|
73
160
|
this.times = Infinity;
|
|
74
161
|
this.count = 0;
|
|
75
162
|
this.complete = false;
|
|
163
|
+
this.listenerBound = false;
|
|
164
|
+
this.init(params);
|
|
76
165
|
}
|
|
77
166
|
init(obj) {
|
|
78
167
|
obj && _extends(this, obj);
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.
|
|
168
|
+
if (!this.listenerBound) {
|
|
169
|
+
this.listenerBound = true;
|
|
170
|
+
this.on('loop', () => {
|
|
171
|
+
var _a;
|
|
172
|
+
if (++this.count >= this.times) {
|
|
173
|
+
if (this.forwards) {
|
|
174
|
+
this.gotoAndStop(this.totalFrames - 1);
|
|
175
|
+
} else {
|
|
176
|
+
(_a = this.animate) === null || _a === void 0 ? void 0 : _a.stop();
|
|
177
|
+
}
|
|
178
|
+
this.complete = true;
|
|
179
|
+
this.emit('complete');
|
|
85
180
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
181
|
+
});
|
|
182
|
+
this.on('complete', () => {
|
|
183
|
+
var _a;
|
|
184
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
185
|
+
});
|
|
186
|
+
this.on('frameChange', () => {
|
|
187
|
+
var _a;
|
|
188
|
+
(_a = this.onFrameChange) === null || _a === void 0 ? void 0 : _a.call(this, this.currentFrame);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
90
191
|
}
|
|
91
|
-
play(
|
|
192
|
+
play(nameOrTimes = Infinity, loop = false) {
|
|
193
|
+
let times = typeof nameOrTimes === 'number' ? nameOrTimes : loop ? Infinity : 1;
|
|
194
|
+
let startFrame;
|
|
195
|
+
if (typeof nameOrTimes === 'string') {
|
|
196
|
+
this.currentAnimation = nameOrTimes;
|
|
197
|
+
const clip = this.animations[nameOrTimes];
|
|
198
|
+
if (clip) {
|
|
199
|
+
startFrame = clip.start;
|
|
200
|
+
if (clip.speed !== undefined) this.speed = clip.speed;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
92
203
|
if (times === 0) {
|
|
93
204
|
return;
|
|
94
205
|
}
|
|
95
206
|
this.times = times;
|
|
96
207
|
if (!this.animate) {
|
|
97
208
|
this.waitPlay = true;
|
|
209
|
+
this.waitAnimation = typeof nameOrTimes === 'string' ? nameOrTimes : undefined;
|
|
210
|
+
this.waitLoop = loop;
|
|
98
211
|
} else {
|
|
99
212
|
if (this.complete) {
|
|
100
213
|
this.gotoAndStop(0);
|
|
101
214
|
}
|
|
102
|
-
|
|
215
|
+
if (startFrame !== undefined) {
|
|
216
|
+
this.animate.gotoAndPlay(startFrame);
|
|
217
|
+
} else {
|
|
218
|
+
this.animate.play();
|
|
219
|
+
}
|
|
103
220
|
this.count = 0;
|
|
104
221
|
this.complete = false;
|
|
105
222
|
}
|
|
@@ -115,7 +232,9 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
115
232
|
this._animate = val;
|
|
116
233
|
if (this.waitPlay) {
|
|
117
234
|
this.waitPlay = false;
|
|
118
|
-
this.
|
|
235
|
+
const waitAnimation = this.waitAnimation;
|
|
236
|
+
this.waitAnimation = undefined;
|
|
237
|
+
this.play(waitAnimation !== null && waitAnimation !== void 0 ? waitAnimation : this.times, this.waitLoop);
|
|
119
238
|
}
|
|
120
239
|
if (this.waitStop) {
|
|
121
240
|
this.waitStop = false;
|
|
@@ -141,19 +260,28 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
141
260
|
}
|
|
142
261
|
}
|
|
143
262
|
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);
|
|
263
|
+
__decorate([type('string'), __metadata("design:type", String)], SpriteAnimation$2.prototype, "resource", void 0);
|
|
264
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "autoPlay", void 0);
|
|
265
|
+
__decorate([type('number'), step(10), __metadata("design:type", Number)], SpriteAnimation$2.prototype, "speed", void 0);
|
|
266
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "forwards", void 0);
|
|
148
267
|
const resourceKeySplit = '_s|r|c_';
|
|
149
268
|
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({
|
|
150
269
|
name,
|
|
151
270
|
data
|
|
152
271
|
}) => {
|
|
153
272
|
return new Promise(r => {
|
|
273
|
+
var _a;
|
|
154
274
|
const textureObj = data.json.data;
|
|
155
275
|
const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
|
|
156
|
-
|
|
276
|
+
let frames = textureObj.frames || {};
|
|
277
|
+
if (Array.isArray(frames)) {
|
|
278
|
+
const hashFrames = {};
|
|
279
|
+
for (const f of frames) {
|
|
280
|
+
const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
|
|
281
|
+
if (key) hashFrames[key] = f;
|
|
282
|
+
}
|
|
283
|
+
frames = hashFrames;
|
|
284
|
+
}
|
|
157
285
|
const animations = textureObj.animations || {};
|
|
158
286
|
const newAnimations = {};
|
|
159
287
|
const newFrames = {};
|
|
@@ -198,7 +326,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
198
326
|
let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
199
327
|
constructor() {
|
|
200
328
|
super(...arguments);
|
|
201
|
-
this.name = '
|
|
329
|
+
this.name = 'SpriteAnimationSystem';
|
|
202
330
|
this.animates = {};
|
|
203
331
|
this.autoPlay = {};
|
|
204
332
|
}
|
|
@@ -310,7 +438,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
310
438
|
}
|
|
311
439
|
}
|
|
312
440
|
};
|
|
313
|
-
SpriteAnimation.systemName = '
|
|
441
|
+
SpriteAnimation.systemName = 'SpriteAnimationSystem';
|
|
314
442
|
SpriteAnimation = __decorate([eva_js.decorators.componentObserver({
|
|
315
443
|
SpriteAnimation: ['speed', 'resource']
|
|
316
444
|
})], 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 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;class c extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const p="IDE_PROPERTY_METADATA";function m(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 d(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);m(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([d("string"),s("design:type",String)],u.prototype,"resource",void 0),r([d("boolean"),s("design:type",Boolean)],u.prototype,"autoPlay",void 0),r([d("number"),function(t){return l({step:t})}(10),s("design:type",Number)],u.prototype,"speed",void 0),r([d("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={},m={};for(const e in a){m[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 d=new o.Spritesheet(s,_extends(_extends({},r),{frames:m,animations:p}));d.parse().then(()=>{const{textures:t}=d,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;
|
|
@@ -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,8 @@ class SpriteAnimation$2 extends eva_js.Component {
|
|
|
104
111
|
this.count = 0;
|
|
105
112
|
/** 是否播放完成 */
|
|
106
113
|
this.complete = false;
|
|
114
|
+
this.listenerBound = false;
|
|
115
|
+
this.init(params);
|
|
107
116
|
}
|
|
108
117
|
/**
|
|
109
118
|
* 初始化组件
|
|
@@ -115,32 +124,62 @@ class SpriteAnimation$2 extends eva_js.Component {
|
|
|
115
124
|
*/
|
|
116
125
|
init(obj) {
|
|
117
126
|
obj && Object.assign(this, obj);
|
|
118
|
-
this.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
if (!this.listenerBound) {
|
|
128
|
+
this.listenerBound = true;
|
|
129
|
+
this.on('loop', () => {
|
|
130
|
+
var _a;
|
|
131
|
+
if (++this.count >= this.times) {
|
|
132
|
+
if (this.forwards) {
|
|
133
|
+
this.gotoAndStop(this.totalFrames - 1);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
(_a = this.animate) === null || _a === void 0 ? void 0 : _a.stop();
|
|
137
|
+
}
|
|
138
|
+
this.complete = true;
|
|
139
|
+
this.emit('complete');
|
|
125
140
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
141
|
+
});
|
|
142
|
+
this.on('complete', () => {
|
|
143
|
+
var _a;
|
|
144
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
145
|
+
});
|
|
146
|
+
this.on('frameChange', () => {
|
|
147
|
+
var _a;
|
|
148
|
+
(_a = this.onFrameChange) === null || _a === void 0 ? void 0 : _a.call(this, this.currentFrame);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
130
151
|
}
|
|
131
|
-
play(
|
|
152
|
+
play(nameOrTimes = Infinity, loop = false) {
|
|
153
|
+
let times = typeof nameOrTimes === 'number' ? nameOrTimes : loop ? Infinity : 1;
|
|
154
|
+
let startFrame;
|
|
155
|
+
if (typeof nameOrTimes === 'string') {
|
|
156
|
+
this.currentAnimation = nameOrTimes;
|
|
157
|
+
const clip = this.animations[nameOrTimes];
|
|
158
|
+
if (clip) {
|
|
159
|
+
startFrame = clip.start;
|
|
160
|
+
if (clip.speed !== undefined)
|
|
161
|
+
this.speed = clip.speed;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
132
164
|
if (times === 0) {
|
|
133
165
|
return;
|
|
134
166
|
}
|
|
135
167
|
this.times = times;
|
|
136
168
|
if (!this.animate) {
|
|
137
169
|
this.waitPlay = true;
|
|
170
|
+
this.waitAnimation = typeof nameOrTimes === 'string' ? nameOrTimes : undefined;
|
|
171
|
+
this.waitLoop = loop;
|
|
138
172
|
}
|
|
139
173
|
else {
|
|
140
174
|
if (this.complete) {
|
|
141
175
|
this.gotoAndStop(0);
|
|
142
176
|
}
|
|
143
|
-
|
|
177
|
+
if (startFrame !== undefined) {
|
|
178
|
+
this.animate.gotoAndPlay(startFrame);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
this.animate.play();
|
|
182
|
+
}
|
|
144
183
|
this.count = 0;
|
|
145
184
|
this.complete = false;
|
|
146
185
|
}
|
|
@@ -157,7 +196,9 @@ class SpriteAnimation$2 extends eva_js.Component {
|
|
|
157
196
|
this._animate = val;
|
|
158
197
|
if (this.waitPlay) {
|
|
159
198
|
this.waitPlay = false;
|
|
160
|
-
this.
|
|
199
|
+
const waitAnimation = this.waitAnimation;
|
|
200
|
+
this.waitAnimation = undefined;
|
|
201
|
+
this.play(waitAnimation !== null && waitAnimation !== void 0 ? waitAnimation : this.times, this.waitLoop);
|
|
161
202
|
}
|
|
162
203
|
if (this.waitStop) {
|
|
163
204
|
this.waitStop = false;
|
|
@@ -185,25 +226,40 @@ class SpriteAnimation$2 extends eva_js.Component {
|
|
|
185
226
|
/** 组件名称 */
|
|
186
227
|
SpriteAnimation$2.componentName = 'SpriteAnimation';
|
|
187
228
|
__decorate([
|
|
188
|
-
inspectorDecorator.type('string')
|
|
229
|
+
inspectorDecorator.type('string'),
|
|
230
|
+
__metadata("design:type", String)
|
|
189
231
|
], SpriteAnimation$2.prototype, "resource", void 0);
|
|
190
232
|
__decorate([
|
|
191
|
-
inspectorDecorator.type('boolean')
|
|
233
|
+
inspectorDecorator.type('boolean'),
|
|
234
|
+
__metadata("design:type", Boolean)
|
|
192
235
|
], SpriteAnimation$2.prototype, "autoPlay", void 0);
|
|
193
236
|
__decorate([
|
|
194
237
|
inspectorDecorator.type('number'),
|
|
195
|
-
inspectorDecorator.step(10)
|
|
238
|
+
inspectorDecorator.step(10),
|
|
239
|
+
__metadata("design:type", Number)
|
|
196
240
|
], SpriteAnimation$2.prototype, "speed", void 0);
|
|
197
241
|
__decorate([
|
|
198
|
-
inspectorDecorator.type('boolean')
|
|
242
|
+
inspectorDecorator.type('boolean'),
|
|
243
|
+
__metadata("design:type", Boolean)
|
|
199
244
|
], SpriteAnimation$2.prototype, "forwards", void 0);
|
|
200
245
|
|
|
201
246
|
const resourceKeySplit = '_s|r|c_';
|
|
202
247
|
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({ name, data }) => {
|
|
203
248
|
return new Promise(r => {
|
|
249
|
+
var _a;
|
|
204
250
|
const textureObj = data.json.data;
|
|
205
251
|
const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
|
|
206
|
-
|
|
252
|
+
// Normalize Phaser JSONArray (`frames: [...]`) to PixiJS-compatible hash (`frames: {name: {...}}`).
|
|
253
|
+
let frames = textureObj.frames || {};
|
|
254
|
+
if (Array.isArray(frames)) {
|
|
255
|
+
const hashFrames = {};
|
|
256
|
+
for (const f of frames) {
|
|
257
|
+
const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
|
|
258
|
+
if (key)
|
|
259
|
+
hashFrames[key] = f;
|
|
260
|
+
}
|
|
261
|
+
frames = hashFrames;
|
|
262
|
+
}
|
|
207
263
|
const animations = textureObj.animations || {};
|
|
208
264
|
const newAnimations = {};
|
|
209
265
|
const newFrames = {};
|
|
@@ -242,7 +298,7 @@ eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({ instan
|
|
|
242
298
|
let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
243
299
|
constructor() {
|
|
244
300
|
super(...arguments);
|
|
245
|
-
this.name = '
|
|
301
|
+
this.name = 'SpriteAnimationSystem';
|
|
246
302
|
this.animates = {};
|
|
247
303
|
this.autoPlay = {};
|
|
248
304
|
}
|
|
@@ -339,7 +395,7 @@ let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
|
339
395
|
}
|
|
340
396
|
}
|
|
341
397
|
};
|
|
342
|
-
SpriteAnimation.systemName = '
|
|
398
|
+
SpriteAnimation.systemName = 'SpriteAnimationSystem';
|
|
343
399
|
SpriteAnimation = __decorate([
|
|
344
400
|
eva_js.decorators.componentObserver({
|
|
345
401
|
SpriteAnimation: ['speed', 'resource'],
|
|
@@ -1 +1 @@
|
|
|
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"),
|
|
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"),n=require("@eva/renderer-adapter"),s=require("pixi.js");function a(e,t,i,n){var s,a=arguments.length,o=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,n);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,i,o):s(t,i))||o);return a>3&&o&&Object.defineProperty(t,i,o),o}function o(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function r(e,t,i,n){return new(i||(i=Promise))(function(s,a){function o(e){try{m(n.next(e))}catch(e){a(e)}}function r(e){try{m(n.throw(e))}catch(e){a(e)}}function m(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(o,r)}m((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class m extends e.Component{constructor(e){super(e),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(e)}init(e){e&&Object.assign(this,e),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var e;++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(e=this.animate)||void 0===e||e.stop(),this.complete=!0,this.emit("complete"))}),this.on("complete",()=>{var e;null===(e=this.onComplete)||void 0===e||e.call(this)}),this.on("frameChange",()=>{var e;null===(e=this.onFrameChange)||void 0===e||e.call(this,this.currentFrame)}))}play(e=1/0,t=!1){let i,n="number"==typeof e?e:t?1/0:1;if("string"==typeof e){this.currentAnimation=e;const t=this.animations[e];t&&(i=t.start,void 0!==t.speed&&(this.speed=t.speed))}0!==n&&(this.times=n,this.animate?(this.complete&&this.gotoAndStop(0),void 0!==i?this.animate.gotoAndPlay(i):this.animate.play(),this.count=0,this.complete=!1):(this.waitPlay=!0,this.waitAnimation="string"==typeof e?e:void 0,this.waitLoop=t))}stop(){this.animate?this.animate.stop():this.waitStop=!0}set animate(e){if(this._animate=e,this.waitPlay){this.waitPlay=!1;const e=this.waitAnimation;this.waitAnimation=void 0,this.play(null!=e?e:this.times,this.waitLoop)}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}}m.componentName="SpriteAnimation",a([t.type("string"),o("design:type",String)],m.prototype,"resource",void 0),a([t.type("boolean"),o("design:type",Boolean)],m.prototype,"autoPlay",void 0),a([t.type("number"),t.step(10),o("design:type",Number)],m.prototype,"speed",void 0),a([t.type("boolean"),o("design:type",Boolean)],m.prototype,"forwards",void 0);const c="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,({name:e,data:t})=>new Promise(i=>{var n;const a=t.json.data,o=t.image instanceof s.Texture?t.image:s.Texture.from(t.image);let r=a.frames||{};if(Array.isArray(r)){const e={};for(const t of r){const i=null!==(n=t.filename)&&void 0!==n?n:t.name;i&&(e[i]=t)}r=e}const m=a.animations||{},p={},d={};for(const t in r){d[e+c+t]=r[t]}for(const t in m){const i=[];if(m[t]&&m[t].length>=0)for(const n of m[t]){const t=e+c+n;i.push(t)}p[t]=i}const h=new s.Spritesheet(o,Object.assign(Object.assign({},a),{frames:d,animations:p}));h.parse().then(()=>{const{textures:e}=h,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 p=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(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 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 s=this.increaseAsyncId(i),{instance:a}=yield e.resource.getResource(n.resource);if(!this.validateAsyncId(i,s))return;a||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.add({frames:a,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 s=this.increaseAsyncId(i),{instance:a}=yield e.resource.getResource(n.resource);if(!this.validateAsyncId(i,s))return;a||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.change({frames:a,id:t.gameObject.id,component:n})}else t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(i),this.remove(t.gameObject.id))}})}add({frames:e,id:t,component:i}){const s=new n.SpriteAnimation({frames:e});this.animates[t]=s,this.containerManager.getContainer(t).addChildAt(s.animatedSprite,0),s.animatedSprite.onComplete=()=>{i.emit("complete")},s.animatedSprite.onFrameChange=()=>{i.emit("frameChange")},s.animatedSprite.onLoop=()=>{i.emit("loop")},i.animate=this.animates[t],this.animates[t].speed=1e3/60/i.speed,this.autoPlay[t]&&s.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])}};p.systemName="SpriteAnimationSystem",p=a([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],p);var d=p;exports.SpriteAnimation=m,exports.SpriteAnimationSystem=d;
|
|
@@ -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,8 @@ export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
|
|
|
68
78
|
private count;
|
|
69
79
|
/** 是否播放完成 */
|
|
70
80
|
private complete;
|
|
81
|
+
private listenerBound;
|
|
82
|
+
constructor(params?: SpriteAnimationParams);
|
|
71
83
|
/**
|
|
72
84
|
* 初始化组件
|
|
73
85
|
* @param obj - 初始化参数
|
|
@@ -77,7 +89,7 @@ export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
|
|
|
77
89
|
* @param obj.forwards - 是否停在最后一帧
|
|
78
90
|
*/
|
|
79
91
|
init(obj?: SpriteAnimationParams): void;
|
|
80
|
-
play(
|
|
92
|
+
play(nameOrTimes?: string | number, loop?: boolean): void;
|
|
81
93
|
stop(): void;
|
|
82
94
|
set animate(val: SpriteAnimation_2);
|
|
83
95
|
get animate(): SpriteAnimation_2;
|
|
@@ -87,12 +99,21 @@ export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
|
|
|
87
99
|
get totalFrames(): number;
|
|
88
100
|
}
|
|
89
101
|
|
|
102
|
+
declare interface SpriteAnimationClip {
|
|
103
|
+
start: number;
|
|
104
|
+
end: number;
|
|
105
|
+
speed?: number;
|
|
106
|
+
}
|
|
107
|
+
|
|
90
108
|
export declare interface SpriteAnimationParams {
|
|
91
109
|
resource: string;
|
|
92
110
|
autoPlay?: boolean;
|
|
93
111
|
speed?: number;
|
|
94
112
|
/** Stop at last frame */
|
|
95
113
|
forwards?: boolean;
|
|
114
|
+
animations?: Record<string, SpriteAnimationClip>;
|
|
115
|
+
onComplete?: () => void;
|
|
116
|
+
onFrameChange?: (frame?: number) => void;
|
|
96
117
|
}
|
|
97
118
|
|
|
98
119
|
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,8 @@ class SpriteAnimation$2 extends Component {
|
|
|
100
107
|
this.count = 0;
|
|
101
108
|
/** 是否播放完成 */
|
|
102
109
|
this.complete = false;
|
|
110
|
+
this.listenerBound = false;
|
|
111
|
+
this.init(params);
|
|
103
112
|
}
|
|
104
113
|
/**
|
|
105
114
|
* 初始化组件
|
|
@@ -111,32 +120,62 @@ class SpriteAnimation$2 extends Component {
|
|
|
111
120
|
*/
|
|
112
121
|
init(obj) {
|
|
113
122
|
obj && Object.assign(this, obj);
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
if (!this.listenerBound) {
|
|
124
|
+
this.listenerBound = true;
|
|
125
|
+
this.on('loop', () => {
|
|
126
|
+
var _a;
|
|
127
|
+
if (++this.count >= this.times) {
|
|
128
|
+
if (this.forwards) {
|
|
129
|
+
this.gotoAndStop(this.totalFrames - 1);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
(_a = this.animate) === null || _a === void 0 ? void 0 : _a.stop();
|
|
133
|
+
}
|
|
134
|
+
this.complete = true;
|
|
135
|
+
this.emit('complete');
|
|
121
136
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
137
|
+
});
|
|
138
|
+
this.on('complete', () => {
|
|
139
|
+
var _a;
|
|
140
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
141
|
+
});
|
|
142
|
+
this.on('frameChange', () => {
|
|
143
|
+
var _a;
|
|
144
|
+
(_a = this.onFrameChange) === null || _a === void 0 ? void 0 : _a.call(this, this.currentFrame);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
126
147
|
}
|
|
127
|
-
play(
|
|
148
|
+
play(nameOrTimes = Infinity, loop = false) {
|
|
149
|
+
let times = typeof nameOrTimes === 'number' ? nameOrTimes : loop ? Infinity : 1;
|
|
150
|
+
let startFrame;
|
|
151
|
+
if (typeof nameOrTimes === 'string') {
|
|
152
|
+
this.currentAnimation = nameOrTimes;
|
|
153
|
+
const clip = this.animations[nameOrTimes];
|
|
154
|
+
if (clip) {
|
|
155
|
+
startFrame = clip.start;
|
|
156
|
+
if (clip.speed !== undefined)
|
|
157
|
+
this.speed = clip.speed;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
128
160
|
if (times === 0) {
|
|
129
161
|
return;
|
|
130
162
|
}
|
|
131
163
|
this.times = times;
|
|
132
164
|
if (!this.animate) {
|
|
133
165
|
this.waitPlay = true;
|
|
166
|
+
this.waitAnimation = typeof nameOrTimes === 'string' ? nameOrTimes : undefined;
|
|
167
|
+
this.waitLoop = loop;
|
|
134
168
|
}
|
|
135
169
|
else {
|
|
136
170
|
if (this.complete) {
|
|
137
171
|
this.gotoAndStop(0);
|
|
138
172
|
}
|
|
139
|
-
|
|
173
|
+
if (startFrame !== undefined) {
|
|
174
|
+
this.animate.gotoAndPlay(startFrame);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
this.animate.play();
|
|
178
|
+
}
|
|
140
179
|
this.count = 0;
|
|
141
180
|
this.complete = false;
|
|
142
181
|
}
|
|
@@ -153,7 +192,9 @@ class SpriteAnimation$2 extends Component {
|
|
|
153
192
|
this._animate = val;
|
|
154
193
|
if (this.waitPlay) {
|
|
155
194
|
this.waitPlay = false;
|
|
156
|
-
this.
|
|
195
|
+
const waitAnimation = this.waitAnimation;
|
|
196
|
+
this.waitAnimation = undefined;
|
|
197
|
+
this.play(waitAnimation !== null && waitAnimation !== void 0 ? waitAnimation : this.times, this.waitLoop);
|
|
157
198
|
}
|
|
158
199
|
if (this.waitStop) {
|
|
159
200
|
this.waitStop = false;
|
|
@@ -181,25 +222,40 @@ class SpriteAnimation$2 extends Component {
|
|
|
181
222
|
/** 组件名称 */
|
|
182
223
|
SpriteAnimation$2.componentName = 'SpriteAnimation';
|
|
183
224
|
__decorate([
|
|
184
|
-
type('string')
|
|
225
|
+
type('string'),
|
|
226
|
+
__metadata("design:type", String)
|
|
185
227
|
], SpriteAnimation$2.prototype, "resource", void 0);
|
|
186
228
|
__decorate([
|
|
187
|
-
type('boolean')
|
|
229
|
+
type('boolean'),
|
|
230
|
+
__metadata("design:type", Boolean)
|
|
188
231
|
], SpriteAnimation$2.prototype, "autoPlay", void 0);
|
|
189
232
|
__decorate([
|
|
190
233
|
type('number'),
|
|
191
|
-
step(10)
|
|
234
|
+
step(10),
|
|
235
|
+
__metadata("design:type", Number)
|
|
192
236
|
], SpriteAnimation$2.prototype, "speed", void 0);
|
|
193
237
|
__decorate([
|
|
194
|
-
type('boolean')
|
|
238
|
+
type('boolean'),
|
|
239
|
+
__metadata("design:type", Boolean)
|
|
195
240
|
], SpriteAnimation$2.prototype, "forwards", void 0);
|
|
196
241
|
|
|
197
242
|
const resourceKeySplit = '_s|r|c_';
|
|
198
243
|
resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, ({ name, data }) => {
|
|
199
244
|
return new Promise(r => {
|
|
245
|
+
var _a;
|
|
200
246
|
const textureObj = data.json.data;
|
|
201
247
|
const texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
|
|
202
|
-
|
|
248
|
+
// Normalize Phaser JSONArray (`frames: [...]`) to PixiJS-compatible hash (`frames: {name: {...}}`).
|
|
249
|
+
let frames = textureObj.frames || {};
|
|
250
|
+
if (Array.isArray(frames)) {
|
|
251
|
+
const hashFrames = {};
|
|
252
|
+
for (const f of frames) {
|
|
253
|
+
const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
|
|
254
|
+
if (key)
|
|
255
|
+
hashFrames[key] = f;
|
|
256
|
+
}
|
|
257
|
+
frames = hashFrames;
|
|
258
|
+
}
|
|
203
259
|
const animations = textureObj.animations || {};
|
|
204
260
|
const newAnimations = {};
|
|
205
261
|
const newFrames = {};
|
|
@@ -238,7 +294,7 @@ resource.registerDestroy(RESOURCE_TYPE.SPRITE_ANIMATION, ({ instance }) => {
|
|
|
238
294
|
let SpriteAnimation = class SpriteAnimation extends Renderer {
|
|
239
295
|
constructor() {
|
|
240
296
|
super(...arguments);
|
|
241
|
-
this.name = '
|
|
297
|
+
this.name = 'SpriteAnimationSystem';
|
|
242
298
|
this.animates = {};
|
|
243
299
|
this.autoPlay = {};
|
|
244
300
|
}
|
|
@@ -335,7 +391,7 @@ let SpriteAnimation = class SpriteAnimation extends Renderer {
|
|
|
335
391
|
}
|
|
336
392
|
}
|
|
337
393
|
};
|
|
338
|
-
SpriteAnimation.systemName = '
|
|
394
|
+
SpriteAnimation.systemName = 'SpriteAnimationSystem';
|
|
339
395
|
SpriteAnimation = __decorate([
|
|
340
396
|
decorators.componentObserver({
|
|
341
397
|
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.1",
|
|
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.1",
|
|
23
|
+
"@eva/renderer-adapter": "2.1.0-beta.1",
|
|
24
|
+
"@eva/eva.js": "2.1.0-beta.1",
|
|
25
25
|
"pixi.js": "^8.17.0"
|
|
26
26
|
}
|
|
27
27
|
}
|