Rename bmod to just mod
This commit is contained in:
+8
-8
@@ -6,7 +6,7 @@
|
||||
import { serveDir, serveFile } from "@std/http/file-server";
|
||||
import { join } from "@std/path";
|
||||
import { GameToHost, HostToGame, READ_DONE, READ_HEADER, READ_TOO_SMALL } from "./game/host_protocol.ts";
|
||||
import { load_bmods } from "./load_bmods.ts";
|
||||
import { load_mods } from "./load_mods.ts";
|
||||
import { list_chunks, read_chunk, write_chunks } from "./regions.ts";
|
||||
import { default_worldgen_workers, start_worldgen_workers } from "./worldgen_workers.ts";
|
||||
import type { SavedChunk } from "./game/saves.ts";
|
||||
@@ -22,7 +22,7 @@ export const DESKTOP_DOWNLOADS = ["windows.zip", "linux.zip"];
|
||||
export interface HostOptions {
|
||||
// what deno task build made: the client and the engine's assets
|
||||
build_dir: string;
|
||||
// the .bmod files to load
|
||||
// the .cubi files to load
|
||||
server_mods_dir: string;
|
||||
// <mod id>.json files that change mods' settings, see docs/modding/misc/config.md. without it every mod uses its
|
||||
// own config.json
|
||||
@@ -47,7 +47,7 @@ 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_bmods(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);
|
||||
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]));
|
||||
@@ -148,12 +148,12 @@ export async function start_host(options: HostOptions): Promise<Host> {
|
||||
type: "init",
|
||||
save,
|
||||
default_seed: options.seed ?? crypto.randomUUID(),
|
||||
mods: mods.map(({ listing, bmod }) => ({
|
||||
mods: mods.map(({ listing, mod }) => ({
|
||||
listing,
|
||||
data: bmod.data,
|
||||
server_code: bmod.scripts.server,
|
||||
worldgen_code: bmod.scripts.worldgen,
|
||||
shared_code: bmod.scripts.shared,
|
||||
data: mod.data,
|
||||
server_code: mod.scripts.server,
|
||||
worldgen_code: mod.scripts.worldgen,
|
||||
shared_code: mod.scripts.shared,
|
||||
})),
|
||||
worldgen_ports: worldgen.ports,
|
||||
} satisfies HostToGame,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the server's mods: every .bmod in server_mods/, checked, with the server's changes to their config, sorted so
|
||||
// the server's mods: every .cubi in server_mods/, checked, with the server's changes to their config, sorted so
|
||||
// dependencies load first, and with the copy players download (the same mod without its server script) ready to serve
|
||||
import { join } from "@std/path";
|
||||
import { type Bmod, BMOD_EXTENSION, client_copy, read_bmod, write_bmod } from "@/common/bmod.ts";
|
||||
import { client_copy, type Mod, MOD_EXTENSION, read_mod, write_mod } from "@/common/mod.ts";
|
||||
import { check_references, load_order, type LoadedMod } from "@/common/mod_check.ts";
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import { data_file, FORMAT_VERSION } from "@/common/mod_data.ts";
|
||||
@@ -12,7 +12,7 @@ import { is_object, json_object } from "@/common/schema.ts";
|
||||
import { sha256 } from "@/common/utils.ts";
|
||||
|
||||
export interface ServerMod {
|
||||
bmod: Bmod;
|
||||
mod: Mod;
|
||||
listing: ModListing;
|
||||
// what's served at listing.file
|
||||
client_bytes: Uint8Array<ArrayBuffer>;
|
||||
@@ -28,7 +28,7 @@ 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
|
||||
export async function load_bmods(
|
||||
export async function load_mods(
|
||||
dir: string,
|
||||
engine_textures: Iterable<string>,
|
||||
config_dir?: string,
|
||||
@@ -36,7 +36,7 @@ export async function load_bmods(
|
||||
let files: string[];
|
||||
try {
|
||||
files = [...Deno.readDirSync(dir)]
|
||||
.filter((entry) => entry.isFile && entry.name.endsWith(BMOD_EXTENSION))
|
||||
.filter((entry) => entry.isFile && entry.name.endsWith(MOD_EXTENSION))
|
||||
.map((entry) => entry.name)
|
||||
.sort();
|
||||
} catch (e) {
|
||||
@@ -45,26 +45,26 @@ export async function load_bmods(
|
||||
}
|
||||
|
||||
const problems: string[] = [];
|
||||
const by_id = new Map<string, { file: string; bmod: Bmod }>();
|
||||
const by_id = new Map<string, { file: string; mod: Mod }>();
|
||||
for (const file of files) {
|
||||
try {
|
||||
const bmod = read_bmod(Deno.readFileSync(join(dir, file)), file);
|
||||
const other = by_id.get(bmod.manifest.id);
|
||||
const mod = read_mod(Deno.readFileSync(join(dir, file)), file);
|
||||
const other = by_id.get(mod.manifest.id);
|
||||
if (other) {
|
||||
problems.push(`${file} and ${other.file} are both the mod "${bmod.manifest.id}"`);
|
||||
problems.push(`${file} and ${other.file} are both the mod "${mod.manifest.id}"`);
|
||||
continue;
|
||||
}
|
||||
by_id.set(bmod.manifest.id, { file, bmod });
|
||||
by_id.set(mod.manifest.id, { file, mod });
|
||||
} catch (e) {
|
||||
problems.push((e as Error).message);
|
||||
}
|
||||
}
|
||||
if (config_dir) {
|
||||
for (const { bmod } of by_id.values()) change_config(bmod, config_dir, problems);
|
||||
for (const { mod } of by_id.values()) change_config(mod, config_dir, problems);
|
||||
}
|
||||
|
||||
// the same checks check-mods runs on mod folders
|
||||
const loaded = [...by_id.values()].map(({ file, bmod }) => as_loaded_mod(file, bmod));
|
||||
const loaded = [...by_id.values()].map(({ file, mod }) => as_loaded_mod(file, mod));
|
||||
check_references(loaded, engine_textures);
|
||||
for (const mod of loaded) {
|
||||
const dependencies = (mod.manifest?.dependencies ?? []) as { id: string }[];
|
||||
@@ -82,29 +82,29 @@ export async function load_bmods(
|
||||
}
|
||||
if (problems.length > 0) throw new ModsError(problems);
|
||||
|
||||
return await Promise.all(ordered.map(async (mod) => {
|
||||
const bmod = by_id.get(mod.id)!.bmod;
|
||||
const client_bytes = write_bmod(client_copy(bmod));
|
||||
return await Promise.all(ordered.map(async ({ id }) => {
|
||||
const mod = by_id.get(id)!.mod;
|
||||
const client_bytes = write_mod(client_copy(mod));
|
||||
const hash = await sha256(client_bytes);
|
||||
return {
|
||||
bmod,
|
||||
mod,
|
||||
client_bytes,
|
||||
listing: {
|
||||
id: bmod.manifest.id,
|
||||
name: bmod.manifest.name,
|
||||
version: bmod.manifest.version,
|
||||
id: mod.manifest.id,
|
||||
name: mod.manifest.name,
|
||||
version: mod.manifest.version,
|
||||
sha256: hash,
|
||||
file: `mods/${hash}${BMOD_EXTENSION}`,
|
||||
file: `mods/${hash}${MOD_EXTENSION}`,
|
||||
size: client_bytes.length,
|
||||
...(bmod.manifest.engine_access ? { engine_access: true } : {}),
|
||||
...(mod.manifest.engine_access ? { engine_access: true } : {}),
|
||||
},
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
// applies config_dir/<mod id>.json to the mod's config, when the server has one
|
||||
function change_config(bmod: Bmod, config_dir: string, problems: string[]) {
|
||||
const file = join(config_dir, `${bmod.manifest.id}.json`);
|
||||
function change_config(mod: Mod, config_dir: string, problems: string[]) {
|
||||
const file = join(config_dir, `${mod.manifest.id}.json`);
|
||||
let text: string;
|
||||
try {
|
||||
text = Deno.readTextFileSync(file);
|
||||
@@ -124,9 +124,9 @@ function change_config(bmod: Bmod, config_dir: string, problems: string[]) {
|
||||
problems.push(`${file}: must be { "format_version": ${FORMAT_VERSION}, "config": { ... } }`);
|
||||
return;
|
||||
}
|
||||
const changed = apply_config(bmod.data.config ?? {}, config_file.data.config as Record<string, unknown>);
|
||||
const changed = apply_config(mod.data.config ?? {}, config_file.data.config as Record<string, unknown>);
|
||||
problems.push(...changed.problems.map((problem) => `${file}: ${problem}`));
|
||||
bmod.data.config = changed.config;
|
||||
mod.data.config = changed.config;
|
||||
}
|
||||
|
||||
// a mod's config with changes made to it, like a server's config/<mod id>.json makes: objects are changed setting by
|
||||
@@ -163,34 +163,34 @@ function json_kind(value: unknown): string {
|
||||
}
|
||||
|
||||
// in the shape the checks in common/mod_check.ts take
|
||||
function as_loaded_mod(file: string, bmod: Bmod): LoadedMod {
|
||||
function as_loaded_mod(file: string, mod: Mod): LoadedMod {
|
||||
const entries = <T>(list: T[]) => list.map((json) => ({ file: `${file} data.json`, json }));
|
||||
return {
|
||||
id: bmod.manifest.id,
|
||||
id: mod.manifest.id,
|
||||
dir: file,
|
||||
report: { id: bmod.manifest.id, errors: [], warnings: [] },
|
||||
manifest: bmod.manifest as unknown as Record<string, unknown>,
|
||||
blocks: entries(bmod.data.blocks),
|
||||
models: entries(bmod.data.models),
|
||||
items: entries(bmod.data.items),
|
||||
recipes: entries(bmod.data.recipes),
|
||||
ores: entries(bmod.data.ores),
|
||||
spawns: entries(bmod.data.spawns),
|
||||
entities: entries(bmod.data.entities),
|
||||
entity_models: entries(bmod.data.entity_models),
|
||||
effects: entries(bmod.data.effects),
|
||||
fluids: entries(bmod.data.fluids),
|
||||
tags: entries(bmod.data.tags),
|
||||
loot_tables: entries(bmod.data.loot_tables ?? []),
|
||||
biomes: entries(bmod.data.biomes ?? []),
|
||||
noises: entries(bmod.data.noises ?? []),
|
||||
density_functions: entries(bmod.data.density_functions ?? []),
|
||||
noise_settings: entries(bmod.data.noise_settings ?? []),
|
||||
biome_sources: entries(bmod.data.biome_sources ?? []),
|
||||
features: entries(bmod.data.features ?? []),
|
||||
config: bmod.data.config,
|
||||
textures: [...bmod.textures.keys()],
|
||||
report: { id: mod.manifest.id, errors: [], warnings: [] },
|
||||
manifest: mod.manifest as unknown as Record<string, unknown>,
|
||||
blocks: entries(mod.data.blocks),
|
||||
models: entries(mod.data.models),
|
||||
items: entries(mod.data.items),
|
||||
recipes: entries(mod.data.recipes),
|
||||
ores: entries(mod.data.ores),
|
||||
spawns: entries(mod.data.spawns),
|
||||
entities: entries(mod.data.entities),
|
||||
entity_models: entries(mod.data.entity_models),
|
||||
effects: entries(mod.data.effects),
|
||||
fluids: entries(mod.data.fluids),
|
||||
tags: entries(mod.data.tags),
|
||||
loot_tables: entries(mod.data.loot_tables ?? []),
|
||||
biomes: entries(mod.data.biomes ?? []),
|
||||
noises: entries(mod.data.noises ?? []),
|
||||
density_functions: entries(mod.data.density_functions ?? []),
|
||||
noise_settings: entries(mod.data.noise_settings ?? []),
|
||||
biome_sources: entries(mod.data.biome_sources ?? []),
|
||||
features: entries(mod.data.features ?? []),
|
||||
config: mod.data.config,
|
||||
textures: [...mod.textures.keys()],
|
||||
texture_files: new Map(),
|
||||
texture_json: new Map(bmod.texture_json),
|
||||
texture_json: new Map(mod.texture_json),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user