@eva/plugin-renderer-sprite 2.0.0-beta.1 → 2.0.0-beta.2

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.
@@ -3,23 +3,6 @@ window.EVA.plugin = window.EVA.plugin || {};
3
3
  window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
4
4
  var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
5
5
  'use strict';
6
- var extendStatics = function (d, b) {
7
- extendStatics = Object.setPrototypeOf || {
8
- __proto__: []
9
- } instanceof Array && function (d, b) {
10
- d.__proto__ = b;
11
- } || function (d, b) {
12
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
13
- };
14
- return extendStatics(d, b);
15
- };
16
- function __extends(d, b) {
17
- extendStatics(d, b);
18
- function __() {
19
- this.constructor = d;
20
- }
21
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22
- }
23
6
  function __decorate(decorators, target, key, desc) {
24
7
  var c = arguments.length,
25
8
  r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
@@ -54,110 +37,6 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
54
37
  step((generator = generator.apply(thisArg, _arguments || [])).next());
55
38
  });
56
39
  }
57
- function __generator(thisArg, body) {
58
- var _ = {
59
- label: 0,
60
- sent: function () {
61
- if (t[0] & 1) throw t[1];
62
- return t[1];
63
- },
64
- trys: [],
65
- ops: []
66
- },
67
- f,
68
- y,
69
- t,
70
- g;
71
- return g = {
72
- next: verb(0),
73
- "throw": verb(1),
74
- "return": verb(2)
75
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
76
- return this;
77
- }), g;
78
- function verb(n) {
79
- return function (v) {
80
- return step([n, v]);
81
- };
82
- }
83
- function step(op) {
84
- if (f) throw new TypeError("Generator is already executing.");
85
- while (_) try {
86
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
87
- if (y = 0, t) op = [op[0] & 2, t.value];
88
- switch (op[0]) {
89
- case 0:
90
- case 1:
91
- t = op;
92
- break;
93
- case 4:
94
- _.label++;
95
- return {
96
- value: op[1],
97
- done: false
98
- };
99
- case 5:
100
- _.label++;
101
- y = op[1];
102
- op = [0];
103
- continue;
104
- case 7:
105
- op = _.ops.pop();
106
- _.trys.pop();
107
- continue;
108
- default:
109
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
110
- _ = 0;
111
- continue;
112
- }
113
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
114
- _.label = op[1];
115
- break;
116
- }
117
- if (op[0] === 6 && _.label < t[1]) {
118
- _.label = t[1];
119
- t = op;
120
- break;
121
- }
122
- if (t && _.label < t[2]) {
123
- _.label = t[2];
124
- _.ops.push(op);
125
- break;
126
- }
127
- if (t[2]) _.ops.pop();
128
- _.trys.pop();
129
- continue;
130
- }
131
- op = body.call(thisArg, _);
132
- } catch (e) {
133
- op = [6, e];
134
- y = 0;
135
- } finally {
136
- f = t = 0;
137
- }
138
- if (op[0] & 5) throw op[1];
139
- return {
140
- value: op[0] ? op[1] : void 0,
141
- done: true
142
- };
143
- }
144
- }
145
- function __values(o) {
146
- var s = typeof Symbol === "function" && Symbol.iterator,
147
- m = s && o[s],
148
- i = 0;
149
- if (m) return m.call(o);
150
- if (o && typeof o.length === "number") return {
151
- next: function () {
152
- if (o && i >= o.length) o = void 0;
153
- return {
154
- value: o && o[i++],
155
- done: !o
156
- };
157
- }
158
- };
159
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
160
- }
161
40
  function getIDEPropsPropertyObj(target, propertyKey) {
162
41
  if (!target.constructor.IDEProps) {
163
42
  target.constructor.IDEProps = {};
@@ -175,28 +54,24 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
175
54
  prop.type = type;
176
55
  };
177
56
  }
178
- var Sprite$3 = function (_super) {
179
- __extends(Sprite, _super);
180
- function Sprite() {
181
- var _this = _super !== null && _super.apply(this, arguments) || this;
182
- _this.resource = '';
183
- _this.spriteName = '';
184
- return _this;
57
+ class Sprite$3 extends eva_js.Component {
58
+ constructor() {
59
+ super(...arguments);
60
+ this.resource = '';
61
+ this.spriteName = '';
185
62
  }
186
- Sprite.prototype.init = function (obj) {
63
+ init(obj) {
187
64
  if (obj && obj.resource) {
188
65
  this.resource = obj.resource;
189
66
  this.spriteName = obj.spriteName;
190
67
  }
191
- };
192
- Sprite.componentName = 'Sprite';
193
- __decorate([type('string')], Sprite.prototype, "resource", void 0);
194
- __decorate([type('string')], Sprite.prototype, "spriteName", void 0);
195
- return Sprite;
196
- }(eva_js.Component);
197
- var Sprite$4 = Sprite$3;
198
- var Sprite$2 = function () {
199
- function Sprite(image) {
68
+ }
69
+ }
70
+ Sprite$3.componentName = 'Sprite';
71
+ __decorate([type('string')], Sprite$3.prototype, "resource", void 0);
72
+ __decorate([type('string')], Sprite$3.prototype, "spriteName", void 0);
73
+ class Sprite$2 {
74
+ constructor(image) {
200
75
  this._image = null;
201
76
  this._image = image;
202
77
  if (image) {
@@ -209,163 +84,131 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
209
84
  this.sprite = new pixi_js.Sprite();
210
85
  }
211
86
  }
212
- Object.defineProperty(Sprite.prototype, "image", {
213
- get: function () {
214
- return this._image;
215
- },
216
- set: function (val) {
217
- if (this._image === val) {
218
- return;
219
- }
220
- if (val instanceof HTMLImageElement) {
221
- this.sprite.texture && this.sprite.texture.destroy(false);
222
- this.sprite.texture = pixi_js.Texture.from(val);
223
- } else if (val instanceof pixi_js.Texture) {
224
- this.sprite.texture = val;
225
- }
226
- this._image = val;
227
- },
228
- enumerable: false,
229
- configurable: true
230
- });
231
- return Sprite;
232
- }();
233
- var SpriteEngine = Sprite$2;
234
- var resourceKeySplit = '_s|r|c_';
235
- eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
236
- var name = _a.name,
237
- data = _a.data;
238
- return new Promise(function (r) {
239
- var e_1, _a;
240
- var textureObj = data.json.data;
241
- var texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
242
- var frames = textureObj.frames || {};
243
- var animations = textureObj.animations || {};
244
- var newFrames = {};
245
- for (var key in frames) {
246
- var newKey = name + resourceKeySplit + key;
87
+ set image(val) {
88
+ if (this._image === val) {
89
+ return;
90
+ }
91
+ if (val instanceof HTMLImageElement) {
92
+ this.sprite.texture && this.sprite.texture.destroy(false);
93
+ this.sprite.texture = pixi_js.Texture.from(val);
94
+ } else if (val instanceof pixi_js.Texture) {
95
+ this.sprite.texture = val;
96
+ }
97
+ this._image = val;
98
+ }
99
+ get image() {
100
+ return this._image;
101
+ }
102
+ }
103
+ const resourceKeySplit = '_s|r|c_';
104
+ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, ({
105
+ name,
106
+ data
107
+ }) => {
108
+ return new Promise(r => {
109
+ const textureObj = data.json.data;
110
+ const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
111
+ const frames = textureObj.frames || {};
112
+ const animations = textureObj.animations || {};
113
+ const newFrames = {};
114
+ for (const key in frames) {
115
+ const newKey = name + resourceKeySplit + key;
247
116
  newFrames[newKey] = frames[key];
248
117
  }
249
- for (var key in animations) {
250
- var spriteList = [];
118
+ for (const key in animations) {
119
+ const spriteList = [];
251
120
  if (animations[key] && animations[key].length >= 0) {
252
- try {
253
- for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
254
- var spriteName = _c.value;
255
- var newSpriteName = name + resourceKeySplit + spriteName;
256
- spriteList.push(newSpriteName);
257
- }
258
- } catch (e_1_1) {
259
- e_1 = {
260
- error: e_1_1
261
- };
262
- } finally {
263
- try {
264
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
265
- } finally {
266
- if (e_1) throw e_1.error;
267
- }
121
+ for (const spriteName of animations[key]) {
122
+ const newSpriteName = name + resourceKeySplit + spriteName;
123
+ spriteList.push(newSpriteName);
268
124
  }
269
125
  }
270
126
  animations[key] = spriteList;
271
127
  }
272
128
  textureObj.frames = newFrames;
273
- var spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
274
- spriteSheet.parse().then(function () {
129
+ const spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
130
+ spriteSheet.parse().then(() => {
275
131
  r(spriteSheet.textures);
276
132
  });
277
133
  });
278
134
  });
279
- eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
280
- var instance = _a.instance;
135
+ eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE, ({
136
+ instance
137
+ }) => {
281
138
  if (!instance) return;
282
- for (var key in instance) {
139
+ for (const key in instance) {
283
140
  instance[key].destroy(true);
284
141
  }
285
142
  });
286
- var Sprite = function (_super) {
287
- __extends(Sprite, _super);
288
- function Sprite() {
289
- var _this = _super !== null && _super.apply(this, arguments) || this;
290
- _this.name = 'Sprite';
291
- _this.sprites = {};
292
- return _this;
143
+ let Sprite = class Sprite extends pluginRenderer.Renderer {
144
+ constructor() {
145
+ super(...arguments);
146
+ this.name = 'Sprite';
147
+ this.sprites = {};
293
148
  }
294
- Sprite.prototype.init = function () {
149
+ init() {
295
150
  this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
296
151
  this.renderSystem.rendererManager.register(this);
297
- };
298
- Sprite.prototype.rendererUpdate = function (gameObject) {
299
- var _a = gameObject.transform.size,
300
- width = _a.width,
301
- height = _a.height;
152
+ }
153
+ rendererUpdate(gameObject) {
154
+ const {
155
+ width,
156
+ height
157
+ } = gameObject.transform.size;
302
158
  if (this.sprites[gameObject.id]) {
303
159
  this.sprites[gameObject.id].sprite.width = width;
304
160
  this.sprites[gameObject.id].sprite.height = height;
305
161
  }
306
- };
307
- Sprite.prototype.componentChanged = function (changed) {
308
- return __awaiter(this, void 0, void 0, function () {
309
- var gameObjectId, component, sprite, asyncId, instance, asyncId, instance, sprite;
310
- return __generator(this, function (_a) {
311
- switch (_a.label) {
312
- case 0:
313
- if (!(changed.componentName === 'Sprite')) return [3, 5];
314
- gameObjectId = changed.gameObject.id;
315
- component = changed.component;
316
- if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 2];
317
- sprite = new SpriteEngine(null);
318
- this.sprites[changed.gameObject.id] = sprite;
319
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite.sprite, 0);
320
- asyncId = this.increaseAsyncId(gameObjectId);
321
- return [4, eva_js.resource.getResource(component.resource)];
322
- case 1:
323
- instance = _a.sent().instance;
324
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
325
- if (!instance) {
326
- console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
327
- return [2];
328
- }
329
- sprite.image = instance[component.resource + resourceKeySplit + component.spriteName];
330
- return [3, 5];
331
- case 2:
332
- if (!(changed.type === eva_js.OBSERVER_TYPE.CHANGE)) return [3, 4];
333
- asyncId = this.increaseAsyncId(gameObjectId);
334
- return [4, eva_js.resource.getResource(component.resource)];
335
- case 3:
336
- instance = _a.sent().instance;
337
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
338
- if (!instance) {
339
- console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
340
- return [2];
341
- }
342
- this.sprites[changed.gameObject.id].image = instance[component.resource + resourceKeySplit + component.spriteName];
343
- return [3, 5];
344
- case 4:
345
- if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
346
- this.increaseAsyncId(gameObjectId);
347
- sprite = this.sprites[changed.gameObject.id];
348
- this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
349
- sprite.sprite.destroy({
350
- children: true
351
- });
352
- delete this.sprites[changed.gameObject.id];
353
- }
354
- _a.label = 5;
355
- case 5:
356
- return [2];
162
+ }
163
+ componentChanged(changed) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ if (changed.componentName === 'Sprite') {
166
+ const gameObjectId = changed.gameObject.id;
167
+ const component = changed.component;
168
+ if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
169
+ const sprite = new Sprite$2(null);
170
+ this.sprites[changed.gameObject.id] = sprite;
171
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite.sprite, 0);
172
+ const asyncId = this.increaseAsyncId(gameObjectId);
173
+ const {
174
+ instance
175
+ } = yield eva_js.resource.getResource(component.resource);
176
+ if (!this.validateAsyncId(gameObjectId, asyncId)) return;
177
+ if (!instance) {
178
+ console.error(`GameObject:${changed.gameObject.name}'s Sprite resource load error`);
179
+ return;
180
+ }
181
+ sprite.image = instance[component.resource + resourceKeySplit + component.spriteName];
182
+ } else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
183
+ const asyncId = this.increaseAsyncId(gameObjectId);
184
+ const {
185
+ instance
186
+ } = yield eva_js.resource.getResource(component.resource);
187
+ if (!this.validateAsyncId(gameObjectId, asyncId)) return;
188
+ if (!instance) {
189
+ console.error(`GameObject:${changed.gameObject.name}'s Sprite resource load error`);
190
+ return;
191
+ }
192
+ this.sprites[changed.gameObject.id].image = instance[component.resource + resourceKeySplit + component.spriteName];
193
+ } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
194
+ this.increaseAsyncId(gameObjectId);
195
+ const sprite = this.sprites[changed.gameObject.id];
196
+ this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
197
+ sprite.sprite.destroy({
198
+ children: true
199
+ });
200
+ delete this.sprites[changed.gameObject.id];
357
201
  }
358
- });
202
+ }
359
203
  });
360
- };
361
- Sprite.systemName = 'Sprite';
362
- Sprite = __decorate([eva_js.decorators.componentObserver({
363
- Sprite: ['spriteName']
364
- })], Sprite);
365
- return Sprite;
366
- }(pluginRenderer.Renderer);
204
+ }
205
+ };
206
+ Sprite.systemName = 'Sprite';
207
+ Sprite = __decorate([eva_js.decorators.componentObserver({
208
+ Sprite: ['spriteName']
209
+ })], Sprite);
367
210
  var Sprite$1 = Sprite;
368
- exports.Sprite = Sprite$4;
211
+ exports.Sprite = Sprite$3;
369
212
  exports.SpriteSystem = Sprite$1;
370
213
  Object.defineProperty(exports, '__esModule', {
371
214
  value: true
@@ -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)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,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){var t;e.done?i(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 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&&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.")}function p(e){return function(t,r){var n=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,r);n.key=r,n.type=e}}var l=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([p("string")],t.prototype,"resource",void 0),s([p("string")],t.prototype,"spriteName",void 0),t}(t.Component),f=l,d=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=d,m="_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,s=r.json.data,a=r.image instanceof n.Texture?r.image:n.Texture.from(r.image),c=s.frames||{},p=s.animations||{},l={};for(var f in c){l[t+m+f]=c[f]}for(var f in p){var d=[];if(p[f]&&p[f].length>=0)try{for(var h=(i=void 0,u(p[f])),y=h.next();!y.done;y=h.next()){var g=y.value,v=t+m+g;d.push(v)}}catch(e){i={error:e}}finally{try{y&&!y.done&&(o=h.return)&&o.call(h)}finally{if(i)throw i.error}}p[f]=d}s.frames=l;var b=new n.Spritesheet(a,s);b.parse().then((function(){e(b.textures)}))}))})),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 y=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 a(this,void 0,void 0,(function(){var r,n,i,o,s;return c(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 h(null),this.sprites[e.gameObject.id]=s,this.containerManager.getContainer(e.gameObject.id).addChildAt(s.sprite,0),i=this.increaseAsyncId(r),[4,t.resource.getResource(n.resource)]));case 1:return o=a.sent().instance,this.validateAsyncId(r,i)?o?(s.image=o[n.resource+m+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=a.sent().instance,this.validateAsyncId(r,i)?o?(this.sprites[e.gameObject.id].image=o[n.resource+m+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=s([t.decorators.componentObserver({Sprite:["spriteName"]})],n)}(r.Renderer),g=y;return e.Sprite=f,e.SpriteSystem=g,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,i){"use strict";function s(e,t,r,i){var s,n=arguments.length,o=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,i);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(o=(n<3?s(o):n>3?s(t,r,o):s(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}function n(e,t,r,i){return new(r||(r=Promise))((function(s,n){function o(e){try{a(i.next(e))}catch(e){n(e)}}function c(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,c)}a((i=i.apply(e,t||[])).next())}))}function o(e){return function(t,r){var i=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,r);i.key=r,i.type=e}}class c extends t.Component{constructor(){super(...arguments),this.resource="",this.spriteName=""}init(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)}}c.componentName="Sprite",s([o("string")],c.prototype,"resource",void 0),s([o("string")],c.prototype,"spriteName",void 0);class a{constructor(e){this._image=null,this._image=e,e?e instanceof HTMLImageElement?this.sprite=i.Sprite.from(e):e instanceof i.Texture&&(this.sprite=new i.Sprite(e)):this.sprite=new i.Sprite}set image(e){this._image!==e&&(e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=i.Texture.from(e)):e instanceof i.Texture&&(this.sprite.texture=e),this._image=e)}get image(){return this._image}}const p="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE,(({name:e,data:t})=>new Promise((r=>{const s=t.json.data,n=t.image instanceof i.Texture?t.image:i.Texture.from(t.image),o=s.frames||{},c=s.animations||{},a={};for(const t in o){a[e+p+t]=o[t]}for(const t in c){const r=[];if(c[t]&&c[t].length>=0)for(const i of c[t]){const t=e+p+i;r.push(t)}c[t]=r}s.frames=a;const u=new i.Spritesheet(n,s);u.parse().then((()=>{r(u.textures)}))})))),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE,(({instance:e})=>{if(e)for(const t in e)e[t].destroy(!0)}));let u=class extends r.Renderer{constructor(){super(...arguments),this.name="Sprite",this.sprites={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:r}=e.transform.size;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=t,this.sprites[e.id].sprite.height=r)}componentChanged(e){return n(this,void 0,void 0,(function*(){if("Sprite"===e.componentName){const r=e.gameObject.id,i=e.component;if(e.type===t.OBSERVER_TYPE.ADD){const s=new a(null);this.sprites[e.gameObject.id]=s,this.containerManager.getContainer(e.gameObject.id).addChildAt(s.sprite,0);const n=this.increaseAsyncId(r),{instance:o}=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(r,n))return;if(!o)return void console.error(`GameObject:${e.gameObject.name}'s Sprite resource load error`);s.image=o[i.resource+p+i.spriteName]}else if(e.type===t.OBSERVER_TYPE.CHANGE){const s=this.increaseAsyncId(r),{instance:n}=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(r,s))return;if(!n)return void console.error(`GameObject:${e.gameObject.name}'s Sprite resource load error`);this.sprites[e.gameObject.id].image=n[i.resource+p+i.spriteName]}else if(e.type===t.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(r);const t=this.sprites[e.gameObject.id];this.containerManager.getContainer(e.gameObject.id).removeChild(t.sprite),t.sprite.destroy({children:!0}),delete this.sprites[e.gameObject.id]}}}))}};u.systemName="Sprite",u=s([t.decorators.componentObserver({Sprite:["spriteName"]})],u);var d=u;return e.Sprite=c,e.SpriteSystem=d,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;
@@ -21,20 +21,6 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
21
21
  See the Apache Version 2.0 License for specific language governing permissions
22
22
  and limitations under the License.
23
23
  ***************************************************************************** */
24
- /* global Reflect, Promise */
25
-
26
- var extendStatics = function(d, b) {
27
- extendStatics = Object.setPrototypeOf ||
28
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
30
- return extendStatics(d, b);
31
- };
32
-
33
- function __extends(d, b) {
34
- extendStatics(d, b);
35
- function __() { this.constructor = d; }
36
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
37
- }
38
24
 
39
25
  function __decorate(decorators, target, key, desc) {
40
26
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -50,74 +36,31 @@ function __awaiter(thisArg, _arguments, P, generator) {
50
36
  function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
51
37
  step((generator = generator.apply(thisArg, _arguments || [])).next());
52
38
  });
53
- }
54
-
55
- function __generator(thisArg, body) {
56
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
57
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
58
- function verb(n) { return function (v) { return step([n, v]); }; }
59
- function step(op) {
60
- if (f) throw new TypeError("Generator is already executing.");
61
- while (_) try {
62
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
63
- if (y = 0, t) op = [op[0] & 2, t.value];
64
- switch (op[0]) {
65
- case 0: case 1: t = op; break;
66
- case 4: _.label++; return { value: op[1], done: false };
67
- case 5: _.label++; y = op[1]; op = [0]; continue;
68
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
69
- default:
70
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
71
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
72
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
73
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
74
- if (t[2]) _.ops.pop();
75
- _.trys.pop(); continue;
76
- }
77
- op = body.call(thisArg, _);
78
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
79
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
80
- }
81
- }
82
-
83
- function __values(o) {
84
- var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
85
- if (m) return m.call(o);
86
- return {
87
- next: function () {
88
- if (o && i >= o.length) o = void 0;
89
- return { value: o && o[i++], done: !o };
90
- }
91
- };
92
39
  }
93
40
 
94
- var Sprite$3 = (function (_super) {
95
- __extends(Sprite, _super);
96
- function Sprite() {
97
- var _this = _super !== null && _super.apply(this, arguments) || this;
98
- _this.resource = '';
99
- _this.spriteName = '';
100
- return _this;
41
+ class Sprite$3 extends eva_js.Component {
42
+ constructor() {
43
+ super(...arguments);
44
+ this.resource = '';
45
+ this.spriteName = '';
101
46
  }
102
- Sprite.prototype.init = function (obj) {
47
+ init(obj) {
103
48
  if (obj && obj.resource) {
104
49
  this.resource = obj.resource;
105
50
  this.spriteName = obj.spriteName;
106
51
  }
107
- };
108
- Sprite.componentName = 'Sprite';
109
- __decorate([
110
- inspectorDecorator.type('string')
111
- ], Sprite.prototype, "resource", void 0);
112
- __decorate([
113
- inspectorDecorator.type('string')
114
- ], Sprite.prototype, "spriteName", void 0);
115
- return Sprite;
116
- }(eva_js.Component));
117
- var Sprite$4 = Sprite$3;
52
+ }
53
+ }
54
+ Sprite$3.componentName = 'Sprite';
55
+ __decorate([
56
+ inspectorDecorator.type('string')
57
+ ], Sprite$3.prototype, "resource", void 0);
58
+ __decorate([
59
+ inspectorDecorator.type('string')
60
+ ], Sprite$3.prototype, "spriteName", void 0);
118
61
 
119
- var Sprite$2 = (function () {
120
- function Sprite(image) {
62
+ class Sprite$2 {
63
+ constructor(image) {
121
64
  this._image = null;
122
65
  this._image = image;
123
66
  if (image) {
@@ -132,161 +75,126 @@ var Sprite$2 = (function () {
132
75
  this.sprite = new pixi_js.Sprite();
133
76
  }
134
77
  }
135
- Object.defineProperty(Sprite.prototype, "image", {
136
- get: function () {
137
- return this._image;
138
- },
139
- set: function (val) {
140
- if (this._image === val) {
141
- return;
142
- }
143
- if (val instanceof HTMLImageElement) {
144
- this.sprite.texture && this.sprite.texture.destroy(false);
145
- this.sprite.texture = pixi_js.Texture.from(val);
146
- }
147
- else if (val instanceof pixi_js.Texture) {
148
- this.sprite.texture = val;
149
- }
150
- this._image = val;
151
- },
152
- enumerable: false,
153
- configurable: true
154
- });
155
- return Sprite;
156
- }());
157
- var SpriteEngine = Sprite$2;
78
+ set image(val) {
79
+ if (this._image === val) {
80
+ return;
81
+ }
82
+ if (val instanceof HTMLImageElement) {
83
+ this.sprite.texture && this.sprite.texture.destroy(false);
84
+ this.sprite.texture = pixi_js.Texture.from(val);
85
+ }
86
+ else if (val instanceof pixi_js.Texture) {
87
+ this.sprite.texture = val;
88
+ }
89
+ this._image = val;
90
+ }
91
+ get image() {
92
+ return this._image;
93
+ }
94
+ }
158
95
 
159
- var resourceKeySplit = '_s|r|c_';
160
- eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
161
- var name = _a.name, data = _a.data;
162
- return new Promise(function (r) {
163
- var e_1, _a;
164
- var textureObj = data.json.data;
165
- var texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
166
- var frames = textureObj.frames || {};
167
- var animations = textureObj.animations || {};
168
- var newFrames = {};
169
- for (var key in frames) {
170
- var newKey = name + resourceKeySplit + key;
96
+ const resourceKeySplit = '_s|r|c_';
97
+ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, ({ name, data }) => {
98
+ return new Promise(r => {
99
+ const textureObj = data.json.data;
100
+ const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
101
+ const frames = textureObj.frames || {};
102
+ const animations = textureObj.animations || {};
103
+ const newFrames = {};
104
+ for (const key in frames) {
105
+ const newKey = name + resourceKeySplit + key;
171
106
  newFrames[newKey] = frames[key];
172
107
  }
173
- for (var key in animations) {
174
- var spriteList = [];
108
+ for (const key in animations) {
109
+ const spriteList = [];
175
110
  if (animations[key] && animations[key].length >= 0) {
176
- try {
177
- for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
178
- var spriteName = _c.value;
179
- var newSpriteName = name + resourceKeySplit + spriteName;
180
- spriteList.push(newSpriteName);
181
- }
182
- }
183
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
184
- finally {
185
- try {
186
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
187
- }
188
- finally { if (e_1) throw e_1.error; }
111
+ for (const spriteName of animations[key]) {
112
+ const newSpriteName = name + resourceKeySplit + spriteName;
113
+ spriteList.push(newSpriteName);
189
114
  }
190
115
  }
191
116
  animations[key] = spriteList;
192
117
  }
193
118
  textureObj.frames = newFrames;
194
- var spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
195
- spriteSheet.parse().then(function () {
119
+ const spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
120
+ spriteSheet.parse().then(() => {
196
121
  r(spriteSheet.textures);
197
122
  });
198
123
  });
199
124
  });
200
- eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
201
- var instance = _a.instance;
125
+ eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE, ({ instance }) => {
202
126
  if (!instance)
203
127
  return;
204
- for (var key in instance) {
128
+ for (const key in instance) {
205
129
  instance[key].destroy(true);
206
130
  }
207
131
  });
208
- var Sprite = (function (_super) {
209
- __extends(Sprite, _super);
210
- function Sprite() {
211
- var _this = _super !== null && _super.apply(this, arguments) || this;
212
- _this.name = 'Sprite';
213
- _this.sprites = {};
214
- return _this;
132
+ let Sprite = class Sprite extends pluginRenderer.Renderer {
133
+ constructor() {
134
+ super(...arguments);
135
+ this.name = 'Sprite';
136
+ this.sprites = {};
215
137
  }
216
- Sprite.prototype.init = function () {
138
+ init() {
217
139
  this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
218
140
  this.renderSystem.rendererManager.register(this);
219
- };
220
- Sprite.prototype.rendererUpdate = function (gameObject) {
221
- var _a = gameObject.transform.size, width = _a.width, height = _a.height;
141
+ }
142
+ rendererUpdate(gameObject) {
143
+ const { width, height } = gameObject.transform.size;
222
144
  if (this.sprites[gameObject.id]) {
223
145
  this.sprites[gameObject.id].sprite.width = width;
224
146
  this.sprites[gameObject.id].sprite.height = height;
225
147
  }
226
- };
227
- Sprite.prototype.componentChanged = function (changed) {
228
- return __awaiter(this, void 0, void 0, function () {
229
- var gameObjectId, component, sprite, asyncId, instance, asyncId, instance, sprite;
230
- return __generator(this, function (_a) {
231
- switch (_a.label) {
232
- case 0:
233
- if (!(changed.componentName === 'Sprite')) return [3, 5];
234
- gameObjectId = changed.gameObject.id;
235
- component = changed.component;
236
- if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 2];
237
- sprite = new SpriteEngine(null);
238
- this.sprites[changed.gameObject.id] = sprite;
239
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite.sprite, 0);
240
- asyncId = this.increaseAsyncId(gameObjectId);
241
- return [4, eva_js.resource.getResource(component.resource)];
242
- case 1:
243
- instance = (_a.sent()).instance;
244
- if (!this.validateAsyncId(gameObjectId, asyncId))
245
- return [2];
246
- if (!instance) {
247
- console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
248
- return [2];
249
- }
250
- sprite.image = instance[component.resource + resourceKeySplit + component.spriteName];
251
- return [3, 5];
252
- case 2:
253
- if (!(changed.type === eva_js.OBSERVER_TYPE.CHANGE)) return [3, 4];
254
- asyncId = this.increaseAsyncId(gameObjectId);
255
- return [4, eva_js.resource.getResource(component.resource)];
256
- case 3:
257
- instance = (_a.sent()).instance;
258
- if (!this.validateAsyncId(gameObjectId, asyncId))
259
- return [2];
260
- if (!instance) {
261
- console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
262
- return [2];
263
- }
264
- this.sprites[changed.gameObject.id].image =
265
- instance[component.resource + resourceKeySplit + component.spriteName];
266
- return [3, 5];
267
- case 4:
268
- if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
269
- this.increaseAsyncId(gameObjectId);
270
- sprite = this.sprites[changed.gameObject.id];
271
- this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
272
- sprite.sprite.destroy({ children: true });
273
- delete this.sprites[changed.gameObject.id];
274
- }
275
- _a.label = 5;
276
- case 5: return [2];
148
+ }
149
+ componentChanged(changed) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ if (changed.componentName === 'Sprite') {
152
+ const gameObjectId = changed.gameObject.id;
153
+ const component = changed.component;
154
+ if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
155
+ const sprite = new Sprite$2(null);
156
+ this.sprites[changed.gameObject.id] = sprite;
157
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite.sprite, 0);
158
+ const asyncId = this.increaseAsyncId(gameObjectId);
159
+ const { instance } = yield eva_js.resource.getResource(component.resource);
160
+ if (!this.validateAsyncId(gameObjectId, asyncId))
161
+ return;
162
+ if (!instance) {
163
+ console.error(`GameObject:${changed.gameObject.name}'s Sprite resource load error`);
164
+ return;
165
+ }
166
+ sprite.image = instance[component.resource + resourceKeySplit + component.spriteName];
167
+ }
168
+ else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
169
+ const asyncId = this.increaseAsyncId(gameObjectId);
170
+ const { instance } = yield eva_js.resource.getResource(component.resource);
171
+ if (!this.validateAsyncId(gameObjectId, asyncId))
172
+ return;
173
+ if (!instance) {
174
+ console.error(`GameObject:${changed.gameObject.name}'s Sprite resource load error`);
175
+ return;
176
+ }
177
+ this.sprites[changed.gameObject.id].image =
178
+ instance[component.resource + resourceKeySplit + component.spriteName];
277
179
  }
278
- });
180
+ else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
181
+ this.increaseAsyncId(gameObjectId);
182
+ const sprite = this.sprites[changed.gameObject.id];
183
+ this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
184
+ sprite.sprite.destroy({ children: true });
185
+ delete this.sprites[changed.gameObject.id];
186
+ }
187
+ }
279
188
  });
280
- };
281
- Sprite.systemName = 'Sprite';
282
- Sprite = __decorate([
283
- eva_js.decorators.componentObserver({
284
- Sprite: ['spriteName'],
285
- })
286
- ], Sprite);
287
- return Sprite;
288
- }(pluginRenderer.Renderer));
189
+ }
190
+ };
191
+ Sprite.systemName = 'Sprite';
192
+ Sprite = __decorate([
193
+ eva_js.decorators.componentObserver({
194
+ Sprite: ['spriteName'],
195
+ })
196
+ ], Sprite);
289
197
  var Sprite$1 = Sprite;
290
198
 
291
- exports.Sprite = Sprite$4;
199
+ exports.Sprite = Sprite$3;
292
200
  exports.SpriteSystem = Sprite$1;
@@ -1 +1,16 @@
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){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 c(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 u=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.type("string")],r.prototype,"resource",void 0),s([t.type("string")],r.prototype,"spriteName",void 0),r}(e.Component),p=u,l=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}(),f=l,h="_s|r|c_";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.data,a=r.image instanceof n.Texture?r.image:n.Texture.from(r.image),u=s.frames||{},p=s.animations||{},l={};for(var f in u){l[t+h+f]=u[f]}for(var f in p){var m=[];if(p[f]&&p[f].length>=0)try{for(var d=(i=void 0,c(p[f])),y=d.next();!y.done;y=d.next()){var g=y.value,v=t+h+g;m.push(v)}}catch(e){i={error:e}}finally{try{y&&!y.done&&(o=d.return)&&o.call(d)}finally{if(i)throw i.error}}p[f]=m}s.frames=l;var b=new n.Spritesheet(a,s);b.parse().then((function(){e(b.textures)}))}))})),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 m=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 a(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 f(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+h+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+h+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=p,exports.SpriteSystem=m;
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"),s=require("pixi.js");
2
+ /*! *****************************************************************************
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
5
+ this file except in compliance with the License. You may obtain a copy of the
6
+ License at http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11
+ MERCHANTABLITY OR NON-INFRINGEMENT.
12
+
13
+ See the Apache Version 2.0 License for specific language governing permissions
14
+ and limitations under the License.
15
+ ***************************************************************************** */
16
+ function i(e,t,r,s){var i,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var c=e.length-1;c>=0;c--)(i=e[c])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}class n extends e.Component{constructor(){super(...arguments),this.resource="",this.spriteName=""}init(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)}}n.componentName="Sprite",i([t.type("string")],n.prototype,"resource",void 0),i([t.type("string")],n.prototype,"spriteName",void 0);class o{constructor(e){this._image=null,this._image=e,e?e instanceof HTMLImageElement?this.sprite=s.Sprite.from(e):e instanceof s.Texture&&(this.sprite=new s.Sprite(e)):this.sprite=new s.Sprite}set image(e){this._image!==e&&(e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=s.Texture.from(e)):e instanceof s.Texture&&(this.sprite.texture=e),this._image=e)}get image(){return this._image}}const c="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE,(({name:e,data:t})=>new Promise((r=>{const i=t.json.data,n=t.image instanceof s.Texture?t.image:s.Texture.from(t.image),o=i.frames||{},a=i.animations||{},p={};for(const t in o){p[e+c+t]=o[t]}for(const t in a){const r=[];if(a[t]&&a[t].length>=0)for(const s of a[t]){const t=e+c+s;r.push(t)}a[t]=r}i.frames=p;const m=new s.Spritesheet(n,i);m.parse().then((()=>{r(m.textures)}))})))),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE,(({instance:e})=>{if(e)for(const t in e)e[t].destroy(!0)}));let a=class extends r.Renderer{constructor(){super(...arguments),this.name="Sprite",this.sprites={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:r}=e.transform.size;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=t,this.sprites[e.id].sprite.height=r)}componentChanged(t){return r=this,s=void 0,n=function*(){if("Sprite"===t.componentName){const r=t.gameObject.id,s=t.component;if(t.type===e.OBSERVER_TYPE.ADD){const i=new o(null);this.sprites[t.gameObject.id]=i,this.containerManager.getContainer(t.gameObject.id).addChildAt(i.sprite,0);const n=this.increaseAsyncId(r),{instance:a}=yield e.resource.getResource(s.resource);if(!this.validateAsyncId(r,n))return;if(!a)return void console.error(`GameObject:${t.gameObject.name}'s Sprite resource load error`);i.image=a[s.resource+c+s.spriteName]}else if(t.type===e.OBSERVER_TYPE.CHANGE){const i=this.increaseAsyncId(r),{instance:n}=yield e.resource.getResource(s.resource);if(!this.validateAsyncId(r,i))return;if(!n)return void console.error(`GameObject:${t.gameObject.name}'s Sprite resource load error`);this.sprites[t.gameObject.id].image=n[s.resource+c+s.spriteName]}else if(t.type===e.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(r);const e=this.sprites[t.gameObject.id];this.containerManager.getContainer(t.gameObject.id).removeChild(e.sprite),e.sprite.destroy({children:!0}),delete this.sprites[t.gameObject.id]}}},new((i=void 0)||(i=Promise))((function(e,t){function o(e){try{a(n.next(e))}catch(e){t(e)}}function c(e){try{a(n.throw(e))}catch(e){t(e)}}function a(t){t.done?e(t.value):new i((function(e){e(t.value)})).then(o,c)}a((n=n.apply(r,s||[])).next())}));var r,s,i,n}};a.systemName="Sprite",a=i([e.decorators.componentObserver({Sprite:["spriteName"]})],a);var p=a;exports.Sprite=n,exports.SpriteSystem=p;
@@ -1,7 +1,7 @@
1
1
  import { Component, resource, RESOURCE_TYPE, decorators, OBSERVER_TYPE } from '@eva/eva.js';
2
2
  import { type } from '@eva/inspector-decorator';
3
- import { RendererSystem, Renderer } from '@eva/plugin-renderer';
4
- import { Sprite as Sprite$5, Texture, Spritesheet } from 'pixi.js';
3
+ import { Renderer, RendererSystem } from '@eva/plugin-renderer';
4
+ import { Sprite as Sprite$4, Texture, Spritesheet } from 'pixi.js';
5
5
 
6
6
  /*! *****************************************************************************
7
7
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -17,20 +17,6 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
17
17
  See the Apache Version 2.0 License for specific language governing permissions
18
18
  and limitations under the License.
19
19
  ***************************************************************************** */
20
- /* global Reflect, Promise */
21
-
22
- var extendStatics = function(d, b) {
23
- extendStatics = Object.setPrototypeOf ||
24
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
26
- return extendStatics(d, b);
27
- };
28
-
29
- function __extends(d, b) {
30
- extendStatics(d, b);
31
- function __() { this.constructor = d; }
32
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
33
- }
34
20
 
35
21
  function __decorate(decorators, target, key, desc) {
36
22
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -46,242 +32,164 @@ function __awaiter(thisArg, _arguments, P, generator) {
46
32
  function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
47
33
  step((generator = generator.apply(thisArg, _arguments || [])).next());
48
34
  });
49
- }
50
-
51
- function __generator(thisArg, body) {
52
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
53
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
54
- function verb(n) { return function (v) { return step([n, v]); }; }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while (_) try {
58
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
- if (y = 0, t) op = [op[0] & 2, t.value];
60
- switch (op[0]) {
61
- case 0: case 1: t = op; break;
62
- case 4: _.label++; return { value: op[1], done: false };
63
- case 5: _.label++; y = op[1]; op = [0]; continue;
64
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
65
- default:
66
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
67
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
68
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
69
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
70
- if (t[2]) _.ops.pop();
71
- _.trys.pop(); continue;
72
- }
73
- op = body.call(thisArg, _);
74
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
75
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
76
- }
77
- }
78
-
79
- function __values(o) {
80
- var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
81
- if (m) return m.call(o);
82
- return {
83
- next: function () {
84
- if (o && i >= o.length) o = void 0;
85
- return { value: o && o[i++], done: !o };
86
- }
87
- };
88
35
  }
89
36
 
90
- var Sprite$3 = (function (_super) {
91
- __extends(Sprite, _super);
92
- function Sprite() {
93
- var _this = _super !== null && _super.apply(this, arguments) || this;
94
- _this.resource = '';
95
- _this.spriteName = '';
96
- return _this;
37
+ class Sprite$3 extends Component {
38
+ constructor() {
39
+ super(...arguments);
40
+ this.resource = '';
41
+ this.spriteName = '';
97
42
  }
98
- Sprite.prototype.init = function (obj) {
43
+ init(obj) {
99
44
  if (obj && obj.resource) {
100
45
  this.resource = obj.resource;
101
46
  this.spriteName = obj.spriteName;
102
47
  }
103
- };
104
- Sprite.componentName = 'Sprite';
105
- __decorate([
106
- type('string')
107
- ], Sprite.prototype, "resource", void 0);
108
- __decorate([
109
- type('string')
110
- ], Sprite.prototype, "spriteName", void 0);
111
- return Sprite;
112
- }(Component));
113
- var Sprite$4 = Sprite$3;
48
+ }
49
+ }
50
+ Sprite$3.componentName = 'Sprite';
51
+ __decorate([
52
+ type('string')
53
+ ], Sprite$3.prototype, "resource", void 0);
54
+ __decorate([
55
+ type('string')
56
+ ], Sprite$3.prototype, "spriteName", void 0);
114
57
 
115
- var Sprite$2 = (function () {
116
- function Sprite(image) {
58
+ class Sprite$2 {
59
+ constructor(image) {
117
60
  this._image = null;
118
61
  this._image = image;
119
62
  if (image) {
120
63
  if (image instanceof HTMLImageElement) {
121
- this.sprite = Sprite$5.from(image);
64
+ this.sprite = Sprite$4.from(image);
122
65
  }
123
66
  else if (image instanceof Texture) {
124
- this.sprite = new Sprite$5(image);
67
+ this.sprite = new Sprite$4(image);
125
68
  }
126
69
  }
127
70
  else {
128
- this.sprite = new Sprite$5();
71
+ this.sprite = new Sprite$4();
129
72
  }
130
73
  }
131
- Object.defineProperty(Sprite.prototype, "image", {
132
- get: function () {
133
- return this._image;
134
- },
135
- set: function (val) {
136
- if (this._image === val) {
137
- return;
138
- }
139
- if (val instanceof HTMLImageElement) {
140
- this.sprite.texture && this.sprite.texture.destroy(false);
141
- this.sprite.texture = Texture.from(val);
142
- }
143
- else if (val instanceof Texture) {
144
- this.sprite.texture = val;
145
- }
146
- this._image = val;
147
- },
148
- enumerable: false,
149
- configurable: true
150
- });
151
- return Sprite;
152
- }());
153
- var SpriteEngine = Sprite$2;
74
+ set image(val) {
75
+ if (this._image === val) {
76
+ return;
77
+ }
78
+ if (val instanceof HTMLImageElement) {
79
+ this.sprite.texture && this.sprite.texture.destroy(false);
80
+ this.sprite.texture = Texture.from(val);
81
+ }
82
+ else if (val instanceof Texture) {
83
+ this.sprite.texture = val;
84
+ }
85
+ this._image = val;
86
+ }
87
+ get image() {
88
+ return this._image;
89
+ }
90
+ }
154
91
 
155
- var resourceKeySplit = '_s|r|c_';
156
- resource.registerInstance(RESOURCE_TYPE.SPRITE, function (_a) {
157
- var name = _a.name, data = _a.data;
158
- return new Promise(function (r) {
159
- var e_1, _a;
160
- var textureObj = data.json.data;
161
- var texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
162
- var frames = textureObj.frames || {};
163
- var animations = textureObj.animations || {};
164
- var newFrames = {};
165
- for (var key in frames) {
166
- var newKey = name + resourceKeySplit + key;
92
+ const resourceKeySplit = '_s|r|c_';
93
+ resource.registerInstance(RESOURCE_TYPE.SPRITE, ({ name, data }) => {
94
+ return new Promise(r => {
95
+ const textureObj = data.json.data;
96
+ const texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
97
+ const frames = textureObj.frames || {};
98
+ const animations = textureObj.animations || {};
99
+ const newFrames = {};
100
+ for (const key in frames) {
101
+ const newKey = name + resourceKeySplit + key;
167
102
  newFrames[newKey] = frames[key];
168
103
  }
169
- for (var key in animations) {
170
- var spriteList = [];
104
+ for (const key in animations) {
105
+ const spriteList = [];
171
106
  if (animations[key] && animations[key].length >= 0) {
172
- try {
173
- for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
174
- var spriteName = _c.value;
175
- var newSpriteName = name + resourceKeySplit + spriteName;
176
- spriteList.push(newSpriteName);
177
- }
178
- }
179
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
180
- finally {
181
- try {
182
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
183
- }
184
- finally { if (e_1) throw e_1.error; }
107
+ for (const spriteName of animations[key]) {
108
+ const newSpriteName = name + resourceKeySplit + spriteName;
109
+ spriteList.push(newSpriteName);
185
110
  }
186
111
  }
187
112
  animations[key] = spriteList;
188
113
  }
189
114
  textureObj.frames = newFrames;
190
- var spriteSheet = new Spritesheet(texture, textureObj);
191
- spriteSheet.parse().then(function () {
115
+ const spriteSheet = new Spritesheet(texture, textureObj);
116
+ spriteSheet.parse().then(() => {
192
117
  r(spriteSheet.textures);
193
118
  });
194
119
  });
195
120
  });
196
- resource.registerDestroy(RESOURCE_TYPE.SPRITE, function (_a) {
197
- var instance = _a.instance;
121
+ resource.registerDestroy(RESOURCE_TYPE.SPRITE, ({ instance }) => {
198
122
  if (!instance)
199
123
  return;
200
- for (var key in instance) {
124
+ for (const key in instance) {
201
125
  instance[key].destroy(true);
202
126
  }
203
127
  });
204
- var Sprite = (function (_super) {
205
- __extends(Sprite, _super);
206
- function Sprite() {
207
- var _this = _super !== null && _super.apply(this, arguments) || this;
208
- _this.name = 'Sprite';
209
- _this.sprites = {};
210
- return _this;
128
+ let Sprite = class Sprite extends Renderer {
129
+ constructor() {
130
+ super(...arguments);
131
+ this.name = 'Sprite';
132
+ this.sprites = {};
211
133
  }
212
- Sprite.prototype.init = function () {
134
+ init() {
213
135
  this.renderSystem = this.game.getSystem(RendererSystem);
214
136
  this.renderSystem.rendererManager.register(this);
215
- };
216
- Sprite.prototype.rendererUpdate = function (gameObject) {
217
- var _a = gameObject.transform.size, width = _a.width, height = _a.height;
137
+ }
138
+ rendererUpdate(gameObject) {
139
+ const { width, height } = gameObject.transform.size;
218
140
  if (this.sprites[gameObject.id]) {
219
141
  this.sprites[gameObject.id].sprite.width = width;
220
142
  this.sprites[gameObject.id].sprite.height = height;
221
143
  }
222
- };
223
- Sprite.prototype.componentChanged = function (changed) {
224
- return __awaiter(this, void 0, void 0, function () {
225
- var gameObjectId, component, sprite, asyncId, instance, asyncId, instance, sprite;
226
- return __generator(this, function (_a) {
227
- switch (_a.label) {
228
- case 0:
229
- if (!(changed.componentName === 'Sprite')) return [3, 5];
230
- gameObjectId = changed.gameObject.id;
231
- component = changed.component;
232
- if (!(changed.type === OBSERVER_TYPE.ADD)) return [3, 2];
233
- sprite = new SpriteEngine(null);
234
- this.sprites[changed.gameObject.id] = sprite;
235
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite.sprite, 0);
236
- asyncId = this.increaseAsyncId(gameObjectId);
237
- return [4, resource.getResource(component.resource)];
238
- case 1:
239
- instance = (_a.sent()).instance;
240
- if (!this.validateAsyncId(gameObjectId, asyncId))
241
- return [2];
242
- if (!instance) {
243
- console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
244
- return [2];
245
- }
246
- sprite.image = instance[component.resource + resourceKeySplit + component.spriteName];
247
- return [3, 5];
248
- case 2:
249
- if (!(changed.type === OBSERVER_TYPE.CHANGE)) return [3, 4];
250
- asyncId = this.increaseAsyncId(gameObjectId);
251
- return [4, resource.getResource(component.resource)];
252
- case 3:
253
- instance = (_a.sent()).instance;
254
- if (!this.validateAsyncId(gameObjectId, asyncId))
255
- return [2];
256
- if (!instance) {
257
- console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
258
- return [2];
259
- }
260
- this.sprites[changed.gameObject.id].image =
261
- instance[component.resource + resourceKeySplit + component.spriteName];
262
- return [3, 5];
263
- case 4:
264
- if (changed.type === OBSERVER_TYPE.REMOVE) {
265
- this.increaseAsyncId(gameObjectId);
266
- sprite = this.sprites[changed.gameObject.id];
267
- this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
268
- sprite.sprite.destroy({ children: true });
269
- delete this.sprites[changed.gameObject.id];
270
- }
271
- _a.label = 5;
272
- case 5: return [2];
144
+ }
145
+ componentChanged(changed) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ if (changed.componentName === 'Sprite') {
148
+ const gameObjectId = changed.gameObject.id;
149
+ const component = changed.component;
150
+ if (changed.type === OBSERVER_TYPE.ADD) {
151
+ const sprite = new Sprite$2(null);
152
+ this.sprites[changed.gameObject.id] = sprite;
153
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite.sprite, 0);
154
+ const asyncId = this.increaseAsyncId(gameObjectId);
155
+ const { instance } = yield resource.getResource(component.resource);
156
+ if (!this.validateAsyncId(gameObjectId, asyncId))
157
+ return;
158
+ if (!instance) {
159
+ console.error(`GameObject:${changed.gameObject.name}'s Sprite resource load error`);
160
+ return;
161
+ }
162
+ sprite.image = instance[component.resource + resourceKeySplit + component.spriteName];
163
+ }
164
+ else if (changed.type === OBSERVER_TYPE.CHANGE) {
165
+ const asyncId = this.increaseAsyncId(gameObjectId);
166
+ const { instance } = yield resource.getResource(component.resource);
167
+ if (!this.validateAsyncId(gameObjectId, asyncId))
168
+ return;
169
+ if (!instance) {
170
+ console.error(`GameObject:${changed.gameObject.name}'s Sprite resource load error`);
171
+ return;
172
+ }
173
+ this.sprites[changed.gameObject.id].image =
174
+ instance[component.resource + resourceKeySplit + component.spriteName];
273
175
  }
274
- });
176
+ else if (changed.type === OBSERVER_TYPE.REMOVE) {
177
+ this.increaseAsyncId(gameObjectId);
178
+ const sprite = this.sprites[changed.gameObject.id];
179
+ this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
180
+ sprite.sprite.destroy({ children: true });
181
+ delete this.sprites[changed.gameObject.id];
182
+ }
183
+ }
275
184
  });
276
- };
277
- Sprite.systemName = 'Sprite';
278
- Sprite = __decorate([
279
- decorators.componentObserver({
280
- Sprite: ['spriteName'],
281
- })
282
- ], Sprite);
283
- return Sprite;
284
- }(Renderer));
185
+ }
186
+ };
187
+ Sprite.systemName = 'Sprite';
188
+ Sprite = __decorate([
189
+ decorators.componentObserver({
190
+ Sprite: ['spriteName'],
191
+ })
192
+ ], Sprite);
285
193
  var Sprite$1 = Sprite;
286
194
 
287
- export { Sprite$4 as Sprite, Sprite$1 as SpriteSystem };
195
+ export { Sprite$3 as Sprite, Sprite$1 as SpriteSystem };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.2",
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.0.5",
22
- "@eva/plugin-renderer": "2.0.0-beta.1",
23
- "@eva/eva.js": "2.0.0-beta.1",
22
+ "@eva/plugin-renderer": "2.0.0-beta.2",
23
+ "@eva/eva.js": "2.0.0-beta.2",
24
24
  "pixi.js": "^8.6.3"
25
25
  }
26
26
  }