BlueGit

timfa questward

Files

questward / client / tests / palette-entries.test.js

palette-entries.test.js

feat: add a palette tab to the world editor sidebar
timfa project_85689633_bot_760517ee9267c86ff1d6c3a0237abf7d · pushed by timfa · 6 weeks ago
4251842f History
palette-entries.test.js 3.9 KiB Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import
4{
5 BlockType,
6 GroundType,
7 listPlaceableBlockPaletteEntries,
8 listPlaceableGrounds
9} from "../../shared/definitions/tiles.js";
10import { listSpawnableMobTypes } from "../../shared/definitions/mobs.js";
11import { OVERWORLD_ID } from "../../shared/world/dimensions.js";
12import
13{
14 PALETTE_TABS,
15 listPaletteEntries,
16 matchingPaletteEntryKeys,
17 paletteLabelMatches
18} from "../src/editor/paletteEntries.js";
19
20test("palette categories match the editor placeable dialog", () =>
21{
22 assert.deepEqual(
23 PALETTE_TABS.map((tab) => tab.label),
24 ["Ground tiles", "Blocks", "Spawners"]
25 );
26});
27
28test("palette entries are the live registries in every dimension", () =>
29{
30 const overworldGrounds = listPaletteEntries("grounds", { dimensionId: OVERWORLD_ID });
31 const caveGrounds = listPaletteEntries("grounds", { dimensionId: "void-hall" });
32 assert.equal(overworldGrounds.length, listPlaceableGrounds().length);
33 assert.ok(caveGrounds.length > 0);
34 assert.deepEqual(
35 caveGrounds.map((entry) => entry.key),
36 overworldGrounds.map((entry) => entry.key)
37 );
38 assert.equal(caveGrounds[0].selection.kind, "ground");
39
40 const blocks = listPaletteEntries("blocks", { dimensionId: "cave-1" });
41 const fromRegistry = listPlaceableBlockPaletteEntries(null);
42 assert.equal(blocks.length, fromRegistry.length);
43 assert.deepEqual(
44 blocks.map((entry) => entry.label),
45 fromRegistry.map((entry) => entry.displayName)
46 );
47 assert.equal(blocks.every((entry) => entry.selection.kind === "block"), true);
48
49 const spawners = listPaletteEntries("spawners", { dimensionId: "house" });
50 assert.equal(spawners[0].label, "Item Spawner");
51 assert.deepEqual(spawners[0].selection, { kind: "spawner", spawnerKind: "item" });
52 assert.equal(spawners.length, 1 + listSpawnableMobTypes().length);
53 assert.deepEqual(
54 spawners.slice(1).map((entry) => entry.label),
55 listSpawnableMobTypes().map((def) => def.displayName)
56 );
57});
58
59test("palette highlight follows the active placement", () =>
60{
61 const grounds = listPaletteEntries("grounds", { dimensionId: "cave-1" });
62 const grass = grounds.find((entry) => entry.selection.typeId === GroundType.grass);
63 assert.ok(grass);
64 assert.deepEqual(
65 [...matchingPaletteEntryKeys(grounds, grounds, {
66 kind: "ground",
67 typeId: GroundType.grass,
68 state: "winter"
69 })],
70 [grass.key]
71 );
72 assert.equal(
73 matchingPaletteEntryKeys(grounds, grounds, { kind: "erase" }).size,
74 0
75 );
76
77 const blocks = listPaletteEntries("blocks", { dimensionId: OVERWORLD_ID });
78 const boulders = blocks.filter((entry) => entry.selection.typeId === BlockType.boulder);
79 assert.ok(boulders.length > 1);
80 assert.deepEqual(
81 [...matchingPaletteEntryKeys(blocks, blocks, boulders[1].selection)],
82 [boulders[1].key]
83 );
84 assert.equal(
85 matchingPaletteEntryKeys(blocks, blocks, {
86 kind: "block",
87 typeId: BlockType.boulder,
88 state: "not-a-palette-card"
89 }).size,
90 0
91 );
92
93 const wall = blocks.find((entry) => entry.selection.typeId === BlockType.stoneWall);
94 assert.ok(wall);
95 assert.deepEqual(
96 [...matchingPaletteEntryKeys(blocks, blocks, {
97 kind: "block",
98 typeId: BlockType.stoneWall,
99 state: "cycled-visual"
100 })],
101 [wall.key]
102 );
103
104 const spawners = listPaletteEntries("spawners", { dimensionId: "house" });
105 assert.deepEqual(
106 [...matchingPaletteEntryKeys(spawners, spawners, { kind: "spawner", spawnerKind: "item" })],
107 ["spawner:item"]
108 );
109 const deer = spawners.find((entry) => entry.selection.mobTypeId === "deer");
110 assert.ok(deer);
111 const deerKeys = matchingPaletteEntryKeys(spawners, spawners, {
112 kind: "spawner",
113 mobTypeId: "deer"
114 });
115 assert.equal(deerKeys.has(deer.key), true);
116 assert.equal(deerKeys.has("spawner:item"), false);
117});
118
119test("palette search matches names without case", () =>
120{
121 assert.equal(paletteLabelMatches("Deep water", ""), true);
122 assert.equal(paletteLabelMatches("Deep water", " WATER "), true);
123 assert.equal(paletteLabelMatches("Deep water", "lava"), false);
124});