92 lines
2.8 KiB
TypeScript
92 lines
2.8 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { blockTint, firstTextureFrame } from "../renderer/block-colors.mjs";
|
|
import { datasetSchema } from "../shared/protocol";
|
|
import { selectDraftLocations } from "../shared/draft-selection";
|
|
|
|
test("waterlogged properties do not turn leaves, grass or vines blue", () => {
|
|
for (const name of ["acacia_leaves", "oak_leaves", "vine", "short_grass"]) {
|
|
assert.equal(
|
|
blockTint(`minecraft:${name}[waterlogged=false]`),
|
|
blockTint(`minecraft:${name}`),
|
|
);
|
|
assert.notEqual(
|
|
blockTint(`minecraft:${name}[waterlogged=true]`),
|
|
blockTint("minecraft:water"),
|
|
);
|
|
}
|
|
assert.equal(
|
|
blockTint("minecraft:birch_leaves[waterlogged=false]"),
|
|
"#80a755",
|
|
);
|
|
assert.notEqual(
|
|
blockTint("minecraft:acacia_leaves", "minecraft:savanna"),
|
|
blockTint("minecraft:acacia_leaves", "minecraft:jungle"),
|
|
);
|
|
});
|
|
|
|
test("animated textures use one frame, including explicit sprite frame order", () => {
|
|
assert.deepEqual(firstTextureFrame(16, 512, {}), {
|
|
x: 0,
|
|
y: 0,
|
|
width: 16,
|
|
height: 16,
|
|
});
|
|
assert.deepEqual(
|
|
firstTextureFrame(32, 64, {
|
|
width: 16,
|
|
height: 16,
|
|
frames: [{ index: 3, time: 4 }],
|
|
}),
|
|
{ x: 16, y: 16, width: 16, height: 16 },
|
|
);
|
|
assert.deepEqual(firstTextureFrame(32, 16, null), {
|
|
x: 0,
|
|
y: 0,
|
|
width: 32,
|
|
height: 16,
|
|
});
|
|
});
|
|
|
|
const capture = datasetSchema.parse({
|
|
format: "minegeo-dataset/v1",
|
|
minecraftVersion: "1.21.11",
|
|
dimension: "minecraft:overworld",
|
|
source: "plugin",
|
|
name: "Selection regression",
|
|
serverName: "Test",
|
|
north: "-z",
|
|
bounds: { minX: 0, minZ: 0, maxX: 16, maxZ: 16 },
|
|
viewpoints: Array.from({ length: 6 }, (_, i) => ({
|
|
id: `p${i}`,
|
|
x: i,
|
|
y: 66,
|
|
z: i,
|
|
})),
|
|
assets: [{ path: "terrain.json.gz", sha256: "a".repeat(64), bytes: 100 }],
|
|
});
|
|
test("saving and reloading a selection retains deselected capture locations", () => {
|
|
const saved = selectDraftLocations(capture, ["p0", "p1", "p2", "p3", "p4"]);
|
|
const reloaded = datasetSchema.parse(JSON.parse(JSON.stringify(saved)));
|
|
assert.equal(reloaded.viewpoints.length, 5);
|
|
assert.equal(reloaded.availableViewpoints?.length, 6);
|
|
const restored = selectDraftLocations(reloaded, [
|
|
"p0",
|
|
"p1",
|
|
"p2",
|
|
"p3",
|
|
"p5",
|
|
]);
|
|
assert.equal(restored.viewpoints[4].id, "p5");
|
|
assert.equal(restored.availableViewpoints?.length, 6);
|
|
});
|
|
test("unknown, duplicate or too few locations cannot enter a published selection", () => {
|
|
assert.throws(() =>
|
|
selectDraftLocations(capture, ["p0", "p1", "p2", "p3", "missing"]),
|
|
);
|
|
assert.throws(() =>
|
|
selectDraftLocations(capture, ["p0", "p1", "p2", "p3", "p3"]),
|
|
);
|
|
assert.throws(() => selectDraftLocations(capture, ["p0", "p1", "p2", "p3"]));
|
|
});
|