@eva/plugin-renderer-sprite 1.2.7-editor.6 → 1.2.7-editor.9

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.
@@ -5,8 +5,8 @@ window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
5
5
  var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
6
6
  'use strict';
7
7
 
8
- var _extendStatics$ = function extendStatics$1(d, b) {
9
- _extendStatics$ = Object.setPrototypeOf || {
8
+ var _extendStatics = function extendStatics(d, b) {
9
+ _extendStatics = Object.setPrototypeOf || {
10
10
  __proto__: []
11
11
  } instanceof Array && function (d, b) {
12
12
  d.__proto__ = b;
@@ -16,13 +16,13 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
16
16
  }
17
17
  };
18
18
 
19
- return _extendStatics$(d, b);
19
+ return _extendStatics(d, b);
20
20
  };
21
21
 
22
- function __extends$1(d, b) {
22
+ function __extends(d, b) {
23
23
  if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
24
24
 
25
- _extendStatics$(d, b);
25
+ _extendStatics(d, b);
26
26
 
27
27
  function __() {
28
28
  this.constructor = d;
@@ -222,7 +222,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
222
222
  }
223
223
 
224
224
  var SymbolKeysNotSupportedError = function (_super) {
225
- __extends$1(SymbolKeysNotSupportedError, _super);
225
+ __extends(SymbolKeysNotSupportedError, _super);
226
226
 
227
227
  function SymbolKeysNotSupportedError() {
228
228
  var _newTarget = this.constructor;
@@ -237,7 +237,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
237
237
  }(Error);
238
238
 
239
239
  (function (_super) {
240
- __extends$1(StaticGetPropertiesIsNotAFunctionError, _super);
240
+ __extends(StaticGetPropertiesIsNotAFunctionError, _super);
241
241
 
242
242
  function StaticGetPropertiesIsNotAFunctionError() {
243
243
  var _newTarget = this.constructor;
@@ -332,8 +332,14 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
332
332
  ExecuteMode[ExecuteMode["All"] = 6] = "All";
333
333
  })(ExecuteMode || (ExecuteMode = {}));
334
334
 
335
+ var sleep = function sleep(time) {
336
+ return new Promise(function (resolve) {
337
+ return setTimeout(resolve, time);
338
+ });
339
+ };
340
+
335
341
  var Sprite$3 = function (_super) {
336
- __extends$1(Sprite, _super);
342
+ __extends(Sprite, _super);
337
343
 
338
344
  function Sprite() {
339
345
  var _this = _super !== null && _super.apply(this, arguments) || this;
@@ -352,93 +358,52 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
352
358
 
353
359
  Sprite.componentName = 'Sprite';
354
360
 
355
- __decorate([Field(), __metadata("design:type", String)], Sprite.prototype, "resource", void 0);
361
+ __decorate([Field({
362
+ type: 'resource'
363
+ }), __metadata("design:type", String)], Sprite.prototype, "resource", void 0);
356
364
 
357
- __decorate([Field(), __metadata("design:type", String)], Sprite.prototype, "spriteName", void 0);
365
+ __decorate([Field({
366
+ type: 'selector',
367
+ options: function options(instance) {
368
+ var _a, _b, _c;
358
369
 
359
- return Sprite;
360
- }(eva_js.Component);
370
+ return __awaiter(this, void 0, void 0, function () {
371
+ var frames;
372
+ return __generator(this, function (_d) {
373
+ switch (_d.label) {
374
+ case 0:
375
+ return [4, sleep(0)];
361
376
 
362
- var Sprite$4 = Sprite$3;
377
+ case 1:
378
+ _d.sent();
363
379
 
364
- var _extendStatics = function extendStatics(d, b) {
365
- _extendStatics = Object.setPrototypeOf || {
366
- __proto__: []
367
- } instanceof Array && function (d, b) {
368
- d.__proto__ = b;
369
- } || function (d, b) {
370
- for (var p in b) {
371
- if (b.hasOwnProperty(p)) d[p] = b[p];
372
- }
373
- };
380
+ if (!instance.resource || !eva_js.resource.promiseMap[instance.resource]) {
381
+ return [2, {}];
382
+ }
374
383
 
375
- return _extendStatics(d, b);
376
- };
384
+ return [4, eva_js.resource.promiseMap[instance.resource]];
377
385
 
378
- function __extends(d, b) {
379
- _extendStatics(d, b);
386
+ case 2:
387
+ _d.sent();
380
388
 
381
- function __() {
382
- this.constructor = d;
383
- }
389
+ frames = (_c = (_b = (_a = eva_js.resource.resourcesMap[instance.resource]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.json) === null || _c === void 0 ? void 0 : _c.frames;
390
+ return [2, frames ? Object.values(frames).map(function (item) {
391
+ return item.name;
392
+ }).reduce(function (prev, key) {
393
+ var _a;
384
394
 
385
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
386
- }
387
-
388
- (function (_super) {
389
- __extends(Application, _super);
390
-
391
- function Application(params) {
392
- var _this = this;
393
-
394
- params.autoStart = false;
395
- _this = _super.call(this, params) || this;
396
- return _this;
397
- }
398
-
399
- return Application;
400
- })(pixi_js.Application);
401
-
402
- (function (_super) {
403
- __extends(Container, _super);
404
-
405
- function Container() {
406
- return _super !== null && _super.apply(this, arguments) || this;
407
- }
408
-
409
- return Container;
410
- })(pixi_js.Container);
411
-
412
- (function (_super) {
413
- __extends(Graphics, _super);
414
-
415
- function Graphics() {
416
- return _super !== null && _super.apply(this, arguments) || this;
417
- }
418
-
419
- return Graphics;
420
- })(pixi_js.Graphics);
421
-
422
- (function (_super) {
423
- __extends(NinePatch, _super);
424
-
425
- function NinePatch(img, leftWidth, topHeight, rightWidth, bottomHeight) {
426
- var _this = this;
427
-
428
- var texture;
429
-
430
- if (img === 'string') {
431
- texture = pixi_js.Texture.fromFrame(img);
432
- } else {
433
- texture = pixi_js.Texture.from(img);
395
+ return _assign(_assign({}, prev), (_a = {}, _a[key] = key, _a));
396
+ }, {}) : {}];
397
+ }
398
+ });
399
+ });
434
400
  }
401
+ }), __metadata("design:type", String)], Sprite.prototype, "spriteName", void 0);
435
402
 
436
- _this = _super.call(this, texture, leftWidth, topHeight, rightWidth, bottomHeight) || this;
437
- return _this;
438
- }
403
+ return Sprite;
404
+ }(eva_js.Component);
439
405
 
440
- return NinePatch;
441
- })(pixi_js.mesh.NineSlicePlane);
406
+ var Sprite$4 = Sprite$3;
442
407
 
443
408
  var Sprite$2 = function () {
444
409
  function Sprite(image) {
@@ -480,94 +445,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
480
445
  return Sprite;
481
446
  }();
482
447
 
483
- var Sprite$1$1 = Sprite$2;
484
-
485
- (function () {
486
- function SpriteAnimation(_a) {
487
- var frames = _a.frames;
488
- this.animatedSprite = new pixi_js.extras.AnimatedSprite(frames);
489
- }
490
-
491
- SpriteAnimation.prototype.play = function () {
492
- this.animatedSprite.play();
493
- };
494
-
495
- SpriteAnimation.prototype.stop = function () {
496
- this.animatedSprite.stop();
497
- };
498
-
499
- SpriteAnimation.prototype.gotoAndPlay = function (frameNumber) {
500
- this.animatedSprite.gotoAndPlay(frameNumber);
501
- };
502
-
503
- SpriteAnimation.prototype.gotoAndStop = function (frameNumber) {
504
- this.animatedSprite.gotoAndStop(frameNumber);
505
- };
506
-
507
- Object.defineProperty(SpriteAnimation.prototype, "speed", {
508
- get: function get() {
509
- return this.animatedSprite.animationSpeed;
510
- },
511
- set: function set(val) {
512
- this.animatedSprite.animationSpeed = val;
513
- },
514
- enumerable: false,
515
- configurable: true
516
- });
517
- return SpriteAnimation;
518
- })();
519
-
520
- (function (_super) {
521
- __extends(Text, _super);
522
-
523
- function Text(text, style) {
524
- return _super.call(this, text, style) || this;
525
- }
526
-
527
- return Text;
528
- })(pixi_js.Text);
529
-
530
- var PIXITilingSprite = pixi_js.extras.TilingSprite;
531
-
532
- (function () {
533
- function TilingSprite(image) {
534
- this._image = null;
535
- this._image = image;
536
-
537
- if (image) {
538
- if (image instanceof HTMLImageElement) {
539
- this.tilingSprite = new PIXITilingSprite(pixi_js.Texture.from(image));
540
- } else if (image instanceof pixi_js.Texture) {
541
- this.tilingSprite = new PIXITilingSprite(image);
542
- }
543
- } else {
544
- this.tilingSprite = new PIXITilingSprite(pixi_js.Texture.EMPTY);
545
- }
546
- }
547
-
548
- Object.defineProperty(TilingSprite.prototype, "image", {
549
- get: function get() {
550
- return this._image;
551
- },
552
- set: function set(val) {
553
- if (this._image === val) {
554
- return;
555
- }
556
-
557
- if (val instanceof HTMLImageElement) {
558
- this.tilingSprite.texture = pixi_js.Texture.from(val);
559
- } else if (val instanceof pixi_js.Texture) {
560
- this.tilingSprite.texture = val;
561
- }
562
-
563
- this._image = val;
564
- },
565
- enumerable: false,
566
- configurable: true
567
- });
568
- return TilingSprite;
569
- })();
570
-
448
+ var SpriteEngine = Sprite$2;
571
449
  var resourceKeySplit = '_s|r|c_';
572
450
  eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
573
451
  var name = _a.name,
@@ -630,7 +508,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
630
508
  });
631
509
 
632
510
  var Sprite = function (_super) {
633
- __extends$1(Sprite, _super);
511
+ __extends(Sprite, _super);
634
512
 
635
513
  function Sprite() {
636
514
  var _this = _super !== null && _super.apply(this, arguments) || this;
@@ -666,7 +544,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
666
544
  gameObjectId = changed.gameObject.id;
667
545
  component = changed.component;
668
546
  if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 2];
669
- sprite = new Sprite$1$1(null);
547
+ sprite = new SpriteEngine(null);
670
548
  this.sprites[changed.gameObject.id] = sprite;
671
549
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite.sprite, 0);
672
550
  asyncId = this.increaseAsyncId(gameObjectId);
@@ -1 +1 @@
1
- window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_sprite=function(e,t,r,n){"use strict";var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},i(e,t)};function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},a.apply(this,arguments)};function s(e,t,r,n){var i,o=arguments.length,a=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(o<3?i(a):o>3?i(t,r,a):i(t,r))||a);return o>3&&a&&Object.defineProperty(t,r,a),a}function c(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function u(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))}function p(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function f(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}var l=function(e){function t(){var t=this.constructor,r=e.call(this,"Symbol keys are not supported yet!")||this;return Object.setPrototypeOf(r,t.prototype),r}return o(t,e),t}(Error);!function(e){function t(){var t=this.constructor,r=e.call(this,"getProperties is not a function!")||this;return Object.setPrototypeOf(r,t.prototype),r}o(t,e)}(Error);var h,y="IDE_PROPERTY_METADATA";function d(e,t,r,n){var i=Reflect.getMetadata("design:type",e,t),o=i===Array,s=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(i);if("unknown"!==s&&(i=s),n){var c=n();Array.isArray(c)?(o=!0,i=c[0]):i=c}var u=Reflect.getMetadata(y,e.constructor)||{};u[t]=a({type:i,isArray:o},r),Reflect.defineMetadata(y,u,e.constructor)}function m(e,t){return function(r,n){if("symbol"==typeof n)throw new l;var i=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(e,t);d(r,n,i.options,i.returnTypeFunc)}}!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(h||(h={}));var g=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.spriteName="",t}return o(t,e),t.prototype.init=function(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)},t.componentName="Sprite",s([m(),c("design:type",String)],t.prototype,"resource",void 0),s([m(),c("design:type",String)],t.prototype,"spriteName",void 0),t}(t.Component),b=g,v=function(e,t){return v=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},v(e,t)};function S(e,t){function r(){this.constructor=e}v(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}!function(e){function t(t){return t.autoStart=!1,e.call(this,t)||this}S(t,e)}(n.Application),function(e){function t(){return null!==e&&e.apply(this,arguments)||this}S(t,e)}(n.Container),function(e){function t(){return null!==e&&e.apply(this,arguments)||this}S(t,e)}(n.Graphics),function(e){function t(t,r,i,o,a){var s;return s="string"===t?n.Texture.fromFrame(t):n.Texture.from(t),e.call(this,s,r,i,o,a)||this}S(t,e)}(n.mesh.NineSlicePlane);var w=function(){function e(e){this._image=null,this._image=e,e?e instanceof HTMLImageElement?this.sprite=n.Sprite.from(e):e instanceof n.Texture&&(this.sprite=new n.Sprite(e)):this.sprite=new n.Sprite}return Object.defineProperty(e.prototype,"image",{get:function(){return this._image},set:function(e){this._image!==e&&(e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=n.Texture.from(e)):e instanceof n.Texture&&(this.sprite.texture=e),this._image=e)},enumerable:!1,configurable:!0}),e}(),E=w;!function(){function e(e){var t=e.frames;this.animatedSprite=new n.extras.AnimatedSprite(t)}e.prototype.play=function(){this.animatedSprite.play()},e.prototype.stop=function(){this.animatedSprite.stop()},e.prototype.gotoAndPlay=function(e){this.animatedSprite.gotoAndPlay(e)},e.prototype.gotoAndStop=function(e){this.animatedSprite.gotoAndStop(e)},Object.defineProperty(e.prototype,"speed",{get:function(){return this.animatedSprite.animationSpeed},set:function(e){this.animatedSprite.animationSpeed=e},enumerable:!1,configurable:!0})}(),function(e){function t(t,r){return e.call(this,t,r)||this}S(t,e)}(n.Text);var O=n.extras.TilingSprite;!function(){function e(e){this._image=null,this._image=e,e?e instanceof HTMLImageElement?this.tilingSprite=new O(n.Texture.from(e)):e instanceof n.Texture&&(this.tilingSprite=new O(e)):this.tilingSprite=new O(n.Texture.EMPTY)}Object.defineProperty(e.prototype,"image",{get:function(){return this._image},set:function(e){this._image!==e&&(e instanceof HTMLImageElement?this.tilingSprite.texture=n.Texture.from(e):e instanceof n.Texture&&(this.tilingSprite.texture=e),this._image=e)},enumerable:!1,configurable:!0})}();var _="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE,(function(e){var t=e.name,r=e.data;return new Promise((function(e){var i,o,a=r.json,s=n.BaseTexture.from(r.image),c=a.frames||{},u=a.animations||{},p={};for(var l in c){p[t+_+l]=c[l]}for(var l in u){var h=[];if(u[l]&&u[l].length>=0)try{for(var y=(i=void 0,f(u[l])),d=y.next();!d.done;d=y.next()){var m=d.value,g=t+_+m;h.push(g)}}catch(e){i={error:e}}finally{try{d&&!d.done&&(o=y.return)&&o.call(y)}finally{if(i)throw i.error}}u[l]=h}a.frames=p;var b=new n.Spritesheet(s,a);b.parse((function(){var t=b.textures;e(t)}))}))})),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE,(function(e){var t=e.instance;if(t)for(var r in t)t[r].destroy(!0)}));var A=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Sprite",t.sprites={},t}return o(n,e),n.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},n.prototype.rendererUpdate=function(e){var t=e.transform.size,r=t.width,n=t.height;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=r,this.sprites[e.id].sprite.height=n)},n.prototype.componentChanged=function(e){return u(this,void 0,void 0,(function(){var r,n,i,o,a;return p(this,(function(s){switch(s.label){case 0:return"Sprite"!==e.componentName?[3,5]:(r=e.gameObject.id,n=e.component,e.type!==t.OBSERVER_TYPE.ADD?[3,2]:(a=new E(null),this.sprites[e.gameObject.id]=a,this.containerManager.getContainer(e.gameObject.id).addChildAt(a.sprite,0),i=this.increaseAsyncId(r),[4,t.resource.getResource(n.resource)]));case 1:return o=s.sent().instance,this.validateAsyncId(r,i)?o?(a.image=o[n.resource+_+n.spriteName],[3,5]):(console.error("GameObject:"+e.gameObject.name+"'s Sprite resource load error"),[2]):[2];case 2:return e.type!==t.OBSERVER_TYPE.CHANGE?[3,4]:(i=this.increaseAsyncId(r),[4,t.resource.getResource(n.resource)]);case 3:return o=s.sent().instance,this.validateAsyncId(r,i)?o?(this.sprites[e.gameObject.id].image=o[n.resource+_+n.spriteName],[3,5]):(console.error("GameObject:"+e.gameObject.name+"'s Sprite resource load error"),[2]):[2];case 4:e.type===t.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(r),a=this.sprites[e.gameObject.id],this.containerManager.getContainer(e.gameObject.id).removeChild(a.sprite),a.sprite.destroy({children:!0}),delete this.sprites[e.gameObject.id]),s.label=5;case 5:return[2]}}))}))},n.systemName="Sprite",n=s([t.decorators.componentObserver({Sprite:["spriteName"]})],n)}(r.Renderer),T=A;return e.Sprite=b,e.SpriteSystem=T,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);window.EVA.plugin.renderer.sprite=window.EVA.plugin.renderer.sprite||_EVA_IIFE_sprite;
1
+ window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_sprite=function(e,t,r,n){"use strict";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},o(e,t)};function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var s=function(){return s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},s.apply(this,arguments)};function a(e,t,r,n){var o,i=arguments.length,s=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,r,s):o(t,r))||s);return i>3&&s&&Object.defineProperty(t,r,s),s}function c(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function u(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function p(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function l(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}var f=function(e){function t(){var t=this.constructor,r=e.call(this,"Symbol keys are not supported yet!")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(Error);!function(e){function t(){var t=this.constructor,r=e.call(this,"getProperties is not a function!")||this;return Object.setPrototypeOf(r,t.prototype),r}i(t,e)}(Error);var d,y="IDE_PROPERTY_METADATA";function h(e,t,r,n){var o=Reflect.getMetadata("design:type",e,t),i=o===Array,a=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==a&&(o=a),n){var c=n();Array.isArray(c)?(i=!0,o=c[0]):o=c}var u=Reflect.getMetadata(y,e.constructor)||{};u[t]=s({type:o,isArray:i},r),Reflect.defineMetadata(y,u,e.constructor)}function m(e,t){return function(r,n){if("symbol"==typeof n)throw new f;var o=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(e,t);h(r,n,o.options,o.returnTypeFunc)}}!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(d||(d={}));var v=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.spriteName="",t}return i(r,e),r.prototype.init=function(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)},r.componentName="Sprite",a([m({type:"resource"}),c("design:type",String)],r.prototype,"resource",void 0),a([m({type:"selector",options:function(e){var r,n,o;return u(this,void 0,void 0,(function(){var i;return p(this,(function(a){switch(a.label){case 0:return[4,(c=0,new Promise((function(e){return setTimeout(e,c)})))];case 1:return a.sent(),e.resource&&t.resource.promiseMap[e.resource]?[4,t.resource.promiseMap[e.resource]]:[2,{}];case 2:return a.sent(),[2,(i=null===(o=null===(n=null===(r=t.resource.resourcesMap[e.resource])||void 0===r?void 0:r.data)||void 0===n?void 0:n.json)||void 0===o?void 0:o.frames)?Object.values(i).map((function(e){return e.name})).reduce((function(e,t){var r;return s(s({},e),((r={})[t]=t,r))}),{}):{}]}var c}))}))}}),c("design:type",String)],r.prototype,"spriteName",void 0),r}(t.Component),g=v,b=function(){function e(e){this._image=null,this._image=e,e?e instanceof HTMLImageElement?this.sprite=n.Sprite.from(e):e instanceof n.Texture&&(this.sprite=new n.Sprite(e)):this.sprite=new n.Sprite}return Object.defineProperty(e.prototype,"image",{get:function(){return this._image},set:function(e){this._image!==e&&(e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=n.Texture.from(e)):e instanceof n.Texture&&(this.sprite.texture=e),this._image=e)},enumerable:!1,configurable:!0}),e}(),w=b,E="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE,(function(e){var t=e.name,r=e.data;return new Promise((function(e){var o,i,s=r.json,a=n.BaseTexture.from(r.image),c=s.frames||{},u=s.animations||{},p={};for(var f in c){p[t+E+f]=c[f]}for(var f in u){var d=[];if(u[f]&&u[f].length>=0)try{for(var y=(o=void 0,l(u[f])),h=y.next();!h.done;h=y.next()){var m=h.value,v=t+E+m;d.push(v)}}catch(e){o={error:e}}finally{try{h&&!h.done&&(i=y.return)&&i.call(y)}finally{if(o)throw o.error}}u[f]=d}s.frames=p;var g=new n.Spritesheet(a,s);g.parse((function(){var t=g.textures;e(t)}))}))})),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE,(function(e){var t=e.instance;if(t)for(var r in t)t[r].destroy(!0)}));var O=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Sprite",t.sprites={},t}return i(n,e),n.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},n.prototype.rendererUpdate=function(e){var t=e.transform.size,r=t.width,n=t.height;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=r,this.sprites[e.id].sprite.height=n)},n.prototype.componentChanged=function(e){return u(this,void 0,void 0,(function(){var r,n,o,i,s;return p(this,(function(a){switch(a.label){case 0:return"Sprite"!==e.componentName?[3,5]:(r=e.gameObject.id,n=e.component,e.type!==t.OBSERVER_TYPE.ADD?[3,2]:(s=new w(null),this.sprites[e.gameObject.id]=s,this.containerManager.getContainer(e.gameObject.id).addChildAt(s.sprite,0),o=this.increaseAsyncId(r),[4,t.resource.getResource(n.resource)]));case 1:return i=a.sent().instance,this.validateAsyncId(r,o)?i?(s.image=i[n.resource+E+n.spriteName],[3,5]):(console.error("GameObject:"+e.gameObject.name+"'s Sprite resource load error"),[2]):[2];case 2:return e.type!==t.OBSERVER_TYPE.CHANGE?[3,4]:(o=this.increaseAsyncId(r),[4,t.resource.getResource(n.resource)]);case 3:return i=a.sent().instance,this.validateAsyncId(r,o)?i?(this.sprites[e.gameObject.id].image=i[n.resource+E+n.spriteName],[3,5]):(console.error("GameObject:"+e.gameObject.name+"'s Sprite resource load error"),[2]):[2];case 4:e.type===t.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(r),s=this.sprites[e.gameObject.id],this.containerManager.getContainer(e.gameObject.id).removeChild(s.sprite),s.sprite.destroy({children:!0}),delete this.sprites[e.gameObject.id]),a.label=5;case 5:return[2]}}))}))},n.systemName="Sprite",n=a([t.decorators.componentObserver({Sprite:["spriteName"]})],n)}(r.Renderer),S=O;return e.Sprite=g,e.SpriteSystem=S,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);window.EVA.plugin.renderer.sprite=window.EVA.plugin.renderer.sprite||_EVA_IIFE_sprite;
@@ -36,6 +36,17 @@ function __extends(d, b) {
36
36
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
37
37
  }
38
38
 
39
+ var __assign = function() {
40
+ __assign = Object.assign || function __assign(t) {
41
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
42
+ s = arguments[i];
43
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
44
+ }
45
+ return t;
46
+ };
47
+ return __assign.apply(this, arguments);
48
+ };
49
+
39
50
  function __decorate(decorators, target, key, desc) {
40
51
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
41
52
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -95,6 +106,7 @@ function __values(o) {
95
106
  };
96
107
  }
97
108
 
109
+ var sleep = function (time) { return new Promise(function (resolve) { return setTimeout(resolve, time); }); };
98
110
  var Sprite$3 = (function (_super) {
99
111
  __extends(Sprite, _super);
100
112
  function Sprite() {
@@ -111,11 +123,41 @@ var Sprite$3 = (function (_super) {
111
123
  };
112
124
  Sprite.componentName = 'Sprite';
113
125
  __decorate([
114
- inspectorDecorator.Field(),
126
+ inspectorDecorator.Field({ type: 'resource' }),
115
127
  __metadata("design:type", String)
116
128
  ], Sprite.prototype, "resource", void 0);
117
129
  __decorate([
118
- inspectorDecorator.Field(),
130
+ inspectorDecorator.Field({
131
+ type: 'selector',
132
+ options: function (instance) {
133
+ var _a, _b, _c;
134
+ return __awaiter(this, void 0, void 0, function () {
135
+ var frames;
136
+ return __generator(this, function (_d) {
137
+ switch (_d.label) {
138
+ case 0: return [4, sleep(0)];
139
+ case 1:
140
+ _d.sent();
141
+ if (!instance.resource || !eva_js.resource.promiseMap[instance.resource]) {
142
+ return [2, {}];
143
+ }
144
+ return [4, eva_js.resource.promiseMap[instance.resource]];
145
+ case 2:
146
+ _d.sent();
147
+ frames = (_c = (_b = (_a = eva_js.resource.resourcesMap[instance.resource]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.json) === null || _c === void 0 ? void 0 : _c.frames;
148
+ return [2, frames
149
+ ? Object.values(frames)
150
+ .map(function (item) { return item.name; })
151
+ .reduce(function (prev, key) {
152
+ var _a;
153
+ return (__assign(__assign({}, prev), (_a = {}, _a[key] = key, _a)));
154
+ }, {})
155
+ : {}];
156
+ }
157
+ });
158
+ });
159
+ },
160
+ }),
119
161
  __metadata("design:type", String)
120
162
  ], Sprite.prototype, "spriteName", void 0);
121
163
  return Sprite;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),n=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 r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},i(e,t)};function o(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function s(e,t,r,n){var i,o=arguments.length,s=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(o<3?i(s):o>3?i(t,r,s):i(t,r))||s);return o>3&&s&&Object.defineProperty(t,r,s),s}function a(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function c(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function u(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}var p=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.spriteName="",t}return o(r,e),r.prototype.init=function(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)},r.componentName="Sprite",s([t.Field(),a("design:type",String)],r.prototype,"resource",void 0),s([t.Field(),a("design:type",String)],r.prototype,"spriteName",void 0),r}(e.Component),l=p,f=function(){function e(e){this._image=null,this._image=e,e?e instanceof HTMLImageElement?this.sprite=n.Sprite.from(e):e instanceof n.Texture&&(this.sprite=new n.Sprite(e)):this.sprite=new n.Sprite}return Object.defineProperty(e.prototype,"image",{get:function(){return this._image},set:function(e){this._image!==e&&(e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=n.Texture.from(e)):e instanceof n.Texture&&(this.sprite.texture=e),this._image=e)},enumerable:!1,configurable:!0}),e}(),h=f;e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE,(function(e){var t=e.name,r=e.data;return new Promise((function(e){var i,o,s=r.json,a=n.BaseTexture.from(r.image),c=s.frames||{},p=s.animations||{},l={};for(var f in c){l[t+"_s|r|c_"+f]=c[f]}for(var f in p){var h=[];if(p[f]&&p[f].length>=0)try{for(var d=(i=void 0,u(p[f])),m=d.next();!m.done;m=d.next()){var y=m.value,g=t+"_s|r|c_"+y;h.push(g)}}catch(e){i={error:e}}finally{try{m&&!m.done&&(o=d.return)&&o.call(d)}finally{if(i)throw i.error}}p[f]=h}s.frames=l;var v=new n.Spritesheet(a,s);v.parse((function(){var t=v.textures;e(t)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE,(function(e){var t=e.instance;if(t)for(var r in t)t[r].destroy(!0)}));var d=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="Sprite",e.sprites={},e}return o(n,t),n.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},n.prototype.rendererUpdate=function(e){var t=e.transform.size,r=t.width,n=t.height;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=r,this.sprites[e.id].sprite.height=n)},n.prototype.componentChanged=function(t){return r=this,n=void 0,o=function(){var r,n,i,o,s;return c(this,(function(a){switch(a.label){case 0:return"Sprite"!==t.componentName?[3,5]:(r=t.gameObject.id,n=t.component,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:(s=new h(null),this.sprites[t.gameObject.id]=s,this.containerManager.getContainer(t.gameObject.id).addChildAt(s.sprite,0),i=this.increaseAsyncId(r),[4,e.resource.getResource(n.resource)]));case 1:return o=a.sent().instance,this.validateAsyncId(r,i)?o?(s.image=o[n.resource+"_s|r|c_"+n.spriteName],[3,5]):(console.error("GameObject:"+t.gameObject.name+"'s Sprite resource load error"),[2]):[2];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,4]:(i=this.increaseAsyncId(r),[4,e.resource.getResource(n.resource)]);case 3:return o=a.sent().instance,this.validateAsyncId(r,i)?o?(this.sprites[t.gameObject.id].image=o[n.resource+"_s|r|c_"+n.spriteName],[3,5]):(console.error("GameObject:"+t.gameObject.name+"'s Sprite resource load error"),[2]):[2];case 4:t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(r),s=this.sprites[t.gameObject.id],this.containerManager.getContainer(t.gameObject.id).removeChild(s.sprite),s.sprite.destroy({children:!0}),delete this.sprites[t.gameObject.id]),a.label=5;case 5:return[2]}}))},new((i=void 0)||(i=Promise))((function(e,t){function s(e){try{c(o.next(e))}catch(e){t(e)}}function a(e){try{c(o.throw(e))}catch(e){t(e)}}function c(t){t.done?e(t.value):new i((function(e){e(t.value)})).then(s,a)}c((o=o.apply(r,n||[])).next())}));var r,n,i,o},n.systemName="Sprite",n=s([e.decorators.componentObserver({Sprite:["spriteName"]})],n)}(r.Renderer);exports.Sprite=l,exports.SpriteSystem=d;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),n=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 r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},i(e,t)};function o(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var s=function(){return s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},s.apply(this,arguments)};function a(e,t,r,n){var i,o=arguments.length,s=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(o<3?i(s):o>3?i(t,r,s):i(t,r))||s);return o>3&&s&&Object.defineProperty(t,r,s),s}function c(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function u(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){e.done?i(e.value):new r((function(t){t(e.value)})).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function p(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function l(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}var f=function(r){function n(){var e=null!==r&&r.apply(this,arguments)||this;return e.resource="",e.spriteName="",e}return o(n,r),n.prototype.init=function(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)},n.componentName="Sprite",a([t.Field({type:"resource"}),c("design:type",String)],n.prototype,"resource",void 0),a([t.Field({type:"selector",options:function(t){var r,n,i;return u(this,void 0,void 0,(function(){var o;return p(this,(function(a){switch(a.label){case 0:return[4,(c=0,new Promise((function(e){return setTimeout(e,c)})))];case 1:return a.sent(),t.resource&&e.resource.promiseMap[t.resource]?[4,e.resource.promiseMap[t.resource]]:[2,{}];case 2:return a.sent(),[2,(o=null===(i=null===(n=null===(r=e.resource.resourcesMap[t.resource])||void 0===r?void 0:r.data)||void 0===n?void 0:n.json)||void 0===i?void 0:i.frames)?Object.values(o).map((function(e){return e.name})).reduce((function(e,t){var r;return s(s({},e),((r={})[t]=t,r))}),{}):{}]}var c}))}))}}),c("design:type",String)],n.prototype,"spriteName",void 0),n}(e.Component),d=f,h=function(){function e(e){this._image=null,this._image=e,e?e instanceof HTMLImageElement?this.sprite=n.Sprite.from(e):e instanceof n.Texture&&(this.sprite=new n.Sprite(e)):this.sprite=new n.Sprite}return Object.defineProperty(e.prototype,"image",{get:function(){return this._image},set:function(e){this._image!==e&&(e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=n.Texture.from(e)):e instanceof n.Texture&&(this.sprite.texture=e),this._image=e)},enumerable:!1,configurable:!0}),e}(),m=h;e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE,(function(e){var t=e.name,r=e.data;return new Promise((function(e){var i,o,s=r.json,a=n.BaseTexture.from(r.image),c=s.frames||{},u=s.animations||{},p={};for(var f in c){p[t+"_s|r|c_"+f]=c[f]}for(var f in u){var d=[];if(u[f]&&u[f].length>=0)try{for(var h=(i=void 0,l(u[f])),m=h.next();!m.done;m=h.next()){var y=m.value,v=t+"_s|r|c_"+y;d.push(v)}}catch(e){i={error:e}}finally{try{m&&!m.done&&(o=h.return)&&o.call(h)}finally{if(i)throw i.error}}u[f]=d}s.frames=p;var g=new n.Spritesheet(a,s);g.parse((function(){var t=g.textures;e(t)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE,(function(e){var t=e.instance;if(t)for(var r in t)t[r].destroy(!0)}));var y=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="Sprite",e.sprites={},e}return o(n,t),n.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},n.prototype.rendererUpdate=function(e){var t=e.transform.size,r=t.width,n=t.height;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=r,this.sprites[e.id].sprite.height=n)},n.prototype.componentChanged=function(t){return u(this,void 0,void 0,(function(){var r,n,i,o,s;return p(this,(function(a){switch(a.label){case 0:return"Sprite"!==t.componentName?[3,5]:(r=t.gameObject.id,n=t.component,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:(s=new m(null),this.sprites[t.gameObject.id]=s,this.containerManager.getContainer(t.gameObject.id).addChildAt(s.sprite,0),i=this.increaseAsyncId(r),[4,e.resource.getResource(n.resource)]));case 1:return o=a.sent().instance,this.validateAsyncId(r,i)?o?(s.image=o[n.resource+"_s|r|c_"+n.spriteName],[3,5]):(console.error("GameObject:"+t.gameObject.name+"'s Sprite resource load error"),[2]):[2];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,4]:(i=this.increaseAsyncId(r),[4,e.resource.getResource(n.resource)]);case 3:return o=a.sent().instance,this.validateAsyncId(r,i)?o?(this.sprites[t.gameObject.id].image=o[n.resource+"_s|r|c_"+n.spriteName],[3,5]):(console.error("GameObject:"+t.gameObject.name+"'s Sprite resource load error"),[2]):[2];case 4:t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(r),s=this.sprites[t.gameObject.id],this.containerManager.getContainer(t.gameObject.id).removeChild(s.sprite),s.sprite.destroy({children:!0}),delete this.sprites[t.gameObject.id]),a.label=5;case 5:return[2]}}))}))},n.systemName="Sprite",n=a([e.decorators.componentObserver({Sprite:["spriteName"]})],n)}(r.Renderer);exports.Sprite=d,exports.SpriteSystem=y;
@@ -32,6 +32,17 @@ function __extends(d, b) {
32
32
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
33
33
  }
34
34
 
35
+ var __assign = function() {
36
+ __assign = Object.assign || function __assign(t) {
37
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
38
+ s = arguments[i];
39
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
40
+ }
41
+ return t;
42
+ };
43
+ return __assign.apply(this, arguments);
44
+ };
45
+
35
46
  function __decorate(decorators, target, key, desc) {
36
47
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
37
48
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -91,6 +102,7 @@ function __values(o) {
91
102
  };
92
103
  }
93
104
 
105
+ var sleep = function (time) { return new Promise(function (resolve) { return setTimeout(resolve, time); }); };
94
106
  var Sprite$3 = (function (_super) {
95
107
  __extends(Sprite, _super);
96
108
  function Sprite() {
@@ -107,11 +119,41 @@ var Sprite$3 = (function (_super) {
107
119
  };
108
120
  Sprite.componentName = 'Sprite';
109
121
  __decorate([
110
- Field(),
122
+ Field({ type: 'resource' }),
111
123
  __metadata("design:type", String)
112
124
  ], Sprite.prototype, "resource", void 0);
113
125
  __decorate([
114
- Field(),
126
+ Field({
127
+ type: 'selector',
128
+ options: function (instance) {
129
+ var _a, _b, _c;
130
+ return __awaiter(this, void 0, void 0, function () {
131
+ var frames;
132
+ return __generator(this, function (_d) {
133
+ switch (_d.label) {
134
+ case 0: return [4, sleep(0)];
135
+ case 1:
136
+ _d.sent();
137
+ if (!instance.resource || !resource.promiseMap[instance.resource]) {
138
+ return [2, {}];
139
+ }
140
+ return [4, resource.promiseMap[instance.resource]];
141
+ case 2:
142
+ _d.sent();
143
+ frames = (_c = (_b = (_a = resource.resourcesMap[instance.resource]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.json) === null || _c === void 0 ? void 0 : _c.frames;
144
+ return [2, frames
145
+ ? Object.values(frames)
146
+ .map(function (item) { return item.name; })
147
+ .reduce(function (prev, key) {
148
+ var _a;
149
+ return (__assign(__assign({}, prev), (_a = {}, _a[key] = key, _a)));
150
+ }, {})
151
+ : {}];
152
+ }
153
+ });
154
+ });
155
+ },
156
+ }),
115
157
  __metadata("design:type", String)
116
158
  ], Sprite.prototype, "spriteName", void 0);
117
159
  return Sprite;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite",
3
- "version": "1.2.7-editor.6",
3
+ "version": "1.2.7-editor.9",
4
4
  "description": "@eva/plugin-renderer-sprite",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-sprite.esm.js",
@@ -19,8 +19,8 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "0.1.0-alpha.2",
22
- "@eva/plugin-renderer": "1.2.7-editor.6",
23
- "@eva/eva.js": "1.2.7-editor.6",
22
+ "@eva/plugin-renderer": "1.2.7-editor.9",
23
+ "@eva/eva.js": "1.2.7-editor.9",
24
24
  "pixi.js": "^4.8.7"
25
25
  }
26
26
  }
@@ -1,197 +0,0 @@
1
- import { __extends, __decorate, __metadata, __values, __awaiter, __generator } from 'tslib';
2
- import { Component, resource, RESOURCE_TYPE, OBSERVER_TYPE, decorators } from '@eva/eva.js/dist/miniprogram';
3
- import { Field } from '@eva/inspector-decorator';
4
- import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
5
- import { Sprite as Sprite$4 } from '@eva/renderer-adapter/dist/miniprogram';
6
- import { BaseTexture, Spritesheet } from '@eva/miniprogram-pixi';
7
-
8
- var Sprite$2 = function (_super) {
9
- __extends(Sprite, _super);
10
-
11
- function Sprite() {
12
- var _this = _super !== null && _super.apply(this, arguments) || this;
13
-
14
- _this.resource = '';
15
- _this.spriteName = '';
16
- return _this;
17
- }
18
-
19
- Sprite.prototype.init = function (obj) {
20
- if (obj && obj.resource) {
21
- this.resource = obj.resource;
22
- this.spriteName = obj.spriteName;
23
- }
24
- };
25
-
26
- Sprite.componentName = 'Sprite';
27
-
28
- __decorate([Field(), __metadata("design:type", String)], Sprite.prototype, "resource", void 0);
29
-
30
- __decorate([Field(), __metadata("design:type", String)], Sprite.prototype, "spriteName", void 0);
31
-
32
- return Sprite;
33
- }(Component);
34
-
35
- var Sprite$3 = Sprite$2;
36
- var resourceKeySplit = '_s|r|c_';
37
- resource.registerInstance(RESOURCE_TYPE.SPRITE, function (_a) {
38
- var name = _a.name,
39
- data = _a.data;
40
- return new Promise(function (r) {
41
- var e_1, _a;
42
-
43
- var textureObj = data.json;
44
- var texture = BaseTexture.from(data.image);
45
- var frames = textureObj.frames || {};
46
- var animations = textureObj.animations || {};
47
- var newFrames = {};
48
-
49
- for (var key in frames) {
50
- var newKey = name + resourceKeySplit + key;
51
- newFrames[newKey] = frames[key];
52
- }
53
-
54
- for (var key in animations) {
55
- var spriteList = [];
56
-
57
- if (animations[key] && animations[key].length >= 0) {
58
- try {
59
- for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
60
- var spriteName = _c.value;
61
- var newSpriteName = name + resourceKeySplit + spriteName;
62
- spriteList.push(newSpriteName);
63
- }
64
- } catch (e_1_1) {
65
- e_1 = {
66
- error: e_1_1
67
- };
68
- } finally {
69
- try {
70
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
71
- } finally {
72
- if (e_1) throw e_1.error;
73
- }
74
- }
75
- }
76
-
77
- animations[key] = spriteList;
78
- }
79
-
80
- textureObj.frames = newFrames;
81
- var spriteSheet = new Spritesheet(texture, textureObj);
82
- spriteSheet.parse(function () {
83
- var textures = spriteSheet.textures;
84
- r(textures);
85
- });
86
- });
87
- });
88
- resource.registerDestroy(RESOURCE_TYPE.SPRITE, function (_a) {
89
- var instance = _a.instance;
90
- if (!instance) return;
91
-
92
- for (var key in instance) {
93
- instance[key].destroy(true);
94
- }
95
- });
96
-
97
- var Sprite = function (_super) {
98
- __extends(Sprite, _super);
99
-
100
- function Sprite() {
101
- var _this = _super !== null && _super.apply(this, arguments) || this;
102
-
103
- _this.name = 'Sprite';
104
- _this.sprites = {};
105
- return _this;
106
- }
107
-
108
- Sprite.prototype.init = function () {
109
- this.renderSystem = this.game.getSystem(RendererSystem);
110
- this.renderSystem.rendererManager.register(this);
111
- };
112
-
113
- Sprite.prototype.rendererUpdate = function (gameObject) {
114
- var _a = gameObject.transform.size,
115
- width = _a.width,
116
- height = _a.height;
117
-
118
- if (this.sprites[gameObject.id]) {
119
- this.sprites[gameObject.id].sprite.width = width;
120
- this.sprites[gameObject.id].sprite.height = height;
121
- }
122
- };
123
-
124
- Sprite.prototype.componentChanged = function (changed) {
125
- return __awaiter(this, void 0, void 0, function () {
126
- var gameObjectId, component, sprite, asyncId, instance, asyncId, instance, sprite;
127
- return __generator(this, function (_a) {
128
- switch (_a.label) {
129
- case 0:
130
- if (!(changed.componentName === 'Sprite')) return [3, 5];
131
- gameObjectId = changed.gameObject.id;
132
- component = changed.component;
133
- if (!(changed.type === OBSERVER_TYPE.ADD)) return [3, 2];
134
- sprite = new Sprite$4(null);
135
- this.sprites[changed.gameObject.id] = sprite;
136
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite.sprite, 0);
137
- asyncId = this.increaseAsyncId(gameObjectId);
138
- return [4, resource.getResource(component.resource)];
139
-
140
- case 1:
141
- instance = _a.sent().instance;
142
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
143
-
144
- if (!instance) {
145
- console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
146
- return [2];
147
- }
148
-
149
- sprite.image = instance[component.resource + resourceKeySplit + component.spriteName];
150
- return [3, 5];
151
-
152
- case 2:
153
- if (!(changed.type === OBSERVER_TYPE.CHANGE)) return [3, 4];
154
- asyncId = this.increaseAsyncId(gameObjectId);
155
- return [4, resource.getResource(component.resource)];
156
-
157
- case 3:
158
- instance = _a.sent().instance;
159
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
160
-
161
- if (!instance) {
162
- console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
163
- return [2];
164
- }
165
-
166
- this.sprites[changed.gameObject.id].image = instance[component.resource + resourceKeySplit + component.spriteName];
167
- return [3, 5];
168
-
169
- case 4:
170
- if (changed.type === OBSERVER_TYPE.REMOVE) {
171
- this.increaseAsyncId(gameObjectId);
172
- sprite = this.sprites[changed.gameObject.id];
173
- this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
174
- sprite.sprite.destroy({
175
- children: true
176
- });
177
- delete this.sprites[changed.gameObject.id];
178
- }
179
-
180
- _a.label = 5;
181
-
182
- case 5:
183
- return [2];
184
- }
185
- });
186
- });
187
- };
188
-
189
- Sprite.systemName = 'Sprite';
190
- Sprite = __decorate([decorators.componentObserver({
191
- Sprite: ['spriteName']
192
- })], Sprite);
193
- return Sprite;
194
- }(Renderer);
195
-
196
- var Sprite$1 = Sprite;
197
- export { Sprite$3 as Sprite, Sprite$1 as SpriteSystem };