import test from "node:test"; import assert from "node:assert/strict"; import { CHUNK_SIZE } from "../../shared/protocol/constants.js"; import { GroundType } from "../../shared/definitions/tiles.js"; import { computeChunkAtlasKeys, EMPTY_BLOCK_ROW_KEY, EMPTY_BLOOM_KEY } from "../../shared/render/chunkAtlasKeys.js"; const catalog = { grounds: { grass: { states: ["summer"] } }, blocks: {} }; function grassSnapshot (chunkX = 0, chunkY = 0) { return { chunkX, chunkY, grounds: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => ({ typeId: GroundType.grass })), blocks: Array.from({ length: CHUNK_SIZE * CHUNK_SIZE }, () => null) }; } test("uniform grass chunks share atlas keys regardless of chunk coords", () => { const a = computeChunkAtlasKeys({ snapshot: grassSnapshot(0, 0), catalog, season: "summer", softTerrain: false }); const b = computeChunkAtlasKeys({ snapshot: grassSnapshot(3, 7), catalog, season: "summer", softTerrain: false }); assert.equal(a.groundKey, b.groundKey); assert.equal(a.bloomKey, b.bloomKey); assert.equal(a.blockRowKeys.length, CHUNK_SIZE); assert.ok(a.blockRowKeys.every((key) => key === EMPTY_BLOCK_ROW_KEY)); assert.equal(a.bloomKey, EMPTY_BLOOM_KEY); }); test("soft border fingerprint differs when neighbor ground changes", () => { const snapshot = grassSnapshot(1, 1); const flat = computeChunkAtlasKeys({ snapshot, catalog, season: "summer", softTerrain: true, resolveGround: () => ({ typeId: GroundType.grass }) }); const edgeDirt = computeChunkAtlasKeys({ snapshot, catalog, season: "summer", softTerrain: true, resolveGround: (tileX, tileY) => { if (tileX < snapshot.chunkX * CHUNK_SIZE) { return { typeId: GroundType.dirt }; } return { typeId: GroundType.grass }; } }); assert.notEqual(flat.groundKey, edgeDirt.groundKey); });