sharing contexts

This commit is contained in:
2026-11-14 13:49:21 -03:00
parent 313098892e
commit a69db0cd2a
13 changed files with 192 additions and 208 deletions
+5 -3
View File
@@ -16,13 +16,15 @@ export class FluidRules {
// run runs a mod's code, reporting what it throws instead of letting it take the game down
constructor(readonly run: <T>(mod: string, what: string, fn: () => T) => T | undefined) {}
// checked by the shared context, see common/shared_context.ts
register(mod: string, id: string, rules: Rules) {
if (!id.startsWith(`${mod}:`)) throw new Error(`[${mod}] fluid ${id} must be in the namespace "${mod}"`);
if (!EverythingRegistry.get("fluids", id)) throw new Error(`[${mod}] unknown fluid ${id}`);
if (this.#rules.has(id)) throw new Error(`[${mod}] the rules of fluid ${id} are registered twice`);
this.#rules.set(id, { mod, rules });
}
has(id: string) {
return this.#rules.has(id);
}
name(fluid: FluidVariant): string {
const json = known_fluid(fluid.id);
const valid = (value: unknown): value is string => typeof value === "string" && value.length > 0;