@eva/plugin-renderer-render-texture 2.1.0-beta.1 → 2.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-render-texture",
3
- "version": "2.1.0-beta.1",
3
+ "version": "2.1.0-beta.3",
4
4
  "description": "@eva/plugin-renderer-render-texture",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-render-texture.esm.js",
@@ -20,8 +20,8 @@
20
20
  "homepage": "https://eva.js.org",
21
21
  "dependencies": {
22
22
  "@eva/inspector-decorator": "^2.0.0-beta.0",
23
- "@eva/eva.js": "2.1.0-beta.1",
24
- "@eva/plugin-renderer": "2.1.0-beta.1",
23
+ "@eva/eva.js": "2.1.0-beta.3",
24
+ "@eva/plugin-renderer": "2.1.0-beta.3",
25
25
  "pixi.js": "^8.6.3"
26
26
  }
27
27
  }
@@ -1,545 +0,0 @@
1
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- globalThis.EVA = globalThis.EVA || {};
3
- globalThis.EVA.plugin = globalThis.EVA.plugin || {};
4
- globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
5
- globalThis.EVA.plugin.renderer.render = globalThis.EVA.plugin.renderer.render || {};
6
- var _EVA_IIFE_texture = function (exports, eva_js, pluginRenderer, pixi_js) {
7
- 'use strict';
8
- function __decorate(decorators, target, key, desc) {
9
- var c = arguments.length,
10
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
11
- d;
12
- 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;
13
- return c > 3 && r && Object.defineProperty(target, key, r), r;
14
- }
15
- function __metadata(metadataKey, metadataValue) {
16
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
17
- }
18
- function __awaiter(thisArg, _arguments, P, generator) {
19
- function adopt(value) {
20
- return value instanceof P ? value : new P(function (resolve) {
21
- resolve(value);
22
- });
23
- }
24
- return new (P || (P = Promise))(function (resolve, reject) {
25
- function fulfilled(value) {
26
- try {
27
- step(generator.next(value));
28
- } catch (e) {
29
- reject(e);
30
- }
31
- }
32
- function rejected(value) {
33
- try {
34
- step(generator["throw"](value));
35
- } catch (e) {
36
- reject(e);
37
- }
38
- }
39
- function step(result) {
40
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
41
- }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- }
45
- function __rest(s, e) {
46
- var t = {};
47
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
48
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
49
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
50
- }
51
- return t;
52
- }
53
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
54
- var e = new Error(message);
55
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
56
- };
57
- class SymbolKeysNotSupportedError extends Error {
58
- constructor() {
59
- super('Symbol keys are not supported yet!');
60
- Object.setPrototypeOf(this, new.target.prototype);
61
- }
62
- }
63
- const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
64
- function transformBasicType(type) {
65
- if (type === String) {
66
- return 'string';
67
- }
68
- if (type === Number) {
69
- return 'number';
70
- }
71
- if (type === Boolean) {
72
- return 'boolean';
73
- }
74
- return 'unknown';
75
- }
76
- function defineLegacyIDEProp(target, propertyKey, patch) {
77
- const constructor = target.constructor;
78
- const current = constructor.IDEProps || {};
79
- current[propertyKey] = _extends(_extends({
80
- key: propertyKey
81
- }, current[propertyKey]), patch);
82
- constructor.IDEProps = current;
83
- }
84
- function defineTypes(target, key, options, returnTypeFunction) {
85
- let type = Reflect.getMetadata('design:type', target, key);
86
- let isArray = type === Array;
87
- const str = transformBasicType(type);
88
- if (str !== 'unknown') {
89
- type = str;
90
- }
91
- if (returnTypeFunction) {
92
- const returnType = returnTypeFunction();
93
- if (Array.isArray(returnType)) {
94
- isArray = true;
95
- type = returnType[0];
96
- } else {
97
- type = returnType;
98
- }
99
- }
100
- const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
101
- const current = properties[key] || {};
102
- const property = _extends(_extends(_extends({}, current), {
103
- type,
104
- isArray: isArray
105
- }), options);
106
- properties[key] = property;
107
- Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
108
- const legacyProperty = __rest(property, ["isArray"]);
109
- defineLegacyIDEProp(target, key, legacyProperty);
110
- }
111
- function type(type) {
112
- return Field({
113
- type
114
- });
115
- }
116
- function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
117
- if (typeof returnTypeFuncOrOptions === 'function') {
118
- return {
119
- returnTypeFunc: returnTypeFuncOrOptions,
120
- options: maybeOptions || {}
121
- };
122
- }
123
- return {
124
- options: returnTypeFuncOrOptions || {}
125
- };
126
- }
127
- function Field(returnTypeFunction, maybeOptions) {
128
- return (target, propertyKey) => {
129
- if (typeof propertyKey === 'symbol') {
130
- throw new SymbolKeysNotSupportedError();
131
- }
132
- const {
133
- options,
134
- returnTypeFunc
135
- } = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
136
- defineTypes(target, propertyKey, options, returnTypeFunc);
137
- };
138
- }
139
- var ExecuteMode;
140
- (function (ExecuteMode) {
141
- ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
142
- ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
143
- ExecuteMode[ExecuteMode["All"] = 6] = "All";
144
- })(ExecuteMode || (ExecuteMode = {}));
145
- class RenderTexture extends eva_js.Component {
146
- constructor() {
147
- super(...arguments);
148
- this.width = 256;
149
- this.height = 256;
150
- this.ops = [];
151
- this.backgroundColor = -1;
152
- this.backgroundAlpha = 1;
153
- this.append = true;
154
- this.dirty = 0;
155
- }
156
- init(obj) {
157
- if (obj) _extends(this, obj);
158
- if (!Array.isArray(this.ops)) this.ops = [];
159
- }
160
- addOp(op) {
161
- this.ops = [...this.ops, op];
162
- this.dirty++;
163
- }
164
- clearOps() {
165
- this.ops = [{
166
- type: 'clear'
167
- }];
168
- this.dirty++;
169
- }
170
- }
171
- RenderTexture.componentName = 'RenderTexture';
172
- __decorate([type('number'), __metadata("design:type", Number)], RenderTexture.prototype, "width", void 0);
173
- __decorate([type('number'), __metadata("design:type", Number)], RenderTexture.prototype, "height", void 0);
174
- __decorate([type('array'), __metadata("design:type", Array)], RenderTexture.prototype, "ops", void 0);
175
- __decorate([type('number'), __metadata("design:type", Number)], RenderTexture.prototype, "backgroundColor", void 0);
176
- __decorate([type('number'), __metadata("design:type", Number)], RenderTexture.prototype, "backgroundAlpha", void 0);
177
- const FRAME_SEP = '#';
178
- let RenderTextureSystem = class RenderTextureSystem extends pluginRenderer.Renderer {
179
- constructor() {
180
- super(...arguments);
181
- this.name = 'RenderTexture';
182
- this.records = {};
183
- }
184
- init() {
185
- this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
186
- this.renderSystem.rendererManager.register(this);
187
- }
188
- rendererUpdate(gameObject) {
189
- const record = this.records[gameObject.id];
190
- if (!record) return;
191
- if (record.needsReplay) {
192
- record.needsReplay = false;
193
- this.replay(gameObject.id);
194
- }
195
- }
196
- componentChanged(changed) {
197
- var _a, _b, _c, _d;
198
- return __awaiter(this, void 0, void 0, function* () {
199
- if (changed.componentName !== 'RenderTexture') return;
200
- const component = changed.component;
201
- const gameObjectId = changed.gameObject.id;
202
- if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
203
- const rt = pixi_js.RenderTexture.create({
204
- width: Math.max(1, component.width || 1),
205
- height: Math.max(1, component.height || 1),
206
- resolution: 1
207
- });
208
- const sprite = new pixi_js.Sprite(rt);
209
- sprite.width = component.width;
210
- sprite.height = component.height;
211
- this.containerManager.getContainer(gameObjectId).addChildAt(sprite, 0);
212
- this.records[gameObjectId] = {
213
- rt,
214
- sprite,
215
- component,
216
- lastSig: '',
217
- needsReplay: true
218
- };
219
- this.maybeSave(gameObjectId);
220
- } else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
221
- const record = this.records[gameObjectId];
222
- if (!record) return;
223
- record.component = component;
224
- if (record.rt.width !== component.width || record.rt.height !== component.height) {
225
- try {
226
- (_b = (_a = record.rt).resize) === null || _b === void 0 ? void 0 : _b.call(_a, Math.max(1, component.width), Math.max(1, component.height));
227
- } catch (e) {}
228
- record.sprite.width = component.width;
229
- record.sprite.height = component.height;
230
- }
231
- record.needsReplay = true;
232
- this.maybeSave(gameObjectId);
233
- } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
234
- const record = this.records[gameObjectId];
235
- if (!record) return;
236
- (_d = (_c = this.containerManager) === null || _c === void 0 ? void 0 : _c.getContainer(gameObjectId)) === null || _d === void 0 ? void 0 : _d.removeChild(record.sprite);
237
- record.sprite.destroy({
238
- children: true
239
- });
240
- record.rt.destroy(true);
241
- delete this.records[gameObjectId];
242
- }
243
- });
244
- }
245
- resolveTexture(name, explicitFrame) {
246
- return __awaiter(this, void 0, void 0, function* () {
247
- if (!name) return null;
248
- let resName = name;
249
- let frame = explicitFrame;
250
- if (!frame && name.includes(FRAME_SEP)) {
251
- const idx = name.indexOf(FRAME_SEP);
252
- resName = name.slice(0, idx);
253
- frame = name.slice(idx + 1);
254
- }
255
- try {
256
- const {
257
- instance
258
- } = yield eva_js.resource.getResource(resName);
259
- if (!instance) return null;
260
- if (frame) {
261
- if (instance && instance[frame] instanceof pixi_js.Texture) {
262
- return instance[frame];
263
- }
264
- const textures = instance.textures;
265
- if (textures && textures[frame] instanceof pixi_js.Texture) {
266
- return textures[frame];
267
- }
268
- }
269
- if (instance instanceof pixi_js.Texture) return instance;
270
- if (instance.baseTexture) return instance;
271
- if (typeof instance === 'object') {
272
- const keys = Object.keys(instance);
273
- for (const k of keys) {
274
- const v = instance[k];
275
- if (v instanceof pixi_js.Texture) return v;
276
- }
277
- }
278
- return null;
279
- } catch (_a) {
280
- return null;
281
- }
282
- });
283
- }
284
- replay(gameObjectId) {
285
- var _a, _b, _c, _d, _e, _f;
286
- return __awaiter(this, void 0, void 0, function* () {
287
- const record = this.records[gameObjectId];
288
- if (!record) return;
289
- const {
290
- rt,
291
- component
292
- } = record;
293
- const sig = `${component.dirty}|${(_b = (_a = component.ops) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0}|${component.width}|${component.height}`;
294
- if (record.lastSig === sig && component.append) ;
295
- record.lastSig = sig;
296
- const renderer = (_c = this.renderSystem.application) === null || _c === void 0 ? void 0 : _c.renderer;
297
- if (!renderer) return;
298
- const stage = new pixi_js.Container();
299
- const bg = component.backgroundColor;
300
- const bgA = (_d = component.backgroundAlpha) !== null && _d !== void 0 ? _d : 1;
301
- if (!component.append) {
302
- const g = new pixi_js.Graphics();
303
- if (bg != null && bg >= 0) {
304
- g.rect(0, 0, component.width, component.height).fill({
305
- color: bg,
306
- alpha: bgA
307
- });
308
- } else {
309
- g.rect(0, 0, component.width, component.height).fill({
310
- color: 0x000000,
311
- alpha: 0
312
- });
313
- }
314
- stage.addChild(g);
315
- }
316
- for (const op of component.ops || []) {
317
- const node = yield this.buildOpNode(op);
318
- if (node) stage.addChild(node);
319
- }
320
- try {
321
- renderer.render({
322
- container: stage,
323
- target: rt,
324
- clear: !component.append
325
- });
326
- if (globalThis.__RT_DEBUG) {
327
- console.log('[RT] replayed', {
328
- ops: (_e = component.ops) === null || _e === void 0 ? void 0 : _e.length,
329
- w: rt.width,
330
- h: rt.height,
331
- stageChildren: (_f = stage.children) === null || _f === void 0 ? void 0 : _f.length
332
- });
333
- }
334
- } catch (e) {
335
- try {
336
- renderer.render(stage, {
337
- renderTexture: rt,
338
- clear: !component.append
339
- });
340
- } catch (_g) {
341
- console.warn('[RenderTexture] renderer.render failed', e);
342
- }
343
- } finally {
344
- Promise.resolve().then(() => {
345
- try {
346
- stage.destroy({
347
- children: true
348
- });
349
- } catch (_a) {}
350
- });
351
- }
352
- });
353
- }
354
- buildOpNode(op) {
355
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
356
- return __awaiter(this, void 0, void 0, function* () {
357
- if (op.type === 'clear') {
358
- const g = new pixi_js.Graphics();
359
- g.rect(0, 0, 1e6, 1e6).fill({
360
- color: 0x000000,
361
- alpha: 0
362
- });
363
- return g;
364
- }
365
- if (op.type === 'fill') {
366
- const g = new pixi_js.Graphics();
367
- const x = (_a = op.x) !== null && _a !== void 0 ? _a : 0;
368
- const y = (_b = op.y) !== null && _b !== void 0 ? _b : 0;
369
- const w = (_c = op.width) !== null && _c !== void 0 ? _c : 1e6;
370
- const h = (_d = op.height) !== null && _d !== void 0 ? _d : 1e6;
371
- g.rect(x, y, w, h).fill({
372
- color: op.color,
373
- alpha: (_e = op.alpha) !== null && _e !== void 0 ? _e : 1
374
- });
375
- return g;
376
- }
377
- if (op.type === 'draw' || op.type === 'drawFrame') {
378
- const tex = yield this.resolveTexture(op.resource, op.frame);
379
- if (!tex) return null;
380
- const sp = new pixi_js.Sprite(tex);
381
- sp.x = (_f = op.x) !== null && _f !== void 0 ? _f : 0;
382
- sp.y = (_g = op.y) !== null && _g !== void 0 ? _g : 0;
383
- const o = op;
384
- sp.alpha = (_h = o.alpha) !== null && _h !== void 0 ? _h : 1;
385
- if (o.tint != null) sp.tint = o.tint;
386
- if (o.width != null) sp.width = o.width;
387
- if (o.height != null) sp.height = o.height;
388
- if (o.rotation != null) sp.rotation = o.rotation;
389
- if (o.anchorX != null || o.anchorY != null) {
390
- sp.anchor.set((_j = o.anchorX) !== null && _j !== void 0 ? _j : 0, (_k = o.anchorY) !== null && _k !== void 0 ? _k : 0);
391
- }
392
- if (o.scaleX != null || o.scaleY != null) {
393
- sp.scale.set((_l = o.scaleX) !== null && _l !== void 0 ? _l : 1, (_m = o.scaleY) !== null && _m !== void 0 ? _m : 1);
394
- }
395
- if (o.blendMode) {
396
- try {
397
- sp.blendMode = o.blendMode;
398
- } catch (_15) {}
399
- }
400
- return sp;
401
- }
402
- if (op.type === 'erase') {
403
- const g = new pixi_js.Graphics();
404
- const w = (_o = op.width) !== null && _o !== void 0 ? _o : 16;
405
- const h = (_p = op.height) !== null && _p !== void 0 ? _p : 16;
406
- const ax = (_q = op.anchorX) !== null && _q !== void 0 ? _q : 0;
407
- const ay = (_r = op.anchorY) !== null && _r !== void 0 ? _r : 0;
408
- const x = ((_s = op.x) !== null && _s !== void 0 ? _s : 0) - w * ax;
409
- const y = ((_t = op.y) !== null && _t !== void 0 ? _t : 0) - h * ay;
410
- g.rect(x, y, w, h).fill({
411
- color: 0xffffff,
412
- alpha: 1
413
- });
414
- try {
415
- g.blendMode = 'erase';
416
- } catch (_16) {}
417
- return g;
418
- }
419
- if (op.type === 'drawText') {
420
- const t = new pixi_js.Text({
421
- text: op.text,
422
- style: {
423
- fontFamily: (_v = (_u = op.style) === null || _u === void 0 ? void 0 : _u.fontFamily) !== null && _v !== void 0 ? _v : 'Arial',
424
- fontSize: (_x = (_w = op.style) === null || _w === void 0 ? void 0 : _w.fontSize) !== null && _x !== void 0 ? _x : 32,
425
- fontWeight: (_z = (_y = op.style) === null || _y === void 0 ? void 0 : _y.fontWeight) !== null && _z !== void 0 ? _z : 'normal',
426
- fill: (_1 = (_0 = op.style) === null || _0 === void 0 ? void 0 : _0.fill) !== null && _1 !== void 0 ? _1 : 0xffffff,
427
- stroke: (_2 = op.style) === null || _2 === void 0 ? void 0 : _2.stroke,
428
- align: (_4 = (_3 = op.style) === null || _3 === void 0 ? void 0 : _3.align) !== null && _4 !== void 0 ? _4 : 'left'
429
- }
430
- });
431
- t.x = (_5 = op.x) !== null && _5 !== void 0 ? _5 : 0;
432
- t.y = (_6 = op.y) !== null && _6 !== void 0 ? _6 : 0;
433
- if (op.alpha != null) t.alpha = op.alpha;
434
- if (op.tint != null) t.tint = op.tint;
435
- return t;
436
- }
437
- if (op.type === 'paint') {
438
- const tex = yield this.resolveTexture(op.resource, op.frame);
439
- if (!tex) return null;
440
- const c = new pixi_js.Container();
441
- const times = Math.max(1, (_7 = op.times) !== null && _7 !== void 0 ? _7 : 1);
442
- const dx = (_9 = (_8 = op.step) === null || _8 === void 0 ? void 0 : _8.x) !== null && _9 !== void 0 ? _9 : 0;
443
- const dy = (_11 = (_10 = op.step) === null || _10 === void 0 ? void 0 : _10.y) !== null && _11 !== void 0 ? _11 : 0;
444
- for (let i = 0; i < times; i++) {
445
- const sp = new pixi_js.Sprite(tex);
446
- sp.x = ((_12 = op.x) !== null && _12 !== void 0 ? _12 : 0) + dx * i;
447
- sp.y = ((_13 = op.y) !== null && _13 !== void 0 ? _13 : 0) + dy * i;
448
- sp.anchor.set(0.5, 0.5);
449
- sp.alpha = (_14 = op.alpha) !== null && _14 !== void 0 ? _14 : 1;
450
- if (op.tintCycle && op.tintCycle.length > 0) {
451
- sp.tint = op.tintCycle[i % op.tintCycle.length];
452
- } else if (op.tint != null) {
453
- sp.tint = op.tint;
454
- }
455
- c.addChild(sp);
456
- }
457
- return c;
458
- }
459
- return null;
460
- });
461
- }
462
- maybeSave(gameObjectId) {
463
- var _a;
464
- const record = this.records[gameObjectId];
465
- if (!record) return;
466
- const key = record.component.saveAs;
467
- if (!key) return;
468
- try {
469
- const existing = (_a = eva_js.resource.resourcesMap) === null || _a === void 0 ? void 0 : _a[key];
470
- if (existing) {
471
- existing.complete = true;
472
- existing.instance = record.rt;
473
- const promiseMap = eva_js.resource.promiseMap;
474
- if (promiseMap) {
475
- promiseMap[key] = Promise.resolve({
476
- instance: record.rt,
477
- name: key
478
- });
479
- }
480
- return;
481
- }
482
- eva_js.resource.resourcesMap = eva_js.resource.resourcesMap || {};
483
- eva_js.resource.resourcesMap[key] = {
484
- name: key,
485
- type: 'IMAGE',
486
- complete: true,
487
- instance: record.rt,
488
- data: {}
489
- };
490
- const promiseMap = eva_js.resource.promiseMap;
491
- if (promiseMap) {
492
- promiseMap[key] = Promise.resolve({
493
- instance: record.rt,
494
- name: key
495
- });
496
- }
497
- } catch (e) {
498
- console.warn('[RenderTexture] saveAs failed', e);
499
- }
500
- }
501
- destroy() {
502
- var _a, _b;
503
- for (const key in this.records) {
504
- const id = parseInt(key);
505
- const record = this.records[id];
506
- (_b = (_a = this.containerManager) === null || _a === void 0 ? void 0 : _a.getContainer(id)) === null || _b === void 0 ? void 0 : _b.removeChild(record.sprite);
507
- record.sprite.destroy({
508
- children: true
509
- });
510
- record.rt.destroy(true);
511
- delete this.records[id];
512
- }
513
- }
514
- };
515
- RenderTextureSystem.systemName = 'RenderTexture';
516
- RenderTextureSystem = __decorate([eva_js.decorators.componentObserver({
517
- RenderTexture: [{
518
- prop: ['width'],
519
- deep: false
520
- }, {
521
- prop: ['height'],
522
- deep: false
523
- }, {
524
- prop: ['ops'],
525
- deep: true
526
- }, {
527
- prop: ['dirty'],
528
- deep: false
529
- }, {
530
- prop: ['backgroundColor'],
531
- deep: false
532
- }, {
533
- prop: ['backgroundAlpha'],
534
- deep: false
535
- }]
536
- })], RenderTextureSystem);
537
- var RenderTextureSystem$1 = RenderTextureSystem;
538
- exports.RenderTexture = RenderTexture;
539
- exports.RenderTextureSystem = RenderTextureSystem$1;
540
- Object.defineProperty(exports, '__esModule', {
541
- value: true
542
- });
543
- return exports;
544
- }({}, EVA, EVA.plugin.renderer, PIXI);
545
- globalThis.EVA.plugin.renderer.render.texture = globalThis.EVA.plugin.renderer.render.texture || _EVA_IIFE_texture;
@@ -1 +0,0 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{},globalThis.EVA.plugin.renderer.render=globalThis.EVA.plugin.renderer.render||{};var _EVA_IIFE_texture=function(e,t,r,n){"use strict";function o(e,t,r,n){var o,i=arguments.length,l=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(l=(i<3?o(l):i>3?o(t,r,l):o(t,r))||l);return i>3&&l&&Object.defineProperty(t,r,l),l}function i(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function l(e,t,r,n){return new(r||(r=Promise))(function(o,i){function l(e){try{d(n.next(e))}catch(e){i(e)}}function s(e){try{d(n.throw(e))}catch(e){i(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(l,s)}d((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class s extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const d="IDE_PROPERTY_METADATA";function a(e,t,r,n){let o=Reflect.getMetadata("design:type",e,t),i=o===Array;const l=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==l&&(o=l),n){const e=n();Array.isArray(e)?(i=!0,o=e[0]):o=e}const s=Reflect.getMetadata(d,e.constructor)||{},a=_extends(_extends(_extends({},s[t]||{}),{type:o,isArray:i}),r);s[t]=a,Reflect.defineMetadata(d,s,e.constructor);!function(e,t,r){const n=e.constructor,o=n.IDEProps||{};o[t]=_extends(_extends({key:t},o[t]),r),n.IDEProps=o}(e,t,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(a,["isArray"]))}function c(e){return t={type:e},(e,n)=>{if("symbol"==typeof n)throw new s;const{options:o,returnTypeFunc:i}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,r);a(e,n,o,i)};var t,r}var u;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(u||(u={}));class h extends t.Component{constructor(){super(...arguments),this.width=256,this.height=256,this.ops=[],this.backgroundColor=-1,this.backgroundAlpha=1,this.append=!0,this.dirty=0}init(e){e&&_extends(this,e),Array.isArray(this.ops)||(this.ops=[])}addOp(e){this.ops=[...this.ops,e],this.dirty++}clearOps(){this.ops=[{type:"clear"}],this.dirty++}}h.componentName="RenderTexture",o([c("number"),i("design:type",Number)],h.prototype,"width",void 0),o([c("number"),i("design:type",Number)],h.prototype,"height",void 0),o([c("array"),i("design:type",Array)],h.prototype,"ops",void 0),o([c("number"),i("design:type",Number)],h.prototype,"backgroundColor",void 0),o([c("number"),i("design:type",Number)],h.prototype,"backgroundAlpha",void 0);let p=class extends r.Renderer{constructor(){super(...arguments),this.name="RenderTexture",this.records={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const t=this.records[e.id];t&&t.needsReplay&&(t.needsReplay=!1,this.replay(e.id))}componentChanged(e){var r,o,i,s;return l(this,void 0,void 0,function*(){if("RenderTexture"!==e.componentName)return;const l=e.component,d=e.gameObject.id;if(e.type===t.OBSERVER_TYPE.ADD){const e=n.RenderTexture.create({width:Math.max(1,l.width||1),height:Math.max(1,l.height||1),resolution:1}),t=new n.Sprite(e);t.width=l.width,t.height=l.height,this.containerManager.getContainer(d).addChildAt(t,0),this.records[d]={rt:e,sprite:t,component:l,lastSig:"",needsReplay:!0},this.maybeSave(d)}else if(e.type===t.OBSERVER_TYPE.CHANGE){const e=this.records[d];if(!e)return;if(e.component=l,e.rt.width!==l.width||e.rt.height!==l.height){try{null===(o=(r=e.rt).resize)||void 0===o||o.call(r,Math.max(1,l.width),Math.max(1,l.height))}catch(e){}e.sprite.width=l.width,e.sprite.height=l.height}e.needsReplay=!0,this.maybeSave(d)}else if(e.type===t.OBSERVER_TYPE.REMOVE){const e=this.records[d];if(!e)return;null===(s=null===(i=this.containerManager)||void 0===i?void 0:i.getContainer(d))||void 0===s||s.removeChild(e.sprite),e.sprite.destroy({children:!0}),e.rt.destroy(!0),delete this.records[d]}})}resolveTexture(e,r){return l(this,void 0,void 0,function*(){if(!e)return null;let o=e,i=r;if(!i&&e.includes("#")){const t=e.indexOf("#");o=e.slice(0,t),i=e.slice(t+1)}try{const{instance:e}=yield t.resource.getResource(o);if(!e)return null;if(i){if(e&&e[i]instanceof n.Texture)return e[i];const t=e.textures;if(t&&t[i]instanceof n.Texture)return t[i]}if(e instanceof n.Texture)return e;if(e.baseTexture)return e;if("object"==typeof e){const t=Object.keys(e);for(const r of t){const t=e[r];if(t instanceof n.Texture)return t}}return null}catch(e){return null}})}replay(e){var t,r,o,i,s,d;return l(this,void 0,void 0,function*(){const l=this.records[e];if(!l)return;const{rt:a,component:c}=l,u=`${c.dirty}|${null!==(r=null===(t=c.ops)||void 0===t?void 0:t.length)&&void 0!==r?r:0}|${c.width}|${c.height}`;l.lastSig===u&&c.append,l.lastSig=u;const h=null===(o=this.renderSystem.application)||void 0===o?void 0:o.renderer;if(!h)return;const p=new n.Container,y=c.backgroundColor,f=null!==(i=c.backgroundAlpha)&&void 0!==i?i:1;if(!c.append){const e=new n.Graphics;null!=y&&y>=0?e.rect(0,0,c.width,c.height).fill({color:y,alpha:f}):e.rect(0,0,c.width,c.height).fill({color:0,alpha:0}),p.addChild(e)}for(const e of c.ops||[]){const t=yield this.buildOpNode(e);t&&p.addChild(t)}try{h.render({container:p,target:a,clear:!c.append}),globalThis.__RT_DEBUG&&console.log("[RT] replayed",{ops:null===(s=c.ops)||void 0===s?void 0:s.length,w:a.width,h:a.height,stageChildren:null===(d=p.children)||void 0===d?void 0:d.length})}catch(e){try{h.render(p,{renderTexture:a,clear:!c.append})}catch(t){console.warn("[RenderTexture] renderer.render failed",e)}}finally{Promise.resolve().then(()=>{try{p.destroy({children:!0})}catch(e){}})}})}buildOpNode(e){var t,r,o,i,s,d,a,c,u,h,p,y,f,v,g,m,b,x,w,T,E,A,R,O,M,S,_,C,P,V,j,k,I,N,G,Y,D,F,X;return l(this,void 0,void 0,function*(){if("clear"===e.type){const e=new n.Graphics;return e.rect(0,0,1e6,1e6).fill({color:0,alpha:0}),e}if("fill"===e.type){const l=new n.Graphics,d=null!==(t=e.x)&&void 0!==t?t:0,a=null!==(r=e.y)&&void 0!==r?r:0,c=null!==(o=e.width)&&void 0!==o?o:1e6,u=null!==(i=e.height)&&void 0!==i?i:1e6;return l.rect(d,a,c,u).fill({color:e.color,alpha:null!==(s=e.alpha)&&void 0!==s?s:1}),l}if("draw"===e.type||"drawFrame"===e.type){const t=yield this.resolveTexture(e.resource,e.frame);if(!t)return null;const r=new n.Sprite(t);r.x=null!==(d=e.x)&&void 0!==d?d:0,r.y=null!==(a=e.y)&&void 0!==a?a:0;const o=e;if(r.alpha=null!==(c=o.alpha)&&void 0!==c?c:1,null!=o.tint&&(r.tint=o.tint),null!=o.width&&(r.width=o.width),null!=o.height&&(r.height=o.height),null!=o.rotation&&(r.rotation=o.rotation),null==o.anchorX&&null==o.anchorY||r.anchor.set(null!==(u=o.anchorX)&&void 0!==u?u:0,null!==(h=o.anchorY)&&void 0!==h?h:0),null==o.scaleX&&null==o.scaleY||r.scale.set(null!==(p=o.scaleX)&&void 0!==p?p:1,null!==(y=o.scaleY)&&void 0!==y?y:1),o.blendMode)try{r.blendMode=o.blendMode}catch(e){}return r}if("erase"===e.type){const t=new n.Graphics,r=null!==(f=e.width)&&void 0!==f?f:16,o=null!==(v=e.height)&&void 0!==v?v:16,i=null!==(g=e.anchorX)&&void 0!==g?g:0,l=null!==(m=e.anchorY)&&void 0!==m?m:0,s=(null!==(b=e.x)&&void 0!==b?b:0)-r*i,d=(null!==(x=e.y)&&void 0!==x?x:0)-o*l;t.rect(s,d,r,o).fill({color:16777215,alpha:1});try{t.blendMode="erase"}catch(e){}return t}if("drawText"===e.type){const t=new n.Text({text:e.text,style:{fontFamily:null!==(T=null===(w=e.style)||void 0===w?void 0:w.fontFamily)&&void 0!==T?T:"Arial",fontSize:null!==(A=null===(E=e.style)||void 0===E?void 0:E.fontSize)&&void 0!==A?A:32,fontWeight:null!==(O=null===(R=e.style)||void 0===R?void 0:R.fontWeight)&&void 0!==O?O:"normal",fill:null!==(S=null===(M=e.style)||void 0===M?void 0:M.fill)&&void 0!==S?S:16777215,stroke:null===(_=e.style)||void 0===_?void 0:_.stroke,align:null!==(P=null===(C=e.style)||void 0===C?void 0:C.align)&&void 0!==P?P:"left"}});return t.x=null!==(V=e.x)&&void 0!==V?V:0,t.y=null!==(j=e.y)&&void 0!==j?j:0,null!=e.alpha&&(t.alpha=e.alpha),null!=e.tint&&(t.tint=e.tint),t}if("paint"===e.type){const t=yield this.resolveTexture(e.resource,e.frame);if(!t)return null;const r=new n.Container,o=Math.max(1,null!==(k=e.times)&&void 0!==k?k:1),i=null!==(N=null===(I=e.step)||void 0===I?void 0:I.x)&&void 0!==N?N:0,l=null!==(Y=null===(G=e.step)||void 0===G?void 0:G.y)&&void 0!==Y?Y:0;for(let s=0;s<o;s++){const o=new n.Sprite(t);o.x=(null!==(D=e.x)&&void 0!==D?D:0)+i*s,o.y=(null!==(F=e.y)&&void 0!==F?F:0)+l*s,o.anchor.set(.5,.5),o.alpha=null!==(X=e.alpha)&&void 0!==X?X:1,e.tintCycle&&e.tintCycle.length>0?o.tint=e.tintCycle[s%e.tintCycle.length]:null!=e.tint&&(o.tint=e.tint),r.addChild(o)}return r}return null})}maybeSave(e){var r;const n=this.records[e];if(!n)return;const o=n.component.saveAs;if(o)try{const e=null===(r=t.resource.resourcesMap)||void 0===r?void 0:r[o];if(e){e.complete=!0,e.instance=n.rt;const r=t.resource.promiseMap;return void(r&&(r[o]=Promise.resolve({instance:n.rt,name:o})))}t.resource.resourcesMap=t.resource.resourcesMap||{},t.resource.resourcesMap[o]={name:o,type:"IMAGE",complete:!0,instance:n.rt,data:{}};const i=t.resource.promiseMap;i&&(i[o]=Promise.resolve({instance:n.rt,name:o}))}catch(e){console.warn("[RenderTexture] saveAs failed",e)}}destroy(){var e,t;for(const r in this.records){const n=parseInt(r),o=this.records[n];null===(t=null===(e=this.containerManager)||void 0===e?void 0:e.getContainer(n))||void 0===t||t.removeChild(o.sprite),o.sprite.destroy({children:!0}),o.rt.destroy(!0),delete this.records[n]}}};p.systemName="RenderTexture",p=o([t.decorators.componentObserver({RenderTexture:[{prop:["width"],deep:!1},{prop:["height"],deep:!1},{prop:["ops"],deep:!0},{prop:["dirty"],deep:!1},{prop:["backgroundColor"],deep:!1},{prop:["backgroundAlpha"],deep:!1}]})],p);var y=p;return e.RenderTexture=h,e.RenderTextureSystem=y,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.renderer.render.texture=globalThis.EVA.plugin.renderer.render.texture||_EVA_IIFE_texture;