@eva/plugin-renderer-render-texture 2.1.0-beta.2 → 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 +3 -3
- package/dist/EVA.plugin.renderer.render.texture.js +0 -545
- package/dist/EVA.plugin.renderer.render.texture.min.js +0 -1
- package/dist/plugin-renderer-render-texture.cjs.js +0 -493
- package/dist/plugin-renderer-render-texture.cjs.prod.js +0 -1
- package/dist/plugin-renderer-render-texture.d.ts +0 -167
- package/dist/plugin-renderer-render-texture.esm.js +0 -488
|
@@ -1,488 +0,0 @@
|
|
|
1
|
-
import { Component, resource, decorators, OBSERVER_TYPE } from '@eva/eva.js';
|
|
2
|
-
import { type } from '@eva/inspector-decorator';
|
|
3
|
-
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
4
|
-
import { RenderTexture as RenderTexture$1, Sprite, Texture, Container, Graphics, Text } from 'pixi.js';
|
|
5
|
-
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
|
|
9
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
-
purpose with or without fee is hereby granted.
|
|
11
|
-
|
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
|
|
21
|
-
function __decorate(decorators, target, key, desc) {
|
|
22
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
23
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
24
|
-
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;
|
|
25
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function __metadata(metadataKey, metadataValue) {
|
|
29
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
43
|
-
var e = new Error(message);
|
|
44
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* RenderTexture component.
|
|
49
|
-
*
|
|
50
|
-
* Equivalent of Phaser RenderTexture / DynamicTexture. Holds a Pixi RenderTexture
|
|
51
|
-
* underneath and lets the DSL declaratively enqueue draw ops via `ops`.
|
|
52
|
-
*
|
|
53
|
-
* Mutating `ops` (or any of the simple props) replays the queue.
|
|
54
|
-
*/
|
|
55
|
-
class RenderTexture extends Component {
|
|
56
|
-
constructor() {
|
|
57
|
-
super(...arguments);
|
|
58
|
-
this.width = 256;
|
|
59
|
-
this.height = 256;
|
|
60
|
-
this.ops = [];
|
|
61
|
-
this.backgroundColor = -1;
|
|
62
|
-
this.backgroundAlpha = 1;
|
|
63
|
-
this.append = true;
|
|
64
|
-
/** Bumped by clear()/fill()/etc. so the system can detect imperative changes. */
|
|
65
|
-
this.dirty = 0;
|
|
66
|
-
}
|
|
67
|
-
init(obj) {
|
|
68
|
-
if (obj)
|
|
69
|
-
Object.assign(this, obj);
|
|
70
|
-
if (!Array.isArray(this.ops))
|
|
71
|
-
this.ops = [];
|
|
72
|
-
}
|
|
73
|
-
/** Append an op + mark dirty (works at runtime, not just init). */
|
|
74
|
-
addOp(op) {
|
|
75
|
-
this.ops = [...this.ops, op];
|
|
76
|
-
this.dirty++;
|
|
77
|
-
}
|
|
78
|
-
/** Clear the queue (and the texture next commit). */
|
|
79
|
-
clearOps() {
|
|
80
|
-
this.ops = [{ type: 'clear' }];
|
|
81
|
-
this.dirty++;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
RenderTexture.componentName = 'RenderTexture';
|
|
85
|
-
__decorate([
|
|
86
|
-
type('number'),
|
|
87
|
-
__metadata("design:type", Number)
|
|
88
|
-
], RenderTexture.prototype, "width", void 0);
|
|
89
|
-
__decorate([
|
|
90
|
-
type('number'),
|
|
91
|
-
__metadata("design:type", Number)
|
|
92
|
-
], RenderTexture.prototype, "height", void 0);
|
|
93
|
-
__decorate([
|
|
94
|
-
type('array'),
|
|
95
|
-
__metadata("design:type", Array)
|
|
96
|
-
], RenderTexture.prototype, "ops", void 0);
|
|
97
|
-
__decorate([
|
|
98
|
-
type('number'),
|
|
99
|
-
__metadata("design:type", Number)
|
|
100
|
-
], RenderTexture.prototype, "backgroundColor", void 0);
|
|
101
|
-
__decorate([
|
|
102
|
-
type('number'),
|
|
103
|
-
__metadata("design:type", Number)
|
|
104
|
-
], RenderTexture.prototype, "backgroundAlpha", void 0);
|
|
105
|
-
|
|
106
|
-
const FRAME_SEP = '#'; // resource name separator: `myAtlas#frame.png`
|
|
107
|
-
let RenderTextureSystem = class RenderTextureSystem extends Renderer {
|
|
108
|
-
constructor() {
|
|
109
|
-
super(...arguments);
|
|
110
|
-
this.name = 'RenderTexture';
|
|
111
|
-
this.records = {};
|
|
112
|
-
}
|
|
113
|
-
init() {
|
|
114
|
-
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
115
|
-
this.renderSystem.rendererManager.register(this);
|
|
116
|
-
}
|
|
117
|
-
rendererUpdate(gameObject) {
|
|
118
|
-
const record = this.records[gameObject.id];
|
|
119
|
-
if (!record)
|
|
120
|
-
return;
|
|
121
|
-
if (record.needsReplay) {
|
|
122
|
-
record.needsReplay = false;
|
|
123
|
-
// fire-and-forget: replay is async (loads textures). next frame will see updated RT.
|
|
124
|
-
this.replay(gameObject.id);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
componentChanged(changed) {
|
|
128
|
-
var _a, _b, _c, _d;
|
|
129
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
if (changed.componentName !== 'RenderTexture')
|
|
131
|
-
return;
|
|
132
|
-
const component = changed.component;
|
|
133
|
-
const gameObjectId = changed.gameObject.id;
|
|
134
|
-
if (changed.type === OBSERVER_TYPE.ADD) {
|
|
135
|
-
const rt = RenderTexture$1.create({
|
|
136
|
-
width: Math.max(1, component.width || 1),
|
|
137
|
-
height: Math.max(1, component.height || 1),
|
|
138
|
-
resolution: 1,
|
|
139
|
-
});
|
|
140
|
-
const sprite = new Sprite(rt);
|
|
141
|
-
// Force sprite display rect to match component.width/height (in design units)
|
|
142
|
-
// so the RT shows at intended logical size regardless of devicePixelRatio.
|
|
143
|
-
sprite.width = component.width;
|
|
144
|
-
sprite.height = component.height;
|
|
145
|
-
this.containerManager.getContainer(gameObjectId).addChildAt(sprite, 0);
|
|
146
|
-
this.records[gameObjectId] = { rt, sprite, component, lastSig: '', needsReplay: true };
|
|
147
|
-
// schedule replay for next frame so PIXI Application & renderer are ready.
|
|
148
|
-
this.maybeSave(gameObjectId);
|
|
149
|
-
}
|
|
150
|
-
else if (changed.type === OBSERVER_TYPE.CHANGE) {
|
|
151
|
-
const record = this.records[gameObjectId];
|
|
152
|
-
if (!record)
|
|
153
|
-
return;
|
|
154
|
-
record.component = component;
|
|
155
|
-
// Resize when width/height changed
|
|
156
|
-
if (record.rt.width !== component.width || record.rt.height !== component.height) {
|
|
157
|
-
try {
|
|
158
|
-
(_b = (_a = record.rt).resize) === null || _b === void 0 ? void 0 : _b.call(_a, Math.max(1, component.width), Math.max(1, component.height));
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
// ignore
|
|
162
|
-
}
|
|
163
|
-
record.sprite.width = component.width;
|
|
164
|
-
record.sprite.height = component.height;
|
|
165
|
-
}
|
|
166
|
-
record.needsReplay = true;
|
|
167
|
-
this.maybeSave(gameObjectId);
|
|
168
|
-
}
|
|
169
|
-
else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
170
|
-
const record = this.records[gameObjectId];
|
|
171
|
-
if (!record)
|
|
172
|
-
return;
|
|
173
|
-
(_d = (_c = this.containerManager) === null || _c === void 0 ? void 0 : _c.getContainer(gameObjectId)) === null || _d === void 0 ? void 0 : _d.removeChild(record.sprite);
|
|
174
|
-
record.sprite.destroy({ children: true });
|
|
175
|
-
record.rt.destroy(true);
|
|
176
|
-
delete this.records[gameObjectId];
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
/** Resolve a resource name (optionally with `#frame` suffix) → Texture. */
|
|
181
|
-
resolveTexture(name, explicitFrame) {
|
|
182
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
if (!name)
|
|
184
|
-
return null;
|
|
185
|
-
let resName = name;
|
|
186
|
-
let frame = explicitFrame;
|
|
187
|
-
if (!frame && name.includes(FRAME_SEP)) {
|
|
188
|
-
const idx = name.indexOf(FRAME_SEP);
|
|
189
|
-
resName = name.slice(0, idx);
|
|
190
|
-
frame = name.slice(idx + 1);
|
|
191
|
-
}
|
|
192
|
-
try {
|
|
193
|
-
const { instance } = yield resource.getResource(resName);
|
|
194
|
-
if (!instance)
|
|
195
|
-
return null;
|
|
196
|
-
// sprite atlas: instance is a frames map
|
|
197
|
-
if (frame) {
|
|
198
|
-
if (instance && instance[frame] instanceof Texture) {
|
|
199
|
-
return instance[frame];
|
|
200
|
-
}
|
|
201
|
-
// Sometimes instance has `.textures[frame]`
|
|
202
|
-
const textures = instance.textures;
|
|
203
|
-
if (textures && textures[frame] instanceof Texture) {
|
|
204
|
-
return textures[frame];
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (instance instanceof Texture)
|
|
208
|
-
return instance;
|
|
209
|
-
// sprite atlas single texture access
|
|
210
|
-
if (instance.baseTexture)
|
|
211
|
-
return instance;
|
|
212
|
-
// grab first frame as fallback
|
|
213
|
-
if (typeof instance === 'object') {
|
|
214
|
-
const keys = Object.keys(instance);
|
|
215
|
-
for (const k of keys) {
|
|
216
|
-
const v = instance[k];
|
|
217
|
-
if (v instanceof Texture)
|
|
218
|
-
return v;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
catch (_a) {
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
/** Build an offscreen Pixi DisplayObject describing the op, then render it into the RT. */
|
|
229
|
-
replay(gameObjectId) {
|
|
230
|
-
var _a, _b, _c, _d, _e, _f;
|
|
231
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
-
const record = this.records[gameObjectId];
|
|
233
|
-
if (!record)
|
|
234
|
-
return;
|
|
235
|
-
const { rt, component } = record;
|
|
236
|
-
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}`;
|
|
237
|
-
if (record.lastSig === sig && component.append) ;
|
|
238
|
-
record.lastSig = sig;
|
|
239
|
-
const renderer = (_c = this.renderSystem.application) === null || _c === void 0 ? void 0 : _c.renderer;
|
|
240
|
-
if (!renderer)
|
|
241
|
-
return;
|
|
242
|
-
// Build a single staging Container that aggregates this commit's ops.
|
|
243
|
-
const stage = new Container();
|
|
244
|
-
// Optional background (fill RT with color, replacing previous content)
|
|
245
|
-
const bg = component.backgroundColor;
|
|
246
|
-
const bgA = (_d = component.backgroundAlpha) !== null && _d !== void 0 ? _d : 1;
|
|
247
|
-
if (!component.append) {
|
|
248
|
-
const g = new Graphics();
|
|
249
|
-
if (bg != null && bg >= 0) {
|
|
250
|
-
g.rect(0, 0, component.width, component.height).fill({ color: bg, alpha: bgA });
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
// transparent clear
|
|
254
|
-
g.rect(0, 0, component.width, component.height).fill({ color: 0x000000, alpha: 0 });
|
|
255
|
-
}
|
|
256
|
-
stage.addChild(g);
|
|
257
|
-
}
|
|
258
|
-
for (const op of component.ops || []) {
|
|
259
|
-
const node = yield this.buildOpNode(op);
|
|
260
|
-
if (node)
|
|
261
|
-
stage.addChild(node);
|
|
262
|
-
}
|
|
263
|
-
try {
|
|
264
|
-
// Pixi v8 render-to-target API
|
|
265
|
-
renderer.render({
|
|
266
|
-
container: stage,
|
|
267
|
-
target: rt,
|
|
268
|
-
clear: !component.append,
|
|
269
|
-
});
|
|
270
|
-
// eslint-disable-next-line no-console
|
|
271
|
-
if (globalThis.__RT_DEBUG) {
|
|
272
|
-
console.log('[RT] replayed', {
|
|
273
|
-
ops: (_e = component.ops) === null || _e === void 0 ? void 0 : _e.length,
|
|
274
|
-
w: rt.width,
|
|
275
|
-
h: rt.height,
|
|
276
|
-
stageChildren: (_f = stage.children) === null || _f === void 0 ? void 0 : _f.length,
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
catch (e) {
|
|
281
|
-
// fallback for older API: renderer.render(displayObject, { renderTexture: rt })
|
|
282
|
-
try {
|
|
283
|
-
renderer.render(stage, { renderTexture: rt, clear: !component.append });
|
|
284
|
-
}
|
|
285
|
-
catch (_g) {
|
|
286
|
-
console.warn('[RenderTexture] renderer.render failed', e);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
finally {
|
|
290
|
-
// Defer destroy to next microtask so the GPU has time to consume.
|
|
291
|
-
// Some Pixi v8 builds upload the geometry lazily.
|
|
292
|
-
Promise.resolve().then(() => {
|
|
293
|
-
try {
|
|
294
|
-
stage.destroy({ children: true });
|
|
295
|
-
}
|
|
296
|
-
catch (_a) {
|
|
297
|
-
/* noop */
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
buildOpNode(op) {
|
|
304
|
-
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;
|
|
305
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
if (op.type === 'clear') {
|
|
307
|
-
const g = new Graphics();
|
|
308
|
-
g.rect(0, 0, 1e6, 1e6).fill({ color: 0x000000, alpha: 0 });
|
|
309
|
-
// Use destination-in trick alternative: simpler — caller knows append=false to actually clear.
|
|
310
|
-
return g;
|
|
311
|
-
}
|
|
312
|
-
if (op.type === 'fill') {
|
|
313
|
-
const g = new Graphics();
|
|
314
|
-
const x = (_a = op.x) !== null && _a !== void 0 ? _a : 0;
|
|
315
|
-
const y = (_b = op.y) !== null && _b !== void 0 ? _b : 0;
|
|
316
|
-
const w = (_c = op.width) !== null && _c !== void 0 ? _c : 1e6;
|
|
317
|
-
const h = (_d = op.height) !== null && _d !== void 0 ? _d : 1e6;
|
|
318
|
-
g.rect(x, y, w, h).fill({ color: op.color, alpha: (_e = op.alpha) !== null && _e !== void 0 ? _e : 1 });
|
|
319
|
-
return g;
|
|
320
|
-
}
|
|
321
|
-
if (op.type === 'draw' || op.type === 'drawFrame') {
|
|
322
|
-
const tex = yield this.resolveTexture(op.resource, op.frame);
|
|
323
|
-
if (!tex)
|
|
324
|
-
return null;
|
|
325
|
-
const sp = new Sprite(tex);
|
|
326
|
-
sp.x = (_f = op.x) !== null && _f !== void 0 ? _f : 0;
|
|
327
|
-
sp.y = (_g = op.y) !== null && _g !== void 0 ? _g : 0;
|
|
328
|
-
const o = op;
|
|
329
|
-
sp.alpha = (_h = o.alpha) !== null && _h !== void 0 ? _h : 1;
|
|
330
|
-
if (o.tint != null)
|
|
331
|
-
sp.tint = o.tint;
|
|
332
|
-
if (o.width != null)
|
|
333
|
-
sp.width = o.width;
|
|
334
|
-
if (o.height != null)
|
|
335
|
-
sp.height = o.height;
|
|
336
|
-
if (o.rotation != null)
|
|
337
|
-
sp.rotation = o.rotation;
|
|
338
|
-
if (o.anchorX != null || o.anchorY != null) {
|
|
339
|
-
sp.anchor.set((_j = o.anchorX) !== null && _j !== void 0 ? _j : 0, (_k = o.anchorY) !== null && _k !== void 0 ? _k : 0);
|
|
340
|
-
}
|
|
341
|
-
if (o.scaleX != null || o.scaleY != null) {
|
|
342
|
-
sp.scale.set((_l = o.scaleX) !== null && _l !== void 0 ? _l : 1, (_m = o.scaleY) !== null && _m !== void 0 ? _m : 1);
|
|
343
|
-
}
|
|
344
|
-
if (o.blendMode) {
|
|
345
|
-
try {
|
|
346
|
-
sp.blendMode = o.blendMode;
|
|
347
|
-
}
|
|
348
|
-
catch (_15) {
|
|
349
|
-
// ignore
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return sp;
|
|
353
|
-
}
|
|
354
|
-
if (op.type === 'erase') {
|
|
355
|
-
const g = new Graphics();
|
|
356
|
-
const w = (_o = op.width) !== null && _o !== void 0 ? _o : 16;
|
|
357
|
-
const h = (_p = op.height) !== null && _p !== void 0 ? _p : 16;
|
|
358
|
-
const ax = (_q = op.anchorX) !== null && _q !== void 0 ? _q : 0;
|
|
359
|
-
const ay = (_r = op.anchorY) !== null && _r !== void 0 ? _r : 0;
|
|
360
|
-
const x = ((_s = op.x) !== null && _s !== void 0 ? _s : 0) - w * ax;
|
|
361
|
-
const y = ((_t = op.y) !== null && _t !== void 0 ? _t : 0) - h * ay;
|
|
362
|
-
g.rect(x, y, w, h).fill({ color: 0xffffff, alpha: 1 });
|
|
363
|
-
try {
|
|
364
|
-
g.blendMode = 'erase';
|
|
365
|
-
}
|
|
366
|
-
catch (_16) {
|
|
367
|
-
// ignore
|
|
368
|
-
}
|
|
369
|
-
return g;
|
|
370
|
-
}
|
|
371
|
-
if (op.type === 'drawText') {
|
|
372
|
-
const t = new Text({
|
|
373
|
-
text: op.text,
|
|
374
|
-
style: {
|
|
375
|
-
fontFamily: (_v = (_u = op.style) === null || _u === void 0 ? void 0 : _u.fontFamily) !== null && _v !== void 0 ? _v : 'Arial',
|
|
376
|
-
fontSize: (_x = (_w = op.style) === null || _w === void 0 ? void 0 : _w.fontSize) !== null && _x !== void 0 ? _x : 32,
|
|
377
|
-
fontWeight: (_z = (_y = op.style) === null || _y === void 0 ? void 0 : _y.fontWeight) !== null && _z !== void 0 ? _z : 'normal',
|
|
378
|
-
fill: (_1 = (_0 = op.style) === null || _0 === void 0 ? void 0 : _0.fill) !== null && _1 !== void 0 ? _1 : 0xffffff,
|
|
379
|
-
stroke: (_2 = op.style) === null || _2 === void 0 ? void 0 : _2.stroke,
|
|
380
|
-
align: (_4 = (_3 = op.style) === null || _3 === void 0 ? void 0 : _3.align) !== null && _4 !== void 0 ? _4 : 'left',
|
|
381
|
-
},
|
|
382
|
-
});
|
|
383
|
-
t.x = (_5 = op.x) !== null && _5 !== void 0 ? _5 : 0;
|
|
384
|
-
t.y = (_6 = op.y) !== null && _6 !== void 0 ? _6 : 0;
|
|
385
|
-
if (op.alpha != null)
|
|
386
|
-
t.alpha = op.alpha;
|
|
387
|
-
if (op.tint != null)
|
|
388
|
-
t.tint = op.tint;
|
|
389
|
-
return t;
|
|
390
|
-
}
|
|
391
|
-
if (op.type === 'paint') {
|
|
392
|
-
const tex = yield this.resolveTexture(op.resource, op.frame);
|
|
393
|
-
if (!tex)
|
|
394
|
-
return null;
|
|
395
|
-
const c = new Container();
|
|
396
|
-
const times = Math.max(1, (_7 = op.times) !== null && _7 !== void 0 ? _7 : 1);
|
|
397
|
-
const dx = (_9 = (_8 = op.step) === null || _8 === void 0 ? void 0 : _8.x) !== null && _9 !== void 0 ? _9 : 0;
|
|
398
|
-
const dy = (_11 = (_10 = op.step) === null || _10 === void 0 ? void 0 : _10.y) !== null && _11 !== void 0 ? _11 : 0;
|
|
399
|
-
for (let i = 0; i < times; i++) {
|
|
400
|
-
const sp = new Sprite(tex);
|
|
401
|
-
sp.x = ((_12 = op.x) !== null && _12 !== void 0 ? _12 : 0) + dx * i;
|
|
402
|
-
sp.y = ((_13 = op.y) !== null && _13 !== void 0 ? _13 : 0) + dy * i;
|
|
403
|
-
sp.anchor.set(0.5, 0.5);
|
|
404
|
-
sp.alpha = (_14 = op.alpha) !== null && _14 !== void 0 ? _14 : 1;
|
|
405
|
-
if (op.tintCycle && op.tintCycle.length > 0) {
|
|
406
|
-
sp.tint = op.tintCycle[i % op.tintCycle.length];
|
|
407
|
-
}
|
|
408
|
-
else if (op.tint != null) {
|
|
409
|
-
sp.tint = op.tint;
|
|
410
|
-
}
|
|
411
|
-
c.addChild(sp);
|
|
412
|
-
}
|
|
413
|
-
return c;
|
|
414
|
-
}
|
|
415
|
-
return null;
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* After a successful replay, save the RT as a resource so other Img/Sprite can reference it.
|
|
420
|
-
* Idempotent: registers once per gameObject.saveAs key.
|
|
421
|
-
*/
|
|
422
|
-
maybeSave(gameObjectId) {
|
|
423
|
-
var _a;
|
|
424
|
-
const record = this.records[gameObjectId];
|
|
425
|
-
if (!record)
|
|
426
|
-
return;
|
|
427
|
-
const key = record.component.saveAs;
|
|
428
|
-
if (!key)
|
|
429
|
-
return;
|
|
430
|
-
try {
|
|
431
|
-
// Check if already in resourcesMap
|
|
432
|
-
const existing = (_a = resource.resourcesMap) === null || _a === void 0 ? void 0 : _a[key];
|
|
433
|
-
if (existing) {
|
|
434
|
-
existing.complete = true;
|
|
435
|
-
existing.instance = record.rt;
|
|
436
|
-
// Make sure callers awaiting getResource get our instance
|
|
437
|
-
const promiseMap = resource.promiseMap;
|
|
438
|
-
if (promiseMap) {
|
|
439
|
-
promiseMap[key] = Promise.resolve({ instance: record.rt, name: key });
|
|
440
|
-
}
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
// Register a fresh entry
|
|
444
|
-
resource.resourcesMap = resource.resourcesMap || {};
|
|
445
|
-
resource.resourcesMap[key] = {
|
|
446
|
-
name: key,
|
|
447
|
-
type: 'IMAGE',
|
|
448
|
-
complete: true,
|
|
449
|
-
instance: record.rt,
|
|
450
|
-
data: {},
|
|
451
|
-
};
|
|
452
|
-
const promiseMap = resource.promiseMap;
|
|
453
|
-
if (promiseMap) {
|
|
454
|
-
promiseMap[key] = Promise.resolve({ instance: record.rt, name: key });
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
catch (e) {
|
|
458
|
-
console.warn('[RenderTexture] saveAs failed', e);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
destroy() {
|
|
462
|
-
var _a, _b;
|
|
463
|
-
for (const key in this.records) {
|
|
464
|
-
const id = parseInt(key);
|
|
465
|
-
const record = this.records[id];
|
|
466
|
-
(_b = (_a = this.containerManager) === null || _a === void 0 ? void 0 : _a.getContainer(id)) === null || _b === void 0 ? void 0 : _b.removeChild(record.sprite);
|
|
467
|
-
record.sprite.destroy({ children: true });
|
|
468
|
-
record.rt.destroy(true);
|
|
469
|
-
delete this.records[id];
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
RenderTextureSystem.systemName = 'RenderTexture';
|
|
474
|
-
RenderTextureSystem = __decorate([
|
|
475
|
-
decorators.componentObserver({
|
|
476
|
-
RenderTexture: [
|
|
477
|
-
{ prop: ['width'], deep: false },
|
|
478
|
-
{ prop: ['height'], deep: false },
|
|
479
|
-
{ prop: ['ops'], deep: true },
|
|
480
|
-
{ prop: ['dirty'], deep: false },
|
|
481
|
-
{ prop: ['backgroundColor'], deep: false },
|
|
482
|
-
{ prop: ['backgroundAlpha'], deep: false },
|
|
483
|
-
],
|
|
484
|
-
})
|
|
485
|
-
], RenderTextureSystem);
|
|
486
|
-
var RenderTextureSystem$1 = RenderTextureSystem;
|
|
487
|
-
|
|
488
|
-
export { RenderTexture, RenderTextureSystem$1 as RenderTextureSystem };
|