@flare-engine/react 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.mts +27 -86
- package/dist/index.d.ts +27 -86
- package/dist/index.js +81 -567
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -576
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -8
package/dist/index.js
CHANGED
|
@@ -28,10 +28,13 @@ __export(index_exports, {
|
|
|
28
28
|
VirtualJoystick: () => VirtualJoystick,
|
|
29
29
|
createSkiaFrameRenderer: () => createSkiaFrameRenderer,
|
|
30
30
|
renderShapesToImage: () => renderShapesToImage,
|
|
31
|
+
useCountUp: () => useCountUp,
|
|
31
32
|
useEntity: () => useEntity,
|
|
32
33
|
useGame: () => useGame,
|
|
33
34
|
useGameLoop: () => useGameLoop,
|
|
34
|
-
|
|
35
|
+
useOverlayFade: () => useOverlayFade,
|
|
36
|
+
useSafeArea: () => useSafeArea,
|
|
37
|
+
useSignalState: () => useSignalState
|
|
35
38
|
});
|
|
36
39
|
module.exports = __toCommonJS(index_exports);
|
|
37
40
|
|
|
@@ -72,521 +75,8 @@ function detachSnapshot(surface) {
|
|
|
72
75
|
}
|
|
73
76
|
return snap;
|
|
74
77
|
}
|
|
75
|
-
var BLEND_SRC_OVER = 3;
|
|
76
|
-
var BLEND_SRC_IN = 5;
|
|
77
|
-
var OUTLINE_OFFSETS = [
|
|
78
|
-
[1, 0],
|
|
79
|
-
[-1, 0],
|
|
80
|
-
[0, 1],
|
|
81
|
-
[0, -1],
|
|
82
|
-
[Math.SQRT1_2, Math.SQRT1_2],
|
|
83
|
-
[Math.SQRT1_2, -Math.SQRT1_2],
|
|
84
|
-
[-Math.SQRT1_2, Math.SQRT1_2],
|
|
85
|
-
[-Math.SQRT1_2, -Math.SQRT1_2]
|
|
86
|
-
];
|
|
87
78
|
function createSkiaFrameRenderer(Skia2) {
|
|
88
|
-
|
|
89
|
-
let tintPaint = null;
|
|
90
|
-
let flashPaint = null;
|
|
91
|
-
let grayscalePaint = null;
|
|
92
|
-
let outlinePaint = null;
|
|
93
|
-
let customPaint = null;
|
|
94
|
-
let waterPaint = null;
|
|
95
|
-
let waterRuntimeEffect = null;
|
|
96
|
-
let fogPaint = null;
|
|
97
|
-
let fogRuntimeEffect = null;
|
|
98
|
-
let firePaint = null;
|
|
99
|
-
let fireRuntimeEffect = null;
|
|
100
|
-
let roofsCityPaint = null;
|
|
101
|
-
let roofsCityEffect = null;
|
|
102
|
-
let forestCanopyPaint = null;
|
|
103
|
-
let forestCanopyEffect = null;
|
|
104
|
-
let riverWavePaint = null;
|
|
105
|
-
let riverWaveEffect = null;
|
|
106
|
-
let moonCraterPaint = null;
|
|
107
|
-
let moonCraterEffect = null;
|
|
108
|
-
let caveInteriorPaint = null;
|
|
109
|
-
let caveInteriorEffect = null;
|
|
110
|
-
let mountainHillsPaint = null;
|
|
111
|
-
let mountainHillsEffect = null;
|
|
112
|
-
const roofsCityUniforms = new Array(10).fill(0);
|
|
113
|
-
const forestCanopyUniforms = new Array(10).fill(0);
|
|
114
|
-
const riverWaveUniforms = new Array(10).fill(0);
|
|
115
|
-
const moonCraterUniforms = new Array(10).fill(0);
|
|
116
|
-
const caveInteriorUniforms = new Array(10).fill(0);
|
|
117
|
-
const mountainHillsUniforms = new Array(10).fill(0);
|
|
118
|
-
const recorder = Skia2.PictureRecorder();
|
|
119
|
-
const recordingBounds = Skia2.XYWHRect(0, 0, 0, 0);
|
|
120
|
-
const srcRects = [];
|
|
121
|
-
const xforms = [];
|
|
122
|
-
const stretchSrcRects = [];
|
|
123
|
-
const stretchDstRects = [];
|
|
124
|
-
let stretchPaint = null;
|
|
125
|
-
const clearColor = new Float32Array(4);
|
|
126
|
-
const tintColor = new Float32Array(4);
|
|
127
|
-
const flashColor = new Float32Array(4);
|
|
128
|
-
const outlineColor = new Float32Array(4);
|
|
129
|
-
const grayMatrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
|
|
130
|
-
const customUniforms = [];
|
|
131
|
-
const waterUniforms = new Array(11).fill(0);
|
|
132
|
-
const fogUniforms = new Array(9).fill(0);
|
|
133
|
-
const fireUniforms = new Array(11).fill(0);
|
|
134
|
-
let currentFrameTime = 0;
|
|
135
|
-
let current = null;
|
|
136
|
-
let _boundRuntime = null;
|
|
137
|
-
let _boundChain = null;
|
|
138
|
-
const _loggedOnce = /* @__PURE__ */ new Set();
|
|
139
|
-
function logOnce(msg) {
|
|
140
|
-
if (_loggedOnce.has(msg)) return;
|
|
141
|
-
_loggedOnce.add(msg);
|
|
142
|
-
console.warn(`[postfx] ${msg}`);
|
|
143
|
-
}
|
|
144
|
-
const canvas = {
|
|
145
|
-
save: () => current?.save() ?? 0,
|
|
146
|
-
restore: () => {
|
|
147
|
-
current?.restore();
|
|
148
|
-
},
|
|
149
|
-
translate: (x, y) => {
|
|
150
|
-
current?.translate(x, y);
|
|
151
|
-
},
|
|
152
|
-
scale: (sx, sy) => {
|
|
153
|
-
current?.scale(sx, sy);
|
|
154
|
-
},
|
|
155
|
-
rotate: (radians, cx, cy) => {
|
|
156
|
-
current?.rotate(radians, cx, cy);
|
|
157
|
-
},
|
|
158
|
-
clear: (argb) => {
|
|
159
|
-
if (current === null) return;
|
|
160
|
-
clearColor[0] = (argb >>> 16 & 255) / 255;
|
|
161
|
-
clearColor[1] = (argb >>> 8 & 255) / 255;
|
|
162
|
-
clearColor[2] = (argb & 255) / 255;
|
|
163
|
-
clearColor[3] = (argb >>> 24 & 255) / 255;
|
|
164
|
-
current.clear(clearColor);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
function ensurePoolCapacity(n) {
|
|
168
|
-
while (srcRects.length < n) {
|
|
169
|
-
srcRects.push(Skia2.XYWHRect(0, 0, 0, 0));
|
|
170
|
-
xforms.push(Skia2.RSXform(1, 0, 0, 0));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function ensureStretchPoolCapacity(n) {
|
|
174
|
-
while (stretchSrcRects.length < n) {
|
|
175
|
-
stretchSrcRects.push(Skia2.XYWHRect(0, 0, 0, 0));
|
|
176
|
-
stretchDstRects.push(Skia2.XYWHRect(0, 0, 0, 0));
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function fillSrcRects(commands, n) {
|
|
180
|
-
for (let i = 0; i < n; i++) {
|
|
181
|
-
const cmd = commands[i];
|
|
182
|
-
srcRects[i]?.setXYWH(cmd.srcX, cmd.srcY, cmd.srcW, cmd.srcH);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
function fillXforms(commands, n, dx, dy) {
|
|
186
|
-
for (let i = 0; i < n; i++) {
|
|
187
|
-
const cmd = commands[i];
|
|
188
|
-
const scale = cmd.srcW === 0 ? 1 : cmd.dstW / cmd.srcW;
|
|
189
|
-
if (cmd.rotation === 0) {
|
|
190
|
-
xforms[i]?.set(scale, 0, cmd.dstX + dx, cmd.dstY + dy);
|
|
191
|
-
} else {
|
|
192
|
-
const c = Math.cos(cmd.rotation);
|
|
193
|
-
const s = Math.sin(cmd.rotation);
|
|
194
|
-
const scos = scale * c;
|
|
195
|
-
const ssin = scale * s;
|
|
196
|
-
const px = cmd.dstX + cmd.anchorX * cmd.dstW + dx;
|
|
197
|
-
const py = cmd.dstY + cmd.anchorY * cmd.dstH + dy;
|
|
198
|
-
const axSrc = cmd.anchorX * cmd.srcW;
|
|
199
|
-
const aySrc = cmd.anchorY * cmd.srcH;
|
|
200
|
-
xforms[i]?.set(
|
|
201
|
-
scos,
|
|
202
|
-
ssin,
|
|
203
|
-
px - scos * axSrc + ssin * aySrc,
|
|
204
|
-
py - ssin * axSrc - scos * aySrc
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
function applyTint(effect) {
|
|
210
|
-
if (tintPaint === null) tintPaint = Skia2.Paint();
|
|
211
|
-
writeColor(tintColor, effect.color, effect.amount);
|
|
212
|
-
tintPaint.setColorFilter(Skia2.ColorFilter.MakeBlend(tintColor, BLEND_SRC_OVER));
|
|
213
|
-
return tintPaint;
|
|
214
|
-
}
|
|
215
|
-
function applyFlash(effect) {
|
|
216
|
-
if (flashPaint === null) flashPaint = Skia2.Paint();
|
|
217
|
-
writeColor(flashColor, effect.color, (0, import_render.flashIntensity)(effect));
|
|
218
|
-
flashPaint.setColorFilter(Skia2.ColorFilter.MakeBlend(flashColor, BLEND_SRC_OVER));
|
|
219
|
-
return flashPaint;
|
|
220
|
-
}
|
|
221
|
-
function applyGrayscale(effect) {
|
|
222
|
-
if (grayscalePaint === null) grayscalePaint = Skia2.Paint();
|
|
223
|
-
writeGrayscaleMatrix(grayMatrix, effect.amount);
|
|
224
|
-
grayscalePaint.setColorFilter(Skia2.ColorFilter.MakeMatrix(grayMatrix));
|
|
225
|
-
return grayscalePaint;
|
|
226
|
-
}
|
|
227
|
-
function applyOutlinePaint(effect) {
|
|
228
|
-
if (outlinePaint === null) outlinePaint = Skia2.Paint();
|
|
229
|
-
writeColor(outlineColor, effect.color, 1);
|
|
230
|
-
outlinePaint.setColorFilter(Skia2.ColorFilter.MakeBlend(outlineColor, BLEND_SRC_IN));
|
|
231
|
-
return outlinePaint;
|
|
232
|
-
}
|
|
233
|
-
function applyCustom(effect) {
|
|
234
|
-
if (customPaint === null) customPaint = Skia2.Paint();
|
|
235
|
-
const shader = effect.shader;
|
|
236
|
-
const floatCount = shader.getUniformFloatCount();
|
|
237
|
-
while (customUniforms.length < floatCount) customUniforms.push(0);
|
|
238
|
-
customUniforms.length = floatCount;
|
|
239
|
-
fillCustomUniforms(effect, shader, customUniforms);
|
|
240
|
-
customPaint.setShader(shader.makeShader(customUniforms));
|
|
241
|
-
return customPaint;
|
|
242
|
-
}
|
|
243
|
-
function applyWater(effect, time) {
|
|
244
|
-
if (Skia2.RuntimeEffect === void 0) return defaultPaint;
|
|
245
|
-
if (waterRuntimeEffect === null) {
|
|
246
|
-
const compiled = Skia2.RuntimeEffect.Make(import_render.WATER_SKSL);
|
|
247
|
-
if (compiled === null) return defaultPaint;
|
|
248
|
-
waterRuntimeEffect = compiled;
|
|
249
|
-
}
|
|
250
|
-
if (waterPaint === null) waterPaint = Skia2.Paint();
|
|
251
|
-
waterUniforms[0] = 0;
|
|
252
|
-
waterUniforms[1] = 0;
|
|
253
|
-
waterUniforms[2] = effect.color.r;
|
|
254
|
-
waterUniforms[3] = effect.color.g;
|
|
255
|
-
waterUniforms[4] = effect.color.b;
|
|
256
|
-
waterUniforms[5] = effect.foamColor.r;
|
|
257
|
-
waterUniforms[6] = effect.foamColor.g;
|
|
258
|
-
waterUniforms[7] = effect.foamColor.b;
|
|
259
|
-
waterUniforms[8] = effect.waveSpeed;
|
|
260
|
-
waterUniforms[9] = effect.waveAmplitude;
|
|
261
|
-
waterUniforms[10] = time;
|
|
262
|
-
waterPaint.setShader(waterRuntimeEffect.makeShader(waterUniforms));
|
|
263
|
-
return waterPaint;
|
|
264
|
-
}
|
|
265
|
-
function applyFog(effect, time) {
|
|
266
|
-
if (Skia2.RuntimeEffect === void 0) return defaultPaint;
|
|
267
|
-
if (fogRuntimeEffect === null) {
|
|
268
|
-
const compiled = Skia2.RuntimeEffect.Make(import_render.FOG_SKSL);
|
|
269
|
-
if (compiled === null) return defaultPaint;
|
|
270
|
-
fogRuntimeEffect = compiled;
|
|
271
|
-
}
|
|
272
|
-
if (fogPaint === null) fogPaint = Skia2.Paint();
|
|
273
|
-
fogUniforms[0] = 0;
|
|
274
|
-
fogUniforms[1] = 0;
|
|
275
|
-
fogUniforms[2] = effect.color.r;
|
|
276
|
-
fogUniforms[3] = effect.color.g;
|
|
277
|
-
fogUniforms[4] = effect.color.b;
|
|
278
|
-
fogUniforms[5] = effect.density;
|
|
279
|
-
fogUniforms[6] = effect.speed;
|
|
280
|
-
fogUniforms[7] = effect.scale;
|
|
281
|
-
fogUniforms[8] = time;
|
|
282
|
-
fogPaint.setShader(fogRuntimeEffect.makeShader(fogUniforms));
|
|
283
|
-
return fogPaint;
|
|
284
|
-
}
|
|
285
|
-
function applyFire(effect, time) {
|
|
286
|
-
if (Skia2.RuntimeEffect === void 0) return defaultPaint;
|
|
287
|
-
if (fireRuntimeEffect === null) {
|
|
288
|
-
const compiled = Skia2.RuntimeEffect.Make(import_render.FIRE_SKSL);
|
|
289
|
-
if (compiled === null) return defaultPaint;
|
|
290
|
-
fireRuntimeEffect = compiled;
|
|
291
|
-
}
|
|
292
|
-
if (firePaint === null) firePaint = Skia2.Paint();
|
|
293
|
-
fireUniforms[0] = 0;
|
|
294
|
-
fireUniforms[1] = 0;
|
|
295
|
-
fireUniforms[2] = effect.color.r;
|
|
296
|
-
fireUniforms[3] = effect.color.g;
|
|
297
|
-
fireUniforms[4] = effect.color.b;
|
|
298
|
-
fireUniforms[5] = effect.tipColor.r;
|
|
299
|
-
fireUniforms[6] = effect.tipColor.g;
|
|
300
|
-
fireUniforms[7] = effect.tipColor.b;
|
|
301
|
-
fireUniforms[8] = effect.speed;
|
|
302
|
-
fireUniforms[9] = effect.intensity;
|
|
303
|
-
fireUniforms[10] = time;
|
|
304
|
-
firePaint.setShader(fireRuntimeEffect.makeShader(fireUniforms));
|
|
305
|
-
return firePaint;
|
|
306
|
-
}
|
|
307
|
-
function applyRoofsCity(effect) {
|
|
308
|
-
if (Skia2.RuntimeEffect === void 0) return defaultPaint;
|
|
309
|
-
if (roofsCityEffect === null) {
|
|
310
|
-
const compiled = Skia2.RuntimeEffect.Make(import_render.ROOFS_CITY_SKSL);
|
|
311
|
-
if (compiled === null) return defaultPaint;
|
|
312
|
-
roofsCityEffect = compiled;
|
|
313
|
-
}
|
|
314
|
-
if (roofsCityPaint === null) roofsCityPaint = Skia2.Paint();
|
|
315
|
-
roofsCityUniforms[0] = effect.resolutionW;
|
|
316
|
-
roofsCityUniforms[1] = effect.resolutionH;
|
|
317
|
-
roofsCityUniforms[2] = effect.skyColor.r;
|
|
318
|
-
roofsCityUniforms[3] = effect.skyColor.g;
|
|
319
|
-
roofsCityUniforms[4] = effect.skyColor.b;
|
|
320
|
-
roofsCityUniforms[5] = effect.roofColor.r;
|
|
321
|
-
roofsCityUniforms[6] = effect.roofColor.g;
|
|
322
|
-
roofsCityUniforms[7] = effect.roofColor.b;
|
|
323
|
-
roofsCityUniforms[8] = effect.scrollOffsetY;
|
|
324
|
-
roofsCityUniforms[9] = effect.density;
|
|
325
|
-
roofsCityPaint.setShader(roofsCityEffect.makeShader(roofsCityUniforms));
|
|
326
|
-
return roofsCityPaint;
|
|
327
|
-
}
|
|
328
|
-
function applyForestCanopy(effect) {
|
|
329
|
-
if (Skia2.RuntimeEffect === void 0) return defaultPaint;
|
|
330
|
-
if (forestCanopyEffect === null) {
|
|
331
|
-
const compiled = Skia2.RuntimeEffect.Make(import_render.FOREST_CANOPY_SKSL);
|
|
332
|
-
if (compiled === null) return defaultPaint;
|
|
333
|
-
forestCanopyEffect = compiled;
|
|
334
|
-
}
|
|
335
|
-
if (forestCanopyPaint === null) forestCanopyPaint = Skia2.Paint();
|
|
336
|
-
forestCanopyUniforms[0] = effect.resolutionW;
|
|
337
|
-
forestCanopyUniforms[1] = effect.resolutionH;
|
|
338
|
-
forestCanopyUniforms[2] = effect.skyColor.r;
|
|
339
|
-
forestCanopyUniforms[3] = effect.skyColor.g;
|
|
340
|
-
forestCanopyUniforms[4] = effect.skyColor.b;
|
|
341
|
-
forestCanopyUniforms[5] = effect.leafColor.r;
|
|
342
|
-
forestCanopyUniforms[6] = effect.leafColor.g;
|
|
343
|
-
forestCanopyUniforms[7] = effect.leafColor.b;
|
|
344
|
-
forestCanopyUniforms[8] = effect.scrollOffsetY;
|
|
345
|
-
forestCanopyUniforms[9] = effect.density;
|
|
346
|
-
forestCanopyPaint.setShader(forestCanopyEffect.makeShader(forestCanopyUniforms));
|
|
347
|
-
return forestCanopyPaint;
|
|
348
|
-
}
|
|
349
|
-
function applyRiverWave(effect) {
|
|
350
|
-
if (Skia2.RuntimeEffect === void 0) return defaultPaint;
|
|
351
|
-
if (riverWaveEffect === null) {
|
|
352
|
-
const compiled = Skia2.RuntimeEffect.Make(import_render.RIVER_WAVE_SKSL);
|
|
353
|
-
if (compiled === null) return defaultPaint;
|
|
354
|
-
riverWaveEffect = compiled;
|
|
355
|
-
}
|
|
356
|
-
if (riverWavePaint === null) riverWavePaint = Skia2.Paint();
|
|
357
|
-
riverWaveUniforms[0] = effect.resolutionW;
|
|
358
|
-
riverWaveUniforms[1] = effect.resolutionH;
|
|
359
|
-
riverWaveUniforms[2] = effect.waterColor.r;
|
|
360
|
-
riverWaveUniforms[3] = effect.waterColor.g;
|
|
361
|
-
riverWaveUniforms[4] = effect.waterColor.b;
|
|
362
|
-
riverWaveUniforms[5] = effect.foamColor.r;
|
|
363
|
-
riverWaveUniforms[6] = effect.foamColor.g;
|
|
364
|
-
riverWaveUniforms[7] = effect.foamColor.b;
|
|
365
|
-
riverWaveUniforms[8] = effect.scrollOffsetY;
|
|
366
|
-
riverWaveUniforms[9] = effect.waveScale;
|
|
367
|
-
riverWavePaint.setShader(riverWaveEffect.makeShader(riverWaveUniforms));
|
|
368
|
-
return riverWavePaint;
|
|
369
|
-
}
|
|
370
|
-
function applyMoonCrater(effect) {
|
|
371
|
-
if (Skia2.RuntimeEffect === void 0) return defaultPaint;
|
|
372
|
-
if (moonCraterEffect === null) {
|
|
373
|
-
const compiled = Skia2.RuntimeEffect.Make(import_render.MOON_CRATER_SKSL);
|
|
374
|
-
if (compiled === null) return defaultPaint;
|
|
375
|
-
moonCraterEffect = compiled;
|
|
376
|
-
}
|
|
377
|
-
if (moonCraterPaint === null) moonCraterPaint = Skia2.Paint();
|
|
378
|
-
moonCraterUniforms[0] = effect.resolutionW;
|
|
379
|
-
moonCraterUniforms[1] = effect.resolutionH;
|
|
380
|
-
moonCraterUniforms[2] = effect.moonColor.r;
|
|
381
|
-
moonCraterUniforms[3] = effect.moonColor.g;
|
|
382
|
-
moonCraterUniforms[4] = effect.moonColor.b;
|
|
383
|
-
moonCraterUniforms[5] = effect.craterColor.r;
|
|
384
|
-
moonCraterUniforms[6] = effect.craterColor.g;
|
|
385
|
-
moonCraterUniforms[7] = effect.craterColor.b;
|
|
386
|
-
moonCraterUniforms[8] = effect.scrollOffsetY;
|
|
387
|
-
moonCraterUniforms[9] = effect.craterCount;
|
|
388
|
-
moonCraterPaint.setShader(moonCraterEffect.makeShader(moonCraterUniforms));
|
|
389
|
-
return moonCraterPaint;
|
|
390
|
-
}
|
|
391
|
-
function applyCaveInterior(effect) {
|
|
392
|
-
if (Skia2.RuntimeEffect === void 0) return defaultPaint;
|
|
393
|
-
if (caveInteriorEffect === null) {
|
|
394
|
-
const compiled = Skia2.RuntimeEffect.Make(import_render.CAVE_INTERIOR_SKSL);
|
|
395
|
-
if (compiled === null) return defaultPaint;
|
|
396
|
-
caveInteriorEffect = compiled;
|
|
397
|
-
}
|
|
398
|
-
if (caveInteriorPaint === null) caveInteriorPaint = Skia2.Paint();
|
|
399
|
-
caveInteriorUniforms[0] = effect.resolutionW;
|
|
400
|
-
caveInteriorUniforms[1] = effect.resolutionH;
|
|
401
|
-
caveInteriorUniforms[2] = effect.caveColor.r;
|
|
402
|
-
caveInteriorUniforms[3] = effect.caveColor.g;
|
|
403
|
-
caveInteriorUniforms[4] = effect.caveColor.b;
|
|
404
|
-
caveInteriorUniforms[5] = effect.glowColor.r;
|
|
405
|
-
caveInteriorUniforms[6] = effect.glowColor.g;
|
|
406
|
-
caveInteriorUniforms[7] = effect.glowColor.b;
|
|
407
|
-
caveInteriorUniforms[8] = effect.scrollOffsetY;
|
|
408
|
-
caveInteriorUniforms[9] = effect.stalactiteCount;
|
|
409
|
-
caveInteriorPaint.setShader(caveInteriorEffect.makeShader(caveInteriorUniforms));
|
|
410
|
-
return caveInteriorPaint;
|
|
411
|
-
}
|
|
412
|
-
function applyMountainHills(effect) {
|
|
413
|
-
if (Skia2.RuntimeEffect === void 0) return defaultPaint;
|
|
414
|
-
if (mountainHillsEffect === null) {
|
|
415
|
-
const compiled = Skia2.RuntimeEffect.Make(import_render.MOUNTAIN_HILLS_SKSL);
|
|
416
|
-
if (compiled === null) return defaultPaint;
|
|
417
|
-
mountainHillsEffect = compiled;
|
|
418
|
-
}
|
|
419
|
-
if (mountainHillsPaint === null) mountainHillsPaint = Skia2.Paint();
|
|
420
|
-
mountainHillsUniforms[0] = effect.resolutionW;
|
|
421
|
-
mountainHillsUniforms[1] = effect.resolutionH;
|
|
422
|
-
mountainHillsUniforms[2] = effect.skyColor.r;
|
|
423
|
-
mountainHillsUniforms[3] = effect.skyColor.g;
|
|
424
|
-
mountainHillsUniforms[4] = effect.skyColor.b;
|
|
425
|
-
mountainHillsUniforms[5] = effect.hillColor.r;
|
|
426
|
-
mountainHillsUniforms[6] = effect.hillColor.g;
|
|
427
|
-
mountainHillsUniforms[7] = effect.hillColor.b;
|
|
428
|
-
mountainHillsUniforms[8] = effect.scrollOffsetY;
|
|
429
|
-
mountainHillsUniforms[9] = effect.ridgeScale;
|
|
430
|
-
mountainHillsPaint.setShader(mountainHillsEffect.makeShader(mountainHillsUniforms));
|
|
431
|
-
return mountainHillsPaint;
|
|
432
|
-
}
|
|
433
|
-
function drawOutlined(canvas2, image, commands, n, effect, alpha) {
|
|
434
|
-
const paint = applyOutlinePaint(effect);
|
|
435
|
-
paint.setAlphaf(alpha);
|
|
436
|
-
const srcs = srcRects.length === n ? srcRects : srcRects.slice(0, n);
|
|
437
|
-
for (let k = 0; k < OUTLINE_OFFSETS.length; k++) {
|
|
438
|
-
const offset = OUTLINE_OFFSETS[k];
|
|
439
|
-
fillXforms(commands, n, offset[0] * effect.width, offset[1] * effect.width);
|
|
440
|
-
const dsts = xforms.length === n ? xforms : xforms.slice(0, n);
|
|
441
|
-
canvas2.drawAtlas(image, srcs, dsts, paint);
|
|
442
|
-
}
|
|
443
|
-
paint.setAlphaf(1);
|
|
444
|
-
defaultPaint.setAlphaf(alpha);
|
|
445
|
-
fillXforms(commands, n, 0, 0);
|
|
446
|
-
const mainDsts = xforms.length === n ? xforms : xforms.slice(0, n);
|
|
447
|
-
canvas2.drawAtlas(image, srcs, mainDsts, defaultPaint);
|
|
448
|
-
defaultPaint.setAlphaf(1);
|
|
449
|
-
}
|
|
450
|
-
function resolveEffectPaint(effect) {
|
|
451
|
-
switch (effect.type) {
|
|
452
|
-
case "tint":
|
|
453
|
-
return applyTint(effect);
|
|
454
|
-
case "flash":
|
|
455
|
-
return applyFlash(effect);
|
|
456
|
-
case "grayscale":
|
|
457
|
-
return applyGrayscale(effect);
|
|
458
|
-
case "custom":
|
|
459
|
-
return applyCustom(effect);
|
|
460
|
-
case "water":
|
|
461
|
-
return applyWater(effect, currentFrameTime);
|
|
462
|
-
case "fog":
|
|
463
|
-
return applyFog(effect, currentFrameTime);
|
|
464
|
-
case "fire":
|
|
465
|
-
return applyFire(effect, currentFrameTime);
|
|
466
|
-
case "outline":
|
|
467
|
-
return applyOutlinePaint(effect);
|
|
468
|
-
case "roofs-city":
|
|
469
|
-
return applyRoofsCity(effect);
|
|
470
|
-
case "forest-canopy":
|
|
471
|
-
return applyForestCanopy(effect);
|
|
472
|
-
case "river-wave":
|
|
473
|
-
return applyRiverWave(effect);
|
|
474
|
-
case "moon-crater":
|
|
475
|
-
return applyMoonCrater(effect);
|
|
476
|
-
case "cave-interior":
|
|
477
|
-
return applyCaveInterior(effect);
|
|
478
|
-
case "mountain-hills":
|
|
479
|
-
return applyMountainHills(effect);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return {
|
|
483
|
-
canvas,
|
|
484
|
-
beginFrame(viewportWidth, viewportHeight, time = 0, pixelDensity = 1) {
|
|
485
|
-
if (viewportWidth === 0 || viewportHeight === 0) return;
|
|
486
|
-
_boundRuntime = null;
|
|
487
|
-
_boundChain = null;
|
|
488
|
-
currentFrameTime = time;
|
|
489
|
-
const pd = pixelDensity;
|
|
490
|
-
recordingBounds.setXYWH(0, 0, viewportWidth * pd, viewportHeight * pd);
|
|
491
|
-
current = recorder.beginRecording(recordingBounds);
|
|
492
|
-
if (pd !== 1) current.scale(pd, pd);
|
|
493
|
-
},
|
|
494
|
-
drawAtlas(image, commands) {
|
|
495
|
-
if (current === null) return;
|
|
496
|
-
const n = commands.length;
|
|
497
|
-
if (n === 0) return;
|
|
498
|
-
const effect = commands[0]?.effect;
|
|
499
|
-
const alpha = commands[0]?.alpha ?? 1;
|
|
500
|
-
const skImage = image;
|
|
501
|
-
if (effect?.type === "roofs-city" || effect?.type === "forest-canopy" || effect?.type === "river-wave" || effect?.type === "moon-crater" || effect?.type === "cave-interior" || effect?.type === "mountain-hills") {
|
|
502
|
-
const paint2 = resolveEffectPaint(effect);
|
|
503
|
-
paint2.setAlphaf(alpha);
|
|
504
|
-
for (let i = 0; i < n; i++) {
|
|
505
|
-
const cmd = commands[i];
|
|
506
|
-
const rect = Skia2.XYWHRect(cmd.dstX, cmd.dstY, cmd.dstW, cmd.dstH);
|
|
507
|
-
current.drawRect(rect, paint2);
|
|
508
|
-
}
|
|
509
|
-
paint2.setAlphaf(1);
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
if (commands[0]?.stretch) {
|
|
513
|
-
if (stretchPaint === null) stretchPaint = Skia2.Paint();
|
|
514
|
-
ensureStretchPoolCapacity(n);
|
|
515
|
-
stretchPaint.setAlphaf(alpha);
|
|
516
|
-
for (let i = 0; i < n; i++) {
|
|
517
|
-
const cmd = commands[i];
|
|
518
|
-
const srcR = stretchSrcRects[i];
|
|
519
|
-
const dstR = stretchDstRects[i];
|
|
520
|
-
srcR.setXYWH(cmd.srcX, cmd.srcY, cmd.srcW, cmd.srcH);
|
|
521
|
-
dstR.setXYWH(cmd.dstX, cmd.dstY, cmd.dstW, cmd.dstH);
|
|
522
|
-
current.drawImageRect(skImage, srcR, dstR, stretchPaint);
|
|
523
|
-
}
|
|
524
|
-
stretchPaint.setAlphaf(1);
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
ensurePoolCapacity(n);
|
|
528
|
-
fillSrcRects(commands, n);
|
|
529
|
-
if (effect?.type === "outline") {
|
|
530
|
-
drawOutlined(current, skImage, commands, n, effect, alpha);
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
fillXforms(commands, n, 0, 0);
|
|
534
|
-
const srcs = srcRects.length === n ? srcRects : srcRects.slice(0, n);
|
|
535
|
-
const dsts = xforms.length === n ? xforms : xforms.slice(0, n);
|
|
536
|
-
const paint = effect === void 0 ? defaultPaint : resolveEffectPaint(effect);
|
|
537
|
-
paint.setAlphaf(alpha);
|
|
538
|
-
current.drawAtlas(skImage, srcs, dsts, paint);
|
|
539
|
-
paint.setAlphaf(1);
|
|
540
|
-
},
|
|
541
|
-
setPostFxBinding(runtime, chain) {
|
|
542
|
-
_boundRuntime = runtime;
|
|
543
|
-
_boundChain = chain;
|
|
544
|
-
},
|
|
545
|
-
buildPostFxPasses(runtime, chain, width, height) {
|
|
546
|
-
const rt = runtime ?? _boundRuntime;
|
|
547
|
-
const ch = chain ?? _boundChain;
|
|
548
|
-
if (rt === null || !rt.supported) return [];
|
|
549
|
-
if (rt.buildPass === void 0) {
|
|
550
|
-
logOnce("buildPostFxPasses: runtime.supported but buildPass absent \u2014 no passes");
|
|
551
|
-
return [];
|
|
552
|
-
}
|
|
553
|
-
if (ch === null) return [];
|
|
554
|
-
const passes = rt.buildPass(ch, width, height);
|
|
555
|
-
if (passes.length === 0) return [];
|
|
556
|
-
const out = [];
|
|
557
|
-
for (const pass of passes) {
|
|
558
|
-
const shader = pass.shader;
|
|
559
|
-
const uniformCount = typeof shader.getUniformCount === "function" ? shader.getUniformCount() : 0;
|
|
560
|
-
const uniforms = {};
|
|
561
|
-
for (let i = 0; i < uniformCount; i++) {
|
|
562
|
-
const name = typeof shader.getUniformName === "function" ? shader.getUniformName(i) : String(i);
|
|
563
|
-
const info = typeof shader.getUniform === "function" ? shader.getUniform(i) : { columns: 1, rows: 1, slot: i };
|
|
564
|
-
const size = info.columns * info.rows;
|
|
565
|
-
if (size === 1) {
|
|
566
|
-
uniforms[name] = pass.uniforms[info.slot] ?? 0;
|
|
567
|
-
} else {
|
|
568
|
-
const vec = [];
|
|
569
|
-
for (let k = 0; k < size; k++) {
|
|
570
|
-
vec.push(pass.uniforms[info.slot + k] ?? 0);
|
|
571
|
-
}
|
|
572
|
-
uniforms[name] = vec;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
out.push({
|
|
576
|
-
id: pass.id,
|
|
577
|
-
source: shader,
|
|
578
|
-
uniforms,
|
|
579
|
-
children: pass.children
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
return out;
|
|
583
|
-
},
|
|
584
|
-
endFrame() {
|
|
585
|
-
if (current === null) return null;
|
|
586
|
-
current = null;
|
|
587
|
-
return recorder.finishRecordingAsPicture();
|
|
588
|
-
}
|
|
589
|
-
};
|
|
79
|
+
return (0, import_render.createFrameRenderer)(Skia2);
|
|
590
80
|
}
|
|
591
81
|
function renderShapesToImage(skia, opts) {
|
|
592
82
|
if (skia.Surface === void 0) return null;
|
|
@@ -599,7 +89,7 @@ function renderShapesToImage(skia, opts) {
|
|
|
599
89
|
const paint = skia.Paint();
|
|
600
90
|
for (const shape of opts.shapes) {
|
|
601
91
|
unpackArgb(scratch, shape.color);
|
|
602
|
-
paint.setColor(scratch);
|
|
92
|
+
if (paint.setColor) paint.setColor(scratch);
|
|
603
93
|
const rect = skia.XYWHRect(shape.x, shape.y, shape.w, shape.h);
|
|
604
94
|
canvas.drawRect(rect, paint);
|
|
605
95
|
}
|
|
@@ -611,56 +101,6 @@ function unpackArgb(out, argb) {
|
|
|
611
101
|
out[2] = (argb & 255) / 255;
|
|
612
102
|
out[3] = (argb >>> 24 & 255) / 255;
|
|
613
103
|
}
|
|
614
|
-
function writeColor(out, color, alphaMul) {
|
|
615
|
-
out[0] = color.r;
|
|
616
|
-
out[1] = color.g;
|
|
617
|
-
out[2] = color.b;
|
|
618
|
-
out[3] = color.a * alphaMul;
|
|
619
|
-
}
|
|
620
|
-
function writeGrayscaleMatrix(out, amount) {
|
|
621
|
-
const inv = 1 - amount;
|
|
622
|
-
const lr = 0.299 * amount;
|
|
623
|
-
const lg = 0.587 * amount;
|
|
624
|
-
const lb = 0.114 * amount;
|
|
625
|
-
out[0] = inv + lr;
|
|
626
|
-
out[1] = lg;
|
|
627
|
-
out[2] = lb;
|
|
628
|
-
out[3] = 0;
|
|
629
|
-
out[4] = 0;
|
|
630
|
-
out[5] = lr;
|
|
631
|
-
out[6] = inv + lg;
|
|
632
|
-
out[7] = lb;
|
|
633
|
-
out[8] = 0;
|
|
634
|
-
out[9] = 0;
|
|
635
|
-
out[10] = lr;
|
|
636
|
-
out[11] = lg;
|
|
637
|
-
out[12] = inv + lb;
|
|
638
|
-
out[13] = 0;
|
|
639
|
-
out[14] = 0;
|
|
640
|
-
out[15] = 0;
|
|
641
|
-
out[16] = 0;
|
|
642
|
-
out[17] = 0;
|
|
643
|
-
out[18] = 1;
|
|
644
|
-
out[19] = 0;
|
|
645
|
-
}
|
|
646
|
-
function fillCustomUniforms(effect, shader, out) {
|
|
647
|
-
const count = shader.getUniformCount();
|
|
648
|
-
for (let i = 0; i < out.length; i++) out[i] = 0;
|
|
649
|
-
for (let i = 0; i < count; i++) {
|
|
650
|
-
const info = shader.getUniform(i);
|
|
651
|
-
const name = shader.getUniformName(i);
|
|
652
|
-
const value = effect.uniforms[name];
|
|
653
|
-
const size = info.columns * info.rows;
|
|
654
|
-
if (value === void 0) continue;
|
|
655
|
-
if (typeof value === "number") {
|
|
656
|
-
out[info.slot] = value;
|
|
657
|
-
continue;
|
|
658
|
-
}
|
|
659
|
-
for (let k = 0; k < size; k++) {
|
|
660
|
-
out[info.slot + k] = value[k] ?? 0;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
104
|
|
|
665
105
|
// src/game-view.tsx
|
|
666
106
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1017,6 +457,77 @@ var styles4 = import_react_native4.StyleSheet.create({
|
|
|
1017
457
|
height: "100%"
|
|
1018
458
|
}
|
|
1019
459
|
});
|
|
460
|
+
|
|
461
|
+
// src/overlay-hooks.ts
|
|
462
|
+
var import_math = require("@flare-engine/math");
|
|
463
|
+
var import_react7 = require("react");
|
|
464
|
+
function useOverlayFade(visible, durationMs = 300) {
|
|
465
|
+
const target = visible ? 1 : 0;
|
|
466
|
+
const [opacity, setOpacity] = (0, import_react7.useState)(target);
|
|
467
|
+
const opacityRef = (0, import_react7.useRef)(opacity);
|
|
468
|
+
const startRef = (0, import_react7.useRef)(null);
|
|
469
|
+
const rafRef = (0, import_react7.useRef)(null);
|
|
470
|
+
opacityRef.current = opacity;
|
|
471
|
+
(0, import_react7.useEffect)(() => {
|
|
472
|
+
if (typeof requestAnimationFrame === "undefined") {
|
|
473
|
+
setOpacity(target);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const from = opacityRef.current;
|
|
477
|
+
startRef.current = null;
|
|
478
|
+
if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
|
|
479
|
+
const step = (now) => {
|
|
480
|
+
if (startRef.current === null) startRef.current = now;
|
|
481
|
+
const t = Math.min((now - startRef.current) / durationMs, 1);
|
|
482
|
+
setOpacity(from + (target - from) * t);
|
|
483
|
+
if (t < 1) {
|
|
484
|
+
rafRef.current = requestAnimationFrame(step);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
rafRef.current = requestAnimationFrame(step);
|
|
488
|
+
return () => {
|
|
489
|
+
if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
|
|
490
|
+
};
|
|
491
|
+
}, [target, durationMs]);
|
|
492
|
+
return opacity;
|
|
493
|
+
}
|
|
494
|
+
function useCountUp(target, durationMs = 600) {
|
|
495
|
+
const [value, setValue] = (0, import_react7.useState)(target);
|
|
496
|
+
const valueRef = (0, import_react7.useRef)(value);
|
|
497
|
+
const startRef = (0, import_react7.useRef)(null);
|
|
498
|
+
const rafRef = (0, import_react7.useRef)(null);
|
|
499
|
+
valueRef.current = value;
|
|
500
|
+
(0, import_react7.useEffect)(() => {
|
|
501
|
+
if (typeof requestAnimationFrame === "undefined") {
|
|
502
|
+
setValue(target);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const from = valueRef.current;
|
|
506
|
+
startRef.current = null;
|
|
507
|
+
if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
|
|
508
|
+
const step = (now) => {
|
|
509
|
+
if (startRef.current === null) startRef.current = now;
|
|
510
|
+
const t = Math.min((now - startRef.current) / durationMs, 1);
|
|
511
|
+
setValue(from + (target - from) * (0, import_math.easeOutCubic)(t));
|
|
512
|
+
if (t < 1) {
|
|
513
|
+
rafRef.current = requestAnimationFrame(step);
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
rafRef.current = requestAnimationFrame(step);
|
|
517
|
+
return () => {
|
|
518
|
+
if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
|
|
519
|
+
};
|
|
520
|
+
}, [target, durationMs]);
|
|
521
|
+
return value;
|
|
522
|
+
}
|
|
523
|
+
function useSignalState(signal, initial) {
|
|
524
|
+
const [state, setState] = (0, import_react7.useState)(initial);
|
|
525
|
+
(0, import_react7.useEffect)(() => {
|
|
526
|
+
const disposer = signal.add(setState);
|
|
527
|
+
return disposer;
|
|
528
|
+
}, [signal]);
|
|
529
|
+
return state;
|
|
530
|
+
}
|
|
1020
531
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1021
532
|
0 && (module.exports = {
|
|
1022
533
|
GameContext,
|
|
@@ -1027,9 +538,12 @@ var styles4 = import_react_native4.StyleSheet.create({
|
|
|
1027
538
|
VirtualJoystick,
|
|
1028
539
|
createSkiaFrameRenderer,
|
|
1029
540
|
renderShapesToImage,
|
|
541
|
+
useCountUp,
|
|
1030
542
|
useEntity,
|
|
1031
543
|
useGame,
|
|
1032
544
|
useGameLoop,
|
|
1033
|
-
|
|
545
|
+
useOverlayFade,
|
|
546
|
+
useSafeArea,
|
|
547
|
+
useSignalState
|
|
1034
548
|
});
|
|
1035
549
|
//# sourceMappingURL=index.js.map
|