@flare-engine/render 0.4.6 → 0.4.8
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/dist/index.d.mts +42 -62
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +42 -62
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ComponentDef, Query, World } from "@flare-engine/ecs";
|
|
2
2
|
import { Rect, Vec2 } from "@flare-engine/math";
|
|
3
3
|
import { SkImageLike, SpriteFrame } from "@flare-engine/assets";
|
|
4
|
-
//#region src/camera2d.d.ts
|
|
5
4
|
/** Camera follow smoothing options. */
|
|
6
5
|
interface FollowOptions {
|
|
7
6
|
/** Smoothing factor (0 = instant, lower = faster, default 0.1). */
|
|
@@ -16,7 +15,7 @@ interface FollowOptions {
|
|
|
16
15
|
* Pure data + methods — no Skia dependency. The renderer reads camera state
|
|
17
16
|
* to build the view transform.
|
|
18
17
|
*/
|
|
19
|
-
declare class Camera2D {
|
|
18
|
+
export declare class Camera2D {
|
|
20
19
|
/** Camera position (world-space center). */
|
|
21
20
|
x: number;
|
|
22
21
|
y: number;
|
|
@@ -86,8 +85,6 @@ declare class Camera2D {
|
|
|
86
85
|
getBoundsInto(out: Rect): Rect;
|
|
87
86
|
private _clampToBounds;
|
|
88
87
|
}
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/draw-order.d.ts
|
|
91
88
|
/** A drawable item with a z-order for sorting. */
|
|
92
89
|
interface Drawable {
|
|
93
90
|
/** Z-index for draw ordering. Higher values draw on top. */
|
|
@@ -104,14 +101,12 @@ interface Drawable {
|
|
|
104
101
|
* @param length Optional upper bound — when provided, only sorts `items[0..length)`.
|
|
105
102
|
* Use this when passing a pooled array that may hold stale tail entries.
|
|
106
103
|
*/
|
|
107
|
-
declare function sortByDrawOrder<T extends Drawable>(items: T[], length?: number): T[];
|
|
104
|
+
export declare function sortByDrawOrder<T extends Drawable>(items: T[], length?: number): T[];
|
|
108
105
|
/**
|
|
109
106
|
* Compare function for use with Array.sort when insertion sort isn't desired.
|
|
110
107
|
* Stable relative order for equal z values (returns 0).
|
|
111
108
|
*/
|
|
112
|
-
declare function drawOrderCompare(a: Drawable, b: Drawable): number;
|
|
113
|
-
//#endregion
|
|
114
|
-
//#region src/renderer.d.ts
|
|
109
|
+
export declare function drawOrderCompare(a: Drawable, b: Drawable): number;
|
|
115
110
|
/** Minimal Skia Canvas-like interface for the Renderer. */
|
|
116
111
|
interface CanvasLike {
|
|
117
112
|
save(): number;
|
|
@@ -147,7 +142,7 @@ interface RenderStats {
|
|
|
147
142
|
* Renderer — manages the Skia Canvas lifecycle for a frame.
|
|
148
143
|
* `begin()` to start, draw your content, `end()` to finish.
|
|
149
144
|
*/
|
|
150
|
-
declare class Renderer {
|
|
145
|
+
export declare class Renderer {
|
|
151
146
|
/** Current frame stats. */
|
|
152
147
|
readonly stats: RenderStats;
|
|
153
148
|
private _canvas;
|
|
@@ -179,8 +174,6 @@ declare class Renderer {
|
|
|
179
174
|
* flush run in SpriteBatch.flush. */
|
|
180
175
|
recordBatch(): void;
|
|
181
176
|
}
|
|
182
|
-
//#endregion
|
|
183
|
-
//#region src/sprite-effects.d.ts
|
|
184
177
|
/** Color as RGBA (0-1 per channel). */
|
|
185
178
|
interface SpriteColor {
|
|
186
179
|
readonly r: number;
|
|
@@ -337,26 +330,26 @@ interface MountainHillsEffect extends SpriteEffect {
|
|
|
337
330
|
/** Any concrete sprite effect. */
|
|
338
331
|
type AnySpriteEffect = TintEffect | FlashEffect | GrayscaleEffect | OutlineEffect | CustomShaderEffect | WaterEffect | FogEffect | FireEffect | DropShadowEffect | RoofsCityEffect | ForestCanopyEffect | RiverWaveEffect | MoonCraterEffect | CaveInteriorEffect | MountainHillsEffect;
|
|
339
332
|
/** Create a tint effect. */
|
|
340
|
-
declare function tint(color: SpriteColor, amount: number): TintEffect;
|
|
333
|
+
export declare function tint(color: SpriteColor, amount: number): TintEffect;
|
|
341
334
|
/** Create a flash effect. */
|
|
342
|
-
declare function flash(color: SpriteColor, durationSec: number): FlashEffect;
|
|
335
|
+
export declare function flash(color: SpriteColor, durationSec: number): FlashEffect;
|
|
343
336
|
/** Create a grayscale effect. */
|
|
344
|
-
declare function grayscale(amount: number): GrayscaleEffect;
|
|
337
|
+
export declare function grayscale(amount: number): GrayscaleEffect;
|
|
345
338
|
/** Create an outline effect. */
|
|
346
|
-
declare function outline(color: SpriteColor, width: number): OutlineEffect;
|
|
339
|
+
export declare function outline(color: SpriteColor, width: number): OutlineEffect;
|
|
347
340
|
/** Create a custom shader effect. `shader` must be pre-compiled; compiling
|
|
348
341
|
* SkSL per frame is expensive. `uniforms` may be mutated externally between
|
|
349
342
|
* frames to animate parameters. */
|
|
350
|
-
declare function custom(shader: CompiledShader, uniforms: ShaderUniforms): CustomShaderEffect;
|
|
343
|
+
export declare function custom(shader: CompiledShader, uniforms: ShaderUniforms): CustomShaderEffect;
|
|
351
344
|
/** Create a water surface effect. Time is passed to the renderer each frame
|
|
352
345
|
* via `beginFrame(w, h, time)` — the effect itself is time-invariant. */
|
|
353
|
-
declare function water(color: SpriteColor, foamColor: SpriteColor, waveSpeed: number, waveAmplitude: number): WaterEffect;
|
|
346
|
+
export declare function water(color: SpriteColor, foamColor: SpriteColor, waveSpeed: number, waveAmplitude: number): WaterEffect;
|
|
354
347
|
/** Create a fog / volumetric haze effect. Time is passed to the renderer each
|
|
355
348
|
* frame via `beginFrame(w, h, time)` — the effect itself is time-invariant. */
|
|
356
|
-
declare function fog(color: SpriteColor, density?: number, speed?: number, scale?: number): FogEffect;
|
|
349
|
+
export declare function fog(color: SpriteColor, density?: number, speed?: number, scale?: number): FogEffect;
|
|
357
350
|
/** Create a fire / flame effect. Time is passed to the renderer each
|
|
358
351
|
* frame via `beginFrame(w, h, time)` — the effect itself is time-invariant. */
|
|
359
|
-
declare function fire(opts: {
|
|
352
|
+
export declare function fire(opts: {
|
|
360
353
|
color: SpriteColor;
|
|
361
354
|
tipColor: SpriteColor;
|
|
362
355
|
speed?: number;
|
|
@@ -364,14 +357,14 @@ declare function fire(opts: {
|
|
|
364
357
|
}): FireEffect;
|
|
365
358
|
/** Create a drop-shadow effect. Defaults to a soft shadow offset downward for
|
|
366
359
|
* grounding; `color.a` is the shadow opacity. */
|
|
367
|
-
declare function dropShadow(opts: {
|
|
360
|
+
export declare function dropShadow(opts: {
|
|
368
361
|
color: SpriteColor;
|
|
369
362
|
offsetX?: number;
|
|
370
363
|
offsetY?: number;
|
|
371
364
|
blur?: number;
|
|
372
365
|
}): DropShadowEffect;
|
|
373
366
|
/** Create a rooftop city skyline effect. */
|
|
374
|
-
declare function roofsCity(opts: {
|
|
367
|
+
export declare function roofsCity(opts: {
|
|
375
368
|
skyColor: SpriteColor;
|
|
376
369
|
roofColor: SpriteColor;
|
|
377
370
|
scrollOffsetY?: number;
|
|
@@ -380,7 +373,7 @@ declare function roofsCity(opts: {
|
|
|
380
373
|
resolutionH?: number;
|
|
381
374
|
}): RoofsCityEffect;
|
|
382
375
|
/** Create a forest canopy effect. */
|
|
383
|
-
declare function forestCanopy(opts: {
|
|
376
|
+
export declare function forestCanopy(opts: {
|
|
384
377
|
skyColor: SpriteColor;
|
|
385
378
|
leafColor: SpriteColor;
|
|
386
379
|
scrollOffsetY?: number;
|
|
@@ -389,7 +382,7 @@ declare function forestCanopy(opts: {
|
|
|
389
382
|
resolutionH?: number;
|
|
390
383
|
}): ForestCanopyEffect;
|
|
391
384
|
/** Create a river wave surface effect. */
|
|
392
|
-
declare function riverWave(opts: {
|
|
385
|
+
export declare function riverWave(opts: {
|
|
393
386
|
waterColor: SpriteColor;
|
|
394
387
|
foamColor: SpriteColor;
|
|
395
388
|
scrollOffsetY?: number;
|
|
@@ -398,7 +391,7 @@ declare function riverWave(opts: {
|
|
|
398
391
|
resolutionH?: number;
|
|
399
392
|
}): RiverWaveEffect;
|
|
400
393
|
/** Create a moon crater surface effect. */
|
|
401
|
-
declare function moonCrater(opts: {
|
|
394
|
+
export declare function moonCrater(opts: {
|
|
402
395
|
moonColor: SpriteColor;
|
|
403
396
|
craterColor: SpriteColor;
|
|
404
397
|
scrollOffsetY?: number;
|
|
@@ -407,7 +400,7 @@ declare function moonCrater(opts: {
|
|
|
407
400
|
resolutionH?: number;
|
|
408
401
|
}): MoonCraterEffect;
|
|
409
402
|
/** Create a cave interior effect. */
|
|
410
|
-
declare function caveInterior(opts: {
|
|
403
|
+
export declare function caveInterior(opts: {
|
|
411
404
|
caveColor: SpriteColor;
|
|
412
405
|
glowColor: SpriteColor;
|
|
413
406
|
scrollOffsetY?: number;
|
|
@@ -416,7 +409,7 @@ declare function caveInterior(opts: {
|
|
|
416
409
|
resolutionH?: number;
|
|
417
410
|
}): CaveInteriorEffect;
|
|
418
411
|
/** Create a mountain / hill ridge effect. */
|
|
419
|
-
declare function mountainHills(opts: {
|
|
412
|
+
export declare function mountainHills(opts: {
|
|
420
413
|
skyColor: SpriteColor;
|
|
421
414
|
hillColor: SpriteColor;
|
|
422
415
|
scrollOffsetY?: number;
|
|
@@ -434,13 +427,11 @@ declare function mountainHills(opts: {
|
|
|
434
427
|
* Effects are immutable — callers must replace their reference with the
|
|
435
428
|
* returned value. Sharing an effect instance across entities is safe.
|
|
436
429
|
*/
|
|
437
|
-
declare function updateEffect(effect: AnySpriteEffect, dt: number): AnySpriteEffect | null;
|
|
430
|
+
export declare function updateEffect(effect: AnySpriteEffect, dt: number): AnySpriteEffect | null;
|
|
438
431
|
/**
|
|
439
432
|
* Get the current intensity of a flash effect (1 at start, 0 at end).
|
|
440
433
|
*/
|
|
441
|
-
declare function flashIntensity(effect: FlashEffect): number;
|
|
442
|
-
//#endregion
|
|
443
|
-
//#region src/sprite-batch.d.ts
|
|
434
|
+
export declare function flashIntensity(effect: FlashEffect): number;
|
|
444
435
|
/**
|
|
445
436
|
* Axis-aligned bounds used for viewport culling in the batch.
|
|
446
437
|
* All coordinates are in the same space as the sprite destination rects.
|
|
@@ -531,7 +522,7 @@ interface SpriteDrawCommand {
|
|
|
531
522
|
* The actual Skia Atlas draw call is delegated to a callback so this module
|
|
532
523
|
* remains testable without Skia.
|
|
533
524
|
*/
|
|
534
|
-
declare class SpriteBatch {
|
|
525
|
+
export declare class SpriteBatch {
|
|
535
526
|
private _commands;
|
|
536
527
|
private _pool;
|
|
537
528
|
private _batches;
|
|
@@ -584,8 +575,6 @@ declare class SpriteBatch {
|
|
|
584
575
|
clear(): void;
|
|
585
576
|
private _acquire;
|
|
586
577
|
}
|
|
587
|
-
//#endregion
|
|
588
|
-
//#region src/frame-renderer.d.ts
|
|
589
578
|
/**
|
|
590
579
|
* A mutable axis-aligned rect.
|
|
591
580
|
*
|
|
@@ -757,9 +746,9 @@ interface FrameRenderer {
|
|
|
757
746
|
* Both `@flare-engine/react` (passing the real RN-Skia module) and
|
|
758
747
|
* `@flare-engine/render-web` (passing a CanvasKit shim) use this factory.
|
|
759
748
|
*/
|
|
760
|
-
declare function createFrameRenderer(Skia: FrameRendererModule): FrameRenderer;
|
|
749
|
+
export declare function createFrameRenderer(Skia: FrameRendererModule): FrameRenderer;
|
|
761
750
|
/** Zero both branch counters unconditionally (no __DEV__ guard). */
|
|
762
|
-
declare function resetXformCounters(): void;
|
|
751
|
+
export declare function resetXformCounters(): void;
|
|
763
752
|
/**
|
|
764
753
|
* Cumulative `fillXforms` branch hit counts since the last reset. Both stay 0
|
|
765
754
|
* when `__DEV__` is falsy or absent.
|
|
@@ -772,12 +761,10 @@ declare function resetXformCounters(): void;
|
|
|
772
761
|
*
|
|
773
762
|
* Allocates one object per call — never call it from the render loop.
|
|
774
763
|
*/
|
|
775
|
-
declare function getXformCounters(): {
|
|
764
|
+
export declare function getXformCounters(): {
|
|
776
765
|
rotated: number;
|
|
777
766
|
unrotated: number;
|
|
778
767
|
};
|
|
779
|
-
//#endregion
|
|
780
|
-
//#region src/nine-slice.d.ts
|
|
781
768
|
/**
|
|
782
769
|
* Draw a sprite using a 9-slice (scale-9) layout.
|
|
783
770
|
*
|
|
@@ -809,9 +796,7 @@ declare function getXformCounters(): {
|
|
|
809
796
|
* @param effect Optional sprite effect applied to every slice identically.
|
|
810
797
|
* @param alpha Per-instance opacity multiplier in [0, 1]. Default 1.
|
|
811
798
|
*/
|
|
812
|
-
declare function drawNineSlice(batch: SpriteBatch, image: SkImageLike, frame: SpriteFrame, x: number, y: number, w: number, h: number, inset: number, effect?: AnySpriteEffect, alpha?: number): void;
|
|
813
|
-
//#endregion
|
|
814
|
-
//#region src/render-system.d.ts
|
|
799
|
+
export declare function drawNineSlice(batch: SpriteBatch, image: SkImageLike, frame: SpriteFrame, x: number, y: number, w: number, h: number, inset: number, effect?: AnySpriteEffect, alpha?: number): void;
|
|
815
800
|
/** Position component data expected by the render system. */
|
|
816
801
|
interface PositionData {
|
|
817
802
|
x: number;
|
|
@@ -889,22 +874,18 @@ interface SpriteData {
|
|
|
889
874
|
* @param spriteDef ComponentDef for Sprite.
|
|
890
875
|
* @param batch SpriteBatch instance to queue draws into.
|
|
891
876
|
*/
|
|
892
|
-
declare function createRenderSystem(world: World, query: Query, positionDef: ComponentDef<PositionData>, spriteDef: ComponentDef<SpriteData>, batch: SpriteBatch): () => void;
|
|
877
|
+
export declare function createRenderSystem(world: World, query: Query, positionDef: ComponentDef<PositionData>, spriteDef: ComponentDef<SpriteData>, batch: SpriteBatch): () => void;
|
|
893
878
|
/** Canonical Sprite component — queried by the render system alongside `Position`. */
|
|
894
|
-
declare const Sprite: ComponentDef<SpriteData>;
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
declare const
|
|
898
|
-
declare const
|
|
899
|
-
declare const
|
|
900
|
-
declare const
|
|
901
|
-
declare const
|
|
902
|
-
declare const
|
|
903
|
-
declare const
|
|
904
|
-
declare const CAVE_INTERIOR_SKSL = "\nuniform float2 resolution;\nuniform float3 caveColor;\nuniform float3 glowColor;\nuniform float scrollOffsetY;\nuniform float stalactiteCount;\n\nfloat hash(float x) { return fract(sin(x * 127.1) * 43758.5453); }\n\nfloat stalactite(float2 uv, float count) {\n float col = floor(uv.x * count);\n float tip = 0.1 + 0.2 * hash(col);\n float w = 0.3 + 0.3 * hash(col + 5.0);\n float dx = abs(fract(uv.x * count) - 0.5) / (w * 0.5);\n float shape = step(dx, 1.0) * step(uv.y, tip * (1.0 - clamp(dx, 0.0, 1.0)));\n return shape;\n}\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n uv.y = 1.0 - uv.y;\n uv.y = uv.y + scrollOffsetY / max(resolution.y, 1.0);\n float stalac = stalactite(uv, stalactiteCount);\n float glow = smoothstep(0.8, 1.0, uv.y) * (1.0 - stalac);\n half3 col = mix(half3(caveColor.r, caveColor.g, caveColor.b),\n half3(glowColor.r, glowColor.g, glowColor.b),\n half(glow));\n col = mix(col, half3(caveColor.r, caveColor.g, caveColor.b) * half(0.3), half(stalac));\n return half4(col, 1.0);\n}\n";
|
|
905
|
-
declare const MOUNTAIN_HILLS_SKSL = "\nuniform float2 resolution;\nuniform float3 skyColor;\nuniform float3 hillColor;\nuniform float scrollOffsetY;\nuniform float ridgeScale;\n\nfloat hash(float x) { return fract(sin(x * 127.1) * 43758.5453); }\n\nfloat heightField(float x, float scale) {\n float h = 0.0;\n float amp = 0.5;\n float freq = scale;\n for (int i = 0; i < 4; i++) {\n float ix = floor(x * freq);\n float fx = fract(x * freq);\n fx = fx * fx * (3.0 - 2.0 * fx);\n h += amp * mix(hash(ix), hash(ix + 1.0), fx);\n freq *= 2.0;\n amp *= 0.5;\n }\n return h;\n}\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n float scroll = scrollOffsetY / max(resolution.y, 1.0);\n float horizon = 0.4 + 0.3 * heightField(uv.x + scroll * 0.3, ridgeScale);\n float mountains = step(uv.y, horizon);\n half3 col = mix(half3(skyColor.r, skyColor.g, skyColor.b),\n half3(hillColor.r, hillColor.g, hillColor.b),\n half(mountains));\n return half4(col, 1.0);\n}\n";
|
|
906
|
-
//#endregion
|
|
907
|
-
//#region src/sprite-font.d.ts
|
|
879
|
+
export declare const Sprite: ComponentDef<SpriteData>;
|
|
880
|
+
export declare const FIRE_SKSL = "\nuniform float2 resolution;\nuniform float3 color;\nuniform float3 tipColor;\nuniform float speed;\nuniform float intensity;\nuniform float time;\n\nfloat hash(float2 p) { return fract(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); }\n\nfloat vnoise(float2 p) {\n float2 i = floor(p);\n float2 f = fract(p);\n float2 u = f * f * (3.0 - 2.0 * f);\n float a = hash(i);\n float b = hash(i + float2(1.0, 0.0));\n float c = hash(i + float2(0.0, 1.0));\n float d = hash(i + float2(1.0, 1.0));\n return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);\n}\n\nfloat fbm(float2 p) {\n return 0.5 * vnoise(p) + 0.25 * vnoise(p * 2.0);\n}\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n float2 np = float2(uv.x * 4.0, uv.y * 6.0 - time * speed * 2.0);\n float n = fbm(np);\n float flameMask = smoothstep(0.0, intensity, n * (1.0 - uv.y));\n float3 fireRgb = mix(color, tipColor, uv.y);\n return half4(fireRgb.r, fireRgb.g, fireRgb.b, flameMask);\n}\n";
|
|
881
|
+
export declare const FOG_SKSL = "\nuniform float2 resolution;\nuniform float3 color;\nuniform float density;\nuniform float speed;\nuniform float scale;\nuniform float time;\n\nfloat hash(float2 p) {\n return fract(sin(dot(p, float2(127.1, 311.7))) * 43758.5453);\n}\n\nfloat valueNoise(float2 p) {\n float2 i = floor(p);\n float2 f = fract(p);\n float2 u = f * f * (3.0 - 2.0 * f);\n float a = hash(i);\n float b = hash(i + float2(1.0, 0.0));\n float c = hash(i + float2(0.0, 1.0));\n float d = hash(i + float2(1.0, 1.0));\n return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);\n}\n\nfloat fbm(float2 p) {\n float value = 0.0;\n float amplitude = 0.5;\n for (int i = 0; i < 4; i++) {\n value += amplitude * valueNoise(p);\n p *= 2.0;\n amplitude *= 0.5;\n }\n return value;\n}\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n float2 drift = float2(time * speed, 0.3 * time * speed);\n float n = clamp(fbm(uv * scale + drift), 0.0, 1.0);\n return half4(color.r, color.g, color.b, clamp(density * n, 0.0, 1.0));\n}\n";
|
|
882
|
+
export declare const WATER_SKSL = "\nuniform float2 resolution;\nuniform float3 color;\nuniform float3 foamColor;\nuniform float waveSpeed;\nuniform float waveAmplitude;\nuniform float time;\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n float waveDeriv = cos(uv.x * 6.2832 * 3.0 + time * waveSpeed * 2.0) * waveAmplitude * 2.0\n + cos(uv.x * 6.2832 * 5.0 - time * waveSpeed * 1.3 + 1.5) * waveAmplitude;\n float foam = smoothstep(waveAmplitude * 0.6, waveAmplitude * 1.5, waveDeriv);\n half3 tinted = half3(color.r, color.g, color.b);\n half3 final = mix(tinted, half3(foamColor.r, foamColor.g, foamColor.b), half(foam));\n return half4(final, 1.0);\n}\n";
|
|
883
|
+
export declare const ROOFS_CITY_SKSL = "\nuniform float2 resolution;\nuniform float3 skyColor;\nuniform float3 roofColor;\nuniform float scrollOffsetY;\nuniform float density;\n\nfloat hash(float x) { return fract(sin(x * 127.1) * 43758.5453); }\n\nfloat buildingTop(float2 uv, float density) {\n float col = floor(uv.x * density);\n float h = 0.35 + 0.35 * hash(col);\n float w = 0.6 + 0.3 * hash(col + 7.3);\n float edge = step(abs(fract(uv.x * density) - 0.5), w * 0.5);\n return edge * step(uv.y, h);\n}\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n uv.y = uv.y + scrollOffsetY / max(resolution.y, 1.0);\n uv.y = fract(uv.y);\n float buildings = buildingTop(uv, density);\n half3 col = mix(half3(skyColor.r, skyColor.g, skyColor.b),\n half3(roofColor.r, roofColor.g, roofColor.b),\n half(buildings));\n return half4(col, 1.0);\n}\n";
|
|
884
|
+
export declare const FOREST_CANOPY_SKSL = "\nuniform float2 resolution;\nuniform float3 skyColor;\nuniform float3 leafColor;\nuniform float scrollOffsetY;\nuniform float density;\n\nfloat hash(float2 p) { return fract(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); }\n\nfloat valueNoise(float2 p) {\n float2 i = floor(p);\n float2 f = fract(p);\n float2 u = f * f * (3.0 - 2.0 * f);\n return mix(mix(hash(i), hash(i + float2(1.0, 0.0)), u.x),\n mix(hash(i + float2(0.0, 1.0)), hash(i + float2(1.0, 1.0)), u.x), u.y);\n}\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n uv.y = uv.y + scrollOffsetY / max(resolution.y, 1.0);\n float n = valueNoise(float2(uv.x * density, uv.y * 3.0));\n float treeLine = 0.55 + 0.25 * valueNoise(float2(uv.x * density * 0.5, 0.0));\n float canopy = step(uv.y, treeLine) * smoothstep(0.3, 0.7, n);\n half3 col = mix(half3(skyColor.r, skyColor.g, skyColor.b),\n half3(leafColor.r, leafColor.g, leafColor.b),\n half(canopy));\n return half4(col, 1.0);\n}\n";
|
|
885
|
+
export declare const RIVER_WAVE_SKSL = "\nuniform float2 resolution;\nuniform float3 waterColor;\nuniform float3 foamColor;\nuniform float scrollOffsetY;\nuniform float waveScale;\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n float scroll = scrollOffsetY / max(resolution.y, 1.0);\n float2 p = float2(uv.x, uv.y + scroll);\n float w1 = sin(p.x * 6.2832 * waveScale + p.y * 4.0) * 0.04;\n float w2 = sin(p.x * 6.2832 * waveScale * 1.7 - p.y * 2.5 + 1.2) * 0.02;\n float surface = 0.5 + w1 + w2;\n float inWater = step(uv.y, surface);\n float crest = smoothstep(surface - 0.015, surface, uv.y) * (1.0 - inWater) +\n smoothstep(surface + 0.015, surface, uv.y) * inWater;\n half3 base = mix(half3(foamColor.r, foamColor.g, foamColor.b),\n half3(waterColor.r, waterColor.g, waterColor.b),\n half(inWater));\n half3 col = mix(base, half3(foamColor.r, foamColor.g, foamColor.b), half(crest * 0.6));\n return half4(col, 1.0);\n}\n";
|
|
886
|
+
export declare const MOON_CRATER_SKSL = "\nuniform float2 resolution;\nuniform float3 moonColor;\nuniform float3 craterColor;\nuniform float scrollOffsetY;\nuniform float craterCount;\n\nfloat hash(float2 p) { return fract(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); }\n\nfloat crater(float2 uv, float2 center, float r) {\n float d = length(uv - center);\n float rim = smoothstep(r, r * 0.85, d) - smoothstep(r * 0.85, r * 0.65, d);\n float floor_ = smoothstep(r * 0.65, r * 0.4, d);\n return rim * 0.6 + floor_ * 0.25;\n}\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n uv.y = uv.y + scrollOffsetY / max(resolution.y, 1.0);\n float c = 0.0;\n for (int i = 0; i < 6; i++) {\n float fi = float(i);\n float2 center = float2(hash(float2(fi, 0.0)), hash(float2(fi, 1.0)));\n float r = 0.04 + 0.07 * hash(float2(fi, 2.0));\n c += crater(fract(uv), center, r) * step(fi, craterCount - 1.0);\n }\n c = clamp(c, 0.0, 1.0);\n half3 col = mix(half3(moonColor.r, moonColor.g, moonColor.b),\n half3(craterColor.r, craterColor.g, craterColor.b),\n half(c));\n return half4(col, 1.0);\n}\n";
|
|
887
|
+
export declare const CAVE_INTERIOR_SKSL = "\nuniform float2 resolution;\nuniform float3 caveColor;\nuniform float3 glowColor;\nuniform float scrollOffsetY;\nuniform float stalactiteCount;\n\nfloat hash(float x) { return fract(sin(x * 127.1) * 43758.5453); }\n\nfloat stalactite(float2 uv, float count) {\n float col = floor(uv.x * count);\n float tip = 0.1 + 0.2 * hash(col);\n float w = 0.3 + 0.3 * hash(col + 5.0);\n float dx = abs(fract(uv.x * count) - 0.5) / (w * 0.5);\n float shape = step(dx, 1.0) * step(uv.y, tip * (1.0 - clamp(dx, 0.0, 1.0)));\n return shape;\n}\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n uv.y = 1.0 - uv.y;\n uv.y = uv.y + scrollOffsetY / max(resolution.y, 1.0);\n float stalac = stalactite(uv, stalactiteCount);\n float glow = smoothstep(0.8, 1.0, uv.y) * (1.0 - stalac);\n half3 col = mix(half3(caveColor.r, caveColor.g, caveColor.b),\n half3(glowColor.r, glowColor.g, glowColor.b),\n half(glow));\n col = mix(col, half3(caveColor.r, caveColor.g, caveColor.b) * half(0.3), half(stalac));\n return half4(col, 1.0);\n}\n";
|
|
888
|
+
export declare const MOUNTAIN_HILLS_SKSL = "\nuniform float2 resolution;\nuniform float3 skyColor;\nuniform float3 hillColor;\nuniform float scrollOffsetY;\nuniform float ridgeScale;\n\nfloat hash(float x) { return fract(sin(x * 127.1) * 43758.5453); }\n\nfloat heightField(float x, float scale) {\n float h = 0.0;\n float amp = 0.5;\n float freq = scale;\n for (int i = 0; i < 4; i++) {\n float ix = floor(x * freq);\n float fx = fract(x * freq);\n fx = fx * fx * (3.0 - 2.0 * fx);\n h += amp * mix(hash(ix), hash(ix + 1.0), fx);\n freq *= 2.0;\n amp *= 0.5;\n }\n return h;\n}\n\nhalf4 main(float2 coord) {\n float2 uv = coord / max(resolution, float2(1.0));\n float scroll = scrollOffsetY / max(resolution.y, 1.0);\n float horizon = 0.4 + 0.3 * heightField(uv.x + scroll * 0.3, ridgeScale);\n float mountains = step(uv.y, horizon);\n half3 col = mix(half3(skyColor.r, skyColor.g, skyColor.b),\n half3(hillColor.r, hillColor.g, hillColor.b),\n half(mountains));\n return half4(col, 1.0);\n}\n";
|
|
908
889
|
/** A single glyph in a bitmap font. */
|
|
909
890
|
interface Glyph {
|
|
910
891
|
/** Character code (Unicode). */
|
|
@@ -940,16 +921,15 @@ interface BitmapFont {
|
|
|
940
921
|
/**
|
|
941
922
|
* Parse BMFont JSON format (common output from tools like Hiero, BMFont, msdf-bmfont).
|
|
942
923
|
*/
|
|
943
|
-
declare function parseBMFontJSON(json: unknown): BitmapFont;
|
|
924
|
+
export declare function parseBMFontJSON(json: unknown): BitmapFont;
|
|
944
925
|
/** Get kerning between two characters. */
|
|
945
|
-
declare function getKerning(font: BitmapFont, first: number, second: number): number;
|
|
926
|
+
export declare function getKerning(font: BitmapFont, first: number, second: number): number;
|
|
946
927
|
/** Measure the width of a text string in pixels. */
|
|
947
|
-
declare function measureText(font: BitmapFont, text: string): number;
|
|
928
|
+
export declare function measureText(font: BitmapFont, text: string): number;
|
|
948
929
|
/**
|
|
949
930
|
* Draw text using a SpriteBatch.
|
|
950
931
|
* Characters are batched as individual sprites from the font texture.
|
|
951
932
|
*/
|
|
952
|
-
declare function drawText(batch: SpriteBatch, font: BitmapFont, image: SkImageLike, text: string, x: number, y: number, scale?: number): void;
|
|
953
|
-
|
|
954
|
-
export { type AnySpriteEffect, type BatchCullBounds, type BitmapFont, CAVE_INTERIOR_SKSL, Camera2D, type CanvasLike, type CaveInteriorEffect, type ColorFilterFactoryLike, type CompiledShader, type CustomShaderEffect, type DrawSurfaceLike, type Drawable, type DropShadowEffect, FIRE_SKSL, FOG_SKSL, FOREST_CANOPY_SKSL, type FireEffect, type FlashEffect, type FogEffect, type FollowOptions, type ForestCanopyEffect, type FrameRenderer, type FrameRendererCompiledPass, type FrameRendererModule, type FrameRendererPostFxChain, type FrameRendererPostFxDescriptor, type FrameRendererPostFxRuntime, type Glyph, type GrayscaleEffect, type ImageFilterFactoryLike, type KerningPair, MOON_CRATER_SKSL, MOUNTAIN_HILLS_SKSL, type MoonCraterEffect, type MountainHillsEffect, type OutlineEffect, type PaintLike, type PictureLike, type PictureRecorderLike, type PositionData, RIVER_WAVE_SKSL, ROOFS_CITY_SKSL, type RSXformLike, type RectLike, type RenderStats, Renderer, type RiverWaveEffect, type RoofsCityEffect, type RuntimeEffectFactoryLike, type RuntimeEffectLike, type ShaderUniforms, Sprite, type SpriteAnchor, SpriteBatch, type SpriteColor, type SpriteData, type SpriteDrawCommand, type SpriteEffect, type TintEffect, WATER_SKSL, type WaterEffect, caveInterior, createFrameRenderer, createRenderSystem, custom, drawNineSlice, drawOrderCompare, drawText, dropShadow, fire, flash, flashIntensity, fog, forestCanopy, getKerning, getXformCounters, grayscale, measureText, moonCrater, mountainHills, outline, parseBMFontJSON, resetXformCounters, riverWave, roofsCity, sortByDrawOrder, tint, updateEffect, water };
|
|
933
|
+
export declare function drawText(batch: SpriteBatch, font: BitmapFont, image: SkImageLike, text: string, x: number, y: number, scale?: number): void;
|
|
934
|
+
export type { AnySpriteEffect, BatchCullBounds, BitmapFont, CanvasLike, CaveInteriorEffect, ColorFilterFactoryLike, CompiledShader, CustomShaderEffect, DrawSurfaceLike, Drawable, DropShadowEffect, FireEffect, FlashEffect, FogEffect, FollowOptions, ForestCanopyEffect, FrameRenderer, FrameRendererCompiledPass, FrameRendererModule, FrameRendererPostFxChain, FrameRendererPostFxDescriptor, FrameRendererPostFxRuntime, Glyph, GrayscaleEffect, ImageFilterFactoryLike, KerningPair, MoonCraterEffect, MountainHillsEffect, OutlineEffect, PaintLike, PictureLike, PictureRecorderLike, PositionData, RSXformLike, RectLike, RenderStats, RiverWaveEffect, RoofsCityEffect, RuntimeEffectFactoryLike, RuntimeEffectLike, ShaderUniforms, SpriteAnchor, SpriteColor, SpriteData, SpriteDrawCommand, SpriteEffect, TintEffect, WaterEffect };
|
|
955
935
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/camera2d.ts","../src/draw-order.ts","../src/renderer.ts","../src/sprite-effects.ts","../src/sprite-batch.ts","../src/frame-renderer.ts","../src/nine-slice.ts","../src/render-system.ts","../src/shaders.ts","../src/sprite-font.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/camera2d.ts","../src/draw-order.ts","../src/renderer.ts","../src/sprite-effects.ts","../src/sprite-batch.ts","../src/frame-renderer.ts","../src/nine-slice.ts","../src/render-system.ts","../src/shaders.ts","../src/sprite-font.ts"],"mappings":";;;;UAGiB;;EAEf;;EAEA,SAAS;;EAET,WAAW;;;;;;;qBAiGA;;EAEX;EACA;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA,QAAQ;UAEA;UACA;UACA;UACA;UACA;UACA;;EAGR,YAAY,eAAe;;EAM3B,OAAO,QAAQ,MAAM,UAAU;;EAK/B;;;;;;;;;;;;EAeA,eAAe;;MAKX;;EAKJ,MAAM,mBAAmB;;;;;EAoBzB,YAAY,mBAAmB;;;;;EAoB/B,OAAO;;MAuEH;;MAKA;;EAKJ,cAAc,gBAAgB,iBAAiB;;EAK/C,kBAAkB,gBAAgB,gBAAgB,KAAK,OAAO;;EAW9D,cAAc,iBAAiB,kBAAkB;;EAKjD,kBAAkB,iBAAiB,iBAAiB,KAAK,OAAO;;EAahE,aAAa;;EAKb,cAAc,KAAK,OAAO;UAUlB;;;UCnVO;;EAEf;;;;;;;;;;;;;wBAcc,gBAAgB,UAAU,UAAU,OAAO,KAAK,kBAAkB;;;;;wBAmBlE,iBAAiB,GAAG,UAAU,GAAG;;UCnChC;EACf;EACA;EACA,UAAU,WAAW;EACrB,MAAM,YAAY;;EAElB,OAAO,iBAAiB,YAAY;EACpC,MAAM;;;UAIS;;;;;;;;;;EAUf;;;;;;;;EAQA;;;;;;qBAOW;;WAEF,OAAO;UAER;UACA;;EAGR,UAAU,QAAQ;;MAKd,UAAU;;MAQV;;;;;EAQJ,MAAM;;;;EAcN;;;;;EAYA,YACE,iBACA,iBACA,cACA,kBACA,uBACA;;;EAkBF;;;EAMA;;;UCzHe;WACN;WACA;WACA;WACA;;;UAIM;WACN;;;UAIM,mBAAmB;WACzB;WACA,OAAO;WACP;;;UAIM,oBAAoB;WAC1B;WACA,OAAO;WACP;WACA;;;UAIM,wBAAwB;WAC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