| 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 | import { DEFAULT_WORLD_SETTINGS } from "../../shared/protocol/constants.js"; |
| 18 | import { WORLD_SETTING_CATEGORIES } from "../../shared/definitions/worldSettings.js"; |
| 19 | |
| 20 | test("sand is blendable wet-shore ground with year-round sprites", () => |
| 21 | { |
| 22 | const sand = GROUND_DEFINITIONS[GroundType.sand]; |
| 23 | assert.ok(sand); |
| 24 | assert.equal(sand.key, "sand"); |
| 25 | assert.equal(sand.blendable, true); |
| 26 | assert.equal(sand.wetShore, true); |
| 27 | assert.equal(sand.outdoor, false); |
| 28 | assert.equal(sand.passable, true); |
| 29 | assert.equal(sand.water, false); |
| 30 | }); |
| 31 | |
| 32 | test("wet sand band defaults to 60% as a world graphics setting", () => |
| 33 | { |
| 34 | assert.equal(WET_SAND_BAND_FRACTION, 0.6); |
| 35 | assert.equal(DEFAULT_WORLD_SETTINGS.wetSandBand, 0.6); |
| 36 | assert.equal(WET_SAND_NEIGHBOR_DIRS.length, 8); |
| 37 | const graphics = WORLD_SETTING_CATEGORIES.find((category) => category.id === "graphics"); |
| 38 | const field = graphics?.fields.find((entry) => entry.key === "wetSandBand"); |
| 39 | assert.ok(field); |
| 40 | assert.equal(field.type, "range"); |
| 41 | assert.equal(field.min, 0); |
| 42 | assert.equal(field.max, 1); |
| 43 | }); |
| 44 | |
| 45 | test("east water: edge fully wet, beyond band dry", () => |
| 46 | { |
| 47 | const band = WET_SAND_BAND_FRACTION * 16; |
| 48 | assert.equal(wetSandBlendWeight(15, 8, 1, 0), 1); |
| 49 | assert.ok(wetSandBlendWeight(14, 8, 1, 0) > 0); |
| 50 | assert.ok(wetSandBlendWeight(14, 8, 1, 0) < 1); |
| 51 | assert.equal(wetSandBlendWeight(15 - Math.ceil(band), 8, 1, 0), 0); |
| 52 | assert.equal(wetSandBlendWeight(0, 8, 1, 0), 0); |
| 53 | assert.equal(wetSandBlendWeight(10, 8, 1, 0, 16, 0), 0); |
| 54 | assert.equal(wetSandBlendWeight(0, 8, 1, 0, 16, 1), 1 / 16); |
| 55 | }); |
| 56 | |
| 57 | test("southeast water wets the corner fan", () => |
| 58 | { |
| 59 | assert.equal(wetSandEdgeDistance(15, 15, 1, 1), 0); |
| 60 | assert.equal(wetSandBlendWeight(15, 15, 1, 1), 1); |
| 61 | // Far from the SE corner along the east edge stays dry under the default 60% band. |
| 62 | assert.equal(wetSandBlendWeight(15, 0, 1, 1), 0); |
| 63 | assert.ok(wetSandBlendWeight(14, 14, 1, 1) > 0); |
| 64 | }); |
| 65 | |
| 66 | test("wetness takes the max across water directions", () => |
| 67 | { |
| 68 | const dirs = [{ ndx: 1, ndy: 0 }, { ndx: 0, ndy: 1 }]; |
| 69 | assert.equal(wetSandWetness(15, 8, dirs), 1); |
| 70 | assert.equal(wetSandWetness(8, 15, dirs), 1); |
| 71 | assert.equal(wetSandWetness(0, 0, dirs), 0); |
| 72 | }); |
| 73 | |
| 74 | test("mixWetSandPixel lerps dry toward wet", () => |
| 75 | { |
| 76 | const dry = { r: 0, g: 0, b: 0, a: 255 }; |
| 77 | const wet = { r: 100, g: 200, b: 50, a: 255 }; |
| 78 | assert.deepEqual(mixWetSandPixel(dry, wet, 0), dry); |
| 79 | assert.deepEqual(mixWetSandPixel(dry, wet, 1), wet); |
| 80 | assert.deepEqual(mixWetSandPixel(dry, wet, 0.5), { r: 50, g: 100, b: 25, a: 255 }); |
| 81 | }); |
| 82 | |
| 83 | test("winter wet shore uses only liquid water (deep), not frozen shallows", () => |
| 84 | { |
| 85 | assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true); |
| 86 | assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.winter), false); |
| 87 | assert.equal(isLiquidWaterGround(GroundType.deepWater, SeasonId.winter), true); |
| 88 | assert.equal(isLiquidWaterGround(GroundType.sand, SeasonId.winter), false); |
| 89 | }); |