BlueGit

timfa questward

Make wet-sand shoreline width a graphics setting (default 60%).

Players can pick Off / 30% / 60% / 100% under Settings; changing it rebakes chunk atlases.

timfa Tim Falken · pushed by timfa

Authored 2026-09-03 · 2 months ago

Hash
3ebdfa957eaa2471d9dafb6026e003b8d16e7d3d
Parent
83d6f12f
9 files changed +154 −32
client/index.html +9 −0
@@ -54,6 +54,15 @@
54 54 <button type="button" data-graphics-key="softTerrain" data-graphics-value="off">Off</button>
55 55 </div>
56 56 </section>
57 <section class="settings-group">
58 <h3>Wet sand</h3>
59 <div class="settings-options">
60 <button type="button" data-graphics-key="wetSand" data-graphics-value="0">Off</button>
61 <button type="button" data-graphics-key="wetSand" data-graphics-value="30">30%</button>
62 <button type="button" data-graphics-key="wetSand" data-graphics-value="60">60%</button>
63 <button type="button" data-graphics-key="wetSand" data-graphics-value="100">100%</button>
64 </div>
65 </section>
57 66 <section class="settings-group">
58 67 <h3>Autorun</h3>
59 68 <div class="settings-options">
@@ -54,6 +54,15 @@
54 <button type="button" data-graphics-key="softTerrain" data-graphics-value="off">Off</button>
54 <button type="button" data-graphics-key="softTerrain" data-graphics-value="off">Off</button>
55 </div>
55 </div>
56 </section>
56 </section>
57 <section class="settings-group">
58 <h3>Wet sand</h3>
59 <div class="settings-options">
60 <button type="button" data-graphics-key="wetSand" data-graphics-value="0">Off</button>
61 <button type="button" data-graphics-key="wetSand" data-graphics-value="30">30%</button>
62 <button type="button" data-graphics-key="wetSand" data-graphics-value="60">60%</button>
63 <button type="button" data-graphics-key="wetSand" data-graphics-value="100">100%</button>
64 </div>
65 </section>
57 <section class="settings-group">
66 <section class="settings-group">
58 <h3>Autorun</h3>
67 <h3>Autorun</h3>
59 <div class="settings-options">
68 <div class="settings-options">
client/src/play/graphicsSettings.js +2 −1
@@ -3,6 +3,7 @@ import {
3 3 LightingMode,
4 4 BloomMode,
5 5 AutorunMode,
6 WetSandBand,
6 7 loadGraphicsSettings,
7 8 saveGraphicsSettings,
8 9 normalizeGraphicsSettings
@@ -119,4 +120,4 @@ export function initGraphicsSettings ({ onChange, onSuppressWorldClick })
119 120 };
120 121 }
121 122
122 export { ViewDistance, LightingMode, BloomMode, AutorunMode };
123 export { ViewDistance, LightingMode, BloomMode, AutorunMode, WetSandBand };
@@ -3,6 +3,7 @@ import {
3 LightingMode,
3 LightingMode,
4 BloomMode,
4 BloomMode,
5 AutorunMode,
5 AutorunMode,
6 WetSandBand,
6 loadGraphicsSettings,
7 loadGraphicsSettings,
7 saveGraphicsSettings,
8 saveGraphicsSettings,
8 normalizeGraphicsSettings
9 normalizeGraphicsSettings
@@ -119,4 +120,4 @@ export function initGraphicsSettings ({ onChange, onSuppressWorldClick })
119 };
120 };
120}
121}
121
122
122export { ViewDistance, LightingMode, BloomMode, AutorunMode };
123export { ViewDistance, LightingMode, BloomMode, AutorunMode, WetSandBand };
client/src/render/chunkBake.js +13 −5
@@ -17,6 +17,7 @@ import {
17 17 mixSoftTerrainPixel
18 18 } from "/shared/render/softTerrain.js";
19 19 import {
20 WET_SAND_BAND_FRACTION,
20 21 WET_SAND_NEIGHBOR_DIRS,
21 22 wetSandWetness,
22 23 mixWetSandPixel
@@ -34,6 +35,7 @@ import { computeChunkAtlasKeys } from "/shared/render/chunkAtlasKeys.js";
34 35 * preview?: object | null,
35 36 * season?: string,
36 37 * softTerrain?: boolean,
38 * wetSandBandFraction?: number,
37 39 * resolveGround?: (tileX: number, tileY: number) => object | number | null,
38 40 * cache?: ReturnType<typeof import("./chunkAtlasCache.js").createChunkAtlasCache>
39 41 * }} options
@@ -45,6 +47,7 @@ export function bakeChunkAtlases ({
45 47 preview = null,
46 48 season = SeasonId.summer,
47 49 softTerrain = false,
50 wetSandBandFraction = WET_SAND_BAND_FRACTION,
48 51 resolveGround = null,
49 52 cache = null
50 53 })
@@ -62,6 +65,7 @@ export function bakeChunkAtlases ({
62 65 preview,
63 66 season,
64 67 softTerrain,
68 wetSandBandFraction,
65 69 resolveGround
66 70 });
67 71 const bakeCtx = {
@@ -71,6 +75,7 @@ export function bakeChunkAtlases ({
71 75 preview,
72 76 season,
73 77 softTerrain,
78 wetSandBandFraction,
74 79 resolveGround
75 80 };
76 81
@@ -195,6 +200,7 @@ function bakeGroundCanvas ({
195 200 preview,
196 201 season,
197 202 softTerrain,
203 wetSandBandFraction = WET_SAND_BAND_FRACTION,
198 204 resolveGround
199 205 })
200 206 {
@@ -207,6 +213,7 @@ function bakeGroundCanvas ({
207 213 const pixelCache = new Map();
208 214 const baseTileX = snapshot.chunkX * CHUNK_SIZE;
209 215 const baseTileY = snapshot.chunkY * CHUNK_SIZE;
216 const wetBand = Math.max(0, Number(wetSandBandFraction) || 0);
210 217
211 218 for (let localY = 0; localY < CHUNK_SIZE; localY++)
212 219 {
@@ -221,7 +228,7 @@ function bakeGroundCanvas ({
221 228 const groundMeta = groundCatalogMeta(catalog, groundEntry);
222 229 if (!isBakeable(images[groundName], groundMeta))
223 230 { continue; }
224 const wetShore = isWetShoreGround(groundEntry);
231 const wetShore = wetBand > 0 && isWetShoreGround(groundEntry);
225 232 const blendable = softTerrain && isGroundBlendable(groundEntry);
226 233 if (wetShore || blendable)
227 234 {
@@ -238,7 +245,7 @@ function bakeGroundCanvas ({
238 245 season,
239 246 resolveGround,
240 247 pixelCache,
241 { softTerrain: blendable, wetShore }
248 { softTerrain: blendable, wetShore, wetSandBandFraction: wetBand }
242 249 );
243 250 }
244 251 else
@@ -436,7 +443,7 @@ function blitBlendedGround (
436 443 season,
437 444 resolveGround,
438 445 pixelCache,
439 { softTerrain = false, wetShore = false } = {}
446 { softTerrain = false, wetShore = false, wetSandBandFraction = WET_SAND_BAND_FRACTION } = {}
440 447 )
441 448 {
442 449 const dryPixels = spritePixels(images[groundName], pixelCache);
@@ -446,8 +453,9 @@ function blitBlendedGround (
446 453 return;
447 454 }
448 455
456 const wetBand = Math.max(0, Number(wetSandBandFraction) || 0);
449 457 const waterDirs = [];
450 if (wetShore)
458 if (wetShore && wetBand > 0)
451 459 {
452 460 for (const { ndx, ndy } of WET_SAND_NEIGHBOR_DIRS)
453 461 {
@@ -511,7 +519,7 @@ function blitBlendedGround (
511 519 let self = readPixel(dryPixels, px, py);
512 520 if (wetPixels && waterDirs.length)
513 521 {
514 const wetness = wetSandWetness(px, py, waterDirs, SPRITE_SIZE_PX);
522 const wetness = wetSandWetness(px, py, waterDirs, SPRITE_SIZE_PX, wetBand);
515 523 if (wetness > 0)
516 524 { self = mixWetSandPixel(self, readPixel(wetPixels, px, py), wetness); }
517 525 }
@@ -17,6 +17,7 @@ import {
17 mixSoftTerrainPixel
17 mixSoftTerrainPixel
18} from "/shared/render/softTerrain.js";
18} from "/shared/render/softTerrain.js";
19import {
19import {
20 WET_SAND_BAND_FRACTION,
20 WET_SAND_NEIGHBOR_DIRS,
21 WET_SAND_NEIGHBOR_DIRS,
21 wetSandWetness,
22 wetSandWetness,
22 mixWetSandPixel
23 mixWetSandPixel
@@ -34,6 +35,7 @@ import { computeChunkAtlasKeys } from "/shared/render/chunkAtlasKeys.js";
34 * preview?: object | null,
35 * preview?: object | null,
35 * season?: string,
36 * season?: string,
36 * softTerrain?: boolean,
37 * softTerrain?: boolean,
38 * wetSandBandFraction?: number,
37 * resolveGround?: (tileX: number, tileY: number) => object | number | null,
39 * resolveGround?: (tileX: number, tileY: number) => object | number | null,
38 * cache?: ReturnType<typeof import("./chunkAtlasCache.js").createChunkAtlasCache>
40 * cache?: ReturnType<typeof import("./chunkAtlasCache.js").createChunkAtlasCache>
39 * }} options
41 * }} options
@@ -45,6 +47,7 @@ export function bakeChunkAtlases ({
45 preview = null,
47 preview = null,
46 season = SeasonId.summer,
48 season = SeasonId.summer,
47 softTerrain = false,
49 softTerrain = false,
50 wetSandBandFraction = WET_SAND_BAND_FRACTION,
48 resolveGround = null,
51 resolveGround = null,
49 cache = null
52 cache = null
50})
53})
@@ -62,6 +65,7 @@ export function bakeChunkAtlases ({
62 preview,
65 preview,
63 season,
66 season,
64 softTerrain,
67 softTerrain,
68 wetSandBandFraction,
65 resolveGround
69 resolveGround
66 });
70 });
67 const bakeCtx = {
71 const bakeCtx = {
@@ -71,6 +75,7 @@ export function bakeChunkAtlases ({
71 preview,
75 preview,
72 season,
76 season,
73 softTerrain,
77 softTerrain,
78 wetSandBandFraction,
74 resolveGround
79 resolveGround
75 };
80 };
76
81
@@ -195,6 +200,7 @@ function bakeGroundCanvas ({
195 preview,
200 preview,
196 season,
201 season,
197 softTerrain,
202 softTerrain,
203 wetSandBandFraction = WET_SAND_BAND_FRACTION,
198 resolveGround
204 resolveGround
199})
205})
200{
206{
@@ -207,6 +213,7 @@ function bakeGroundCanvas ({
207 const pixelCache = new Map();
213 const pixelCache = new Map();
208 const baseTileX = snapshot.chunkX * CHUNK_SIZE;
214 const baseTileX = snapshot.chunkX * CHUNK_SIZE;
209 const baseTileY = snapshot.chunkY * CHUNK_SIZE;
215 const baseTileY = snapshot.chunkY * CHUNK_SIZE;
216 const wetBand = Math.max(0, Number(wetSandBandFraction) || 0);
210
217
211 for (let localY = 0; localY < CHUNK_SIZE; localY++)
218 for (let localY = 0; localY < CHUNK_SIZE; localY++)
212 {
219 {
@@ -221,7 +228,7 @@ function bakeGroundCanvas ({
221 const groundMeta = groundCatalogMeta(catalog, groundEntry);
228 const groundMeta = groundCatalogMeta(catalog, groundEntry);
222 if (!isBakeable(images[groundName], groundMeta))
229 if (!isBakeable(images[groundName], groundMeta))
223 { continue; }
230 { continue; }
224 const wetShore = isWetShoreGround(groundEntry);
231 const wetShore = wetBand > 0 && isWetShoreGround(groundEntry);
225 const blendable = softTerrain && isGroundBlendable(groundEntry);
232 const blendable = softTerrain && isGroundBlendable(groundEntry);
226 if (wetShore || blendable)
233 if (wetShore || blendable)
227 {
234 {
@@ -238,7 +245,7 @@ function bakeGroundCanvas ({
238 season,
245 season,
239 resolveGround,
246 resolveGround,
240 pixelCache,
247 pixelCache,
241 { softTerrain: blendable, wetShore }
248 { softTerrain: blendable, wetShore, wetSandBandFraction: wetBand }
242 );
249 );
243 }
250 }
244 else
251 else
@@ -436,7 +443,7 @@ function blitBlendedGround (
436 season,
443 season,
437 resolveGround,
444 resolveGround,
438 pixelCache,
445 pixelCache,
439 { softTerrain = false, wetShore = false } = {}
446 { softTerrain = false, wetShore = false, wetSandBandFraction = WET_SAND_BAND_FRACTION } = {}
440)
447)
441{
448{
442 const dryPixels = spritePixels(images[groundName], pixelCache);
449 const dryPixels = spritePixels(images[groundName], pixelCache);
@@ -446,8 +453,9 @@ function blitBlendedGround (
446 return;
453 return;
447 }
454 }
448
455
456 const wetBand = Math.max(0, Number(wetSandBandFraction) || 0);
449 const waterDirs = [];
457 const waterDirs = [];
450 if (wetShore)
458 if (wetShore && wetBand > 0)
451 {
459 {
452 for (const { ndx, ndy } of WET_SAND_NEIGHBOR_DIRS)
460 for (const { ndx, ndy } of WET_SAND_NEIGHBOR_DIRS)
453 {
461 {
@@ -511,7 +519,7 @@ function blitBlendedGround (
511 let self = readPixel(dryPixels, px, py);
519 let self = readPixel(dryPixels, px, py);
512 if (wetPixels && waterDirs.length)
520 if (wetPixels && waterDirs.length)
513 {
521 {
514 const wetness = wetSandWetness(px, py, waterDirs, SPRITE_SIZE_PX);
522 const wetness = wetSandWetness(px, py, waterDirs, SPRITE_SIZE_PX, wetBand);
515 if (wetness > 0)
523 if (wetness > 0)
516 { self = mixWetSandPixel(self, readPixel(wetPixels, px, py), wetness); }
524 { self = mixWetSandPixel(self, readPixel(wetPixels, px, py), wetness); }
517 }
525 }
client/src/render/worldView.js +21 −3
@@ -501,6 +501,8 @@ export class WorldView
501 501 this.bloomEnabled = true;
502 502 /** Soft edge blend for blendable grounds (grass, dirt, …). */
503 503 this.softTerrain = false;
504 /** Wet sand shoreline width as a 0–1 tile fraction (graphics setting). */
505 this.wetSandBandFraction = 0.6;
504 506 this.settings = { ...DEFAULT_WORLD_SETTINGS };
505 507 this.worldHour = 12;
506 508 /** Calendar season for seasonal ground/block visuals (`spring` / `summer` / `fall` / `winter`). */
@@ -532,8 +534,8 @@ export class WorldView
532 534 }
533 535
534 536 /**
535 * Client graphics prefs (lighting Soft/Simple, bloom On/Off, soft terrain).
536 * @param {{ lighting?: string, bloom?: string, softTerrain?: string }} prefs
537 * Client graphics prefs (lighting Soft/Simple, bloom On/Off, soft terrain, wet sand).
538 * @param {{ lighting?: string, bloom?: string, softTerrain?: string, wetSand?: string }} prefs
537 539 */
538 540 setGraphicsPrefs (prefs)
539 541 {
@@ -550,15 +552,30 @@ export class WorldView
550 552 else
551 553 { this.bloomEnabled = enabled; }
552 554 }
555 let rebake = false;
553 556 if (prefs?.softTerrain === "on" || prefs?.softTerrain === "off")
554 557 {
555 558 const enabled = prefs.softTerrain === "on";
556 559 if (enabled !== this.softTerrain)
557 560 {
558 561 this.softTerrain = enabled;
559 this.#rebakeAllChunks();
562 rebake = true;
560 563 }
561 564 }
565 if (prefs?.wetSand != null)
566 {
567 const pct = Number(prefs.wetSand);
568 const next = !Number.isFinite(pct) || pct <= 0
569 ? 0
570 : Math.min(1, pct / 100);
571 if (next !== this.wetSandBandFraction)
572 {
573 this.wetSandBandFraction = next;
574 rebake = true;
575 }
576 }
577 if (rebake)
578 { this.#rebakeAllChunks(); }
562 579 }
563 580
564 581 /** Apply server (or local) calendar season; rebakes chunks when it changes. */
@@ -3721,6 +3738,7 @@ export class WorldView
3721 3738 preview: this.preview,
3722 3739 season: this.worldSeason,
3723 3740 softTerrain: this.softTerrain,
3741 wetSandBandFraction: this.wetSandBandFraction,
3724 3742 resolveGround: (tileX, tileY) => this.#groundAtTile(tileX, tileY),
3725 3743 cache: this.#atlasCache
3726 3744 });
@@ -501,6 +501,8 @@ export class WorldView
501 this.bloomEnabled = true;
501 this.bloomEnabled = true;
502 /** Soft edge blend for blendable grounds (grass, dirt, …). */
502 /** Soft edge blend for blendable grounds (grass, dirt, …). */
503 this.softTerrain = false;
503 this.softTerrain = false;
504 /** Wet sand shoreline width as a 0–1 tile fraction (graphics setting). */
505 this.wetSandBandFraction = 0.6;
504 this.settings = { ...DEFAULT_WORLD_SETTINGS };
506 this.settings = { ...DEFAULT_WORLD_SETTINGS };
505 this.worldHour = 12;
507 this.worldHour = 12;
506 /** Calendar season for seasonal ground/block visuals (`spring` / `summer` / `fall` / `winter`). */
508 /** Calendar season for seasonal ground/block visuals (`spring` / `summer` / `fall` / `winter`). */
@@ -532,8 +534,8 @@ export class WorldView
532 }
534 }
533
535
534 /**
536 /**
535 * Client graphics prefs (lighting Soft/Simple, bloom On/Off, soft terrain).
537 * Client graphics prefs (lighting Soft/Simple, bloom On/Off, soft terrain, wet sand).
536 * @param {{ lighting?: string, bloom?: string, softTerrain?: string }} prefs
538 * @param {{ lighting?: string, bloom?: string, softTerrain?: string, wetSand?: string }} prefs
537 */
539 */
538 setGraphicsPrefs (prefs)
540 setGraphicsPrefs (prefs)
539 {
541 {
@@ -550,15 +552,30 @@ export class WorldView
550 else
552 else
551 { this.bloomEnabled = enabled; }
553 { this.bloomEnabled = enabled; }
552 }
554 }
555 let rebake = false;
553 if (prefs?.softTerrain === "on" || prefs?.softTerrain === "off")
556 if (prefs?.softTerrain === "on" || prefs?.softTerrain === "off")
554 {
557 {
555 const enabled = prefs.softTerrain === "on";
558 const enabled = prefs.softTerrain === "on";
556 if (enabled !== this.softTerrain)
559 if (enabled !== this.softTerrain)
557 {
560 {
558 this.softTerrain = enabled;
561 this.softTerrain = enabled;
559 this.#rebakeAllChunks();
562 rebake = true;
560 }
563 }
561 }
564 }
565 if (prefs?.wetSand != null)
566 {
567 const pct = Number(prefs.wetSand);
568 const next = !Number.isFinite(pct) || pct <= 0
569 ? 0
570 : Math.min(1, pct / 100);
571 if (next !== this.wetSandBandFraction)
572 {
573 this.wetSandBandFraction = next;
574 rebake = true;
575 }
576 }
577 if (rebake)
578 { this.#rebakeAllChunks(); }
562 }
579 }
563
580
564 /** Apply server (or local) calendar season; rebakes chunks when it changes. */
581 /** Apply server (or local) calendar season; rebakes chunks when it changes. */
@@ -3721,6 +3738,7 @@ export class WorldView
3721 preview: this.preview,
3738 preview: this.preview,
3722 season: this.worldSeason,
3739 season: this.worldSeason,
3723 softTerrain: this.softTerrain,
3740 softTerrain: this.softTerrain,
3741 wetSandBandFraction: this.wetSandBandFraction,
3724 resolveGround: (tileX, tileY) => this.#groundAtTile(tileX, tileY),
3742 resolveGround: (tileX, tileY) => this.#groundAtTile(tileX, tileY),
3725 cache: this.#atlasCache
3743 cache: this.#atlasCache
3726 });
3744 });
server/tests/chunk-atlas-keys.test.js +33 −1
@@ -131,6 +131,38 @@ test("wet sand border fingerprint differs for liquid water neighbors", () =>
131 131 }
132 132 });
133 133 // Frozen shallow water should not wet the shoreline; deep still does.
134 assert.equal(winterShallow.groundKey.includes("wet:flat"), true);
134 assert.equal(winterShallow.groundKey.includes("wet:flat") || winterShallow.groundKey.includes("wetBand:0.6"), true);
135 assert.ok(winterShallow.groundKey.includes("wet:flat"));
135 136 assert.notEqual(winterShallow.groundKey, winterDeep.groundKey);
136 137 });
138
139 test("wet sand band fraction is part of the ground atlas key", () =>
140 {
141 const catalogSand = {
142 grounds: { sand: { states: ["sand", "sand-wet"] } },
143 blocks: {}
144 };
145 const snapshot = {
146 chunkX: 0,
147 chunkY: 0,
148 grounds: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => ({ typeId: GroundType.sand })),
149 blocks: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => null)
150 };
151 const medium = computeChunkAtlasKeys({
152 snapshot,
153 catalog: catalogSand,
154 season: "summer",
155 wetSandBandFraction: 0.6,
156 resolveGround: () => ({ typeId: GroundType.sand })
157 });
158 const off = computeChunkAtlasKeys({
159 snapshot,
160 catalog: catalogSand,
161 season: "summer",
162 wetSandBandFraction: 0,
163 resolveGround: () => ({ typeId: GroundType.sand })
164 });
165 assert.notEqual(medium.groundKey, off.groundKey);
166 assert.ok(medium.groundKey.includes("wetBand:0.6"));
167 assert.ok(off.groundKey.includes("wetBand:0"));
168 });
@@ -131,6 +131,38 @@ test("wet sand border fingerprint differs for liquid water neighbors", () =>
131 }
131 }
132 });
132 });
133 // Frozen shallow water should not wet the shoreline; deep still does.
133 // Frozen shallow water should not wet the shoreline; deep still does.
134 assert.equal(winterShallow.groundKey.includes("wet:flat"), true);
134 assert.equal(winterShallow.groundKey.includes("wet:flat") || winterShallow.groundKey.includes("wetBand:0.6"), true);
135 assert.ok(winterShallow.groundKey.includes("wet:flat"));
135 assert.notEqual(winterShallow.groundKey, winterDeep.groundKey);
136 assert.notEqual(winterShallow.groundKey, winterDeep.groundKey);
136});
137});
138
139test("wet sand band fraction is part of the ground atlas key", () =>
140{
141 const catalogSand = {
142 grounds: { sand: { states: ["sand", "sand-wet"] } },
143 blocks: {}
144 };
145 const snapshot = {
146 chunkX: 0,
147 chunkY: 0,
148 grounds: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => ({ typeId: GroundType.sand })),
149 blocks: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => null)
150 };
151 const medium = computeChunkAtlasKeys({
152 snapshot,
153 catalog: catalogSand,
154 season: "summer",
155 wetSandBandFraction: 0.6,
156 resolveGround: () => ({ typeId: GroundType.sand })
157 });
158 const off = computeChunkAtlasKeys({
159 snapshot,
160 catalog: catalogSand,
161 season: "summer",
162 wetSandBandFraction: 0,
163 resolveGround: () => ({ typeId: GroundType.sand })
164 });
165 assert.notEqual(medium.groundKey, off.groundKey);
166 assert.ok(medium.groundKey.includes("wetBand:0.6"));
167 assert.ok(off.groundKey.includes("wetBand:0"));
168});
server/tests/wetSand.test.js +21 −4
@@ -14,6 +14,12 @@ import {
14 14 isLiquidWaterGround
15 15 } from "../../shared/definitions/tiles.js";
16 16 import { SeasonId } from "../../shared/world/season.js";
17 import {
18 DEFAULT_GRAPHICS_SETTINGS,
19 WetSandBand,
20 wetSandBandFraction,
21 normalizeGraphicsSettings
22 } from "../../shared/graphics/settings.js";
17 23
18 24 test("sand is blendable wet-shore ground with year-round sprites", () =>
19 25 {
@@ -27,13 +33,21 @@ test("sand is blendable wet-shore ground with year-round sprites", () =>
27 33 assert.equal(sand.water, false);
28 34 });
29 35
30 test("wet sand band is 30% of the tile", () =>
36 test("wet sand band defaults to 60% and is a graphics setting", () =>
31 37 {
32 assert.equal(WET_SAND_BAND_FRACTION, 0.3);
38 assert.equal(WET_SAND_BAND_FRACTION, 0.6);
33 39 assert.equal(WET_SAND_NEIGHBOR_DIRS.length, 8);
40 assert.equal(DEFAULT_GRAPHICS_SETTINGS.wetSand, WetSandBand.medium);
41 assert.equal(wetSandBandFraction(WetSandBand.medium), 0.6);
42 assert.equal(wetSandBandFraction(WetSandBand.off), 0);
43 assert.equal(wetSandBandFraction(WetSandBand.narrow), 0.3);
44 assert.equal(wetSandBandFraction(WetSandBand.wide), 1);
45 assert.equal(normalizeGraphicsSettings({}).wetSand, "60");
46 assert.equal(normalizeGraphicsSettings({ wetSand: "30" }).wetSand, "30");
47 assert.equal(normalizeGraphicsSettings({ wetSand: "nope" }).wetSand, "60");
34 48 });
35 49
36 test("east water: edge fully wet, beyond 30% dry", () =>
50 test("east water: edge fully wet, beyond band dry", () =>
37 51 {
38 52 const band = WET_SAND_BAND_FRACTION * 16;
39 53 assert.equal(wetSandBlendWeight(15, 8, 1, 0), 1);
@@ -41,13 +55,16 @@ test("east water: edge fully wet, beyond 30% dry", () =>
41 55 assert.ok(wetSandBlendWeight(14, 8, 1, 0) < 1);
42 56 assert.equal(wetSandBlendWeight(15 - Math.ceil(band), 8, 1, 0), 0);
43 57 assert.equal(wetSandBlendWeight(0, 8, 1, 0), 0);
58 assert.equal(wetSandBlendWeight(10, 8, 1, 0, 16, 0), 0);
59 assert.equal(wetSandBlendWeight(0, 8, 1, 0, 16, 1), 1 / 16);
44 60 });
45 61
46 62 test("southeast water wets the corner fan", () =>
47 63 {
48 64 assert.equal(wetSandEdgeDistance(15, 15, 1, 1), 0);
49 65 assert.equal(wetSandBlendWeight(15, 15, 1, 1), 1);
50 assert.equal(wetSandBlendWeight(15, 8, 1, 1), 0);
66 // Far from the SE corner along the east edge stays dry under the default 60% band.
67 assert.equal(wetSandBlendWeight(15, 0, 1, 1), 0);
51 68 assert.ok(wetSandBlendWeight(14, 14, 1, 1) > 0);
52 69 });
53 70
@@ -14,6 +14,12 @@ import {
14 isLiquidWaterGround
14 isLiquidWaterGround
15} from "../../shared/definitions/tiles.js";
15} from "../../shared/definitions/tiles.js";
16import { SeasonId } from "../../shared/world/season.js";
16import { SeasonId } from "../../shared/world/season.js";
17import {
18 DEFAULT_GRAPHICS_SETTINGS,
19 WetSandBand,
20 wetSandBandFraction,
21 normalizeGraphicsSettings
22} from "../../shared/graphics/settings.js";
17
23
18test("sand is blendable wet-shore ground with year-round sprites", () =>
24test("sand is blendable wet-shore ground with year-round sprites", () =>
19{
25{
@@ -27,13 +33,21 @@ test("sand is blendable wet-shore ground with year-round sprites", () =>
27 assert.equal(sand.water, false);
33 assert.equal(sand.water, false);
28});
34});
29
35
30test("wet sand band is 30% of the tile", () =>
36test("wet sand band defaults to 60% and is a graphics setting", () =>
31{
37{
32 assert.equal(WET_SAND_BAND_FRACTION, 0.3);
38 assert.equal(WET_SAND_BAND_FRACTION, 0.6);
33 assert.equal(WET_SAND_NEIGHBOR_DIRS.length, 8);
39 assert.equal(WET_SAND_NEIGHBOR_DIRS.length, 8);
40 assert.equal(DEFAULT_GRAPHICS_SETTINGS.wetSand, WetSandBand.medium);
41 assert.equal(wetSandBandFraction(WetSandBand.medium), 0.6);
42 assert.equal(wetSandBandFraction(WetSandBand.off), 0);
43 assert.equal(wetSandBandFraction(WetSandBand.narrow), 0.3);
44 assert.equal(wetSandBandFraction(WetSandBand.wide), 1);
45 assert.equal(normalizeGraphicsSettings({}).wetSand, "60");
46 assert.equal(normalizeGraphicsSettings({ wetSand: "30" }).wetSand, "30");
47 assert.equal(normalizeGraphicsSettings({ wetSand: "nope" }).wetSand, "60");
34});
48});
35
49
36test("east water: edge fully wet, beyond 30% dry", () =>
50test("east water: edge fully wet, beyond band dry", () =>
37{
51{
38 const band = WET_SAND_BAND_FRACTION * 16;
52 const band = WET_SAND_BAND_FRACTION * 16;
39 assert.equal(wetSandBlendWeight(15, 8, 1, 0), 1);
53 assert.equal(wetSandBlendWeight(15, 8, 1, 0), 1);
@@ -41,13 +55,16 @@ test("east water: edge fully wet, beyond 30% dry", () =>
41 assert.ok(wetSandBlendWeight(14, 8, 1, 0) < 1);
55 assert.ok(wetSandBlendWeight(14, 8, 1, 0) < 1);
42 assert.equal(wetSandBlendWeight(15 - Math.ceil(band), 8, 1, 0), 0);
56 assert.equal(wetSandBlendWeight(15 - Math.ceil(band), 8, 1, 0), 0);
43 assert.equal(wetSandBlendWeight(0, 8, 1, 0), 0);
57 assert.equal(wetSandBlendWeight(0, 8, 1, 0), 0);
58 assert.equal(wetSandBlendWeight(10, 8, 1, 0, 16, 0), 0);
59 assert.equal(wetSandBlendWeight(0, 8, 1, 0, 16, 1), 1 / 16);
44});
60});
45
61
46test("southeast water wets the corner fan", () =>
62test("southeast water wets the corner fan", () =>
47{
63{
48 assert.equal(wetSandEdgeDistance(15, 15, 1, 1), 0);
64 assert.equal(wetSandEdgeDistance(15, 15, 1, 1), 0);
49 assert.equal(wetSandBlendWeight(15, 15, 1, 1), 1);
65 assert.equal(wetSandBlendWeight(15, 15, 1, 1), 1);
50 assert.equal(wetSandBlendWeight(15, 8, 1, 1), 0);
66 // Far from the SE corner along the east edge stays dry under the default 60% band.
67 assert.equal(wetSandBlendWeight(15, 0, 1, 1), 0);
51 assert.ok(wetSandBlendWeight(14, 14, 1, 1) > 0);
68 assert.ok(wetSandBlendWeight(14, 14, 1, 1) > 0);
52});
69});
53
70
shared/graphics/settings.js +28 −1
@@ -21,6 +21,17 @@ export const SoftTerrainMode = Object.freeze({
21 21 off: "off"
22 22 });
23 23
24 /**
25 * Wet sand shoreline width (% of the tile facing liquid water).
26 * Stored as percent strings for the settings UI.
27 */
28 export const WetSandBand = Object.freeze({
29 off: "0",
30 narrow: "30",
31 medium: "60",
32 wide: "100"
33 });
34
24 35 /** Auto walk/run by path distance (client-only; ignored while following). */
25 36 export const AutorunMode = Object.freeze({
26 37 on: "on",
@@ -32,11 +43,24 @@ export const DEFAULT_GRAPHICS_SETTINGS = Object.freeze({
32 43 lighting: LightingMode.soft,
33 44 bloom: BloomMode.on,
34 45 softTerrain: SoftTerrainMode.on,
46 wetSand: WetSandBand.medium,
35 47 autorun: AutorunMode.off
36 48 });
37 49
50 const WET_SAND_BAND_VALUES = new Set(Object.values(WetSandBand));
51
38 52 const STORAGE_KEY = "questward-graphics-settings";
39 53
54 /** Map a wetSand settings value to a 0–1 tile fraction. */
55 export function wetSandBandFraction (value)
56 {
57 const raw = String(value ?? WetSandBand.medium);
58 const pct = Number(raw);
59 if (!Number.isFinite(pct) || pct <= 0)
60 { return 0; }
61 return Math.min(1, pct / 100);
62 }
63
40 64 export function normalizeGraphicsSettings (value)
41 65 {
42 66 const raw = value && typeof value === "object" ? value : {};
@@ -52,10 +76,13 @@ export function normalizeGraphicsSettings (value)
52 76 const softTerrain = raw.softTerrain === SoftTerrainMode.off
53 77 ? SoftTerrainMode.off
54 78 : SoftTerrainMode.on;
79 const wetSand = WET_SAND_BAND_VALUES.has(String(raw.wetSand))
80 ? String(raw.wetSand)
81 : WetSandBand.medium;
55 82 const autorun = raw.autorun === AutorunMode.on
56 83 ? AutorunMode.on
57 84 : AutorunMode.off;
58 return { viewDistance, lighting, bloom, softTerrain, autorun };
85 return { viewDistance, lighting, bloom, softTerrain, wetSand, autorun };
59 86 }
60 87
61 88 export function loadGraphicsSettings ()
@@ -21,6 +21,17 @@ export const SoftTerrainMode = Object.freeze({
21 off: "off"
21 off: "off"
22});
22});
23
23
24/**
25 * Wet sand shoreline width (% of the tile facing liquid water).
26 * Stored as percent strings for the settings UI.
27 */
28export const WetSandBand = Object.freeze({
29 off: "0",
30 narrow: "30",
31 medium: "60",
32 wide: "100"
33});
34
24/** Auto walk/run by path distance (client-only; ignored while following). */
35/** Auto walk/run by path distance (client-only; ignored while following). */
25export const AutorunMode = Object.freeze({
36export const AutorunMode = Object.freeze({
26 on: "on",
37 on: "on",
@@ -32,11 +43,24 @@ export const DEFAULT_GRAPHICS_SETTINGS = Object.freeze({
32 lighting: LightingMode.soft,
43 lighting: LightingMode.soft,
33 bloom: BloomMode.on,
44 bloom: BloomMode.on,
34 softTerrain: SoftTerrainMode.on,
45 softTerrain: SoftTerrainMode.on,
46 wetSand: WetSandBand.medium,
35 autorun: AutorunMode.off
47 autorun: AutorunMode.off
36});
48});
37
49
50const WET_SAND_BAND_VALUES = new Set(Object.values(WetSandBand));
51
38const STORAGE_KEY = "questward-graphics-settings";
52const STORAGE_KEY = "questward-graphics-settings";
39
53
54/** Map a wetSand settings value to a 0–1 tile fraction. */
55export function wetSandBandFraction (value)
56{
57 const raw = String(value ?? WetSandBand.medium);
58 const pct = Number(raw);
59 if (!Number.isFinite(pct) || pct <= 0)
60 { return 0; }
61 return Math.min(1, pct / 100);
62}
63
40export function normalizeGraphicsSettings (value)
64export function normalizeGraphicsSettings (value)
41{
65{
42 const raw = value && typeof value === "object" ? value : {};
66 const raw = value && typeof value === "object" ? value : {};
@@ -52,10 +76,13 @@ export function normalizeGraphicsSettings (value)
52 const softTerrain = raw.softTerrain === SoftTerrainMode.off
76 const softTerrain = raw.softTerrain === SoftTerrainMode.off
53 ? SoftTerrainMode.off
77 ? SoftTerrainMode.off
54 : SoftTerrainMode.on;
78 : SoftTerrainMode.on;
79 const wetSand = WET_SAND_BAND_VALUES.has(String(raw.wetSand))
80 ? String(raw.wetSand)
81 : WetSandBand.medium;
55 const autorun = raw.autorun === AutorunMode.on
82 const autorun = raw.autorun === AutorunMode.on
56 ? AutorunMode.on
83 ? AutorunMode.on
57 : AutorunMode.off;
84 : AutorunMode.off;
58 return { viewDistance, lighting, bloom, softTerrain, autorun };
85 return { viewDistance, lighting, bloom, softTerrain, wetSand, autorun };
59}
86}
60
87
61export function loadGraphicsSettings ()
88export function loadGraphicsSettings ()
shared/render/chunkAtlasKeys.js +14 −8
@@ -11,7 +11,7 @@ import {
11 11 import { bloomImageName } from "../definitions/tileSprites.js";
12 12 import { resolveSeasonalVisualState } from "../world/season.js";
13 13 import { SOFT_TERRAIN_NEIGHBOR_DIRS } from "./softTerrain.js";
14 import { WET_SAND_NEIGHBOR_DIRS } from "./wetSand.js";
14 import { WET_SAND_BAND_FRACTION, WET_SAND_NEIGHBOR_DIRS } from "./wetSand.js";
15 15
16 16 export const EMPTY_BLOCK_ROW_KEY = "blockRow|empty";
17 17 export const EMPTY_BLOOM_KEY = "bloom|empty";
@@ -26,6 +26,7 @@ export function computeChunkAtlasKeys ({
26 26 preview = null,
27 27 season,
28 28 softTerrain = false,
29 wetSandBandFraction = WET_SAND_BAND_FRACTION,
29 30 resolveGround = null
30 31 })
31 32 {
@@ -54,13 +55,18 @@ export function computeChunkAtlasKeys ({
54 55 resolveGround
55 56 })}`;
56 57 }
57 groundBody += `|wet:${wetSandBorderFingerprint({
58 snapshot,
59 catalog,
60 season,
61 preview,
62 resolveGround
63 })}`;
58 const wetBand = Math.max(0, Number(wetSandBandFraction) || 0);
59 if (wetBand > 0)
60 {
61 groundBody += `|wetBand:${wetBand}|wet:${wetSandBorderFingerprint({
62 snapshot,
63 season,
64 preview,
65 resolveGround
66 })}`;
67 }
68 else
69 { groundBody += "|wetBand:0"; }
64 70 const groundKey = `ground|${season}|${groundBody}`;
65 71
66 72 const blockRowKeys = [];
@@ -11,7 +11,7 @@ import {
11import { bloomImageName } from "../definitions/tileSprites.js";
11import { bloomImageName } from "../definitions/tileSprites.js";
12import { resolveSeasonalVisualState } from "../world/season.js";
12import { resolveSeasonalVisualState } from "../world/season.js";
13import { SOFT_TERRAIN_NEIGHBOR_DIRS } from "./softTerrain.js";
13import { SOFT_TERRAIN_NEIGHBOR_DIRS } from "./softTerrain.js";
14import { WET_SAND_NEIGHBOR_DIRS } from "./wetSand.js";
14import { WET_SAND_BAND_FRACTION, WET_SAND_NEIGHBOR_DIRS } from "./wetSand.js";
15
15
16export const EMPTY_BLOCK_ROW_KEY = "blockRow|empty";
16export const EMPTY_BLOCK_ROW_KEY = "blockRow|empty";
17export const EMPTY_BLOOM_KEY = "bloom|empty";
17export const EMPTY_BLOOM_KEY = "bloom|empty";
@@ -26,6 +26,7 @@ export function computeChunkAtlasKeys ({
26 preview = null,
26 preview = null,
27 season,
27 season,
28 softTerrain = false,
28 softTerrain = false,
29 wetSandBandFraction = WET_SAND_BAND_FRACTION,
29 resolveGround = null
30 resolveGround = null
30})
31})
31{
32{
@@ -54,13 +55,18 @@ export function computeChunkAtlasKeys ({
54 resolveGround
55 resolveGround
55 })}`;
56 })}`;
56 }
57 }
57 groundBody += `|wet:${wetSandBorderFingerprint({
58 const wetBand = Math.max(0, Number(wetSandBandFraction) || 0);
58 snapshot,
59 if (wetBand > 0)
59 catalog,
60 {
60 season,
61 groundBody += `|wetBand:${wetBand}|wet:${wetSandBorderFingerprint({
61 preview,
62 snapshot,
62 resolveGround
63 season,
63 })}`;
64 preview,
65 resolveGround
66 })}`;
67 }
68 else
69 { groundBody += "|wetBand:0"; }
64 const groundKey = `ground|${season}|${groundBody}`;
70 const groundKey = `ground|${season}|${groundBody}`;
65
71
66 const blockRowKeys = [];
72 const blockRowKeys = [];
shared/render/wetSand.js +13 −9
@@ -1,12 +1,14 @@
1 1 /**
2 2 * Wet-sand edge blend toward liquid water.
3 3 *
4 * Within the outer 30% of a sand tile facing water (cardinal or diagonal),
5 * pixels lerp toward the wet sprite: edge = 100% wet, beyond 30% = dry.
6 * In winter, shallow water is ice — only deep water counts (see isLiquidWaterGround).
4 * Within the outer band of a sand tile facing water (cardinal or diagonal),
5 * pixels lerp toward the wet sprite: edge = 100% wet, beyond the band = dry.
6 * Default band is 60% (client graphics setting). In winter, shallow water is ice —
7 * only deep water counts (see isLiquidWaterGround).
7 8 */
8 9
9 export const WET_SAND_BAND_FRACTION = 0.3;
10 /** Default wet shoreline width as a fraction of the tile (60%). */
11 export const WET_SAND_BAND_FRACTION = 0.6;
10 12
11 13 /** All eight neighbors — diagonals wet the corner fan toward water. */
12 14 export const WET_SAND_NEIGHBOR_DIRS = Object.freeze([
@@ -55,14 +57,15 @@ export function wetSandEdgeDistance (px, py, ndx, ndy, size = 16)
55 57
56 58 /**
57 59 * Wet blend weight for pixel (px, py) toward water neighbor (ndx, ndy).
58 * 1 at the abutting edge/corner, 0 beyond WET_SAND_BAND_FRACTION of the tile.
60 * 1 at the abutting edge/corner, 0 beyond `bandFraction` of the tile.
61 * @param {number} [bandFraction=WET_SAND_BAND_FRACTION]
59 62 */
60 export function wetSandBlendWeight (px, py, ndx, ndy, size = 16)
63 export function wetSandBlendWeight (px, py, ndx, ndy, size = 16, bandFraction = WET_SAND_BAND_FRACTION)
61 64 {
62 65 const dist = wetSandEdgeDistance(px, py, ndx, ndy, size);
63 66 if (dist == null)
64 67 { return 0; }
65 const band = WET_SAND_BAND_FRACTION * size;
68 const band = Math.max(0, Number(bandFraction) || 0) * size;
66 69 if (!(band > 0) || dist >= band)
67 70 { return 0; }
68 71 return 1 - dist / band;
@@ -71,13 +74,14 @@ export function wetSandBlendWeight (px, py, ndx, ndy, size = 16)
71 74 /**
72 75 * Max wetness from all liquid-water neighbor directions.
73 76 * @param {Array<{ ndx: number, ndy: number }>} waterDirs
77 * @param {number} [bandFraction=WET_SAND_BAND_FRACTION]
74 78 */
75 export function wetSandWetness (px, py, waterDirs, size = 16)
79 export function wetSandWetness (px, py, waterDirs, size = 16, bandFraction = WET_SAND_BAND_FRACTION)
76 80 {
77 81 let max = 0;
78 82 for (const dir of waterDirs ?? [])
79 83 {
80 const w = wetSandBlendWeight(px, py, dir.ndx, dir.ndy, size);
84 const w = wetSandBlendWeight(px, py, dir.ndx, dir.ndy, size, bandFraction);
81 85 if (w > max)
82 86 { max = w; }
83 87 }
@@ -1,12 +1,14 @@
1/**
1/**
2 * Wet-sand edge blend toward liquid water.
2 * Wet-sand edge blend toward liquid water.
3 *
3 *
4 * Within the outer 30% of a sand tile facing water (cardinal or diagonal),
4 * Within the outer band of a sand tile facing water (cardinal or diagonal),
5 * pixels lerp toward the wet sprite: edge = 100% wet, beyond 30% = dry.
5 * pixels lerp toward the wet sprite: edge = 100% wet, beyond the band = dry.
6 * In winter, shallow water is ice — only deep water counts (see isLiquidWaterGround).
6 * Default band is 60% (client graphics setting). In winter, shallow water is ice —
7 * only deep water counts (see isLiquidWaterGround).
7 */
8 */
8
9
9export const WET_SAND_BAND_FRACTION = 0.3;
10/** Default wet shoreline width as a fraction of the tile (60%). */
11export const WET_SAND_BAND_FRACTION = 0.6;
10
12
11/** All eight neighbors — diagonals wet the corner fan toward water. */
13/** All eight neighbors — diagonals wet the corner fan toward water. */
12export const WET_SAND_NEIGHBOR_DIRS = Object.freeze([
14export const WET_SAND_NEIGHBOR_DIRS = Object.freeze([
@@ -55,14 +57,15 @@ export function wetSandEdgeDistance (px, py, ndx, ndy, size = 16)
55
57
56/**
58/**
57 * Wet blend weight for pixel (px, py) toward water neighbor (ndx, ndy).
59 * Wet blend weight for pixel (px, py) toward water neighbor (ndx, ndy).
58 * 1 at the abutting edge/corner, 0 beyond WET_SAND_BAND_FRACTION of the tile.
60 * 1 at the abutting edge/corner, 0 beyond `bandFraction` of the tile.
61 * @param {number} [bandFraction=WET_SAND_BAND_FRACTION]
59 */
62 */
60export function wetSandBlendWeight (px, py, ndx, ndy, size = 16)
63export function wetSandBlendWeight (px, py, ndx, ndy, size = 16, bandFraction = WET_SAND_BAND_FRACTION)
61{
64{
62 const dist = wetSandEdgeDistance(px, py, ndx, ndy, size);
65 const dist = wetSandEdgeDistance(px, py, ndx, ndy, size);
63 if (dist == null)
66 if (dist == null)
64 { return 0; }
67 { return 0; }
65 const band = WET_SAND_BAND_FRACTION * size;
68 const band = Math.max(0, Number(bandFraction) || 0) * size;
66 if (!(band > 0) || dist >= band)
69 if (!(band > 0) || dist >= band)
67 { return 0; }
70 { return 0; }
68 return 1 - dist / band;
71 return 1 - dist / band;
@@ -71,13 +74,14 @@ export function wetSandBlendWeight (px, py, ndx, ndy, size = 16)
71/**
74/**
72 * Max wetness from all liquid-water neighbor directions.
75 * Max wetness from all liquid-water neighbor directions.
73 * @param {Array<{ ndx: number, ndy: number }>} waterDirs
76 * @param {Array<{ ndx: number, ndy: number }>} waterDirs
77 * @param {number} [bandFraction=WET_SAND_BAND_FRACTION]
74 */
78 */
75export function wetSandWetness (px, py, waterDirs, size = 16)
79export function wetSandWetness (px, py, waterDirs, size = 16, bandFraction = WET_SAND_BAND_FRACTION)
76{
80{
77 let max = 0;
81 let max = 0;
78 for (const dir of waterDirs ?? [])
82 for (const dir of waterDirs ?? [])
79 {
83 {
80 const w = wetSandBlendWeight(px, py, dir.ndx, dir.ndy, size);
84 const w = wetSandBlendWeight(px, py, dir.ndx, dir.ndy, size, bandFraction);
81 if (w > max)
85 if (w > max)
82 { max = w; }
86 { max = w; }
83 }
87 }