| 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 | }); |