@eva/plugin-renderer-sprite 1.2.0 → 1.2.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,458 @@
|
|
|
1
|
+
this.EVA = this.EVA || {};
|
|
2
|
+
this.EVA.plugin = this.EVA.plugin || {};
|
|
3
|
+
this.EVA.plugin.renderer = this.EVA.plugin.renderer || {};
|
|
4
|
+
|
|
5
|
+
this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, 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 __values(o) {
|
|
186
|
+
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
187
|
+
m = s && o[s],
|
|
188
|
+
i = 0;
|
|
189
|
+
if (m) return m.call(o);
|
|
190
|
+
if (o && typeof o.length === "number") return {
|
|
191
|
+
next: function next() {
|
|
192
|
+
if (o && i >= o.length) o = void 0;
|
|
193
|
+
return {
|
|
194
|
+
value: o && o[i++],
|
|
195
|
+
done: !o
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function getIDEPropsPropertyObj(target, propertyKey) {
|
|
203
|
+
if (!target.constructor.IDEProps) {
|
|
204
|
+
target.constructor.IDEProps = {};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (!target.constructor.IDEProps[propertyKey]) {
|
|
208
|
+
target.constructor.IDEProps[propertyKey] = {};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
var propertyObj = target.constructor.IDEProps[propertyKey];
|
|
212
|
+
return propertyObj;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function type(type) {
|
|
216
|
+
return function (target, propertyKey) {
|
|
217
|
+
var prop = getIDEPropsPropertyObj(target, propertyKey);
|
|
218
|
+
prop.key = propertyKey;
|
|
219
|
+
prop.type = type;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
var Sprite$3 = function (_super) {
|
|
224
|
+
__extends(Sprite, _super);
|
|
225
|
+
|
|
226
|
+
function Sprite() {
|
|
227
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
228
|
+
|
|
229
|
+
_this.resource = '';
|
|
230
|
+
_this.spriteName = '';
|
|
231
|
+
return _this;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
Sprite.prototype.init = function (obj) {
|
|
235
|
+
if (obj && obj.resource) {
|
|
236
|
+
this.resource = obj.resource;
|
|
237
|
+
this.spriteName = obj.spriteName;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
Sprite.componentName = 'Sprite';
|
|
242
|
+
|
|
243
|
+
__decorate([type('string')], Sprite.prototype, "resource", void 0);
|
|
244
|
+
|
|
245
|
+
__decorate([type('string')], Sprite.prototype, "spriteName", void 0);
|
|
246
|
+
|
|
247
|
+
return Sprite;
|
|
248
|
+
}(eva_js.Component);
|
|
249
|
+
|
|
250
|
+
var Sprite$4 = Sprite$3;
|
|
251
|
+
|
|
252
|
+
var Sprite$2 = function () {
|
|
253
|
+
function Sprite(image) {
|
|
254
|
+
this._image = null;
|
|
255
|
+
this._image = image;
|
|
256
|
+
|
|
257
|
+
if (image) {
|
|
258
|
+
if (image instanceof HTMLImageElement) {
|
|
259
|
+
this.sprite = pixi_js.Sprite.from(image);
|
|
260
|
+
} else if (image instanceof pixi_js.Texture) {
|
|
261
|
+
this.sprite = new pixi_js.Sprite(image);
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
this.sprite = new pixi_js.Sprite();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
Object.defineProperty(Sprite.prototype, "image", {
|
|
269
|
+
get: function get() {
|
|
270
|
+
return this._image;
|
|
271
|
+
},
|
|
272
|
+
set: function set(val) {
|
|
273
|
+
if (this._image === val) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (val instanceof HTMLImageElement) {
|
|
278
|
+
this.sprite.texture && this.sprite.texture.destroy(false);
|
|
279
|
+
this.sprite.texture = pixi_js.Texture.from(val);
|
|
280
|
+
} else if (val instanceof pixi_js.Texture) {
|
|
281
|
+
this.sprite.texture = val;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
this._image = val;
|
|
285
|
+
},
|
|
286
|
+
enumerable: false,
|
|
287
|
+
configurable: true
|
|
288
|
+
});
|
|
289
|
+
return Sprite;
|
|
290
|
+
}();
|
|
291
|
+
|
|
292
|
+
var SpriteEngine = Sprite$2;
|
|
293
|
+
var resourceKeySplit = '_s|r|c_';
|
|
294
|
+
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
|
|
295
|
+
var name = _a.name,
|
|
296
|
+
data = _a.data;
|
|
297
|
+
return new Promise(function (r) {
|
|
298
|
+
var e_1, _a;
|
|
299
|
+
|
|
300
|
+
var textureObj = data.json;
|
|
301
|
+
var texture = pixi_js.BaseTexture.from(data.image);
|
|
302
|
+
var frames = textureObj.frames || {};
|
|
303
|
+
var animations = textureObj.animations || {};
|
|
304
|
+
var newFrames = {};
|
|
305
|
+
|
|
306
|
+
for (var key in frames) {
|
|
307
|
+
var newKey = name + resourceKeySplit + key;
|
|
308
|
+
newFrames[newKey] = frames[key];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
for (var key in animations) {
|
|
312
|
+
var spriteList = [];
|
|
313
|
+
|
|
314
|
+
if (animations[key] && animations[key].length >= 0) {
|
|
315
|
+
try {
|
|
316
|
+
for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
317
|
+
var spriteName = _c.value;
|
|
318
|
+
var newSpriteName = name + resourceKeySplit + spriteName;
|
|
319
|
+
spriteList.push(newSpriteName);
|
|
320
|
+
}
|
|
321
|
+
} catch (e_1_1) {
|
|
322
|
+
e_1 = {
|
|
323
|
+
error: e_1_1
|
|
324
|
+
};
|
|
325
|
+
} finally {
|
|
326
|
+
try {
|
|
327
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
328
|
+
} finally {
|
|
329
|
+
if (e_1) throw e_1.error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
animations[key] = spriteList;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
textureObj.frames = newFrames;
|
|
338
|
+
var spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
|
|
339
|
+
spriteSheet.parse(function () {
|
|
340
|
+
var textures = spriteSheet.textures;
|
|
341
|
+
r(textures);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
|
|
346
|
+
var instance = _a.instance;
|
|
347
|
+
if (!instance) return;
|
|
348
|
+
|
|
349
|
+
for (var key in instance) {
|
|
350
|
+
instance[key].destroy(true);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
var Sprite = function (_super) {
|
|
355
|
+
__extends(Sprite, _super);
|
|
356
|
+
|
|
357
|
+
function Sprite() {
|
|
358
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
359
|
+
|
|
360
|
+
_this.name = 'Sprite';
|
|
361
|
+
_this.sprites = {};
|
|
362
|
+
return _this;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
Sprite.prototype.init = function () {
|
|
366
|
+
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
367
|
+
this.renderSystem.rendererManager.register(this);
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
Sprite.prototype.rendererUpdate = function (gameObject) {
|
|
371
|
+
var _a = gameObject.transform.size,
|
|
372
|
+
width = _a.width,
|
|
373
|
+
height = _a.height;
|
|
374
|
+
|
|
375
|
+
if (this.sprites[gameObject.id]) {
|
|
376
|
+
this.sprites[gameObject.id].sprite.width = width;
|
|
377
|
+
this.sprites[gameObject.id].sprite.height = height;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
Sprite.prototype.componentChanged = function (changed) {
|
|
382
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
383
|
+
var component_1, sprite_1, instance, sprite;
|
|
384
|
+
|
|
385
|
+
var _this = this;
|
|
386
|
+
|
|
387
|
+
return __generator(this, function (_a) {
|
|
388
|
+
switch (_a.label) {
|
|
389
|
+
case 0:
|
|
390
|
+
if (!(changed.componentName === 'Sprite')) return [3, 4];
|
|
391
|
+
component_1 = changed.component;
|
|
392
|
+
if (!(changed.type === eva_js.OBSERVER_TYPE.ADD)) return [3, 1];
|
|
393
|
+
sprite_1 = new SpriteEngine(null);
|
|
394
|
+
eva_js.resource.getResource(component_1.resource).then(function (_a) {
|
|
395
|
+
var instance = _a.instance;
|
|
396
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
397
|
+
return __generator(this, function (_b) {
|
|
398
|
+
if (!instance) {
|
|
399
|
+
throw new Error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
sprite_1.image = instance[component_1.resource + resourceKeySplit + component_1.spriteName];
|
|
403
|
+
return [2];
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
this.sprites[changed.gameObject.id] = sprite_1;
|
|
408
|
+
this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite_1.sprite, 0);
|
|
409
|
+
return [3, 4];
|
|
410
|
+
|
|
411
|
+
case 1:
|
|
412
|
+
if (!(changed.type === eva_js.OBSERVER_TYPE.CHANGE)) return [3, 3];
|
|
413
|
+
return [4, eva_js.resource.getResource(component_1.resource)];
|
|
414
|
+
|
|
415
|
+
case 2:
|
|
416
|
+
instance = _a.sent().instance;
|
|
417
|
+
|
|
418
|
+
if (!instance) {
|
|
419
|
+
throw new Error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
this.sprites[changed.gameObject.id].image = instance[component_1.resource + resourceKeySplit + component_1.spriteName];
|
|
423
|
+
return [3, 4];
|
|
424
|
+
|
|
425
|
+
case 3:
|
|
426
|
+
if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
427
|
+
sprite = this.sprites[changed.gameObject.id];
|
|
428
|
+
this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
|
|
429
|
+
sprite.sprite.destroy({
|
|
430
|
+
children: true
|
|
431
|
+
});
|
|
432
|
+
delete this.sprites[changed.gameObject.id];
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
_a.label = 4;
|
|
436
|
+
|
|
437
|
+
case 4:
|
|
438
|
+
return [2];
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
Sprite.systemName = 'Sprite';
|
|
445
|
+
Sprite = __decorate([eva_js.decorators.componentObserver({
|
|
446
|
+
Sprite: ['spriteName']
|
|
447
|
+
})], Sprite);
|
|
448
|
+
return Sprite;
|
|
449
|
+
}(pluginRenderer.Renderer);
|
|
450
|
+
|
|
451
|
+
var Sprite$1 = Sprite;
|
|
452
|
+
exports.Sprite = Sprite$4;
|
|
453
|
+
exports.SpriteSystem = Sprite$1;
|
|
454
|
+
Object.defineProperty(exports, '__esModule', {
|
|
455
|
+
value: true
|
|
456
|
+
});
|
|
457
|
+
return exports;
|
|
458
|
+
}({}, EVA, EVA.plugin.renderer, PIXI);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
this.EVA=this.EVA||{},this.EVA.plugin=this.EVA.plugin||{},this.EVA.plugin.renderer=this.EVA.plugin.renderer||{},this.EVA.plugin.renderer.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])})(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 f=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),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}(),h="_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,a=n.BaseTexture.from(r.image),c=s.frames||{},p=s.animations||{},f={};for(var l in c){f[t+h+l]=c[l]}for(var l in p){var m=[];if(p[l]&&p[l].length>=0)try{for(var d=(i=void 0,u(p[l])),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[l]=m}s.frames=f;var b=new n.Spritesheet(a,s);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 m=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=this;return c(this,(function(u){switch(u.label){case 0:return"Sprite"!==e.componentName?[3,4]:(r=e.component,e.type!==t.OBSERVER_TYPE.ADD?[3,1]:(n=new l(null),t.resource.getResource(r.resource).then((function(t){var i=t.instance;return a(s,void 0,void 0,(function(){return c(this,(function(t){if(!i)throw new Error("GameObject:"+e.gameObject.name+"'s Sprite resource load error");return n.image=i[r.resource+h+r.spriteName],[2]}))}))})),this.sprites[e.gameObject.id]=n,this.containerManager.getContainer(e.gameObject.id).addChildAt(n.sprite,0),[3,4]));case 1:return e.type!==t.OBSERVER_TYPE.CHANGE?[3,3]:[4,t.resource.getResource(r.resource)];case 2:if(!(i=u.sent().instance))throw new Error("GameObject:"+e.gameObject.name+"'s Sprite resource load error");return this.sprites[e.gameObject.id].image=i[r.resource+h+r.spriteName],[3,4];case 3:e.type===t.OBSERVER_TYPE.REMOVE&&(o=this.sprites[e.gameObject.id],this.containerManager.getContainer(e.gameObject.id).removeChild(o.sprite),o.sprite.destroy({children:!0}),delete this.sprites[e.gameObject.id]),u.label=4;case 4:return[2]}}))}))},n.systemName="Sprite",n=s([t.decorators.componentObserver({Sprite:["spriteName"]})],n)}(r.Renderer);return e.Sprite=f,e.SpriteSystem=m,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-sprite",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
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": "1.2.
|
|
23
|
-
"@eva/eva.js": "1.2.
|
|
22
|
+
"@eva/plugin-renderer": "1.2.1",
|
|
23
|
+
"@eva/eva.js": "1.2.1",
|
|
24
24
|
"pixi.js": "^4.8.7"
|
|
25
25
|
}
|
|
26
26
|
}
|