Actually fix default dimensions with multiple mods

This commit is contained in:
2026-11-15 09:53:31 -03:00
parent 2282abc3bc
commit afacd10a18
5 changed files with 16 additions and 12 deletions
+2 -8
View File
@@ -186,8 +186,6 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
"biome source": new Map(), "biome source": new Map(),
dimension: new Map(), dimension: new Map(),
}; };
// the dimensions that say they're the default, only one can be
const defaults: string[] = [];
const biome_rule_owners = new Map<string, string[]>(); const biome_rule_owners = new Map<string, string[]>();
const all_noise_settings: NoiseSettingsJson[] = []; const all_noise_settings: NoiseSettingsJson[] = [];
const feature_owners = new Map<string, string[]>(); const feature_owners = new Map<string, string[]>();
@@ -225,7 +223,6 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
} }
for (const { json } of mod.dimensions ?? []) { for (const { json } of mod.dimensions ?? []) {
add(worldgen_owners.dimension, json.id, mod.id); add(worldgen_owners.dimension, json.id, mod.id);
if (json.default) defaults.push(`${json.id} (${mod.id})`);
} }
for (const { json } of mod.biome_sources ?? []) { for (const { json } of mod.biome_sources ?? []) {
add(worldgen_owners["biome source"], json.id, mod.id); add(worldgen_owners["biome source"], json.id, mod.id);
@@ -432,11 +429,8 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
[settings.terrain.cell_height, settings.caves.cell_height], [settings.terrain.cell_height, settings.caves.cell_height],
); );
if (problem) errors.push(`${file}: can't be generated by ${json.generator}: ${problem}`); if (problem) errors.push(`${file}: can't be generated by ${json.generator}: ${problem}`);
if (json.default && defaults.length > 1) { // whether exactly one is the default is up to the server, with the mods a world plays: a folder of mods
errors.push( // can hold several games, each with its own
`${file}: only one dimension can be the default, and these all are: ${defaults.join(", ")}`,
);
}
} }
for (const { file, json } of mod.biome_sources ?? []) { for (const { file, json } of mod.biome_sources ?? []) {
const refs = new_refs(); const refs = new_refs();
+5 -2
View File
@@ -335,8 +335,11 @@ torches, light it, and day and night don't change how bright it is. The sky is s
The world plays the dimension with `"default": true`. Exactly one dimension in the loaded mods can be the default: with The world plays the dimension with `"default": true`. Exactly one dimension in the loaded mods can be the default: with
none, or more than one, the server doesn't start, and the error names them. A mod can have dimensions that aren't the none, or more than one, the server doesn't start, and the error names them. A mod can have dimensions that aren't the
default, but nothing plays them yet. Since a mod can't change another mod's files yet, a mod with a default dimension of default, but nothing plays them yet.
its own, like a flat world, can't be loaded with the base game's for now.
A mod with a default dimension of its own, like a flat world or a game that doesn't build on the base game, is played
without the base game: a singleplayer world picks its mods, and a dedicated server loads the ones `MODS` names, like
`MODS=my_game,recipe_viewer`. `check-mods` doesn't mind a folder holding several, since each world plays one.
There's one dimension per world for now, there's no travelling between them yet. There's one dimension per world for now, there's no travelling between them yet.
@@ -3,6 +3,6 @@
"dimension": { "dimension": {
"id": "dangerous_business:void", "id": "dangerous_business:void",
"generator": "dangerous_business:void", "generator": "dangerous_business:void",
"default": false "default": true
} }
} }
+4
View File
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
// a dedicated server: the host from server/host.ts on a port, saving the world when it's stopped // a dedicated server: the host from server/host.ts on a port, saving the world when it's stopped
import { MOD_EXTENSION } from "@/common/mod.ts";
import { type Host, start_host } from "./host.ts"; import { type Host, start_host } from "./host.ts";
const PORT = Number(Deno.env.get("PORT") ?? 8000); const PORT = Number(Deno.env.get("PORT") ?? 8000);
@@ -11,6 +12,9 @@ try {
host = await start_host({ host = await start_host({
build_dir: Deno.env.get("BUILD_DIR") ?? "build", build_dir: Deno.env.get("BUILD_DIR") ?? "build",
server_mods_dir: Deno.env.get("SERVER_MODS_DIR") ?? "server_mods", server_mods_dir: Deno.env.get("SERVER_MODS_DIR") ?? "server_mods",
// which mods to play, by id, like MODS=bworld,create. each is <id>.cubi, as deno task build names them. every
// one when left out, which only works while server_mods/ has a single game with a default dimension
mod_files: Deno.env.get("MODS")?.split(",").map((id) => `${id.trim()}${MOD_EXTENSION}`),
config_dir: Deno.env.get("CONFIG_DIR") ?? "config", config_dir: Deno.env.get("CONFIG_DIR") ?? "config",
dist_dir: Deno.env.get("DIST_DIR") ?? "dist", dist_dir: Deno.env.get("DIST_DIR") ?? "dist",
world_dir: Deno.env.get("WORLD_DIR") ?? "world", world_dir: Deno.env.get("WORLD_DIR") ?? "world",
+4 -1
View File
@@ -42,7 +42,10 @@ let repo_mods: ServerModSource[] | undefined;
// own copy, so a test that changes what it got can't change another test's // own copy, so a test that changes what it got can't change another test's
export async function mod_sources(mods_dir: string): Promise<ServerModSource[]> { export async function mod_sources(mods_dir: string): Promise<ServerModSource[]> {
if (resolve(mods_dir) !== resolve("mods")) return await read_mod_sources(mods_dir); if (resolve(mods_dir) !== resolve("mods")) return await read_mod_sources(mods_dir);
repo_mods ??= await read_mod_sources(mods_dir); // other games in mods/, the ones with a default dimension of their own, are left out: tests play bworld
repo_mods ??= (await read_mod_sources(mods_dir)).filter((mod) =>
mod.listing.id === "bworld" || !mod.data.dimensions?.some((json) => json.default)
);
return structuredClone(repo_mods); return structuredClone(repo_mods);
} }