Single module modding

This commit is contained in:
2026-11-14 12:18:41 -03:00
parent 605008f584
commit 313098892e
134 changed files with 919 additions and 924 deletions
+5 -8
View File
@@ -31,7 +31,7 @@ import { collision_shape_at, covers_face, is_solid } from "@/common/block_shapes
import { tag_api } from "@/common/tags.ts";
import { get_state_value, set_state_value, shared_items_api } from "@/common/utils.ts";
import type { Face, SharedWorld } from "@/common/mod_api/shared.ts";
import { setup as setup_shared } from "@/mods/bworld/scripts/shared.ts";
import { shared as setup_shared } from "@/mods/bworld/scripts/shared.ts";
// the repo's own mods/, read once: reading and checking every mod's files is most of starting a game in a test. only
// mods/ is kept, since tests change the temporary folders they make between games
@@ -50,8 +50,7 @@ async function read_mod_sources(mods_dir: string): Promise<ServerModSource[]> {
const errors = mods.flatMap((mod) => mod.report.errors.map((e) => `${mod.id}: ${e}`));
if (errors.length) throw new Error(errors.join("\n"));
return load_order(mods).map((mod) => {
const scripts = (mod.manifest?.scripts ?? {}) as Record<string, string>;
const url = (path?: string) => path ? toFileUrl(resolve(mod.dir, path)).href : undefined;
const main = mod.manifest?.main as string | undefined;
return {
listing: {
id: mod.id,
@@ -63,9 +62,7 @@ async function read_mod_sources(mods_dir: string): Promise<ServerModSource[]> {
...(mod.manifest?.engine_access === true ? { engine_access: true } : {}),
},
data: mod_data(mod),
server_url: url(scripts.server),
worldgen_url: url(scripts.worldgen),
shared_url: url(scripts.shared),
url: main ? toFileUrl(resolve(mod.dir, main)).href : undefined,
};
});
}
@@ -284,7 +281,7 @@ export const GROUND_BLOCKS = "#bworld:raw_rocks";
export const ENGINE_TEXTURES = ["cubi:missing", ...Array.from({ length: 9 }, (_, i) => `cubi:break_${i}`)];
// registers a folder of mod sources the way a player gets them: packed, loaded by a server, which adds the blocks
// content scripts register, and the copies it serves loaded on the client
// content phases register, and the copies it serves loaded on the client
export async function load_as_player(sources: string) {
const folder = Deno.makeTempDirSync({ prefix: "bworld_player_mods_" });
try {
@@ -369,7 +366,7 @@ export function server_blocks(game: GameServer, area: Area) {
return blocks_in(area, (x, y, z) => [game.world.get_block_id(x, y, z), game.world.get_block_value(x, y, z) >>> 16]);
}
// a client: its copy of the area, and the bworld shared script's rules running on it the way client/mods.ts does
// a client: its copy of the area, and the bworld shared phase's rules running on it the way client/mods.ts does
export function client_of(game: GameServer, area: Area) {
const copy = new Map<string, [string, number]>();
for (const line of server_blocks(game, area)) {