Engine api

This commit is contained in:
2026-10-06 20:27:17 -03:00
parent d13938550d
commit 69c5c187db
27 changed files with 1026 additions and 90 deletions
+13 -7
View File
@@ -3,11 +3,15 @@ import type { WorldgenContext } from "$/common/mod_api/worldgen.ts";
import type { OreJson } from "$/common/mod_data.ts";
import type { WorldgenSetup } from "./generation.ts";
import { ModLoadError } from "./mod_loader.ts";
import { loading_mod } from "./hooks.ts";
export async function load_worldgen(scripts: { mod: string; url: string }[], ores: OreJson[]): Promise<WorldgenSetup> {
export async function load_worldgen(
scripts: { mod: string; url: string; engine_access?: boolean }[],
ores: OreJson[],
): Promise<WorldgenSetup> {
const setup: WorldgenSetup = { ores, features: [] };
for (const { mod, url } of scripts) {
for (const { mod, url, engine_access } of scripts) {
const ctx: WorldgenContext = {
register_feature(id, generate) {
if (!id.startsWith(`${mod}:`)) {
@@ -26,11 +30,13 @@ export async function load_worldgen(scripts: { mod: string; url: string }[], ore
},
};
const module = await import(url);
if (typeof module.setup !== "function") {
throw new ModLoadError(mod, "the worldgen script doesn't export a setup function");
}
await module.setup(ctx);
await loading_mod(mod, engine_access ?? false, async () => {
const module = await import(url);
if (typeof module.setup !== "function") {
throw new ModLoadError(mod, "the worldgen script doesn't export a setup function");
}
await module.setup(ctx);
});
}
return setup;