@eva/plugin-renderer-sprite 2.0.0-beta.1 → 2.0.0-beta.3
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
return
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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 (
|
|
250
|
-
|
|
118
|
+
for (const key in animations) {
|
|
119
|
+
const spriteList = [];
|
|
251
120
|
if (animations[key] && animations[key].length >= 0) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
274
|
-
spriteSheet.parse().then(
|
|
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,
|
|
280
|
-
|
|
135
|
+
eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE, ({
|
|
136
|
+
instance
|
|
137
|
+
}) => {
|
|
281
138
|
if (!instance) return;
|
|
282
|
-
for (
|
|
139
|
+
for (const key in instance) {
|
|
283
140
|
instance[key].destroy(true);
|
|
284
141
|
}
|
|
285
142
|
});
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
-
|
|
149
|
+
init() {
|
|
295
150
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
296
151
|
this.renderSystem.rendererManager.register(this);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
width
|
|
301
|
-
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
|
-
|
|
308
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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$
|
|
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,
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
120
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
return
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
160
|
-
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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 (
|
|
174
|
-
|
|
108
|
+
for (const key in animations) {
|
|
109
|
+
const spriteList = [];
|
|
175
110
|
if (animations[key] && animations[key].length >= 0) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
195
|
-
spriteSheet.parse().then(
|
|
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,
|
|
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 (
|
|
128
|
+
for (const key in instance) {
|
|
205
129
|
instance[key].destroy(true);
|
|
206
130
|
}
|
|
207
131
|
});
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
138
|
+
init() {
|
|
217
139
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
218
140
|
this.renderSystem.rendererManager.register(this);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
228
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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$
|
|
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"),
|
|
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 {
|
|
4
|
-
import { Sprite as Sprite$
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
116
|
-
|
|
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$
|
|
64
|
+
this.sprite = Sprite$4.from(image);
|
|
122
65
|
}
|
|
123
66
|
else if (image instanceof Texture) {
|
|
124
|
-
this.sprite = new Sprite$
|
|
67
|
+
this.sprite = new Sprite$4(image);
|
|
125
68
|
}
|
|
126
69
|
}
|
|
127
70
|
else {
|
|
128
|
-
this.sprite = new Sprite$
|
|
71
|
+
this.sprite = new Sprite$4();
|
|
129
72
|
}
|
|
130
73
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
156
|
-
resource.registerInstance(RESOURCE_TYPE.SPRITE,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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 (
|
|
170
|
-
|
|
104
|
+
for (const key in animations) {
|
|
105
|
+
const spriteList = [];
|
|
171
106
|
if (animations[key] && animations[key].length >= 0) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
191
|
-
spriteSheet.parse().then(
|
|
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,
|
|
197
|
-
var instance = _a.instance;
|
|
121
|
+
resource.registerDestroy(RESOURCE_TYPE.SPRITE, ({ instance }) => {
|
|
198
122
|
if (!instance)
|
|
199
123
|
return;
|
|
200
|
-
for (
|
|
124
|
+
for (const key in instance) {
|
|
201
125
|
instance[key].destroy(true);
|
|
202
126
|
}
|
|
203
127
|
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
134
|
+
init() {
|
|
213
135
|
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
214
136
|
this.renderSystem.rendererManager.register(this);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
224
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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$
|
|
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.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
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.
|
|
23
|
-
"@eva/eva.js": "2.0.0-beta.
|
|
22
|
+
"@eva/plugin-renderer": "2.0.0-beta.3",
|
|
23
|
+
"@eva/eva.js": "2.0.0-beta.3",
|
|
24
24
|
"pixi.js": "^8.6.3"
|
|
25
25
|
}
|
|
26
26
|
}
|