@eva/plugin-renderer-sprite-animation 1.2.6 → 1.2.7-editor.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 +135 -21
- package/dist/EVA.plugin.renderer.spriteAnimation.min.js +1 -1
- package/dist/plugin-renderer-sprite-animation.cjs.js +25 -7
- package/dist/plugin-renderer-sprite-animation.cjs.prod.js +1 -1
- package/dist/plugin-renderer-sprite-animation.esm.js +26 -8
- package/package.json +5 -5
- package/dist/miniprogram.js +0 -380
|
@@ -14,7 +14,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
14
14
|
d.__proto__ = b;
|
|
15
15
|
} || function (d, b) {
|
|
16
16
|
for (var p in b) {
|
|
17
|
-
if (
|
|
17
|
+
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
|
|
@@ -22,6 +22,8 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
function __extends(d, b) {
|
|
25
|
+
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
26
|
+
|
|
25
27
|
_extendStatics(d, b);
|
|
26
28
|
|
|
27
29
|
function __() {
|
|
@@ -31,6 +33,22 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
31
33
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
var _assign = function __assign() {
|
|
37
|
+
_assign = Object.assign || function __assign(t) {
|
|
38
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
39
|
+
s = arguments[i];
|
|
40
|
+
|
|
41
|
+
for (var p in s) {
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return t;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return _assign.apply(this, arguments);
|
|
50
|
+
};
|
|
51
|
+
|
|
34
52
|
function __decorate(decorators, target, key, desc) {
|
|
35
53
|
var c = arguments.length,
|
|
36
54
|
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
@@ -41,6 +59,10 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
41
59
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
42
60
|
}
|
|
43
61
|
|
|
62
|
+
function __metadata(metadataKey, metadataValue) {
|
|
63
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
64
|
+
}
|
|
65
|
+
|
|
44
66
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
45
67
|
function adopt(value) {
|
|
46
68
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -201,34 +223,117 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
201
223
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
202
224
|
}
|
|
203
225
|
|
|
204
|
-
function
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
var SymbolKeysNotSupportedError = function (_super) {
|
|
227
|
+
__extends(SymbolKeysNotSupportedError, _super);
|
|
228
|
+
|
|
229
|
+
function SymbolKeysNotSupportedError() {
|
|
230
|
+
var _newTarget = this.constructor;
|
|
231
|
+
|
|
232
|
+
var _this = _super.call(this, 'Symbol keys are not supported yet!') || this;
|
|
233
|
+
|
|
234
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
235
|
+
return _this;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return SymbolKeysNotSupportedError;
|
|
239
|
+
}(Error);
|
|
240
|
+
|
|
241
|
+
(function (_super) {
|
|
242
|
+
__extends(StaticGetPropertiesIsNotAFunctionError, _super);
|
|
243
|
+
|
|
244
|
+
function StaticGetPropertiesIsNotAFunctionError() {
|
|
245
|
+
var _newTarget = this.constructor;
|
|
246
|
+
|
|
247
|
+
var _this = _super.call(this, 'getProperties is not a function!') || this;
|
|
248
|
+
|
|
249
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
250
|
+
return _this;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return StaticGetPropertiesIsNotAFunctionError;
|
|
254
|
+
})(Error);
|
|
255
|
+
|
|
256
|
+
var IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
|
|
257
|
+
|
|
258
|
+
function transformBasicType(type) {
|
|
259
|
+
if (type === String) {
|
|
260
|
+
return 'string';
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (type === Number) {
|
|
264
|
+
return 'number';
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (type === Boolean) {
|
|
268
|
+
return 'boolean';
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return 'unknown';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function defineTypes(target, key, options, returnTypeFunction) {
|
|
275
|
+
var type = Reflect.getMetadata('design:type', target, key);
|
|
276
|
+
var isArray = type === Array;
|
|
277
|
+
var str = transformBasicType(type);
|
|
278
|
+
|
|
279
|
+
if (str !== 'unknown') {
|
|
280
|
+
type = str;
|
|
207
281
|
}
|
|
208
282
|
|
|
209
|
-
if (
|
|
210
|
-
|
|
283
|
+
if (returnTypeFunction) {
|
|
284
|
+
var returnType = returnTypeFunction();
|
|
285
|
+
|
|
286
|
+
if (Array.isArray(returnType)) {
|
|
287
|
+
isArray = true;
|
|
288
|
+
type = returnType[0];
|
|
289
|
+
} else {
|
|
290
|
+
type = returnType;
|
|
291
|
+
}
|
|
211
292
|
}
|
|
212
293
|
|
|
213
|
-
var
|
|
214
|
-
|
|
294
|
+
var properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
|
|
295
|
+
properties[key] = _assign({
|
|
296
|
+
type: type,
|
|
297
|
+
isArray: isArray
|
|
298
|
+
}, options);
|
|
299
|
+
Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
|
|
215
300
|
}
|
|
216
301
|
|
|
217
|
-
function
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
302
|
+
function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
|
|
303
|
+
if (typeof returnTypeFuncOrOptions === 'function') {
|
|
304
|
+
return {
|
|
305
|
+
returnTypeFunc: returnTypeFuncOrOptions,
|
|
306
|
+
options: maybeOptions || {}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
options: returnTypeFuncOrOptions || {}
|
|
222
312
|
};
|
|
223
313
|
}
|
|
224
314
|
|
|
225
|
-
function
|
|
315
|
+
function Field(returnTypeFunction, maybeOptions) {
|
|
226
316
|
return function (target, propertyKey) {
|
|
227
|
-
|
|
228
|
-
|
|
317
|
+
if (typeof propertyKey === 'symbol') {
|
|
318
|
+
throw new SymbolKeysNotSupportedError();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
var _a = getTypeDecoratorParams(returnTypeFunction, maybeOptions),
|
|
322
|
+
options = _a.options,
|
|
323
|
+
returnTypeFunc = _a.returnTypeFunc;
|
|
324
|
+
|
|
325
|
+
defineTypes(target, propertyKey, options, returnTypeFunc);
|
|
229
326
|
};
|
|
230
327
|
}
|
|
231
328
|
|
|
329
|
+
var ExecuteMode;
|
|
330
|
+
|
|
331
|
+
(function (ExecuteMode) {
|
|
332
|
+
ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
|
|
333
|
+
ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
|
|
334
|
+
ExecuteMode[ExecuteMode["All"] = 6] = "All";
|
|
335
|
+
})(ExecuteMode || (ExecuteMode = {}));
|
|
336
|
+
|
|
232
337
|
var SpriteAnimation$2 = function (_super) {
|
|
233
338
|
__extends(SpriteAnimation, _super);
|
|
234
339
|
|
|
@@ -347,13 +452,15 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
347
452
|
});
|
|
348
453
|
SpriteAnimation.componentName = 'SpriteAnimation';
|
|
349
454
|
|
|
350
|
-
__decorate([
|
|
455
|
+
__decorate([Field(), __metadata("design:type", String)], SpriteAnimation.prototype, "resource", void 0);
|
|
351
456
|
|
|
352
|
-
__decorate([
|
|
457
|
+
__decorate([Field(), __metadata("design:type", Boolean)], SpriteAnimation.prototype, "autoPlay", void 0);
|
|
353
458
|
|
|
354
|
-
__decorate([
|
|
459
|
+
__decorate([Field({
|
|
460
|
+
step: 10
|
|
461
|
+
}), __metadata("design:type", Number)], SpriteAnimation.prototype, "speed", void 0);
|
|
355
462
|
|
|
356
|
-
__decorate([
|
|
463
|
+
__decorate([Field(), __metadata("design:type", Boolean)], SpriteAnimation.prototype, "forwards", void 0);
|
|
357
464
|
|
|
358
465
|
return SpriteAnimation;
|
|
359
466
|
}(eva_js.Component);
|
|
@@ -471,18 +578,21 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
471
578
|
|
|
472
579
|
SpriteAnimation.prototype.componentChanged = function (changed) {
|
|
473
580
|
return __awaiter(this, void 0, void 0, function () {
|
|
474
|
-
var component, frames_1, frames_2;
|
|
581
|
+
var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
|
|
475
582
|
return __generator(this, function (_a) {
|
|
476
583
|
switch (_a.label) {
|
|
477
584
|
case 0:
|
|
585
|
+
gameObjectId = changed.gameObject.id;
|
|
478
586
|
if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
|
|
479
587
|
component = changed.component;
|
|
480
588
|
this.autoPlay[changed.gameObject.id] = component.autoPlay;
|
|
481
589
|
if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 2];
|
|
590
|
+
asyncId = this.increaseAsyncId(gameObjectId);
|
|
482
591
|
return [4, eva_js.resource.getResource(component.resource)];
|
|
483
592
|
|
|
484
593
|
case 1:
|
|
485
594
|
frames_1 = _a.sent().instance;
|
|
595
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
486
596
|
|
|
487
597
|
if (!frames_1) {
|
|
488
598
|
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
@@ -502,10 +612,12 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
502
612
|
return [3, 5];
|
|
503
613
|
|
|
504
614
|
case 3:
|
|
615
|
+
asyncId = this.increaseAsyncId(gameObjectId);
|
|
505
616
|
return [4, eva_js.resource.getResource(component.resource)];
|
|
506
617
|
|
|
507
618
|
case 4:
|
|
508
619
|
frames_2 = _a.sent().instance;
|
|
620
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
509
621
|
|
|
510
622
|
if (!frames_2) {
|
|
511
623
|
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
@@ -523,6 +635,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
523
635
|
|
|
524
636
|
case 6:
|
|
525
637
|
if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
638
|
+
this.increaseAsyncId(gameObjectId);
|
|
526
639
|
this.remove(changed.gameObject.id);
|
|
527
640
|
}
|
|
528
641
|
|
|
@@ -579,6 +692,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
579
692
|
|
|
580
693
|
SpriteAnimation.prototype.remove = function (id, isChange) {
|
|
581
694
|
var animate = this.animates[id];
|
|
695
|
+
if (!animate) return;
|
|
582
696
|
this.autoPlay[id] = animate.animatedSprite.playing;
|
|
583
697
|
this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
|
|
584
698
|
animate.animatedSprite.destroy({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return
|
|
1
|
+
function _extends(){return _extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},_extends.apply(this,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_spriteAnimation=function(t,e,n,r,o){"use strict";var i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},i(t,e)};function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var s=function(){return s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},s.apply(this,arguments)};function c(t,e,n,r){var o,i=arguments.length,a=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(o=t[s])&&(a=(i<3?o(a):i>3?o(e,n,a):o(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}function p(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function u(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(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(a,s)}c((r=r.apply(t,e||[])).next())}))}function l(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function f(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}var d=function(t){function e(){var e=this.constructor,n=t.call(this,"Symbol keys are not supported yet!")||this;return Object.setPrototypeOf(n,e.prototype),n}return a(e,t),e}(Error);!function(t){function e(){var e=this.constructor,n=t.call(this,"getProperties is not a function!")||this;return Object.setPrototypeOf(n,e.prototype),n}a(e,t)}(Error);var m,y="IDE_PROPERTY_METADATA";function h(t,e,n,r){var o=Reflect.getMetadata("design:type",t,e),i=o===Array,a=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==a&&(o=a),r){var c=r();Array.isArray(c)?(i=!0,o=c[0]):o=c}var p=Reflect.getMetadata(y,t.constructor)||{};p[e]=s({type:o,isArray:i},n),Reflect.defineMetadata(y,p,t.constructor)}function v(t,e){return function(n,r){if("symbol"==typeof r)throw new d;var o=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);h(n,r,o.options,o.returnTypeFunc)}}!function(t){t[t.Edit=2]="Edit",t[t.Game=4]="Game",t[t.All=6]="All"}(m||(m={}));var g=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.resource="",e.autoPlay=!0,e.speed=100,e.forwards=!1,e.waitPlay=!1,e.waitStop=!1,e.times=1/0,e.count=0,e.complete=!1,e}return a(e,t),e.prototype.init=function(t){var e=this;t&&_extends(this,t),this.on("loop",(function(){++e.count>=e.times&&(e.forwards?e.gotoAndStop(e.totalFrames-1):e.animate.stop(),e.complete=!0,e.emit("complete"))}))},e.prototype.play=function(t){void 0===t&&(t=1/0),0!==t&&(this.times=t,this.animate?(this.complete&&this.gotoAndStop(0),this.animate.play(),this.count=0,this.complete=!1):this.waitPlay=!0)},e.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(e.prototype,"animate",{get:function(){return this._animate},set:function(t){this._animate=t,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),e.prototype.gotoAndPlay=function(t){this.animate.gotoAndPlay(t)},e.prototype.gotoAndStop=function(t){this.animate.gotoAndStop(t)},Object.defineProperty(e.prototype,"currentFrame",{get:function(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.currentFrame},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"totalFrames",{get:function(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.totalFrames},enumerable:!1,configurable:!0}),e.componentName="SpriteAnimation",c([v(),p("design:type",String)],e.prototype,"resource",void 0),c([v(),p("design:type",Boolean)],e.prototype,"autoPlay",void 0),c([v({step:10}),p("design:type",Number)],e.prototype,"speed",void 0),c([v(),p("design:type",Boolean)],e.prototype,"forwards",void 0),e}(e.Component),b=g,w="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(t){var e=t.name,n=t.data;return new Promise((function(t){var r,i,a=n.json,s=o.BaseTexture.from(n.image),c=a.frames||{},p=a.animations||{},u={};for(var l in c){u[e+w+l]=c[l]}for(var l in p){var d=[];if(p[l]&&p[l].length>=0)try{for(var m=(r=void 0,f(p[l])),y=m.next();!y.done;y=m.next()){var h=y.value,v=e+w+h;d.push(v)}}catch(t){r={error:t}}finally{try{y&&!y.done&&(i=m.return)&&i.call(m)}finally{if(r)throw r.error}}p[l]=d}a.frames=u;var g=new o.Spritesheet(s,a);g.parse((function(){var e=g.textures,n=[];for(var r in e)n.push(e[r]);t(n)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(t){var e,n,r=t.instance;if(r)try{for(var o=f(r),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}}));var A=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="SpriteAnimation",e.animates={},e.autoPlay={},e}return a(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(t){var e=t.transform.size,n=e.width,r=e.height;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=n,this.animates[t.id].animatedSprite.height=r)},o.prototype.componentChanged=function(t){return u(this,void 0,void 0,(function(){var n,r,o,i,a;return l(this,(function(s){switch(s.label){case 0:return n=t.gameObject.id,"SpriteAnimation"!==t.componentName?[3,7]:(r=t.component,this.autoPlay[t.gameObject.id]=r.autoPlay,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:(i=this.increaseAsyncId(n),[4,e.resource.getResource(r.resource)]));case 1:return o=s.sent().instance,this.validateAsyncId(n,i)?(o||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.add({frames:o,id:t.gameObject.id,component:r}),[3,7]):[2];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,6]:t.prop&&"speed"===t.prop.prop[0]?(this.animates[t.gameObject.id].speed=1e3/60/r.speed,[3,5]):[3,3];case 3:return i=this.increaseAsyncId(n),[4,e.resource.getResource(r.resource)];case 4:if(a=s.sent().instance,!this.validateAsyncId(n,i))return[2];a||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.change({frames:a,id:t.gameObject.id,component:r}),s.label=5;case 5:return[3,7];case 6:t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(n),this.remove(t.gameObject.id)),s.label=7;case 7:return[2]}}))}))},o.prototype.add=function(t){var e=t.frames,n=t.id,o=t.component,i=new r.SpriteAnimation({frames:e});this.animates[n]=i,this.containerManager.getContainer(n).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[n],this.animates[n].speed=1e3/60/o.speed,this.autoPlay[n]&&i.animatedSprite.play()},o.prototype.change=function(t){var e=t.frames,n=t.id,r=t.component;this.remove(n,!0),this.add({frames:e,id:n,component:r})},o.prototype.remove=function(t,e){var n=this.animates[t];n&&(this.autoPlay[t]=n.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(n.animatedSprite),n.animatedSprite.destroy({children:!0}),delete this.animates[t],e||delete this.autoPlay[t])},o.systemName="SpriteAnimation",o=c([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(n.Renderer),S=A;return t.SpriteAnimation=b,t.SpriteAnimationSystem=S,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);window.EVA.plugin.renderer.spriteAnimation=window.EVA.plugin.renderer.spriteAnimation||_EVA_IIFE_spriteAnimation;
|
|
@@ -44,6 +44,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
44
44
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
function __metadata(metadataKey, metadataValue) {
|
|
48
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
49
|
+
}
|
|
50
|
+
|
|
47
51
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
48
52
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
49
53
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -191,17 +195,20 @@ var SpriteAnimation$2 = (function (_super) {
|
|
|
191
195
|
});
|
|
192
196
|
SpriteAnimation.componentName = 'SpriteAnimation';
|
|
193
197
|
__decorate([
|
|
194
|
-
inspectorDecorator.
|
|
198
|
+
inspectorDecorator.Field(),
|
|
199
|
+
__metadata("design:type", String)
|
|
195
200
|
], SpriteAnimation.prototype, "resource", void 0);
|
|
196
201
|
__decorate([
|
|
197
|
-
inspectorDecorator.
|
|
202
|
+
inspectorDecorator.Field(),
|
|
203
|
+
__metadata("design:type", Boolean)
|
|
198
204
|
], SpriteAnimation.prototype, "autoPlay", void 0);
|
|
199
205
|
__decorate([
|
|
200
|
-
inspectorDecorator.
|
|
201
|
-
|
|
206
|
+
inspectorDecorator.Field({ step: 10 }),
|
|
207
|
+
__metadata("design:type", Number)
|
|
202
208
|
], SpriteAnimation.prototype, "speed", void 0);
|
|
203
209
|
__decorate([
|
|
204
|
-
inspectorDecorator.
|
|
210
|
+
inspectorDecorator.Field(),
|
|
211
|
+
__metadata("design:type", Boolean)
|
|
205
212
|
], SpriteAnimation.prototype, "forwards", void 0);
|
|
206
213
|
return SpriteAnimation;
|
|
207
214
|
}(eva_js.Component));
|
|
@@ -294,17 +301,21 @@ var SpriteAnimation = (function (_super) {
|
|
|
294
301
|
};
|
|
295
302
|
SpriteAnimation.prototype.componentChanged = function (changed) {
|
|
296
303
|
return __awaiter(this, void 0, void 0, function () {
|
|
297
|
-
var component, frames_1, frames_2;
|
|
304
|
+
var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
|
|
298
305
|
return __generator(this, function (_a) {
|
|
299
306
|
switch (_a.label) {
|
|
300
307
|
case 0:
|
|
308
|
+
gameObjectId = changed.gameObject.id;
|
|
301
309
|
if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
|
|
302
310
|
component = changed.component;
|
|
303
311
|
this.autoPlay[changed.gameObject.id] = component.autoPlay;
|
|
304
312
|
if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 2];
|
|
313
|
+
asyncId = this.increaseAsyncId(gameObjectId);
|
|
305
314
|
return [4, eva_js.resource.getResource(component.resource)];
|
|
306
315
|
case 1:
|
|
307
316
|
frames_1 = (_a.sent()).instance;
|
|
317
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
318
|
+
return [2];
|
|
308
319
|
if (!frames_1) {
|
|
309
320
|
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
310
321
|
}
|
|
@@ -319,9 +330,13 @@ var SpriteAnimation = (function (_super) {
|
|
|
319
330
|
if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
|
|
320
331
|
this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
|
|
321
332
|
return [3, 5];
|
|
322
|
-
case 3:
|
|
333
|
+
case 3:
|
|
334
|
+
asyncId = this.increaseAsyncId(gameObjectId);
|
|
335
|
+
return [4, eva_js.resource.getResource(component.resource)];
|
|
323
336
|
case 4:
|
|
324
337
|
frames_2 = (_a.sent()).instance;
|
|
338
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
339
|
+
return [2];
|
|
325
340
|
if (!frames_2) {
|
|
326
341
|
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
327
342
|
}
|
|
@@ -334,6 +349,7 @@ var SpriteAnimation = (function (_super) {
|
|
|
334
349
|
case 5: return [3, 7];
|
|
335
350
|
case 6:
|
|
336
351
|
if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
352
|
+
this.increaseAsyncId(gameObjectId);
|
|
337
353
|
this.remove(changed.gameObject.id);
|
|
338
354
|
}
|
|
339
355
|
_a.label = 7;
|
|
@@ -369,6 +385,8 @@ var SpriteAnimation = (function (_super) {
|
|
|
369
385
|
};
|
|
370
386
|
SpriteAnimation.prototype.remove = function (id, isChange) {
|
|
371
387
|
var animate = this.animates[id];
|
|
388
|
+
if (!animate)
|
|
389
|
+
return;
|
|
372
390
|
this.autoPlay[id] = animate.animatedSprite.playing;
|
|
373
391
|
this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
|
|
374
392
|
animate.animatedSprite.destroy({ children: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),n=require("@eva/plugin-renderer"),r=require("@eva/renderer-adapter"),o=require("pixi.js"),i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},i(e,t)};function a(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function s(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function c(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function p(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function u(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}var l=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.autoPlay=!0,t.speed=100,t.forwards=!1,t.waitPlay=!1,t.waitStop=!1,t.times=1/0,t.count=0,t.complete=!1,t}return a(n,e),n.prototype.init=function(e){var t=this;e&&Object.assign(this,e),this.on("loop",(function(){++t.count>=t.times&&(t.forwards?t.gotoAndStop(t.totalFrames-1):t.animate.stop(),t.complete=!0,t.emit("complete"))}))},n.prototype.play=function(e){void 0===e&&(e=1/0),0!==e&&(this.times=e,this.animate?(this.complete&&this.gotoAndStop(0),this.animate.play(),this.count=0,this.complete=!1):this.waitPlay=!0)},n.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(n.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),n.prototype.gotoAndPlay=function(e){this.animate.gotoAndPlay(e)},n.prototype.gotoAndStop=function(e){this.animate.gotoAndStop(e)},Object.defineProperty(n.prototype,"currentFrame",{get:function(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.currentFrame},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"totalFrames",{get:function(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.totalFrames},enumerable:!1,configurable:!0}),n.componentName="SpriteAnimation",s([t.Field(),c("design:type",String)],n.prototype,"resource",void 0),s([t.Field(),c("design:type",Boolean)],n.prototype,"autoPlay",void 0),s([t.Field({step:10}),c("design:type",Number)],n.prototype,"speed",void 0),s([t.Field(),c("design:type",Boolean)],n.prototype,"forwards",void 0),n}(e.Component),d=l;e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t=e.name,n=e.data;return new Promise((function(e){var r,i,a=n.json,s=o.BaseTexture.from(n.image),c=a.frames||{},p=a.animations||{},l={};for(var d in c){l[t+"_s|r|c_"+d]=c[d]}for(var d in p){var m=[];if(p[d]&&p[d].length>=0)try{for(var f=(r=void 0,u(p[d])),h=f.next();!h.done;h=f.next()){var y=h.value,v=t+"_s|r|c_"+y;m.push(v)}}catch(e){r={error:e}}finally{try{h&&!h.done&&(i=f.return)&&i.call(f)}finally{if(r)throw r.error}}p[d]=m}a.frames=l;var g=new o.Spritesheet(s,a);g.parse((function(){var t=g.textures,n=[];for(var r in t)n.push(t[r]);e(n)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t,n,r=e.instance;if(r)try{for(var o=u(r),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}}));var m=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="SpriteAnimation",e.animates={},e.autoPlay={},e}return a(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(e){var t=e.transform.size,n=t.width,r=t.height;this.animates[e.id]&&(this.animates[e.id].animatedSprite.width=n,this.animates[e.id].animatedSprite.height=r)},o.prototype.componentChanged=function(t){return n=this,r=void 0,i=function(){var n,r,o,i,a;return p(this,(function(s){switch(s.label){case 0:return n=t.gameObject.id,"SpriteAnimation"!==t.componentName?[3,7]:(r=t.component,this.autoPlay[t.gameObject.id]=r.autoPlay,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:(i=this.increaseAsyncId(n),[4,e.resource.getResource(r.resource)]));case 1:return o=s.sent().instance,this.validateAsyncId(n,i)?(o||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.add({frames:o,id:t.gameObject.id,component:r}),[3,7]):[2];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,6]:t.prop&&"speed"===t.prop.prop[0]?(this.animates[t.gameObject.id].speed=1e3/60/r.speed,[3,5]):[3,3];case 3:return i=this.increaseAsyncId(n),[4,e.resource.getResource(r.resource)];case 4:if(a=s.sent().instance,!this.validateAsyncId(n,i))return[2];a||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.change({frames:a,id:t.gameObject.id,component:r}),s.label=5;case 5:return[3,7];case 6:t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(n),this.remove(t.gameObject.id)),s.label=7;case 7:return[2]}}))},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{c(i.next(e))}catch(e){t(e)}}function s(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){t.done?e(t.value):new o((function(e){e(t.value)})).then(a,s)}c((i=i.apply(n,r||[])).next())}));var n,r,o,i},o.prototype.add=function(e){var t=e.frames,n=e.id,o=e.component,i=new r.SpriteAnimation({frames:t});this.animates[n]=i,this.containerManager.getContainer(n).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[n],this.animates[n].speed=1e3/60/o.speed,this.autoPlay[n]&&i.animatedSprite.play()},o.prototype.change=function(e){var t=e.frames,n=e.id,r=e.component;this.remove(n,!0),this.add({frames:t,id:n,component:r})},o.prototype.remove=function(e,t){var n=this.animates[e];n&&(this.autoPlay[e]=n.animatedSprite.playing,this.containerManager.getContainer(e).removeChild(n.animatedSprite),n.animatedSprite.destroy({children:!0}),delete this.animates[e],t||delete this.autoPlay[e])},o.systemName="SpriteAnimation",o=s([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(n.Renderer);exports.SpriteAnimation=d,exports.SpriteAnimationSystem=m;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component, resource, RESOURCE_TYPE, decorators, OBSERVER_TYPE } from '@eva/eva.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Field } from '@eva/inspector-decorator';
|
|
3
3
|
import { RendererSystem, Renderer } from '@eva/plugin-renderer';
|
|
4
4
|
import { SpriteAnimation as SpriteAnimation$4 } from '@eva/renderer-adapter';
|
|
5
5
|
import { BaseTexture, Spritesheet } from 'pixi.js';
|
|
@@ -40,6 +40,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
40
40
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
function __metadata(metadataKey, metadataValue) {
|
|
44
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
45
|
+
}
|
|
46
|
+
|
|
43
47
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
44
48
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
45
49
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -187,17 +191,20 @@ var SpriteAnimation$2 = (function (_super) {
|
|
|
187
191
|
});
|
|
188
192
|
SpriteAnimation.componentName = 'SpriteAnimation';
|
|
189
193
|
__decorate([
|
|
190
|
-
|
|
194
|
+
Field(),
|
|
195
|
+
__metadata("design:type", String)
|
|
191
196
|
], SpriteAnimation.prototype, "resource", void 0);
|
|
192
197
|
__decorate([
|
|
193
|
-
|
|
198
|
+
Field(),
|
|
199
|
+
__metadata("design:type", Boolean)
|
|
194
200
|
], SpriteAnimation.prototype, "autoPlay", void 0);
|
|
195
201
|
__decorate([
|
|
196
|
-
|
|
197
|
-
|
|
202
|
+
Field({ step: 10 }),
|
|
203
|
+
__metadata("design:type", Number)
|
|
198
204
|
], SpriteAnimation.prototype, "speed", void 0);
|
|
199
205
|
__decorate([
|
|
200
|
-
|
|
206
|
+
Field(),
|
|
207
|
+
__metadata("design:type", Boolean)
|
|
201
208
|
], SpriteAnimation.prototype, "forwards", void 0);
|
|
202
209
|
return SpriteAnimation;
|
|
203
210
|
}(Component));
|
|
@@ -290,17 +297,21 @@ var SpriteAnimation = (function (_super) {
|
|
|
290
297
|
};
|
|
291
298
|
SpriteAnimation.prototype.componentChanged = function (changed) {
|
|
292
299
|
return __awaiter(this, void 0, void 0, function () {
|
|
293
|
-
var component, frames_1, frames_2;
|
|
300
|
+
var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
|
|
294
301
|
return __generator(this, function (_a) {
|
|
295
302
|
switch (_a.label) {
|
|
296
303
|
case 0:
|
|
304
|
+
gameObjectId = changed.gameObject.id;
|
|
297
305
|
if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
|
|
298
306
|
component = changed.component;
|
|
299
307
|
this.autoPlay[changed.gameObject.id] = component.autoPlay;
|
|
300
308
|
if (!(changed.type === OBSERVER_TYPE.ADD)) return [3, 2];
|
|
309
|
+
asyncId = this.increaseAsyncId(gameObjectId);
|
|
301
310
|
return [4, resource.getResource(component.resource)];
|
|
302
311
|
case 1:
|
|
303
312
|
frames_1 = (_a.sent()).instance;
|
|
313
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
314
|
+
return [2];
|
|
304
315
|
if (!frames_1) {
|
|
305
316
|
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
306
317
|
}
|
|
@@ -315,9 +326,13 @@ var SpriteAnimation = (function (_super) {
|
|
|
315
326
|
if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
|
|
316
327
|
this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
|
|
317
328
|
return [3, 5];
|
|
318
|
-
case 3:
|
|
329
|
+
case 3:
|
|
330
|
+
asyncId = this.increaseAsyncId(gameObjectId);
|
|
331
|
+
return [4, resource.getResource(component.resource)];
|
|
319
332
|
case 4:
|
|
320
333
|
frames_2 = (_a.sent()).instance;
|
|
334
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
335
|
+
return [2];
|
|
321
336
|
if (!frames_2) {
|
|
322
337
|
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
323
338
|
}
|
|
@@ -330,6 +345,7 @@ var SpriteAnimation = (function (_super) {
|
|
|
330
345
|
case 5: return [3, 7];
|
|
331
346
|
case 6:
|
|
332
347
|
if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
348
|
+
this.increaseAsyncId(gameObjectId);
|
|
333
349
|
this.remove(changed.gameObject.id);
|
|
334
350
|
}
|
|
335
351
|
_a.label = 7;
|
|
@@ -365,6 +381,8 @@ var SpriteAnimation = (function (_super) {
|
|
|
365
381
|
};
|
|
366
382
|
SpriteAnimation.prototype.remove = function (id, isChange) {
|
|
367
383
|
var animate = this.animates[id];
|
|
384
|
+
if (!animate)
|
|
385
|
+
return;
|
|
368
386
|
this.autoPlay[id] = animate.animatedSprite.playing;
|
|
369
387
|
this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
|
|
370
388
|
animate.animatedSprite.destroy({ children: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-sprite-animation",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7-editor.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": "
|
|
22
|
-
"@eva/plugin-renderer": "1.2.
|
|
23
|
-
"@eva/renderer-adapter": "1.2.
|
|
24
|
-
"@eva/eva.js": "1.2.
|
|
21
|
+
"@eva/inspector-decorator": "0.1.0-alpha.2",
|
|
22
|
+
"@eva/plugin-renderer": "1.2.7-editor.10",
|
|
23
|
+
"@eva/renderer-adapter": "1.2.7-editor.10",
|
|
24
|
+
"@eva/eva.js": "1.2.7-editor.10",
|
|
25
25
|
"pixi.js": "^4.8.7"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/dist/miniprogram.js
DELETED
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
|
-
import { __extends, __decorate, __values, __awaiter, __generator } from 'tslib';
|
|
4
|
-
import { Component, resource, RESOURCE_TYPE, OBSERVER_TYPE, decorators } from '@eva/eva.js/dist/miniprogram';
|
|
5
|
-
import { type, step } from '@eva/inspector-decorator';
|
|
6
|
-
import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
|
|
7
|
-
import { SpriteAnimation as SpriteAnimation$4 } from '@eva/renderer-adapter/dist/miniprogram';
|
|
8
|
-
import { BaseTexture, Spritesheet } from '@eva/miniprogram-pixi';
|
|
9
|
-
|
|
10
|
-
var SpriteAnimation$2 = function (_super) {
|
|
11
|
-
__extends(SpriteAnimation, _super);
|
|
12
|
-
|
|
13
|
-
function SpriteAnimation() {
|
|
14
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
15
|
-
|
|
16
|
-
_this.resource = '';
|
|
17
|
-
_this.autoPlay = true;
|
|
18
|
-
_this.speed = 100;
|
|
19
|
-
_this.forwards = false;
|
|
20
|
-
_this.waitPlay = false;
|
|
21
|
-
_this.waitStop = false;
|
|
22
|
-
_this.times = Infinity;
|
|
23
|
-
_this.count = 0;
|
|
24
|
-
_this.complete = false;
|
|
25
|
-
return _this;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
SpriteAnimation.prototype.init = function (obj) {
|
|
29
|
-
var _this = this;
|
|
30
|
-
|
|
31
|
-
obj && _extends(this, obj);
|
|
32
|
-
this.on('loop', function () {
|
|
33
|
-
if (++_this.count >= _this.times) {
|
|
34
|
-
if (_this.forwards) {
|
|
35
|
-
_this.gotoAndStop(_this.totalFrames - 1);
|
|
36
|
-
} else {
|
|
37
|
-
_this.animate.stop();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
_this.complete = true;
|
|
41
|
-
|
|
42
|
-
_this.emit('complete');
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
SpriteAnimation.prototype.play = function (times) {
|
|
48
|
-
if (times === void 0) {
|
|
49
|
-
times = Infinity;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (times === 0) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.times = times;
|
|
57
|
-
|
|
58
|
-
if (!this.animate) {
|
|
59
|
-
this.waitPlay = true;
|
|
60
|
-
} else {
|
|
61
|
-
if (this.complete) {
|
|
62
|
-
this.gotoAndStop(0);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this.animate.play();
|
|
66
|
-
this.count = 0;
|
|
67
|
-
this.complete = false;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
SpriteAnimation.prototype.stop = function () {
|
|
72
|
-
if (!this.animate) {
|
|
73
|
-
this.waitStop = true;
|
|
74
|
-
} else {
|
|
75
|
-
this.animate.stop();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
Object.defineProperty(SpriteAnimation.prototype, "animate", {
|
|
80
|
-
get: function get() {
|
|
81
|
-
return this._animate;
|
|
82
|
-
},
|
|
83
|
-
set: function set(val) {
|
|
84
|
-
this._animate = val;
|
|
85
|
-
|
|
86
|
-
if (this.waitPlay) {
|
|
87
|
-
this.waitPlay = false;
|
|
88
|
-
this.play(this.times);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (this.waitStop) {
|
|
92
|
-
this.waitStop = false;
|
|
93
|
-
this.stop();
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
enumerable: false,
|
|
97
|
-
configurable: true
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
SpriteAnimation.prototype.gotoAndPlay = function (frameNumber) {
|
|
101
|
-
this.animate.gotoAndPlay(frameNumber);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
SpriteAnimation.prototype.gotoAndStop = function (frameNumber) {
|
|
105
|
-
this.animate.gotoAndStop(frameNumber);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
Object.defineProperty(SpriteAnimation.prototype, "currentFrame", {
|
|
109
|
-
get: function get() {
|
|
110
|
-
var _a, _b;
|
|
111
|
-
|
|
112
|
-
return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
|
|
113
|
-
},
|
|
114
|
-
enumerable: false,
|
|
115
|
-
configurable: true
|
|
116
|
-
});
|
|
117
|
-
Object.defineProperty(SpriteAnimation.prototype, "totalFrames", {
|
|
118
|
-
get: function get() {
|
|
119
|
-
var _a, _b;
|
|
120
|
-
|
|
121
|
-
return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
|
|
122
|
-
},
|
|
123
|
-
enumerable: false,
|
|
124
|
-
configurable: true
|
|
125
|
-
});
|
|
126
|
-
SpriteAnimation.componentName = 'SpriteAnimation';
|
|
127
|
-
|
|
128
|
-
__decorate([type('string')], SpriteAnimation.prototype, "resource", void 0);
|
|
129
|
-
|
|
130
|
-
__decorate([type('boolean')], SpriteAnimation.prototype, "autoPlay", void 0);
|
|
131
|
-
|
|
132
|
-
__decorate([type('number'), step(10)], SpriteAnimation.prototype, "speed", void 0);
|
|
133
|
-
|
|
134
|
-
__decorate([type('boolean')], SpriteAnimation.prototype, "forwards", void 0);
|
|
135
|
-
|
|
136
|
-
return SpriteAnimation;
|
|
137
|
-
}(Component);
|
|
138
|
-
|
|
139
|
-
var SpriteAnimation$3 = SpriteAnimation$2;
|
|
140
|
-
var resourceKeySplit = '_s|r|c_';
|
|
141
|
-
resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
|
|
142
|
-
var name = _a.name,
|
|
143
|
-
data = _a.data;
|
|
144
|
-
return new Promise(function (r) {
|
|
145
|
-
var e_1, _a;
|
|
146
|
-
|
|
147
|
-
var textureObj = data.json;
|
|
148
|
-
var texture = BaseTexture.from(data.image);
|
|
149
|
-
var frames = textureObj.frames || {};
|
|
150
|
-
var animations = textureObj.animations || {};
|
|
151
|
-
var newFrames = {};
|
|
152
|
-
|
|
153
|
-
for (var key in frames) {
|
|
154
|
-
var newKey = name + resourceKeySplit + key;
|
|
155
|
-
newFrames[newKey] = frames[key];
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
for (var key in animations) {
|
|
159
|
-
var spriteList = [];
|
|
160
|
-
|
|
161
|
-
if (animations[key] && animations[key].length >= 0) {
|
|
162
|
-
try {
|
|
163
|
-
for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
164
|
-
var spriteName = _c.value;
|
|
165
|
-
var newSpriteName = name + resourceKeySplit + spriteName;
|
|
166
|
-
spriteList.push(newSpriteName);
|
|
167
|
-
}
|
|
168
|
-
} catch (e_1_1) {
|
|
169
|
-
e_1 = {
|
|
170
|
-
error: e_1_1
|
|
171
|
-
};
|
|
172
|
-
} finally {
|
|
173
|
-
try {
|
|
174
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
175
|
-
} finally {
|
|
176
|
-
if (e_1) throw e_1.error;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
animations[key] = spriteList;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
textureObj.frames = newFrames;
|
|
185
|
-
var spriteSheet = new Spritesheet(texture, textureObj);
|
|
186
|
-
spriteSheet.parse(function () {
|
|
187
|
-
var textures = spriteSheet.textures;
|
|
188
|
-
var spriteFrames = [];
|
|
189
|
-
|
|
190
|
-
for (var key in textures) {
|
|
191
|
-
spriteFrames.push(textures[key]);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
r(spriteFrames);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
resource.registerDestroy(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
|
|
199
|
-
var e_2, _b;
|
|
200
|
-
|
|
201
|
-
var instance = _a.instance;
|
|
202
|
-
if (!instance) return;
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
for (var instance_1 = __values(instance), instance_1_1 = instance_1.next(); !instance_1_1.done; instance_1_1 = instance_1.next()) {
|
|
206
|
-
var texture = instance_1_1.value;
|
|
207
|
-
texture.destroy(true);
|
|
208
|
-
}
|
|
209
|
-
} catch (e_2_1) {
|
|
210
|
-
e_2 = {
|
|
211
|
-
error: e_2_1
|
|
212
|
-
};
|
|
213
|
-
} finally {
|
|
214
|
-
try {
|
|
215
|
-
if (instance_1_1 && !instance_1_1.done && (_b = instance_1.return)) _b.call(instance_1);
|
|
216
|
-
} finally {
|
|
217
|
-
if (e_2) throw e_2.error;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
var SpriteAnimation = function (_super) {
|
|
223
|
-
__extends(SpriteAnimation, _super);
|
|
224
|
-
|
|
225
|
-
function SpriteAnimation() {
|
|
226
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
227
|
-
|
|
228
|
-
_this.name = 'SpriteAnimation';
|
|
229
|
-
_this.animates = {};
|
|
230
|
-
_this.autoPlay = {};
|
|
231
|
-
return _this;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
SpriteAnimation.prototype.init = function () {
|
|
235
|
-
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
236
|
-
this.renderSystem.rendererManager.register(this);
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
SpriteAnimation.prototype.rendererUpdate = function (gameObject) {
|
|
240
|
-
var _a = gameObject.transform.size,
|
|
241
|
-
width = _a.width,
|
|
242
|
-
height = _a.height;
|
|
243
|
-
|
|
244
|
-
if (this.animates[gameObject.id]) {
|
|
245
|
-
this.animates[gameObject.id].animatedSprite.width = width;
|
|
246
|
-
this.animates[gameObject.id].animatedSprite.height = height;
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
SpriteAnimation.prototype.componentChanged = function (changed) {
|
|
251
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
252
|
-
var component, frames_1, frames_2;
|
|
253
|
-
return __generator(this, function (_a) {
|
|
254
|
-
switch (_a.label) {
|
|
255
|
-
case 0:
|
|
256
|
-
if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
|
|
257
|
-
component = changed.component;
|
|
258
|
-
this.autoPlay[changed.gameObject.id] = component.autoPlay;
|
|
259
|
-
if (!(changed.type === OBSERVER_TYPE.ADD)) return [3, 2];
|
|
260
|
-
return [4, resource.getResource(component.resource)];
|
|
261
|
-
|
|
262
|
-
case 1:
|
|
263
|
-
frames_1 = _a.sent().instance;
|
|
264
|
-
|
|
265
|
-
if (!frames_1) {
|
|
266
|
-
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
this.add({
|
|
270
|
-
frames: frames_1,
|
|
271
|
-
id: changed.gameObject.id,
|
|
272
|
-
component: component
|
|
273
|
-
});
|
|
274
|
-
return [3, 7];
|
|
275
|
-
|
|
276
|
-
case 2:
|
|
277
|
-
if (!(changed.type === OBSERVER_TYPE.CHANGE)) return [3, 6];
|
|
278
|
-
if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
|
|
279
|
-
this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
|
|
280
|
-
return [3, 5];
|
|
281
|
-
|
|
282
|
-
case 3:
|
|
283
|
-
return [4, resource.getResource(component.resource)];
|
|
284
|
-
|
|
285
|
-
case 4:
|
|
286
|
-
frames_2 = _a.sent().instance;
|
|
287
|
-
|
|
288
|
-
if (!frames_2) {
|
|
289
|
-
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
this.change({
|
|
293
|
-
frames: frames_2,
|
|
294
|
-
id: changed.gameObject.id,
|
|
295
|
-
component: component
|
|
296
|
-
});
|
|
297
|
-
_a.label = 5;
|
|
298
|
-
|
|
299
|
-
case 5:
|
|
300
|
-
return [3, 7];
|
|
301
|
-
|
|
302
|
-
case 6:
|
|
303
|
-
if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
304
|
-
this.remove(changed.gameObject.id);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
_a.label = 7;
|
|
308
|
-
|
|
309
|
-
case 7:
|
|
310
|
-
return [2];
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
SpriteAnimation.prototype.add = function (_a) {
|
|
317
|
-
var frames = _a.frames,
|
|
318
|
-
id = _a.id,
|
|
319
|
-
component = _a.component;
|
|
320
|
-
var animate = new SpriteAnimation$4({
|
|
321
|
-
frames: frames
|
|
322
|
-
});
|
|
323
|
-
this.animates[id] = animate;
|
|
324
|
-
this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
|
|
325
|
-
|
|
326
|
-
animate.animatedSprite.onComplete = function () {
|
|
327
|
-
component.emit('complete');
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
animate.animatedSprite.onFrameChange = function () {
|
|
331
|
-
component.emit('frameChange');
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
animate.animatedSprite.onLoop = function () {
|
|
335
|
-
component.emit('loop');
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
component.animate = this.animates[id];
|
|
339
|
-
this.animates[id].speed = 1000 / 60 / component.speed;
|
|
340
|
-
|
|
341
|
-
if (this.autoPlay[id]) {
|
|
342
|
-
animate.animatedSprite.play();
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
SpriteAnimation.prototype.change = function (_a) {
|
|
347
|
-
var frames = _a.frames,
|
|
348
|
-
id = _a.id,
|
|
349
|
-
component = _a.component;
|
|
350
|
-
this.remove(id, true);
|
|
351
|
-
this.add({
|
|
352
|
-
frames: frames,
|
|
353
|
-
id: id,
|
|
354
|
-
component: component
|
|
355
|
-
});
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
SpriteAnimation.prototype.remove = function (id, isChange) {
|
|
359
|
-
var animate = this.animates[id];
|
|
360
|
-
this.autoPlay[id] = animate.animatedSprite.playing;
|
|
361
|
-
this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
|
|
362
|
-
animate.animatedSprite.destroy({
|
|
363
|
-
children: true
|
|
364
|
-
});
|
|
365
|
-
delete this.animates[id];
|
|
366
|
-
|
|
367
|
-
if (!isChange) {
|
|
368
|
-
delete this.autoPlay[id];
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
SpriteAnimation.systemName = 'SpriteAnimation';
|
|
373
|
-
SpriteAnimation = __decorate([decorators.componentObserver({
|
|
374
|
-
SpriteAnimation: ['speed', 'resource']
|
|
375
|
-
})], SpriteAnimation);
|
|
376
|
-
return SpriteAnimation;
|
|
377
|
-
}(Renderer);
|
|
378
|
-
|
|
379
|
-
var SpriteAnimation$1 = SpriteAnimation;
|
|
380
|
-
export { SpriteAnimation$3 as SpriteAnimation, SpriteAnimation$1 as SpriteAnimationSystem };
|