@eva/plugin-renderer-img 1.2.0 → 1.2.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,352 @@
1
+ window.EVA = window.EVA || {};
2
+ window.EVA.plugin = window.EVA.plugin || {};
3
+ window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
4
+
5
+ var _EVA_IIFE_img = function (exports, eva_js, pluginRenderer, rendererAdapter, pixi_js) {
6
+ 'use strict';
7
+
8
+ var _extendStatics = function extendStatics(d, b) {
9
+ _extendStatics = Object.setPrototypeOf || {
10
+ __proto__: []
11
+ } instanceof Array && function (d, b) {
12
+ d.__proto__ = b;
13
+ } || function (d, b) {
14
+ for (var p in b) {
15
+ if (b.hasOwnProperty(p)) d[p] = b[p];
16
+ }
17
+ };
18
+
19
+ return _extendStatics(d, b);
20
+ };
21
+
22
+ function __extends(d, b) {
23
+ _extendStatics(d, b);
24
+
25
+ function __() {
26
+ this.constructor = d;
27
+ }
28
+
29
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
30
+ }
31
+
32
+ function __decorate(decorators, target, key, desc) {
33
+ var c = arguments.length,
34
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
35
+ d;
36
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
37
+ if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
38
+ }
39
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
40
+ }
41
+
42
+ function __awaiter(thisArg, _arguments, P, generator) {
43
+ function adopt(value) {
44
+ return value instanceof P ? value : new P(function (resolve) {
45
+ resolve(value);
46
+ });
47
+ }
48
+
49
+ return new (P || (P = Promise))(function (resolve, reject) {
50
+ function fulfilled(value) {
51
+ try {
52
+ step(generator.next(value));
53
+ } catch (e) {
54
+ reject(e);
55
+ }
56
+ }
57
+
58
+ function rejected(value) {
59
+ try {
60
+ step(generator["throw"](value));
61
+ } catch (e) {
62
+ reject(e);
63
+ }
64
+ }
65
+
66
+ function step(result) {
67
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
68
+ }
69
+
70
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
71
+ });
72
+ }
73
+
74
+ function __generator(thisArg, body) {
75
+ var _ = {
76
+ label: 0,
77
+ sent: function sent() {
78
+ if (t[0] & 1) throw t[1];
79
+ return t[1];
80
+ },
81
+ trys: [],
82
+ ops: []
83
+ },
84
+ f,
85
+ y,
86
+ t,
87
+ g;
88
+ return g = {
89
+ next: verb(0),
90
+ "throw": verb(1),
91
+ "return": verb(2)
92
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
93
+ return this;
94
+ }), g;
95
+
96
+ function verb(n) {
97
+ return function (v) {
98
+ return step([n, v]);
99
+ };
100
+ }
101
+
102
+ function step(op) {
103
+ if (f) throw new TypeError("Generator is already executing.");
104
+
105
+ while (_) {
106
+ try {
107
+ 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;
108
+ if (y = 0, t) op = [op[0] & 2, t.value];
109
+
110
+ switch (op[0]) {
111
+ case 0:
112
+ case 1:
113
+ t = op;
114
+ break;
115
+
116
+ case 4:
117
+ _.label++;
118
+ return {
119
+ value: op[1],
120
+ done: false
121
+ };
122
+
123
+ case 5:
124
+ _.label++;
125
+ y = op[1];
126
+ op = [0];
127
+ continue;
128
+
129
+ case 7:
130
+ op = _.ops.pop();
131
+
132
+ _.trys.pop();
133
+
134
+ continue;
135
+
136
+ default:
137
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
138
+ _ = 0;
139
+ continue;
140
+ }
141
+
142
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
143
+ _.label = op[1];
144
+ break;
145
+ }
146
+
147
+ if (op[0] === 6 && _.label < t[1]) {
148
+ _.label = t[1];
149
+ t = op;
150
+ break;
151
+ }
152
+
153
+ if (t && _.label < t[2]) {
154
+ _.label = t[2];
155
+
156
+ _.ops.push(op);
157
+
158
+ break;
159
+ }
160
+
161
+ if (t[2]) _.ops.pop();
162
+
163
+ _.trys.pop();
164
+
165
+ continue;
166
+ }
167
+
168
+ op = body.call(thisArg, _);
169
+ } catch (e) {
170
+ op = [6, e];
171
+ y = 0;
172
+ } finally {
173
+ f = t = 0;
174
+ }
175
+ }
176
+
177
+ if (op[0] & 5) throw op[1];
178
+ return {
179
+ value: op[0] ? op[1] : void 0,
180
+ done: true
181
+ };
182
+ }
183
+ }
184
+
185
+ function getIDEPropsPropertyObj(target, propertyKey) {
186
+ if (!target.constructor.IDEProps) {
187
+ target.constructor.IDEProps = {};
188
+ }
189
+
190
+ if (!target.constructor.IDEProps[propertyKey]) {
191
+ target.constructor.IDEProps[propertyKey] = {};
192
+ }
193
+
194
+ var propertyObj = target.constructor.IDEProps[propertyKey];
195
+ return propertyObj;
196
+ }
197
+
198
+ function type(type) {
199
+ return function (target, propertyKey) {
200
+ var prop = getIDEPropsPropertyObj(target, propertyKey);
201
+ prop.key = propertyKey;
202
+ prop.type = type;
203
+ };
204
+ }
205
+
206
+ var Img$2 = function (_super) {
207
+ __extends(Img, _super);
208
+
209
+ function Img() {
210
+ var _this = _super !== null && _super.apply(this, arguments) || this;
211
+
212
+ _this.resource = '';
213
+ return _this;
214
+ }
215
+
216
+ Img.prototype.init = function (obj) {
217
+ if (obj && obj.resource) {
218
+ this.resource = obj.resource;
219
+ }
220
+ };
221
+
222
+ Img.componentName = 'Img';
223
+
224
+ __decorate([type('string')], Img.prototype, "resource", void 0);
225
+
226
+ return Img;
227
+ }(eva_js.Component);
228
+
229
+ var Img$3 = Img$2;
230
+ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.IMAGE, function (_a) {
231
+ var _b = _a.data,
232
+ data = _b === void 0 ? {} : _b;
233
+ var image = data.image;
234
+
235
+ if (image) {
236
+ var texture = pixi_js.Texture.from(image);
237
+ return texture;
238
+ }
239
+
240
+ return;
241
+ });
242
+ eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.IMAGE, function (_a) {
243
+ var instance = _a.instance;
244
+
245
+ if (instance) {
246
+ instance.destroy(true);
247
+ }
248
+ });
249
+
250
+ var Img = function (_super) {
251
+ __extends(Img, _super);
252
+
253
+ function Img() {
254
+ var _this = _super !== null && _super.apply(this, arguments) || this;
255
+
256
+ _this.name = 'Img';
257
+ _this.imgs = {};
258
+ return _this;
259
+ }
260
+
261
+ Img.prototype.init = function () {
262
+ this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
263
+ this.renderSystem.rendererManager.register(this);
264
+ };
265
+
266
+ Img.prototype.rendererUpdate = function (gameObject) {
267
+ var _a = gameObject.transform.size,
268
+ width = _a.width,
269
+ height = _a.height;
270
+
271
+ if (this.imgs[gameObject.id]) {
272
+ this.imgs[gameObject.id].sprite.width = width;
273
+ this.imgs[gameObject.id].sprite.height = height;
274
+ }
275
+ };
276
+
277
+ Img.prototype.componentChanged = function (changed) {
278
+ return __awaiter(this, void 0, void 0, function () {
279
+ var component, sprite_1, instance, sprite;
280
+ return __generator(this, function (_a) {
281
+ switch (_a.label) {
282
+ case 0:
283
+ if (!(changed.componentName === 'Img')) return [3, 4];
284
+ component = changed.component;
285
+ if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 1];
286
+ sprite_1 = new rendererAdapter.Sprite(null);
287
+ eva_js.resource.getResource(component.resource).then(function (_a) {
288
+ var instance = _a.instance;
289
+
290
+ if (!instance) {
291
+ console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
292
+ }
293
+
294
+ sprite_1.image = instance;
295
+ });
296
+ this.imgs[changed.gameObject.id] = sprite_1;
297
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite_1.sprite, 0);
298
+ return [3, 4];
299
+
300
+ case 1:
301
+ if (!(changed.type === eva_js.OBSERVER_TYPE.CHANGE)) return [3, 3];
302
+ return [4, eva_js.resource.getResource(component.resource)];
303
+
304
+ case 2:
305
+ instance = _a.sent().instance;
306
+
307
+ if (!instance) {
308
+ console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
309
+ }
310
+
311
+ this.imgs[changed.gameObject.id].image = instance;
312
+ return [3, 4];
313
+
314
+ case 3:
315
+ if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
316
+ sprite = this.imgs[changed.gameObject.id];
317
+ this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
318
+ sprite.sprite.destroy({
319
+ children: true
320
+ });
321
+ delete this.imgs[changed.gameObject.id];
322
+ }
323
+
324
+ _a.label = 4;
325
+
326
+ case 4:
327
+ return [2];
328
+ }
329
+ });
330
+ });
331
+ };
332
+
333
+ Img.systemName = 'Img';
334
+ Img = __decorate([eva_js.decorators.componentObserver({
335
+ Img: [{
336
+ prop: ['resource'],
337
+ deep: false
338
+ }]
339
+ })], Img);
340
+ return Img;
341
+ }(pluginRenderer.Renderer);
342
+
343
+ var Img$1 = Img;
344
+ exports.Img = Img$3;
345
+ exports.ImgSystem = Img$1;
346
+ Object.defineProperty(exports, '__esModule', {
347
+ value: true
348
+ });
349
+ return exports;
350
+ }({}, EVA, EVA.plugin.renderer, EVA.rendererAdapter, PIXI);
351
+
352
+ window.EVA.plugin.renderer.img = window.EVA.plugin.renderer.img || _EVA_IIFE_img;
@@ -0,0 +1 @@
1
+ var _EVA_IIFE_img=function(e,t,r,n,o){"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])})(e,t)};function c(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 o,i=arguments.length,c=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(c=(i<3?o(c):i>3?o(t,r,c):o(t,r))||c);return i>3&&c&&Object.defineProperty(t,r,c),c}function a(e,t,r,n){return new(r||(r=Promise))((function(o,i){function c(e){try{a(n.next(e))}catch(e){i(e)}}function s(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(c,s)}a((n=n.apply(e,t||[])).next())}))}function u(e,t){var r,n,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;c;)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 c.label++,{value:i[1],done:!1};case 5:c.label++,n=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=t.call(e,c)}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,s])}}}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}return c(t,e),t.prototype.init=function(e){e&&e.resource&&(this.resource=e.resource)},t.componentName="Img",s([p("string")],t.prototype,"resource",void 0),t}(t.Component);t.resource.registerInstance(t.RESOURCE_TYPE.IMAGE,(function(e){var t=e.data,r=(void 0===t?{}:t).image;if(r)return o.Texture.from(r)})),t.resource.registerDestroy(t.RESOURCE_TYPE.IMAGE,(function(e){var t=e.instance;t&&t.destroy(!0)}));var f=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Img",t.imgs={},t}return c(o,e),o.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(e){var t=e.transform.size,r=t.width,n=t.height;this.imgs[e.id]&&(this.imgs[e.id].sprite.width=r,this.imgs[e.id].sprite.height=n)},o.prototype.componentChanged=function(e){return a(this,void 0,void 0,(function(){var r,o,i,c;return u(this,(function(s){switch(s.label){case 0:return"Img"!==e.componentName?[3,4]:(r=e.component,e.type!==t.OBSERVER_TYPE.ADD?[3,1]:(o=new n.Sprite(null),t.resource.getResource(r.resource).then((function(t){var r=t.instance;r||console.error("GameObject:"+e.gameObject.name+"'s Img resource load error"),o.image=r})),this.imgs[e.gameObject.id]=o,this.containerManager.getContainer(e.gameObject.id).addChildAt(o.sprite,0),[3,4]));case 1:return e.type!==t.OBSERVER_TYPE.CHANGE?[3,3]:[4,t.resource.getResource(r.resource)];case 2:return(i=s.sent().instance)||console.error("GameObject:"+e.gameObject.name+"'s Img resource load error"),this.imgs[e.gameObject.id].image=i,[3,4];case 3:e.type===t.OBSERVER_TYPE.REMOVE&&(c=this.imgs[e.gameObject.id],this.containerManager.getContainer(e.gameObject.id).removeChild(c.sprite),c.sprite.destroy({children:!0}),delete this.imgs[e.gameObject.id]),s.label=4;case 4:return[2]}}))}))},o.systemName="Img",o=s([t.decorators.componentObserver({Img:[{prop:["resource"],deep:!1}]})],o)}(r.Renderer);return e.Img=l,e.ImgSystem=f,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-img",
3
- "version": "1.2.0",
3
+ "version": "1.2.2-alpha.1",
4
4
  "description": "@eva/plugin-renderer-img",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-img.esm.js",
@@ -19,9 +19,9 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "^0.0.5",
22
- "@eva/plugin-renderer": "1.2.0",
23
- "@eva/renderer-adapter": "1.2.0",
24
- "@eva/eva.js": "1.2.0",
22
+ "@eva/plugin-renderer": "1.2.2-alpha.1",
23
+ "@eva/renderer-adapter": "1.2.2-alpha.1",
24
+ "@eva/eva.js": "1.2.2-alpha.1",
25
25
  "pixi.js": "^4.8.7"
26
26
  }
27
27
  }