Single module modding
This commit is contained in:
+10
-19
@@ -1,8 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// starts a game server with its mods: registers their data, then imports worldgen and server scripts.
|
||||
// the worker loads built mods, tests can load mods straight from their source folders
|
||||
// starts a game server with its mods: registers their data, then runs the worldgen, shared and server phases of their
|
||||
// scripts. the worker loads built mods, tests can load mods straight from their source folders
|
||||
import { register_mod_data } from "@/common/mod_loader.ts";
|
||||
import type { ModData, ModListing } from "@/common/mod_loader.ts";
|
||||
import { load_worldgen } from "@/common/worldgen_loader.ts";
|
||||
@@ -22,10 +22,8 @@ import { server_engine } from "./engine_modules.ts";
|
||||
export interface ServerModSource {
|
||||
listing: ModListing;
|
||||
data: ModData;
|
||||
// importable urls of the scripts: data: urls in the worker, file urls in tests
|
||||
server_url?: string;
|
||||
worldgen_url?: string;
|
||||
shared_url?: string;
|
||||
// importable url of its script: a data: url in the worker, a file url in tests
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export async function start_game(
|
||||
@@ -47,9 +45,7 @@ export async function start_game(
|
||||
const generator = dimension.generator;
|
||||
const shape = dimension_shape(dimension);
|
||||
const worldgen_scripts = mods.flatMap((mod) =>
|
||||
mod.worldgen_url
|
||||
? [{ mod: mod.listing.id, url: mod.worldgen_url, engine_access: mod.listing.engine_access }]
|
||||
: []
|
||||
mod.url ? [{ mod: mod.listing.id, url: mod.url, engine_access: mod.listing.engine_access }] : []
|
||||
);
|
||||
const worldgen = await load_worldgen({
|
||||
mods: mods.map((mod) => mod.listing.id),
|
||||
@@ -72,15 +68,10 @@ export async function start_game(
|
||||
runtime,
|
||||
});
|
||||
|
||||
// every mod's shared rules first, so server scripts can count on any mod's being there
|
||||
await runtime.load_shared_scripts(
|
||||
game,
|
||||
mods.flatMap((mod) => mod.shared_url ? [{ ...script_of(mod), url: mod.shared_url }] : []),
|
||||
);
|
||||
await runtime.load_scripts(
|
||||
game,
|
||||
mods.flatMap((mod) => mod.server_url ? [{ ...script_of(mod), url: mod.server_url }] : []),
|
||||
);
|
||||
const scripts = mods.flatMap((mod) => mod.url ? [{ ...script_of(mod), url: mod.url }] : []);
|
||||
// every mod's shared rules first, so server phases can count on any mod's being there
|
||||
await runtime.load_shared_scripts(game, scripts);
|
||||
await runtime.load_scripts(game, scripts);
|
||||
runtime.finish_setup();
|
||||
game.find_ticking_tiles();
|
||||
// what a worldgen worker needs to generate the same chunks, see worldgen_pool.ts
|
||||
@@ -91,7 +82,7 @@ export async function start_game(
|
||||
mods.map((mod) => ({
|
||||
id: mod.listing.id,
|
||||
data: mod.data,
|
||||
worldgen_url: mod.worldgen_url,
|
||||
url: mod.url,
|
||||
engine_access: mod.listing.engine_access,
|
||||
})),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user