import test from "node:test"; import assert from "node:assert/strict"; import { BlockType, GroundType, listPlaceableBlockPaletteEntries, listPlaceableGrounds } from "../../shared/definitions/tiles.js"; import { listSpawnableMobTypes } from "../../shared/definitions/mobs.js"; import { OVERWORLD_ID } from "../../shared/world/dimensions.js"; import { PALETTE_TABS, listPaletteEntries, matchingPaletteEntryKeys, paletteLabelMatches } from "../src/editor/paletteEntries.js"; test("palette categories match the editor placeable dialog", () => { assert.deepEqual( PALETTE_TABS.map((tab) => tab.label), ["Ground tiles", "Blocks", "Spawners"] ); }); test("palette entries are the live registries in every dimension", () => { const overworldGrounds = listPaletteEntries("grounds", { dimensionId: OVERWORLD_ID }); const caveGrounds = listPaletteEntries("grounds", { dimensionId: "void-hall" }); assert.equal(overworldGrounds.length, listPlaceableGrounds().length); assert.ok(caveGrounds.length > 0); assert.deepEqual( caveGrounds.map((entry) => entry.key), overworldGrounds.map((entry) => entry.key) ); assert.equal(caveGrounds[0].selection.kind, "ground"); const blocks = listPaletteEntries("blocks", { dimensionId: "cave-1" }); const fromRegistry = listPlaceableBlockPaletteEntries(null); assert.equal(blocks.length, fromRegistry.length); assert.deepEqual( blocks.map((entry) => entry.label), fromRegistry.map((entry) => entry.displayName) ); assert.equal(blocks.every((entry) => entry.selection.kind === "block"), true); const spawners = listPaletteEntries("spawners", { dimensionId: "house" }); assert.equal(spawners[0].label, "Item Spawner"); assert.deepEqual(spawners[0].selection, { kind: "spawner", spawnerKind: "item" }); assert.equal(spawners.length, 1 + listSpawnableMobTypes().length); assert.deepEqual( spawners.slice(1).map((entry) => entry.label), listSpawnableMobTypes().map((def) => def.displayName) ); }); test("palette highlight follows the active placement", () => { const grounds = listPaletteEntries("grounds", { dimensionId: "cave-1" }); const grass = grounds.find((entry) => entry.selection.typeId === GroundType.grass); assert.ok(grass); assert.deepEqual( [...matchingPaletteEntryKeys(grounds, grounds, { kind: "ground", typeId: GroundType.grass, state: "winter" })], [grass.key] ); assert.equal( matchingPaletteEntryKeys(grounds, grounds, { kind: "erase" }).size, 0 ); const blocks = listPaletteEntries("blocks", { dimensionId: OVERWORLD_ID }); const boulders = blocks.filter((entry) => entry.selection.typeId === BlockType.boulder); assert.ok(boulders.length > 1); assert.deepEqual( [...matchingPaletteEntryKeys(blocks, blocks, boulders[1].selection)], [boulders[1].key] ); assert.equal( matchingPaletteEntryKeys(blocks, blocks, { kind: "block", typeId: BlockType.boulder, state: "not-a-palette-card" }).size, 0 ); const wall = blocks.find((entry) => entry.selection.typeId === BlockType.stoneWall); assert.ok(wall); assert.deepEqual( [...matchingPaletteEntryKeys(blocks, blocks, { kind: "block", typeId: BlockType.stoneWall, state: "cycled-visual" })], [wall.key] ); const spawners = listPaletteEntries("spawners", { dimensionId: "house" }); assert.deepEqual( [...matchingPaletteEntryKeys(spawners, spawners, { kind: "spawner", spawnerKind: "item" })], ["spawner:item"] ); const deer = spawners.find((entry) => entry.selection.mobTypeId === "deer"); assert.ok(deer); const deerKeys = matchingPaletteEntryKeys(spawners, spawners, { kind: "spawner", mobTypeId: "deer" }); assert.equal(deerKeys.has(deer.key), true); assert.equal(deerKeys.has("spawner:item"), false); }); test("palette search matches names without case", () => { assert.equal(paletteLabelMatches("Deep water", ""), true); assert.equal(paletteLabelMatches("Deep water", " WATER "), true); assert.equal(paletteLabelMatches("Deep water", "lava"), false); });