Add sand ground with wet shoreline blend toward liquid water.
Bake sand→sand-wet within the outer 30% facing water (including diagonals). In winter only deep water counts, since shallow water is ice. Soft-terrain blending still applies; darkness stays on the lit atlas path.
@@ -1,5 +1,13 @@
1
1
import { CHUNK_SIZE, SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
2
import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType, normalizeGround, normalizeBlock, isChunkAtlasBakedBlock } from "/shared/definitions/tiles.js";
2
import {
3
GROUND_DEFINITIONS,
4
BLOCK_DEFINITIONS,
5
GroundType,
6
normalizeGround,
7
normalizeBlock,
8
isChunkAtlasBakedBlock,
9
isLiquidWaterGround
10
} from "/shared/definitions/tiles.js";
3
11
import { bloomImageName, spriteImageName } from "/shared/definitions/tileSprites.js";
4
12
import { resolveSeasonalVisualState, SeasonId } from "/shared/world/season.js";
5
13
import {
@@ -8,6 +16,11 @@ import {
8
16
softTerrainNeighborSample,
9
17
mixSoftTerrainPixel
10
18
} from "/shared/render/softTerrain.js";
19
import {
20
WET_SAND_NEIGHBOR_DIRS,
21
wetSandWetness,
22
mixWetSandPixel
23
} from "/shared/render/wetSand.js";
11
24
import { computeChunkAtlasKeys } from "/shared/render/chunkAtlasKeys.js";
12
25
13
26
/**
@@ -188,10 +201,10 @@ function bakeGroundCanvas ({
188
201
const width = CHUNK_SIZE * SPRITE_SIZE_PX;
189
202
const height = CHUNK_SIZE * SPRITE_SIZE_PX;
190
203
const ground = makeCanvas(width, height);
191
const groundCtx = ground.getContext("2d", { willReadFrequently: softTerrain });
204
const groundCtx = ground.getContext("2d", { willReadFrequently: true });
192
205
groundCtx.imageSmoothingEnabled = false;
193
206
groundCtx.clearRect(0, 0, width, height);
194
const pixelCache = softTerrain ? new Map() : null;
207
const pixelCache = new Map();
195
208
const baseTileX = snapshot.chunkX * CHUNK_SIZE;
196
209
const baseTileY = snapshot.chunkY * CHUNK_SIZE;
197
210
@@ -208,10 +221,11 @@ function bakeGroundCanvas ({
208
221
const groundMeta = groundCatalogMeta(catalog, groundEntry);
209
222
if (!isBakeable(images[groundName], groundMeta))
210
223
{ continue; }
224
const wetShore = isWetShoreGround(groundEntry);
211
225
const blendable = softTerrain && isGroundBlendable(groundEntry);
212
if (blendable)
226
if (wetShore || blendable)
213
227
{
214
blitSoftGround(
228
blitBlendedGround(
215
229
groundCtx,
216
230
images,
217
231
catalog,
@@ -223,7 +237,8 @@ function bakeGroundCanvas ({
223
237
tileY,
224
238
season,
225
239
resolveGround,
226
pixelCache
240
pixelCache,
241
{ softTerrain: blendable, wetShore }
227
242
);
228
243
}
229
244
else
@@ -380,6 +395,25 @@ function isGroundBlendable (ground)
380
395
return !!GROUND_DEFINITIONS[entry.typeId]?.blendable;
381
396
}
382
397
398
function isWetShoreGround (ground)
399
{
400
const entry = normalizeGround(ground);
401
return !!GROUND_DEFINITIONS[entry.typeId]?.wetShore;
402
}
403
404
function wetShoreSpriteName (catalog, ground)
405
{
406
const entry = normalizeGround(ground);
407
const def = GROUND_DEFINITIONS[entry.typeId];
408
if (!def?.wetShore)
409
{ return null; }
410
const wetState = `${def.key}-wet`;
411
const states = catalog.grounds?.[def.key]?.states ?? [];
412
if (!states.includes(wetState))
413
{ return null; }
414
return spriteImageName("ground", def.key, wetState);
415
}
416
383
417
function groundVisualKey (catalog, ground, season)
384
418
{
385
419
const entry = normalizeGround(ground);
@@ -389,7 +423,7 @@ function groundVisualKey (catalog, ground, season)
389
423
return `${entry.typeId}:${state ?? ""}`;
390
424
}
391
425
392
function blitSoftGround (
426
function blitBlendedGround (
393
427
ctx,
394
428
images,
395
429
catalog,
@@ -401,42 +435,68 @@ function blitSoftGround (
401
435
tileY,
402
436
season,
403
437
resolveGround,
404
pixelCache
438
pixelCache,
439
{ softTerrain = false, wetShore = false } = {}
405
440
)
406
441
{
407
const selfPixels = spritePixels(images[groundName], pixelCache);
408
if (!selfPixels)
442
const dryPixels = spritePixels(images[groundName], pixelCache);
443
if (!dryPixels)
409
444
{
410
445
blit(ctx, images[groundName], dx, dy);
411
446
return;
412
447
}
413
448
449
const waterDirs = [];
450
if (wetShore)
451
{
452
for (const { ndx, ndy } of WET_SAND_NEIGHBOR_DIRS)
453
{
454
const neighborGround = resolveNeighborGround(
455
tileX + ndx,
456
tileY + ndy,
457
resolveGround
458
);
459
if (neighborGround == null)
460
{ continue; }
461
const typeId = normalizeGround(neighborGround).typeId;
462
if (!isLiquidWaterGround(typeId, season))
463
{ continue; }
464
waterDirs.push({ ndx, ndy });
465
}
466
}
467
468
const wetName = wetShore && waterDirs.length ? wetShoreSpriteName(catalog, groundEntry) : null;
469
const wetPixels = wetName ? spritePixels(images[wetName], pixelCache) : null;
470
414
471
const selfKey = groundVisualKey(catalog, groundEntry, season);
415
472
const neighborSprites = [];
416
for (const { ndx, ndy } of SOFT_TERRAIN_NEIGHBOR_DIRS)
473
if (softTerrain)
417
474
{
418
const neighborGround = resolveNeighborGround(
419
tileX + ndx,
420
tileY + ndy,
421
resolveGround
422
);
423
if (neighborGround == null)
424
{ continue; }
425
if (groundVisualKey(catalog, neighborGround, season) === selfKey)
426
{ continue; }
427
const neighborName = groundSpriteName(catalog, neighborGround, season);
428
const pixels = spritePixels(images[neighborName], pixelCache);
429
if (!pixels)
430
{ continue; }
431
neighborSprites.push({
432
ndx,
433
ndy,
434
pixels,
435
neighborBlendable: isGroundBlendable(neighborGround)
436
});
475
for (const { ndx, ndy } of SOFT_TERRAIN_NEIGHBOR_DIRS)
476
{
477
const neighborGround = resolveNeighborGround(
478
tileX + ndx,
479
tileY + ndy,
480
resolveGround
481
);
482
if (neighborGround == null)
483
{ continue; }
484
if (groundVisualKey(catalog, neighborGround, season) === selfKey)
485
{ continue; }
486
const neighborName = groundSpriteName(catalog, neighborGround, season);
487
const pixels = spritePixels(images[neighborName], pixelCache);
488
if (!pixels)
489
{ continue; }
490
neighborSprites.push({
491
ndx,
492
ndy,
493
pixels,
494
neighborBlendable: isGroundBlendable(neighborGround)
495
});
496
}
437
497
}
438
498
439
if (!neighborSprites.length)
499
if (!waterDirs.length && !neighborSprites.length)
440
500
{
441
501
blit(ctx, images[groundName], dx, dy);
442
502
return;
@@ -448,7 +508,13 @@ function blitSoftGround (
448
508
{
449
509
for (let px = 0; px < SPRITE_SIZE_PX; px++)
450
510
{
451
const self = readPixel(selfPixels, px, py);
511
let self = readPixel(dryPixels, px, py);
512
if (wetPixels && waterDirs.length)
513
{
514
const wetness = wetSandWetness(px, py, waterDirs, SPRITE_SIZE_PX);
515
if (wetness > 0)
516
{ self = mixWetSandPixel(self, readPixel(wetPixels, px, py), wetness); }
517
}
452
518
const contribs = [];
453
519
for (const neighbor of neighborSprites)
454
520
{
@@ -1,5 +1,13 @@1
import { CHUNK_SIZE, SPRITE_SIZE_PX } from "/shared/protocol/constants.js";1
import { CHUNK_SIZE, SPRITE_SIZE_PX } from "/shared/protocol/constants.js";2
import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType, normalizeGround, normalizeBlock, isChunkAtlasBakedBlock } from "/shared/definitions/tiles.js";2
import {3
GROUND_DEFINITIONS,4
BLOCK_DEFINITIONS,5
GroundType,6
normalizeGround,7
normalizeBlock,8
isChunkAtlasBakedBlock,9
isLiquidWaterGround10
} from "/shared/definitions/tiles.js";3
import { bloomImageName, spriteImageName } from "/shared/definitions/tileSprites.js";11
import { bloomImageName, spriteImageName } from "/shared/definitions/tileSprites.js";4
import { resolveSeasonalVisualState, SeasonId } from "/shared/world/season.js";12
import { resolveSeasonalVisualState, SeasonId } from "/shared/world/season.js";5
import {13
import {@@ -8,6 +16,11 @@ import {8
softTerrainNeighborSample,16
softTerrainNeighborSample,9
mixSoftTerrainPixel17
mixSoftTerrainPixel10
} from "/shared/render/softTerrain.js";18
} from "/shared/render/softTerrain.js";19
import {20
WET_SAND_NEIGHBOR_DIRS,21
wetSandWetness,22
mixWetSandPixel23
} from "/shared/render/wetSand.js";11
import { computeChunkAtlasKeys } from "/shared/render/chunkAtlasKeys.js";24
import { computeChunkAtlasKeys } from "/shared/render/chunkAtlasKeys.js";12
25
13
/**26
/**@@ -188,10 +201,10 @@ function bakeGroundCanvas ({188
const width = CHUNK_SIZE * SPRITE_SIZE_PX;201
const width = CHUNK_SIZE * SPRITE_SIZE_PX;189
const height = CHUNK_SIZE * SPRITE_SIZE_PX;202
const height = CHUNK_SIZE * SPRITE_SIZE_PX;190
const ground = makeCanvas(width, height);203
const ground = makeCanvas(width, height);191
const groundCtx = ground.getContext("2d", { willReadFrequently: softTerrain });204
const groundCtx = ground.getContext("2d", { willReadFrequently: true });192
groundCtx.imageSmoothingEnabled = false;205
groundCtx.imageSmoothingEnabled = false;193
groundCtx.clearRect(0, 0, width, height);206
groundCtx.clearRect(0, 0, width, height);194
const pixelCache = softTerrain ? new Map() : null;207
const pixelCache = new Map();195
const baseTileX = snapshot.chunkX * CHUNK_SIZE;208
const baseTileX = snapshot.chunkX * CHUNK_SIZE;196
const baseTileY = snapshot.chunkY * CHUNK_SIZE;209
const baseTileY = snapshot.chunkY * CHUNK_SIZE;197
210
@@ -208,10 +221,11 @@ function bakeGroundCanvas ({208
const groundMeta = groundCatalogMeta(catalog, groundEntry);221
const groundMeta = groundCatalogMeta(catalog, groundEntry);209
if (!isBakeable(images[groundName], groundMeta))222
if (!isBakeable(images[groundName], groundMeta))210
{ continue; }223
{ continue; }224
const wetShore = isWetShoreGround(groundEntry);211
const blendable = softTerrain && isGroundBlendable(groundEntry);225
const blendable = softTerrain && isGroundBlendable(groundEntry);212
if (blendable)226
if (wetShore || blendable)213
{227
{214
blitSoftGround(228
blitBlendedGround(215
groundCtx,229
groundCtx,216
images,230
images,217
catalog,231
catalog,@@ -223,7 +237,8 @@ function bakeGroundCanvas ({223
tileY,237
tileY,224
season,238
season,225
resolveGround,239
resolveGround,226
pixelCache240
pixelCache,241
{ softTerrain: blendable, wetShore }227
);242
);228
}243
}229
else244
else@@ -380,6 +395,25 @@ function isGroundBlendable (ground)380
return !!GROUND_DEFINITIONS[entry.typeId]?.blendable;395
return !!GROUND_DEFINITIONS[entry.typeId]?.blendable;381
}396
}382
397
398
function isWetShoreGround (ground)399
{400
const entry = normalizeGround(ground);401
return !!GROUND_DEFINITIONS[entry.typeId]?.wetShore;402
}403
404
function wetShoreSpriteName (catalog, ground)405
{406
const entry = normalizeGround(ground);407
const def = GROUND_DEFINITIONS[entry.typeId];408
if (!def?.wetShore)409
{ return null; }410
const wetState = `${def.key}-wet`;411
const states = catalog.grounds?.[def.key]?.states ?? [];412
if (!states.includes(wetState))413
{ return null; }414
return spriteImageName("ground", def.key, wetState);415
}416
383
function groundVisualKey (catalog, ground, season)417
function groundVisualKey (catalog, ground, season)384
{418
{385
const entry = normalizeGround(ground);419
const entry = normalizeGround(ground);@@ -389,7 +423,7 @@ function groundVisualKey (catalog, ground, season)389
return `${entry.typeId}:${state ?? ""}`;423
return `${entry.typeId}:${state ?? ""}`;390
}424
}391
425
392
function blitSoftGround (426
function blitBlendedGround (393
ctx,427
ctx,394
images,428
images,395
catalog,429
catalog,@@ -401,42 +435,68 @@ function blitSoftGround (401
tileY,435
tileY,402
season,436
season,403
resolveGround,437
resolveGround,404
pixelCache438
pixelCache,439
{ softTerrain = false, wetShore = false } = {}405
)440
)406
{441
{407
const selfPixels = spritePixels(images[groundName], pixelCache);442
const dryPixels = spritePixels(images[groundName], pixelCache);408
if (!selfPixels)443
if (!dryPixels)409
{444
{410
blit(ctx, images[groundName], dx, dy);445
blit(ctx, images[groundName], dx, dy);411
return;446
return;412
}447
}413
448
449
const waterDirs = [];450
if (wetShore)451
{452
for (const { ndx, ndy } of WET_SAND_NEIGHBOR_DIRS)453
{454
const neighborGround = resolveNeighborGround(455
tileX + ndx,456
tileY + ndy,457
resolveGround458
);459
if (neighborGround == null)460
{ continue; }461
const typeId = normalizeGround(neighborGround).typeId;462
if (!isLiquidWaterGround(typeId, season))463
{ continue; }464
waterDirs.push({ ndx, ndy });465
}466
}467
468
const wetName = wetShore && waterDirs.length ? wetShoreSpriteName(catalog, groundEntry) : null;469
const wetPixels = wetName ? spritePixels(images[wetName], pixelCache) : null;470
414
const selfKey = groundVisualKey(catalog, groundEntry, season);471
const selfKey = groundVisualKey(catalog, groundEntry, season);415
const neighborSprites = [];472
const neighborSprites = [];416
for (const { ndx, ndy } of SOFT_TERRAIN_NEIGHBOR_DIRS)473
if (softTerrain)417
{474
{418
const neighborGround = resolveNeighborGround(475
for (const { ndx, ndy } of SOFT_TERRAIN_NEIGHBOR_DIRS)419
tileX + ndx,476
{420
tileY + ndy,477
const neighborGround = resolveNeighborGround(421
resolveGround478
tileX + ndx,422
);479
tileY + ndy,423
if (neighborGround == null)480
resolveGround424
{ continue; }481
);425
if (groundVisualKey(catalog, neighborGround, season) === selfKey)482
if (neighborGround == null)426
{ continue; }483
{ continue; }427
const neighborName = groundSpriteName(catalog, neighborGround, season);484
if (groundVisualKey(catalog, neighborGround, season) === selfKey)428
const pixels = spritePixels(images[neighborName], pixelCache);485
{ continue; }429
if (!pixels)486
const neighborName = groundSpriteName(catalog, neighborGround, season);430
{ continue; }487
const pixels = spritePixels(images[neighborName], pixelCache);431
neighborSprites.push({488
if (!pixels)432
ndx,489
{ continue; }433
ndy,490
neighborSprites.push({434
pixels,491
ndx,435
neighborBlendable: isGroundBlendable(neighborGround)492
ndy,436
});493
pixels,494
neighborBlendable: isGroundBlendable(neighborGround)495
});496
}437
}497
}438
498
439
if (!neighborSprites.length)499
if (!waterDirs.length && !neighborSprites.length)440
{500
{441
blit(ctx, images[groundName], dx, dy);501
blit(ctx, images[groundName], dx, dy);442
return;502
return;@@ -448,7 +508,13 @@ function blitSoftGround (448
{508
{449
for (let px = 0; px < SPRITE_SIZE_PX; px++)509
for (let px = 0; px < SPRITE_SIZE_PX; px++)450
{510
{451
const self = readPixel(selfPixels, px, py);511
let self = readPixel(dryPixels, px, py);512
if (wetPixels && waterDirs.length)513
{514
const wetness = wetSandWetness(px, py, waterDirs, SPRITE_SIZE_PX);515
if (wetness > 0)516
{ self = mixWetSandPixel(self, readPixel(wetPixels, px, py), wetness); }517
}452
const contribs = [];518
const contribs = [];453
for (const neighbor of neighborSprites)519
for (const neighbor of neighborSprites)454
{520
{@@ -3412,7 +3412,8 @@ export class WorldView
3412
3412
{
3413
3413
this.#bakeAndPlaceChunk(snapshot);
3414
3414
this.#relayoutChunkTiles(snapshot);
3415
if (this.softTerrain && refreshSoftNeighbors)
3415
// Soft terrain and wet-sand shorelines both sample cross-chunk neighbors.
3416
if (refreshSoftNeighbors)
3416
3417
{ this.#rebuildSoftTerrainNeighborChunks(snapshot); }
3417
3418
}
3418
3419
@@ -3412,7 +3412,8 @@ export class WorldView3412
{3412
{3413
this.#bakeAndPlaceChunk(snapshot);3413
this.#bakeAndPlaceChunk(snapshot);3414
this.#relayoutChunkTiles(snapshot);3414
this.#relayoutChunkTiles(snapshot);3415
if (this.softTerrain && refreshSoftNeighbors)3415
// Soft terrain and wet-sand shorelines both sample cross-chunk neighbors.3416
if (refreshSoftNeighbors)3416
{ this.#rebuildSoftTerrainNeighborChunks(snapshot); }3417
{ this.#rebuildSoftTerrainNeighborChunks(snapshot); }3417
}3418
}3418
3419
@@ -402,7 +402,9 @@ function scanLayer (layerDir, definitions, layer, urlFolder)
402
402
? "fishing-spot"
403
403
: def.door && states.includes("pine-s-closed")
404
404
? "pine-s-closed"
405
: (def.outdoor && preferredSeasonalDefaultState(states)) || states[0],
405
: def.key === "sand" && states.includes("sand")
406
? "sand"
407
: (def.outdoor && preferredSeasonalDefaultState(states)) || states[0],
406
408
blooms,
407
409
equips,
408
410
equipBlooms,
@@ -402,7 +402,9 @@ function scanLayer (layerDir, definitions, layer, urlFolder)402
? "fishing-spot"402
? "fishing-spot"403
: def.door && states.includes("pine-s-closed")403
: def.door && states.includes("pine-s-closed")404
? "pine-s-closed"404
? "pine-s-closed"405
: (def.outdoor && preferredSeasonalDefaultState(states)) || states[0],405
: def.key === "sand" && states.includes("sand")406
? "sand"407
: (def.outdoor && preferredSeasonalDefaultState(states)) || states[0],406
blooms,408
blooms,407
equips,409
equips,408
equipBlooms,410
equipBlooms,@@ -68,3 +68,69 @@ test("soft border fingerprint differs when neighbor ground changes", () =>
68
68
});
69
69
assert.notEqual(flat.groundKey, edgeDirt.groundKey);
70
70
});
71
72
test("wet sand border fingerprint differs for liquid water neighbors", () =>
73
{
74
const catalogSand = {
75
grounds: {
76
sand: { states: ["sand", "sand-wet"] },
77
water: { states: ["summer"] },
78
"deep-water": { states: ["summer"] }
79
},
80
blocks: {}
81
};
82
const snapshot = {
83
chunkX: 1,
84
chunkY: 1,
85
grounds: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => ({ typeId: GroundType.sand })),
86
blocks: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => null)
87
};
88
const dry = computeChunkAtlasKeys({
89
snapshot,
90
catalog: catalogSand,
91
season: "summer",
92
softTerrain: false,
93
resolveGround: () => ({ typeId: GroundType.sand })
94
});
95
const besideWater = computeChunkAtlasKeys({
96
snapshot,
97
catalog: catalogSand,
98
season: "summer",
99
softTerrain: false,
100
resolveGround: (tileX, tileY) =>
101
{
102
if (tileX < snapshot.chunkX * CHUNK_SIZE)
103
{ return { typeId: GroundType.water }; }
104
return { typeId: GroundType.sand };
105
}
106
});
107
assert.notEqual(dry.groundKey, besideWater.groundKey);
108
109
const winterShallow = computeChunkAtlasKeys({
110
snapshot,
111
catalog: catalogSand,
112
season: "winter",
113
softTerrain: false,
114
resolveGround: (tileX, tileY) =>
115
{
116
if (tileX < snapshot.chunkX * CHUNK_SIZE)
117
{ return { typeId: GroundType.water }; }
118
return { typeId: GroundType.sand };
119
}
120
});
121
const winterDeep = computeChunkAtlasKeys({
122
snapshot,
123
catalog: catalogSand,
124
season: "winter",
125
softTerrain: false,
126
resolveGround: (tileX, tileY) =>
127
{
128
if (tileX < snapshot.chunkX * CHUNK_SIZE)
129
{ return { typeId: GroundType.deepWater }; }
130
return { typeId: GroundType.sand };
131
}
132
});
133
// Frozen shallow water should not wet the shoreline; deep still does.
134
assert.equal(winterShallow.groundKey.includes("wet:flat"), true);
135
assert.notEqual(winterShallow.groundKey, winterDeep.groundKey);
136
});
@@ -68,3 +68,69 @@ test("soft border fingerprint differs when neighbor ground changes", () =>68
});68
});69
assert.notEqual(flat.groundKey, edgeDirt.groundKey);69
assert.notEqual(flat.groundKey, edgeDirt.groundKey);70
});70
});71
72
test("wet sand border fingerprint differs for liquid water neighbors", () =>73
{74
const catalogSand = {75
grounds: {76
sand: { states: ["sand", "sand-wet"] },77
water: { states: ["summer"] },78
"deep-water": { states: ["summer"] }79
},80
blocks: {}81
};82
const snapshot = {83
chunkX: 1,84
chunkY: 1,85
grounds: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => ({ typeId: GroundType.sand })),86
blocks: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => null)87
};88
const dry = computeChunkAtlasKeys({89
snapshot,90
catalog: catalogSand,91
season: "summer",92
softTerrain: false,93
resolveGround: () => ({ typeId: GroundType.sand })94
});95
const besideWater = computeChunkAtlasKeys({96
snapshot,97
catalog: catalogSand,98
season: "summer",99
softTerrain: false,100
resolveGround: (tileX, tileY) =>101
{102
if (tileX < snapshot.chunkX * CHUNK_SIZE)103
{ return { typeId: GroundType.water }; }104
return { typeId: GroundType.sand };105
}106
});107
assert.notEqual(dry.groundKey, besideWater.groundKey);108
109
const winterShallow = computeChunkAtlasKeys({110
snapshot,111
catalog: catalogSand,112
season: "winter",113
softTerrain: false,114
resolveGround: (tileX, tileY) =>115
{116
if (tileX < snapshot.chunkX * CHUNK_SIZE)117
{ return { typeId: GroundType.water }; }118
return { typeId: GroundType.sand };119
}120
});121
const winterDeep = computeChunkAtlasKeys({122
snapshot,123
catalog: catalogSand,124
season: "winter",125
softTerrain: false,126
resolveGround: (tileX, tileY) =>127
{128
if (tileX < snapshot.chunkX * CHUNK_SIZE)129
{ return { typeId: GroundType.deepWater }; }130
return { typeId: GroundType.sand };131
}132
});133
// Frozen shallow water should not wet the shoreline; deep still does.134
assert.equal(winterShallow.groundKey.includes("wet:flat"), true);135
assert.notEqual(winterShallow.groundKey, winterDeep.groundKey);136
});@@ -14,7 +14,7 @@ import {
14
14
import { GroundType, GROUND_DEFINITIONS } from "../../shared/definitions/tiles.js";
15
15
import { normalizeGraphicsSettings, SoftTerrainMode, DEFAULT_GRAPHICS_SETTINGS } from "../../shared/graphics/settings.js";
16
16
17
test("grass, dirt, and path are blendable outdoor grounds", () =>
17
test("grass, dirt, path, and sand are blendable grounds", () =>
18
18
{
19
19
assert.equal(GROUND_DEFINITIONS[GroundType.grass].blendable, true);
20
20
assert.equal(GROUND_DEFINITIONS[GroundType.dirt].blendable, true);
@@ -22,6 +22,8 @@ test("grass, dirt, and path are blendable outdoor grounds", () =>
22
22
assert.equal(GROUND_DEFINITIONS[GroundType.path].blendable, true);
23
23
assert.equal(GROUND_DEFINITIONS[GroundType.path].outdoor, true);
24
24
assert.equal(GROUND_DEFINITIONS[GroundType.path].pathSurface, true);
25
assert.equal(GROUND_DEFINITIONS[GroundType.sand].blendable, true);
26
assert.equal(GROUND_DEFINITIONS[GroundType.sand].wetShore, true);
25
27
assert.equal(GROUND_DEFINITIONS[GroundType.wood].blendable, undefined);
26
28
assert.equal(GROUND_DEFINITIONS[GroundType.water].blendable, undefined);
27
29
});
@@ -14,7 +14,7 @@ import {14
import { GroundType, GROUND_DEFINITIONS } from "../../shared/definitions/tiles.js";14
import { GroundType, GROUND_DEFINITIONS } from "../../shared/definitions/tiles.js";15
import { normalizeGraphicsSettings, SoftTerrainMode, DEFAULT_GRAPHICS_SETTINGS } from "../../shared/graphics/settings.js";15
import { normalizeGraphicsSettings, SoftTerrainMode, DEFAULT_GRAPHICS_SETTINGS } from "../../shared/graphics/settings.js";16
16
17
test("grass, dirt, and path are blendable outdoor grounds", () =>17
test("grass, dirt, path, and sand are blendable grounds", () =>18
{18
{19
assert.equal(GROUND_DEFINITIONS[GroundType.grass].blendable, true);19
assert.equal(GROUND_DEFINITIONS[GroundType.grass].blendable, true);20
assert.equal(GROUND_DEFINITIONS[GroundType.dirt].blendable, true);20
assert.equal(GROUND_DEFINITIONS[GroundType.dirt].blendable, true);@@ -22,6 +22,8 @@ test("grass, dirt, and path are blendable outdoor grounds", () =>22
assert.equal(GROUND_DEFINITIONS[GroundType.path].blendable, true);22
assert.equal(GROUND_DEFINITIONS[GroundType.path].blendable, true);23
assert.equal(GROUND_DEFINITIONS[GroundType.path].outdoor, true);23
assert.equal(GROUND_DEFINITIONS[GroundType.path].outdoor, true);24
assert.equal(GROUND_DEFINITIONS[GroundType.path].pathSurface, true);24
assert.equal(GROUND_DEFINITIONS[GroundType.path].pathSurface, true);25
assert.equal(GROUND_DEFINITIONS[GroundType.sand].blendable, true);26
assert.equal(GROUND_DEFINITIONS[GroundType.sand].wetShore, true);25
assert.equal(GROUND_DEFINITIONS[GroundType.wood].blendable, undefined);27
assert.equal(GROUND_DEFINITIONS[GroundType.wood].blendable, undefined);26
assert.equal(GROUND_DEFINITIONS[GroundType.water].blendable, undefined);28
assert.equal(GROUND_DEFINITIONS[GroundType.water].blendable, undefined);27
});29
});@@ -0,0 +1,77 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import {
4
wetSandBlendWeight,
5
wetSandEdgeDistance,
6
wetSandWetness,
7
mixWetSandPixel,
8
WET_SAND_BAND_FRACTION,
9
WET_SAND_NEIGHBOR_DIRS
10
} from "../../shared/render/wetSand.js";
11
import {
12
GroundType,
13
GROUND_DEFINITIONS,
14
isLiquidWaterGround
15
} from "../../shared/definitions/tiles.js";
16
import { SeasonId } from "../../shared/world/season.js";
17
18
test("sand is blendable wet-shore ground with year-round sprites", () =>
19
{
20
const sand = GROUND_DEFINITIONS[GroundType.sand];
21
assert.ok(sand);
22
assert.equal(sand.key, "sand");
23
assert.equal(sand.blendable, true);
24
assert.equal(sand.wetShore, true);
25
assert.equal(sand.outdoor, false);
26
assert.equal(sand.passable, true);
27
assert.equal(sand.water, false);
28
});
29
30
test("wet sand band is 30% of the tile", () =>
31
{
32
assert.equal(WET_SAND_BAND_FRACTION, 0.3);
33
assert.equal(WET_SAND_NEIGHBOR_DIRS.length, 8);
34
});
35
36
test("east water: edge fully wet, beyond 30% dry", () =>
37
{
38
const band = WET_SAND_BAND_FRACTION * 16;
39
assert.equal(wetSandBlendWeight(15, 8, 1, 0), 1);
40
assert.ok(wetSandBlendWeight(14, 8, 1, 0) > 0);
41
assert.ok(wetSandBlendWeight(14, 8, 1, 0) < 1);
42
assert.equal(wetSandBlendWeight(15 - Math.ceil(band), 8, 1, 0), 0);
43
assert.equal(wetSandBlendWeight(0, 8, 1, 0), 0);
44
});
45
46
test("southeast water wets the corner fan", () =>
47
{
48
assert.equal(wetSandEdgeDistance(15, 15, 1, 1), 0);
49
assert.equal(wetSandBlendWeight(15, 15, 1, 1), 1);
50
assert.equal(wetSandBlendWeight(15, 8, 1, 1), 0);
51
assert.ok(wetSandBlendWeight(14, 14, 1, 1) > 0);
52
});
53
54
test("wetness takes the max across water directions", () =>
55
{
56
const dirs = [{ ndx: 1, ndy: 0 }, { ndx: 0, ndy: 1 }];
57
assert.equal(wetSandWetness(15, 8, dirs), 1);
58
assert.equal(wetSandWetness(8, 15, dirs), 1);
59
assert.equal(wetSandWetness(0, 0, dirs), 0);
60
});
61
62
test("mixWetSandPixel lerps dry toward wet", () =>
63
{
64
const dry = { r: 0, g: 0, b: 0, a: 255 };
65
const wet = { r: 100, g: 200, b: 50, a: 255 };
66
assert.deepEqual(mixWetSandPixel(dry, wet, 0), dry);
67
assert.deepEqual(mixWetSandPixel(dry, wet, 1), wet);
68
assert.deepEqual(mixWetSandPixel(dry, wet, 0.5), { r: 50, g: 100, b: 25, a: 255 });
69
});
70
71
test("winter wet shore uses only liquid water (deep), not frozen shallows", () =>
72
{
73
assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true);
74
assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.winter), false);
75
assert.equal(isLiquidWaterGround(GroundType.deepWater, SeasonId.winter), true);
76
assert.equal(isLiquidWaterGround(GroundType.sand, SeasonId.winter), false);
77
});
@@ -0,0 +1,77 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import {4
wetSandBlendWeight,5
wetSandEdgeDistance,6
wetSandWetness,7
mixWetSandPixel,8
WET_SAND_BAND_FRACTION,9
WET_SAND_NEIGHBOR_DIRS10
} from "../../shared/render/wetSand.js";11
import {12
GroundType,13
GROUND_DEFINITIONS,14
isLiquidWaterGround15
} from "../../shared/definitions/tiles.js";16
import { SeasonId } from "../../shared/world/season.js";17
18
test("sand is blendable wet-shore ground with year-round sprites", () =>19
{20
const sand = GROUND_DEFINITIONS[GroundType.sand];21
assert.ok(sand);22
assert.equal(sand.key, "sand");23
assert.equal(sand.blendable, true);24
assert.equal(sand.wetShore, true);25
assert.equal(sand.outdoor, false);26
assert.equal(sand.passable, true);27
assert.equal(sand.water, false);28
});29
30
test("wet sand band is 30% of the tile", () =>31
{32
assert.equal(WET_SAND_BAND_FRACTION, 0.3);33
assert.equal(WET_SAND_NEIGHBOR_DIRS.length, 8);34
});35
36
test("east water: edge fully wet, beyond 30% dry", () =>37
{38
const band = WET_SAND_BAND_FRACTION * 16;39
assert.equal(wetSandBlendWeight(15, 8, 1, 0), 1);40
assert.ok(wetSandBlendWeight(14, 8, 1, 0) > 0);41
assert.ok(wetSandBlendWeight(14, 8, 1, 0) < 1);42
assert.equal(wetSandBlendWeight(15 - Math.ceil(band), 8, 1, 0), 0);43
assert.equal(wetSandBlendWeight(0, 8, 1, 0), 0);44
});45
46
test("southeast water wets the corner fan", () =>47
{48
assert.equal(wetSandEdgeDistance(15, 15, 1, 1), 0);49
assert.equal(wetSandBlendWeight(15, 15, 1, 1), 1);50
assert.equal(wetSandBlendWeight(15, 8, 1, 1), 0);51
assert.ok(wetSandBlendWeight(14, 14, 1, 1) > 0);52
});53
54
test("wetness takes the max across water directions", () =>55
{56
const dirs = [{ ndx: 1, ndy: 0 }, { ndx: 0, ndy: 1 }];57
assert.equal(wetSandWetness(15, 8, dirs), 1);58
assert.equal(wetSandWetness(8, 15, dirs), 1);59
assert.equal(wetSandWetness(0, 0, dirs), 0);60
});61
62
test("mixWetSandPixel lerps dry toward wet", () =>63
{64
const dry = { r: 0, g: 0, b: 0, a: 255 };65
const wet = { r: 100, g: 200, b: 50, a: 255 };66
assert.deepEqual(mixWetSandPixel(dry, wet, 0), dry);67
assert.deepEqual(mixWetSandPixel(dry, wet, 1), wet);68
assert.deepEqual(mixWetSandPixel(dry, wet, 0.5), { r: 50, g: 100, b: 25, a: 255 });69
});70
71
test("winter wet shore uses only liquid water (deep), not frozen shallows", () =>72
{73
assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true);74
assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.winter), false);75
assert.equal(isLiquidWaterGround(GroundType.deepWater, SeasonId.winter), true);76
assert.equal(isLiquidWaterGround(GroundType.sand, SeasonId.winter), false);77
});