sharing contexts
This commit is contained in:
+5
-3
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user