Seasons based on a calendar
This commit is contained in:
+30
-4
@@ -1,6 +1,14 @@
|
||||
// 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 { 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", filler: "bworld:dirt", filler_depth: 3 } };
|
||||
@@ -12,11 +20,29 @@ Deno.test("the bworld mod registers every biome the overworld picks", async () =
|
||||
assertEquals(get_biome("bworld:river")?.surface.underwater_top, "bworld:sand");
|
||||
});
|
||||
|
||||
Deno.test("a biome is in spring unless it says otherwise", async () => {
|
||||
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, "spring");
|
||||
assertEquals(biome_from_json(PLAIN).season, "spring");
|
||||
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", () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// blocks, entities, players and the world tell scripts their biome's season, see docs/modding/worldgen/biomes.md
|
||||
import { assertEquals } from "@std/assert";
|
||||
import type { ServerContext } from "$/common/mod_api/server.ts";
|
||||
import { get_biome } from "$/common/worldgen/biomes.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
|
||||
const SCRIPT = `
|
||||
@@ -16,7 +17,7 @@ export function setup(ctx: ServerContext) {
|
||||
}
|
||||
`;
|
||||
|
||||
// bworld's biomes, with every one but the oceans in winter. oceans keep spring by leaving it out
|
||||
// bworld's biomes, with every one but the oceans in winter. oceans follow the calendar, spring on day 1
|
||||
function season_mods() {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_seasons_" });
|
||||
copy_dir("mods/bworld", `${dir}/bworld`);
|
||||
@@ -64,7 +65,8 @@ Deno.test("blocks, entities, players and the world know their biome's season", a
|
||||
const { ctx, created } = (globalThis as unknown as {
|
||||
season_test: { ctx: ServerContext; created: { biome: string; season: string }[] };
|
||||
}).season_test;
|
||||
const season_of = (biome: string) => biome.includes("ocean") ? "spring" : "winter";
|
||||
// it's day 1, so oceans without their own season are in spring
|
||||
const season_of = (biome: string) => get_biome(biome)?.season ?? "spring";
|
||||
|
||||
// spawn is on dry land
|
||||
const biome = ctx.world.biome_at(0, 0);
|
||||
|
||||
+4
-3
@@ -8,9 +8,10 @@ Deno.test("a day is 30 minutes and a night 10, tick 0 is 06:00 of day 1", () =>
|
||||
assertEquals(format_clock(0), "Day 1, 06:00");
|
||||
assertEquals(format_clock(DAY_TICKS / 2), "Day 1, 12:00");
|
||||
assertEquals(format_clock(DAY_TICKS), "Day 1, 18:00");
|
||||
// midnight is halfway through the night, and the day number goes up there
|
||||
// midnight is halfway through the night, the day number goes up at 06:00 like the farming day
|
||||
assertEquals(format_clock(DAY_TICKS + NIGHT_TICKS / 2 - 1), "Day 1, 23:59");
|
||||
assertEquals(format_clock(DAY_TICKS + NIGHT_TICKS / 2), "Day 2, 00:00");
|
||||
assertEquals(format_clock(DAY_TICKS + NIGHT_TICKS / 2), "Day 1, 00:00");
|
||||
assertEquals(format_clock(CYCLE_TICKS - 1), "Day 1, 05:59");
|
||||
assertEquals(format_clock(CYCLE_TICKS), "Day 2, 06:00");
|
||||
assertEquals(clock(3 * CYCLE_TICKS + DAY_TICKS / 4), { day: 4, hour: 9, minute: 0 });
|
||||
assert(is_day(DAY_TICKS - 1) && !is_day(DAY_TICKS) && is_day(CYCLE_TICKS));
|
||||
@@ -40,7 +41,7 @@ Deno.test("the server keeps the time, tells players, saves it, and /time changes
|
||||
send(1, { type: "chat", text: "/time set midnight" });
|
||||
let messages = take(1);
|
||||
assertEquals(messages.find((m) => m.type === "time").time, DAY_TICKS + NIGHT_TICKS / 2);
|
||||
assert(messages.some((m) => m.text === "alice set the time to Day 2, 00:00"));
|
||||
assert(messages.some((m) => m.text === "alice set the time to Day 1, 00:00"));
|
||||
|
||||
// named times are the next one, so time never goes backwards
|
||||
send(1, { type: "chat", text: "/time set day" });
|
||||
|
||||
Reference in New Issue
Block a user