Files
bworld/tests/biome_test.ts
T
2026-10-08 13:34:32 -03:00

38 lines
1.9 KiB
TypeScript

// biomes are data, worldgen/biomes/<name>.json in a mod. see common/worldgen/biomes.ts
import { assert, assertEquals } from "@std/assert";
import { biome_from_json, biome_ids, get_biome, validate_biome } from "$/common/worldgen/biomes.ts";
import { test_game } from "./helpers.ts";
const PLAIN = { id: "my_mod:flat", surface: { top: "bworld:grass", filler: "bworld:dirt", filler_depth: 3 } };
Deno.test("the bworld mod registers every biome the overworld picks", async () => {
await test_game("mods");
assertEquals(biome_ids().length, 26);
assertEquals(get_biome("bworld:dark_forest")?.trees?.wood.big_oak, "dark_oak");
assertEquals(get_biome("bworld:river")?.surface.underwater_top, "bworld:sand");
});
Deno.test("a biome is in spring unless it says otherwise", async () => {
await test_game("mods");
assertEquals(get_biome("bworld:plains")?.season, "spring");
assertEquals(biome_from_json(PLAIN).season, "spring");
assertEquals(biome_from_json({ ...PLAIN, season: "winter" }).season, "winter");
});
Deno.test("a biome's surface defaults: underwater is its filler, cliffs aren't bare", () => {
const { surface, colors, trees } = biome_from_json(PLAIN);
assertEquals(surface.underwater_top, "bworld:dirt");
assertEquals(surface.underwater_filler, "bworld:dirt");
assertEquals(surface.bare_cliffs, false);
assertEquals(colors, { grass: undefined, foliage: undefined, water: undefined });
assertEquals(trees, undefined);
});
Deno.test("bad biome json is reported", () => {
assertEquals(validate_biome(PLAIN), []);
assert(validate_biome({ ...PLAIN, season: "monsoon" }).some((p) => p.startsWith("season")));
assert(validate_biome({ ...PLAIN, colors: { grass: "green" } }).some((p) => p.startsWith("colors.grass")));
assert(validate_biome({ ...PLAIN, trees: { chance: 2, kinds: ["palm"] } }).length === 2);
assert(validate_biome({ id: "my_mod:flat" }).some((p) => p.startsWith("surface")));
});