| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { createEmptyChunkData } from "../src/world/chunkData.js"; |
| 4 | import { diffChunks } from "../src/editor/service.js"; |
| 5 | import { GroundType, BlockType } from "../../shared/definitions/tiles.js"; |
| 6 | |
| 7 | test("chunk diffs describe ground, block, and open-closed changes", () => |
| 8 | { |
| 9 | const previous = createEmptyChunkData(); |
| 10 | const next = createEmptyChunkData(); |
| 11 | next.open = true; |
| 12 | next.grounds[0] = GroundType.wood; |
| 13 | next.blocks[1] = { typeId: BlockType.torch, config: null }; |
| 14 | const bullets = diffChunks(0, 0, previous, next, false); |
| 15 | assert.ok(bullets.includes("Chunk opened.")); |
| 16 | assert.ok(bullets.some((line) => line.includes("Ground at 0, 0 changed from Grass to Wood."))); |
| 17 | assert.ok(bullets.some((line) => line.includes("Block Torch placed at 1, 0."))); |
| 18 | }); |
| 19 | |
| 20 | test("chunk diffs describe spawner placement", () => |
| 21 | { |
| 22 | const previous = createEmptyChunkData(); |
| 23 | const next = createEmptyChunkData(); |
| 24 | next.spawners = [{ |
| 25 | localX: 2, |
| 26 | localY: 3, |
| 27 | config: { spawnerId: "0:0:50", mobTypeId: "deer", maxAlive: 2, spawnRangeTiles: 4 } |
| 28 | }]; |
| 29 | const bullets = diffChunks(0, 0, previous, next, true); |
| 30 | assert.ok(bullets.some((line) => line.includes("Spawner (deer) placed at 2, 3."))); |
| 31 | }); |