Rename bmod to just mod
This commit is contained in:
+23
-23
@@ -1,7 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// loads the mods the server lists: downloads their .bmod files, registers their data, then runs their client scripts.
|
||||
// loads the mods the server lists: downloads their .cubi files, registers their data, then runs their client scripts.
|
||||
// see docs/modding/networking/index.md
|
||||
import { AIR } from "@/common/constants.ts";
|
||||
import { BlockRegistry, EverythingRegistry, type ItemRegistry } from "@/common/everything_registry.ts";
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
register_mod_data,
|
||||
shared_recipes_api,
|
||||
} from "@/common/mod_loader.ts";
|
||||
import { type Bmod, read_bmod } from "@/common/bmod.ts";
|
||||
import { type Mod, read_mod } from "@/common/mod.ts";
|
||||
import { get_state_value, set_state_value, shared_items_api } from "@/common/utils.ts";
|
||||
import { BlockRules } from "@/common/block_rules.ts";
|
||||
import { fluid_exists, FluidRules, same_fluid } from "@/common/fluids.ts";
|
||||
@@ -135,19 +135,19 @@ export function set_mods_client(game_client: Client) {
|
||||
client = game_client;
|
||||
}
|
||||
|
||||
// downloads every mod's .bmod and checks it against the hash the server listed. everything a mod runs comes from
|
||||
// downloads every mod's .cubi and checks it against the hash the server listed. everything a mod runs comes from
|
||||
// the checked bytes, never fetched twice
|
||||
export async function download_mods(listings: ModListing[], base: URL): Promise<Bmod[]> {
|
||||
export async function download_mods(listings: ModListing[], base: URL): Promise<Mod[]> {
|
||||
return await Promise.all(listings.map(async (listing) => {
|
||||
try {
|
||||
const bytes = await fetch_verified(new URL(listing.file, base), listing.sha256, `${listing.name}`);
|
||||
const bmod = read_bmod(bytes, `${listing.id}.bmod`);
|
||||
if (bmod.manifest.id !== listing.id) throw new Error(`the server listed it as ${listing.id}`);
|
||||
const mod = read_mod(bytes, `${listing.id}.cubi`);
|
||||
if (mod.manifest.id !== listing.id) throw new Error(`the server listed it as ${listing.id}`);
|
||||
// the confirm screen said whether it has engine access, going by the listing
|
||||
if ((bmod.manifest.engine_access ?? false) !== (listing.engine_access ?? false)) {
|
||||
if ((mod.manifest.engine_access ?? false) !== (listing.engine_access ?? false)) {
|
||||
throw new Error("its engine access isn't what the server listed");
|
||||
}
|
||||
return bmod;
|
||||
return mod;
|
||||
} catch (e) {
|
||||
throw new ModLoadError(listing.id, (e as Error).message);
|
||||
}
|
||||
@@ -155,14 +155,14 @@ export async function download_mods(listings: ModListing[], base: URL): Promise<
|
||||
}
|
||||
|
||||
// registers the mods' data and runs their client scripts, in the order the server listed them
|
||||
export async function load_client_mods(listings: ModListing[], bmods: Bmod[]) {
|
||||
for (const [i, bmod] of bmods.entries()) {
|
||||
if (bmod.credits) {
|
||||
mod_credits.push({ name: listings[i].name, version: listings[i].version, text: bmod.credits });
|
||||
export async function load_client_mods(listings: ModListing[], mods: Mod[]) {
|
||||
for (const [i, mod] of mods.entries()) {
|
||||
if (mod.credits) {
|
||||
mod_credits.push({ name: listings[i].name, version: listings[i].version, text: mod.credits });
|
||||
}
|
||||
}
|
||||
|
||||
const recipes = register_mod_data(bmods.map((bmod) => ({ id: bmod.manifest.id, data: bmod.data })));
|
||||
const recipes = register_mod_data(mods.map((mod) => ({ id: mod.manifest.id, data: mod.data })));
|
||||
recipe_book = recipes;
|
||||
inventory_overlays.length = 0;
|
||||
menu_screens.clear();
|
||||
@@ -174,20 +174,20 @@ export async function load_client_mods(listings: ModListing[], bmods: Bmod[]) {
|
||||
// for engine access mods. the last server's hooks go first
|
||||
clear_hooks();
|
||||
expose_engine({ common: common_engine(), client: client_engine() });
|
||||
const as_mod = (bmod: Bmod, fn: () => Promise<void>) =>
|
||||
loading_mod(bmod.manifest.id, bmod.manifest.engine_access ?? false, fn);
|
||||
const as_mod = (mod: Mod, fn: () => Promise<void>) =>
|
||||
loading_mod(mod.manifest.id, mod.manifest.engine_access ?? false, fn);
|
||||
|
||||
// every mod's shared rules first, so client scripts can count on any mod's being there
|
||||
block_rules = new BlockRules(run_mod, rules_world.get_block);
|
||||
set_fluid_rules(new FluidRules(run_mod));
|
||||
rules_setup = true;
|
||||
for (const [i, bmod] of bmods.entries()) {
|
||||
const code = bmod.scripts.shared;
|
||||
for (const [i, mod] of mods.entries()) {
|
||||
const code = mod.scripts.shared;
|
||||
if (!code) continue;
|
||||
await as_mod(bmod, async () => {
|
||||
await as_mod(mod, async () => {
|
||||
const module = await import(script_url(code));
|
||||
if (typeof module.setup !== "function") {
|
||||
throw new ModLoadError(bmod.manifest.id, "the shared script doesn't export a setup function");
|
||||
throw new ModLoadError(mod.manifest.id, "the shared script doesn't export a setup function");
|
||||
}
|
||||
await module.setup(shared_context(listings[i]));
|
||||
});
|
||||
@@ -196,13 +196,13 @@ export async function load_client_mods(listings: ModListing[], bmods: Bmod[]) {
|
||||
check_recipe_types(recipe_book);
|
||||
|
||||
client_setup = true;
|
||||
for (const [i, bmod] of bmods.entries()) {
|
||||
const code = bmod.scripts.client;
|
||||
for (const [i, mod] of mods.entries()) {
|
||||
const code = mod.scripts.client;
|
||||
if (!code) continue;
|
||||
await as_mod(bmod, async () => {
|
||||
await as_mod(mod, async () => {
|
||||
const module = await import(script_url(code));
|
||||
if (typeof module.setup !== "function") {
|
||||
throw new ModLoadError(bmod.manifest.id, "the client script doesn't export a setup function");
|
||||
throw new ModLoadError(mod.manifest.id, "the client script doesn't export a setup function");
|
||||
}
|
||||
await module.setup(client_context(listings[i]));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user