@eva/plugin-renderer-sprite 1.3.0-alpha.1 → 2.0.0-beta.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.
|
@@ -1,51 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
1
|
+
window.EVA = window.EVA || {};
|
|
2
|
+
window.EVA.plugin = window.EVA.plugin || {};
|
|
3
|
+
window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
|
|
4
|
+
var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
6
5
|
'use strict';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
_extendStatics = Object.setPrototypeOf || {
|
|
6
|
+
var extendStatics = function (d, b) {
|
|
7
|
+
extendStatics = Object.setPrototypeOf || {
|
|
10
8
|
__proto__: []
|
|
11
9
|
} instanceof Array && function (d, b) {
|
|
12
10
|
d.__proto__ = b;
|
|
13
11
|
} || function (d, b) {
|
|
14
|
-
for (var p in b)
|
|
15
|
-
if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
16
|
-
}
|
|
12
|
+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
17
13
|
};
|
|
18
|
-
|
|
19
|
-
return _extendStatics(d, b);
|
|
14
|
+
return extendStatics(d, b);
|
|
20
15
|
};
|
|
21
|
-
|
|
22
16
|
function __extends(d, b) {
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
extendStatics(d, b);
|
|
25
18
|
function __() {
|
|
26
19
|
this.constructor = d;
|
|
27
20
|
}
|
|
28
|
-
|
|
29
21
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
function __decorate(decorators, target, key, desc) {
|
|
33
24
|
var c = arguments.length,
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
}
|
|
25
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
26
|
+
d;
|
|
27
|
+
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--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
39
28
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
40
29
|
}
|
|
41
|
-
|
|
42
30
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
43
31
|
function adopt(value) {
|
|
44
32
|
return value instanceof P ? value : new P(function (resolve) {
|
|
45
33
|
resolve(value);
|
|
46
34
|
});
|
|
47
35
|
}
|
|
48
|
-
|
|
49
36
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
50
37
|
function fulfilled(value) {
|
|
51
38
|
try {
|
|
@@ -54,7 +41,6 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
54
41
|
reject(e);
|
|
55
42
|
}
|
|
56
43
|
}
|
|
57
|
-
|
|
58
44
|
function rejected(value) {
|
|
59
45
|
try {
|
|
60
46
|
step(generator["throw"](value));
|
|
@@ -62,29 +48,26 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
62
48
|
reject(e);
|
|
63
49
|
}
|
|
64
50
|
}
|
|
65
|
-
|
|
66
51
|
function step(result) {
|
|
67
52
|
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
68
53
|
}
|
|
69
|
-
|
|
70
54
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
71
55
|
});
|
|
72
56
|
}
|
|
73
|
-
|
|
74
57
|
function __generator(thisArg, body) {
|
|
75
58
|
var _ = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
label: 0,
|
|
60
|
+
sent: function () {
|
|
61
|
+
if (t[0] & 1) throw t[1];
|
|
62
|
+
return t[1];
|
|
63
|
+
},
|
|
64
|
+
trys: [],
|
|
65
|
+
ops: []
|
|
80
66
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
y,
|
|
86
|
-
t,
|
|
87
|
-
g;
|
|
67
|
+
f,
|
|
68
|
+
y,
|
|
69
|
+
t,
|
|
70
|
+
g;
|
|
88
71
|
return g = {
|
|
89
72
|
next: verb(0),
|
|
90
73
|
"throw": verb(1),
|
|
@@ -92,88 +75,66 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
92
75
|
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
93
76
|
return this;
|
|
94
77
|
}), g;
|
|
95
|
-
|
|
96
78
|
function verb(n) {
|
|
97
79
|
return function (v) {
|
|
98
80
|
return step([n, v]);
|
|
99
81
|
};
|
|
100
82
|
}
|
|
101
|
-
|
|
102
83
|
function step(op) {
|
|
103
84
|
if (f) throw new TypeError("Generator is already executing.");
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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];
|
|
113
119
|
t = op;
|
|
114
120
|
break;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
_.label
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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;
|
|
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;
|
|
174
130
|
}
|
|
131
|
+
op = body.call(thisArg, _);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
op = [6, e];
|
|
134
|
+
y = 0;
|
|
135
|
+
} finally {
|
|
136
|
+
f = t = 0;
|
|
175
137
|
}
|
|
176
|
-
|
|
177
138
|
if (op[0] & 5) throw op[1];
|
|
178
139
|
return {
|
|
179
140
|
value: op[0] ? op[1] : void 0,
|
|
@@ -181,14 +142,13 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
181
142
|
};
|
|
182
143
|
}
|
|
183
144
|
}
|
|
184
|
-
|
|
185
145
|
function __values(o) {
|
|
186
146
|
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
187
|
-
|
|
188
|
-
|
|
147
|
+
m = s && o[s],
|
|
148
|
+
i = 0;
|
|
189
149
|
if (m) return m.call(o);
|
|
190
150
|
if (o && typeof o.length === "number") return {
|
|
191
|
-
next: function
|
|
151
|
+
next: function () {
|
|
192
152
|
if (o && i >= o.length) o = void 0;
|
|
193
153
|
return {
|
|
194
154
|
value: o && o[i++],
|
|
@@ -198,20 +158,16 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
198
158
|
};
|
|
199
159
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
200
160
|
}
|
|
201
|
-
|
|
202
161
|
function getIDEPropsPropertyObj(target, propertyKey) {
|
|
203
162
|
if (!target.constructor.IDEProps) {
|
|
204
163
|
target.constructor.IDEProps = {};
|
|
205
164
|
}
|
|
206
|
-
|
|
207
165
|
if (!target.constructor.IDEProps[propertyKey]) {
|
|
208
166
|
target.constructor.IDEProps[propertyKey] = {};
|
|
209
167
|
}
|
|
210
|
-
|
|
211
168
|
var propertyObj = target.constructor.IDEProps[propertyKey];
|
|
212
169
|
return propertyObj;
|
|
213
170
|
}
|
|
214
|
-
|
|
215
171
|
function type(type) {
|
|
216
172
|
return function (target, propertyKey) {
|
|
217
173
|
var prop = getIDEPropsPropertyObj(target, propertyKey);
|
|
@@ -219,41 +175,30 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
219
175
|
prop.type = type;
|
|
220
176
|
};
|
|
221
177
|
}
|
|
222
|
-
|
|
223
178
|
var Sprite$3 = function (_super) {
|
|
224
179
|
__extends(Sprite, _super);
|
|
225
|
-
|
|
226
180
|
function Sprite() {
|
|
227
181
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
228
|
-
|
|
229
182
|
_this.resource = '';
|
|
230
183
|
_this.spriteName = '';
|
|
231
184
|
return _this;
|
|
232
185
|
}
|
|
233
|
-
|
|
234
186
|
Sprite.prototype.init = function (obj) {
|
|
235
187
|
if (obj && obj.resource) {
|
|
236
188
|
this.resource = obj.resource;
|
|
237
189
|
this.spriteName = obj.spriteName;
|
|
238
190
|
}
|
|
239
191
|
};
|
|
240
|
-
|
|
241
192
|
Sprite.componentName = 'Sprite';
|
|
242
|
-
|
|
243
193
|
__decorate([type('string')], Sprite.prototype, "resource", void 0);
|
|
244
|
-
|
|
245
194
|
__decorate([type('string')], Sprite.prototype, "spriteName", void 0);
|
|
246
|
-
|
|
247
195
|
return Sprite;
|
|
248
196
|
}(eva_js.Component);
|
|
249
|
-
|
|
250
197
|
var Sprite$4 = Sprite$3;
|
|
251
|
-
|
|
252
198
|
var Sprite$2 = function () {
|
|
253
199
|
function Sprite(image) {
|
|
254
200
|
this._image = null;
|
|
255
201
|
this._image = image;
|
|
256
|
-
|
|
257
202
|
if (image) {
|
|
258
203
|
if (image instanceof HTMLImageElement) {
|
|
259
204
|
this.sprite = pixi_js.Sprite.from(image);
|
|
@@ -264,23 +209,20 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
264
209
|
this.sprite = new pixi_js.Sprite();
|
|
265
210
|
}
|
|
266
211
|
}
|
|
267
|
-
|
|
268
212
|
Object.defineProperty(Sprite.prototype, "image", {
|
|
269
|
-
get: function
|
|
213
|
+
get: function () {
|
|
270
214
|
return this._image;
|
|
271
215
|
},
|
|
272
|
-
set: function
|
|
216
|
+
set: function (val) {
|
|
273
217
|
if (this._image === val) {
|
|
274
218
|
return;
|
|
275
219
|
}
|
|
276
|
-
|
|
277
220
|
if (val instanceof HTMLImageElement) {
|
|
278
221
|
this.sprite.texture && this.sprite.texture.destroy(false);
|
|
279
222
|
this.sprite.texture = pixi_js.Texture.from(val);
|
|
280
223
|
} else if (val instanceof pixi_js.Texture) {
|
|
281
224
|
this.sprite.texture = val;
|
|
282
225
|
}
|
|
283
|
-
|
|
284
226
|
this._image = val;
|
|
285
227
|
},
|
|
286
228
|
enumerable: false,
|
|
@@ -288,29 +230,24 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
288
230
|
});
|
|
289
231
|
return Sprite;
|
|
290
232
|
}();
|
|
291
|
-
|
|
292
233
|
var SpriteEngine = Sprite$2;
|
|
293
234
|
var resourceKeySplit = '_s|r|c_';
|
|
294
235
|
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
|
|
295
236
|
var name = _a.name,
|
|
296
|
-
|
|
237
|
+
data = _a.data;
|
|
297
238
|
return new Promise(function (r) {
|
|
298
239
|
var e_1, _a;
|
|
299
|
-
|
|
300
|
-
var
|
|
301
|
-
var texture = pixi_js.BaseTexture.from(data.image);
|
|
240
|
+
var textureObj = data.json.data;
|
|
241
|
+
var texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
|
|
302
242
|
var frames = textureObj.frames || {};
|
|
303
243
|
var animations = textureObj.animations || {};
|
|
304
244
|
var newFrames = {};
|
|
305
|
-
|
|
306
245
|
for (var key in frames) {
|
|
307
246
|
var newKey = name + resourceKeySplit + key;
|
|
308
247
|
newFrames[newKey] = frames[key];
|
|
309
248
|
}
|
|
310
|
-
|
|
311
249
|
for (var key in animations) {
|
|
312
250
|
var spriteList = [];
|
|
313
|
-
|
|
314
251
|
if (animations[key] && animations[key].length >= 0) {
|
|
315
252
|
try {
|
|
316
253
|
for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -330,100 +267,83 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
330
267
|
}
|
|
331
268
|
}
|
|
332
269
|
}
|
|
333
|
-
|
|
334
270
|
animations[key] = spriteList;
|
|
335
271
|
}
|
|
336
|
-
|
|
337
272
|
textureObj.frames = newFrames;
|
|
338
273
|
var spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
|
|
339
|
-
spriteSheet.parse(function () {
|
|
340
|
-
|
|
341
|
-
r(textures);
|
|
274
|
+
spriteSheet.parse().then(function () {
|
|
275
|
+
r(spriteSheet.textures);
|
|
342
276
|
});
|
|
343
277
|
});
|
|
344
278
|
});
|
|
345
279
|
eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
|
|
346
280
|
var instance = _a.instance;
|
|
347
281
|
if (!instance) return;
|
|
348
|
-
|
|
349
282
|
for (var key in instance) {
|
|
350
283
|
instance[key].destroy(true);
|
|
351
284
|
}
|
|
352
285
|
});
|
|
353
|
-
|
|
354
286
|
var Sprite = function (_super) {
|
|
355
287
|
__extends(Sprite, _super);
|
|
356
|
-
|
|
357
288
|
function Sprite() {
|
|
358
289
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
359
|
-
|
|
360
290
|
_this.name = 'Sprite';
|
|
361
291
|
_this.sprites = {};
|
|
362
292
|
return _this;
|
|
363
293
|
}
|
|
364
|
-
|
|
365
294
|
Sprite.prototype.init = function () {
|
|
366
295
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
367
296
|
this.renderSystem.rendererManager.register(this);
|
|
368
297
|
};
|
|
369
|
-
|
|
370
298
|
Sprite.prototype.rendererUpdate = function (gameObject) {
|
|
371
299
|
var _a = gameObject.transform.size,
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
300
|
+
width = _a.width,
|
|
301
|
+
height = _a.height;
|
|
375
302
|
if (this.sprites[gameObject.id]) {
|
|
376
303
|
this.sprites[gameObject.id].sprite.width = width;
|
|
377
304
|
this.sprites[gameObject.id].sprite.height = height;
|
|
378
305
|
}
|
|
379
306
|
};
|
|
380
|
-
|
|
381
307
|
Sprite.prototype.componentChanged = function (changed) {
|
|
382
308
|
return __awaiter(this, void 0, void 0, function () {
|
|
383
|
-
var
|
|
384
|
-
|
|
385
|
-
var _this = this;
|
|
386
|
-
|
|
309
|
+
var gameObjectId, component, sprite, asyncId, instance, asyncId, instance, sprite;
|
|
387
310
|
return __generator(this, function (_a) {
|
|
388
311
|
switch (_a.label) {
|
|
389
312
|
case 0:
|
|
390
|
-
if (!(changed.componentName === 'Sprite')) return [3,
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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
|
-
|
|
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)];
|
|
411
322
|
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
323
|
instance = _a.sent().instance;
|
|
417
|
-
|
|
324
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
418
325
|
if (!instance) {
|
|
419
|
-
|
|
326
|
+
console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
|
|
327
|
+
return [2];
|
|
420
328
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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)];
|
|
425
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:
|
|
426
345
|
if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
346
|
+
this.increaseAsyncId(gameObjectId);
|
|
427
347
|
sprite = this.sprites[changed.gameObject.id];
|
|
428
348
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
|
|
429
349
|
sprite.sprite.destroy({
|
|
@@ -431,23 +351,19 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
431
351
|
});
|
|
432
352
|
delete this.sprites[changed.gameObject.id];
|
|
433
353
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
case 4:
|
|
354
|
+
_a.label = 5;
|
|
355
|
+
case 5:
|
|
438
356
|
return [2];
|
|
439
357
|
}
|
|
440
358
|
});
|
|
441
359
|
});
|
|
442
360
|
};
|
|
443
|
-
|
|
444
361
|
Sprite.systemName = 'Sprite';
|
|
445
362
|
Sprite = __decorate([eva_js.decorators.componentObserver({
|
|
446
363
|
Sprite: ['spriteName']
|
|
447
364
|
})], Sprite);
|
|
448
365
|
return Sprite;
|
|
449
366
|
}(pluginRenderer.Renderer);
|
|
450
|
-
|
|
451
367
|
var Sprite$1 = Sprite;
|
|
452
368
|
exports.Sprite = Sprite$4;
|
|
453
369
|
exports.SpriteSystem = Sprite$1;
|
|
@@ -456,3 +372,4 @@ this.EVA.plugin.renderer.sprite = function (exports, eva_js, pluginRenderer, pix
|
|
|
456
372
|
});
|
|
457
373
|
return exports;
|
|
458
374
|
}({}, EVA, EVA.plugin.renderer, PIXI);
|
|
375
|
+
window.EVA.plugin.renderer.sprite = window.EVA.plugin.renderer.sprite || _EVA_IIFE_sprite;
|
|
@@ -1 +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;
|
|
@@ -161,8 +161,8 @@ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
|
|
|
161
161
|
var name = _a.name, data = _a.data;
|
|
162
162
|
return new Promise(function (r) {
|
|
163
163
|
var e_1, _a;
|
|
164
|
-
var textureObj = data.json;
|
|
165
|
-
var texture = pixi_js.
|
|
164
|
+
var textureObj = data.json.data;
|
|
165
|
+
var texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
|
|
166
166
|
var frames = textureObj.frames || {};
|
|
167
167
|
var animations = textureObj.animations || {};
|
|
168
168
|
var newFrames = {};
|
|
@@ -192,9 +192,8 @@ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, function (_a) {
|
|
|
192
192
|
}
|
|
193
193
|
textureObj.frames = newFrames;
|
|
194
194
|
var spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
|
|
195
|
-
spriteSheet.parse(function () {
|
|
196
|
-
|
|
197
|
-
r(textures);
|
|
195
|
+
spriteSheet.parse().then(function () {
|
|
196
|
+
r(spriteSheet.textures);
|
|
198
197
|
});
|
|
199
198
|
});
|
|
200
199
|
});
|
|
@@ -227,50 +226,54 @@ var Sprite = (function (_super) {
|
|
|
227
226
|
};
|
|
228
227
|
Sprite.prototype.componentChanged = function (changed) {
|
|
229
228
|
return __awaiter(this, void 0, void 0, function () {
|
|
230
|
-
var
|
|
231
|
-
var _this = this;
|
|
229
|
+
var gameObjectId, component, sprite, asyncId, instance, asyncId, instance, sprite;
|
|
232
230
|
return __generator(this, function (_a) {
|
|
233
231
|
switch (_a.label) {
|
|
234
232
|
case 0:
|
|
235
|
-
if (!(changed.componentName === 'Sprite')) return [3,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
throw new Error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
|
|
245
|
-
}
|
|
246
|
-
sprite_1.image = instance[component_1.resource + resourceKeySplit + component_1.spriteName];
|
|
247
|
-
return [2];
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
this.sprites[changed.gameObject.id] = sprite_1;
|
|
252
|
-
this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite_1.sprite, 0);
|
|
253
|
-
return [3, 4];
|
|
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)];
|
|
254
242
|
case 1:
|
|
255
|
-
|
|
256
|
-
|
|
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];
|
|
257
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:
|
|
258
257
|
instance = (_a.sent()).instance;
|
|
258
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
259
|
+
return [2];
|
|
259
260
|
if (!instance) {
|
|
260
|
-
|
|
261
|
+
console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
|
|
262
|
+
return [2];
|
|
261
263
|
}
|
|
262
264
|
this.sprites[changed.gameObject.id].image =
|
|
263
|
-
instance[
|
|
264
|
-
return [3,
|
|
265
|
-
case
|
|
265
|
+
instance[component.resource + resourceKeySplit + component.spriteName];
|
|
266
|
+
return [3, 5];
|
|
267
|
+
case 4:
|
|
266
268
|
if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
269
|
+
this.increaseAsyncId(gameObjectId);
|
|
267
270
|
sprite = this.sprites[changed.gameObject.id];
|
|
268
271
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
|
|
269
272
|
sprite.sprite.destroy({ children: true });
|
|
270
273
|
delete this.sprites[changed.gameObject.id];
|
|
271
274
|
}
|
|
272
|
-
_a.label =
|
|
273
|
-
case
|
|
275
|
+
_a.label = 5;
|
|
276
|
+
case 5: return [2];
|
|
274
277
|
}
|
|
275
278
|
});
|
|
276
279
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),n=require("pixi.js"),i=function(e,t){return
|
|
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,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
3
|
import { RendererSystem, Renderer } from '@eva/plugin-renderer';
|
|
4
|
-
import {
|
|
4
|
+
import { Sprite as Sprite$5, Texture, Spritesheet } from 'pixi.js';
|
|
5
5
|
|
|
6
6
|
/*! *****************************************************************************
|
|
7
7
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -157,8 +157,8 @@ resource.registerInstance(RESOURCE_TYPE.SPRITE, function (_a) {
|
|
|
157
157
|
var name = _a.name, data = _a.data;
|
|
158
158
|
return new Promise(function (r) {
|
|
159
159
|
var e_1, _a;
|
|
160
|
-
var textureObj = data.json;
|
|
161
|
-
var texture =
|
|
160
|
+
var textureObj = data.json.data;
|
|
161
|
+
var texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
|
|
162
162
|
var frames = textureObj.frames || {};
|
|
163
163
|
var animations = textureObj.animations || {};
|
|
164
164
|
var newFrames = {};
|
|
@@ -188,9 +188,8 @@ resource.registerInstance(RESOURCE_TYPE.SPRITE, function (_a) {
|
|
|
188
188
|
}
|
|
189
189
|
textureObj.frames = newFrames;
|
|
190
190
|
var spriteSheet = new Spritesheet(texture, textureObj);
|
|
191
|
-
spriteSheet.parse(function () {
|
|
192
|
-
|
|
193
|
-
r(textures);
|
|
191
|
+
spriteSheet.parse().then(function () {
|
|
192
|
+
r(spriteSheet.textures);
|
|
194
193
|
});
|
|
195
194
|
});
|
|
196
195
|
});
|
|
@@ -223,50 +222,54 @@ var Sprite = (function (_super) {
|
|
|
223
222
|
};
|
|
224
223
|
Sprite.prototype.componentChanged = function (changed) {
|
|
225
224
|
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
-
var
|
|
227
|
-
var _this = this;
|
|
225
|
+
var gameObjectId, component, sprite, asyncId, instance, asyncId, instance, sprite;
|
|
228
226
|
return __generator(this, function (_a) {
|
|
229
227
|
switch (_a.label) {
|
|
230
228
|
case 0:
|
|
231
|
-
if (!(changed.componentName === 'Sprite')) return [3,
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
throw new Error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
|
|
241
|
-
}
|
|
242
|
-
sprite_1.image = instance[component_1.resource + resourceKeySplit + component_1.spriteName];
|
|
243
|
-
return [2];
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
this.sprites[changed.gameObject.id] = sprite_1;
|
|
248
|
-
this.containerManager.getContainer(changed.gameObject.id).addChildAt(sprite_1.sprite, 0);
|
|
249
|
-
return [3, 4];
|
|
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)];
|
|
250
238
|
case 1:
|
|
251
|
-
|
|
252
|
-
|
|
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];
|
|
253
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:
|
|
254
253
|
instance = (_a.sent()).instance;
|
|
254
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
255
|
+
return [2];
|
|
255
256
|
if (!instance) {
|
|
256
|
-
|
|
257
|
+
console.error("GameObject:" + changed.gameObject.name + "'s Sprite resource load error");
|
|
258
|
+
return [2];
|
|
257
259
|
}
|
|
258
260
|
this.sprites[changed.gameObject.id].image =
|
|
259
|
-
instance[
|
|
260
|
-
return [3,
|
|
261
|
-
case
|
|
261
|
+
instance[component.resource + resourceKeySplit + component.spriteName];
|
|
262
|
+
return [3, 5];
|
|
263
|
+
case 4:
|
|
262
264
|
if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
265
|
+
this.increaseAsyncId(gameObjectId);
|
|
263
266
|
sprite = this.sprites[changed.gameObject.id];
|
|
264
267
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite.sprite);
|
|
265
268
|
sprite.sprite.destroy({ children: true });
|
|
266
269
|
delete this.sprites[changed.gameObject.id];
|
|
267
270
|
}
|
|
268
|
-
_a.label =
|
|
269
|
-
case
|
|
271
|
+
_a.label = 5;
|
|
272
|
+
case 5: return [2];
|
|
270
273
|
}
|
|
271
274
|
});
|
|
272
275
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-sprite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.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": "
|
|
23
|
-
"@eva/eva.js": "
|
|
24
|
-
"pixi.js": "^
|
|
22
|
+
"@eva/plugin-renderer": "2.0.0-beta.1",
|
|
23
|
+
"@eva/eva.js": "2.0.0-beta.1",
|
|
24
|
+
"pixi.js": "^8.6.3"
|
|
25
25
|
}
|
|
26
26
|
}
|