Awesome menu and saves

This commit is contained in:
2026-11-14 14:48:07 -03:00
parent a69db0cd2a
commit 95e058d659
11 changed files with 861 additions and 128 deletions
+8 -1
View File
@@ -24,6 +24,8 @@ export interface HostOptions {
build_dir: string;
// the .cubi files to load
server_mods_dir: string;
// which of server_mods_dir's files to load, by file name. every one when left out
mod_files?: string[];
// <mod id>.json files that change mods' settings, see docs/modding/misc/config.md. without it every mod uses its
// own config.json
config_dir?: string;
@@ -47,7 +49,12 @@ export interface Host {
// throws when the mods have problems, saying what they are
export async function start_host(options: HostOptions): Promise<Host> {
const mods = await load_mods(options.server_mods_dir, engine_texture_ids(options.build_dir), options.config_dir);
const mods = await load_mods(
options.server_mods_dir,
engine_texture_ids(options.build_dir),
options.config_dir,
options.mod_files,
);
console.log(`Mods: ${mods.map((mod) => `${mod.listing.id} ${mod.listing.version}`).join(", ") || "none"}`);
// what players download, by path
const downloads = new Map(mods.map((mod) => [`/${mod.listing.file}`, mod.client_bytes]));
+13 -6
View File
@@ -27,19 +27,18 @@ export class ModsError extends Error {
}
// engine_textures are the cubi: texture ids, for checking the textures mods use. config_dir has the server's
// <mod id>.json files that change mods' config. a mod with problems stops the whole server from starting, the game
// never runs with some mods missing
// <mod id>.json files that change mods' config. only, when given, is which of dir's files to load, like a
// singleplayer world's mods. a mod with problems stops the whole server from starting, the game never runs with some
// mods missing
export async function load_mods(
dir: string,
engine_textures: Iterable<string>,
config_dir?: string,
only?: string[],
): Promise<ServerMod[]> {
let files: string[];
try {
files = [...Deno.readDirSync(dir)]
.filter((entry) => entry.isFile && entry.name.endsWith(MOD_EXTENSION))
.map((entry) => entry.name)
.sort();
files = only ?? mod_files(dir);
} catch (e) {
if (e instanceof Deno.errors.NotFound) return [];
throw e;
@@ -104,6 +103,14 @@ export async function load_mods(
}));
}
// the .cubi files in a folder, by name
export function mod_files(dir: string): string[] {
return [...Deno.readDirSync(dir)]
.filter((entry) => entry.isFile && entry.name.endsWith(MOD_EXTENSION))
.map((entry) => entry.name)
.sort();
}
// runs the content phase of the mods' scripts in a worker without permissions and adds the blocks they register to
// their data, after their files' ones. from then on they're the mod's data like the rest: checked, in the copy players
// download, and in the worldgen bundle