64 lines
2.7 KiB
TypeScript
64 lines
2.7 KiB
TypeScript
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// biomes are data, worldgen/biomes/<name>.json in a mod. see common/worldgen/biomes.ts
|
|
import { assert, assertEquals } from "@std/assert";
|
|
import { CYCLE_TICKS } from "@/common/time.ts";
|
|
import {
|
|
biome_from_json,
|
|
biome_ids,
|
|
biome_season,
|
|
calendar_season,
|
|
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_block", 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:river")?.surface.underwater_top, "bworld:sand");
|
|
});
|
|
|
|
Deno.test("seasons last 49 days, starting with spring on day 1 and changing at 06:00", () => {
|
|
assertEquals(calendar_season(0), "spring");
|
|
assertEquals(calendar_season(48), "spring");
|
|
assertEquals(calendar_season(49), "summer");
|
|
assertEquals(calendar_season(97), "summer");
|
|
assertEquals(calendar_season(98), "autumn");
|
|
assertEquals(calendar_season(147), "winter");
|
|
assertEquals(calendar_season(195), "winter");
|
|
assertEquals(calendar_season(196), "spring");
|
|
});
|
|
|
|
Deno.test("a biome follows the calendar unless it says otherwise", async () => {
|
|
await test_game("mods");
|
|
assertEquals(get_biome("bworld:plains")?.season, undefined);
|
|
assertEquals(biome_from_json(PLAIN).season, undefined);
|
|
assertEquals(biome_from_json({ ...PLAIN, season: "winter" }).season, "winter");
|
|
// 06:00 of day 50
|
|
const day_50 = 49 * CYCLE_TICKS;
|
|
assertEquals(biome_season("bworld:plains", 0), "spring");
|
|
assertEquals(biome_season("bworld:plains", day_50 - 1), "spring");
|
|
assertEquals(biome_season("bworld:plains", day_50), "summer");
|
|
assertEquals(biome_season("bworld:snowy_plains", day_50), "winter");
|
|
assertEquals(biome_season("my_mod:removed", day_50), "summer");
|
|
});
|
|
|
|
Deno.test("a biome's surface defaults: underwater is its filler, cliffs aren't bare", () => {
|
|
const { surface, colors } = 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 });
|
|
});
|
|
|
|
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({ id: "my_mod:flat" }).some((p) => p.startsWith("surface")));
|
|
});
|