Engine api
This commit is contained in:
@@ -9,6 +9,9 @@ import { ModRuntime } from "./mod_runtime.ts";
|
||||
import { register_entity_type } from "./entity/entity_types.ts";
|
||||
import { mod_entity_factory } from "./entity/mod_entity.ts";
|
||||
import { set_effect_types } from "./entity/effects.ts";
|
||||
import { clear_hooks, expose_engine } from "$/common/hooks.ts";
|
||||
import { common_engine } from "$/common/engine_modules.ts";
|
||||
import { server_engine } from "./engine_modules.ts";
|
||||
|
||||
export interface ServerModSource {
|
||||
listing: ModListing;
|
||||
@@ -25,13 +28,19 @@ export async function start_game(
|
||||
default_seed: string,
|
||||
mods: ServerModSource[],
|
||||
): Promise<GameServer> {
|
||||
// for engine access mods. the last game's hooks go first, a realm only runs one game at a time
|
||||
clear_hooks();
|
||||
expose_engine({ common: common_engine(), server: server_engine() });
|
||||
|
||||
const recipes = register_mod_data(mods.map((mod) => ({ id: mod.listing.id, data: mod.data })));
|
||||
for (const mod of mods) {
|
||||
for (const json of mod.data.entities) register_entity_type(json.id, mod_entity_factory(json));
|
||||
}
|
||||
|
||||
const worldgen_scripts = mods.flatMap((mod) =>
|
||||
mod.worldgen_url ? [{ mod: mod.listing.id, url: mod.worldgen_url }] : []
|
||||
mod.worldgen_url
|
||||
? [{ mod: mod.listing.id, url: mod.worldgen_url, engine_access: mod.listing.engine_access }]
|
||||
: []
|
||||
);
|
||||
const worldgen = await load_worldgen(worldgen_scripts, recipes.ores);
|
||||
|
||||
@@ -48,15 +57,11 @@ export async function start_game(
|
||||
// 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 ? [{ mod: mod.listing.id, version: mod.listing.version, url: mod.shared_url }] : []
|
||||
),
|
||||
mods.flatMap((mod) => mod.shared_url ? [{ ...script_of(mod), url: mod.shared_url }] : []),
|
||||
);
|
||||
await runtime.load_scripts(
|
||||
game,
|
||||
mods.flatMap((mod) =>
|
||||
mod.server_url ? [{ mod: mod.listing.id, version: mod.listing.version, url: mod.server_url }] : []
|
||||
),
|
||||
mods.flatMap((mod) => mod.server_url ? [{ ...script_of(mod), url: mod.server_url }] : []),
|
||||
);
|
||||
runtime.finish_setup();
|
||||
runtime.after.server_start.emit({});
|
||||
@@ -64,6 +69,10 @@ export async function start_game(
|
||||
return game;
|
||||
}
|
||||
|
||||
function script_of(mod: ServerModSource) {
|
||||
return { mod: mod.listing.id, version: mod.listing.version, engine_access: mod.listing.engine_access ?? false };
|
||||
}
|
||||
|
||||
export function data_url(code: string) {
|
||||
const bytes = new TextEncoder().encode(code);
|
||||
let binary = "";
|
||||
|
||||
Reference in New Issue
Block a user