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
+9 -8
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// 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
// dependencies load first, and with the copy players download (the same mod without its server phase) ready to serve
import { join } from "@std/path";
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";
@@ -104,16 +104,17 @@ export async function load_mods(
}));
}
// runs the mods' content 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
// 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
async function add_registered_content(mods: { file: string; mod: Mod }[], problems: string[]) {
const with_scripts = mods.filter(({ mod }) => mod.scripts.content !== undefined);
const with_scripts = mods.filter(({ mod }) => mod.script !== undefined);
if (with_scripts.length === 0) return;
const scripts: ContentScriptCode[] = with_scripts.map(({ mod }) => ({
mod: mod.manifest.id,
version: mod.manifest.version,
code: mod.scripts.content!,
engine_access: mod.manifest.engine_access,
code: mod.script!,
}));
const worker = new Worker(new URL("./content_worker.ts", import.meta.url), {
type: "module",
@@ -125,7 +126,7 @@ async function add_registered_content(mods: { file: string; mod: Mod }[], proble
worker.onmessage = (event) => resolve(event.data);
worker.onerror = (event) => {
event.preventDefault();
reject(new Error(`content scripts: ${event.message}`));
reject(new Error(`content phases: ${event.message}`));
};
worker.postMessage(scripts);
});
@@ -134,7 +135,7 @@ async function add_registered_content(mods: { file: string; mod: Mod }[], proble
}
with_scripts.forEach(({ file, mod }, i) => {
mod.data.blocks.push(...results[i].blocks);
problems.push(...results[i].problems.map((problem) => `${file}: ${mod.manifest.scripts!.content}: ${problem}`));
problems.push(...results[i].problems.map((problem) => `${file}: ${mod.manifest.main}: ${problem}`));
});
}