BlueGit

timfa questward

Files

questward / server / tests / wetSand.test.js

wetSand.test.js

wetSand.test.js 3.4 KiB Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import {
4 wetSandBlendWeight,
5 wetSandEdgeDistance,
6 wetSandWetness,
7 mixWetSandPixel,
8 WET_SAND_BAND_FRACTION,
9 WET_SAND_NEIGHBOR_DIRS
10} from "../../shared/render/wetSand.js";
11import {
12 GroundType,
13 GROUND_DEFINITIONS,
14 isLiquidWaterGround
15} from "../../shared/definitions/tiles.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";
23
24test("sand is blendable wet-shore ground with year-round sprites", () =>
25{
26 const sand = GROUND_DEFINITIONS[GroundType.sand];
27 assert.ok(sand);
28 assert.equal(sand.key, "sand");
29 assert.equal(sand.blendable, true);
30 assert.equal(sand.wetShore, true);
31 assert.equal(sand.outdoor, false);
32 assert.equal(sand.passable, true);
33 assert.equal(sand.water, false);
34});
35
36test("wet sand band defaults to 60% and is a graphics setting", () =>
37{
38 assert.equal(WET_SAND_BAND_FRACTION, 0.6);
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");
48});
49
50test("east water: edge fully wet, beyond band dry", () =>
51{
52 const band = WET_SAND_BAND_FRACTION * 16;
53 assert.equal(wetSandBlendWeight(15, 8, 1, 0), 1);
54 assert.ok(wetSandBlendWeight(14, 8, 1, 0) > 0);
55 assert.ok(wetSandBlendWeight(14, 8, 1, 0) < 1);
56 assert.equal(wetSandBlendWeight(15 - Math.ceil(band), 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);
60});
61
62test("southeast water wets the corner fan", () =>
63{
64 assert.equal(wetSandEdgeDistance(15, 15, 1, 1), 0);
65 assert.equal(wetSandBlendWeight(15, 15, 1, 1), 1);
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);
68 assert.ok(wetSandBlendWeight(14, 14, 1, 1) > 0);
69});
70
71test("wetness takes the max across water directions", () =>
72{
73 const dirs = [{ ndx: 1, ndy: 0 }, { ndx: 0, ndy: 1 }];
74 assert.equal(wetSandWetness(15, 8, dirs), 1);
75 assert.equal(wetSandWetness(8, 15, dirs), 1);
76 assert.equal(wetSandWetness(0, 0, dirs), 0);
77});
78
79test("mixWetSandPixel lerps dry toward wet", () =>
80{
81 const dry = { r: 0, g: 0, b: 0, a: 255 };
82 const wet = { r: 100, g: 200, b: 50, a: 255 };
83 assert.deepEqual(mixWetSandPixel(dry, wet, 0), dry);
84 assert.deepEqual(mixWetSandPixel(dry, wet, 1), wet);
85 assert.deepEqual(mixWetSandPixel(dry, wet, 0.5), { r: 50, g: 100, b: 25, a: 255 });
86});
87
88test("winter wet shore uses only liquid water (deep), not frozen shallows", () =>
89{
90 assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true);
91 assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.winter), false);
92 assert.equal(isLiquidWaterGround(GroundType.deepWater, SeasonId.winter), true);
93 assert.equal(isLiquidWaterGround(GroundType.sand, SeasonId.winter), false);
94});