Skip to main content

lib/module

Angular-style module registration system.

This module provides a declarative way to register modules with their services, lifecycle hooks, and dependencies. Services are automatically instantiated and registered with the RPC system.

Usage

// modules/spawning/module.ts
import { registerModule } from "@core/module";
import { SpawnService } from "@modules/spawning/spawn.service";

export default registerModule({
name: "spawning",
services: [SpawnService],
dependencies: ["characters"],
});

Then in the runtime:

// runtime/client/main.ts
import spawningModule from "@modules/spawning/module";
import needsModule from "@modules/needs/module";

const MODULES = [spawningModule, needsModule];

Service Classes

Services use RPC decorators for client/server communication:

// spawn.service.ts
export class SpawnService {
@Server
async playerLoaded(ctx: EventContext<[]>) {
// Runs on server, callable from client
}

@Client
async onSpawned(ctx: EventContext<[position: Vector3]>) {
const [position] = ctx.args;
// Runs on client, callable from server
}
}

Interfaces

InterfaceDescription
ModuleModule handle returned by registerModule. This is what gets exported from each module and imported by the runtime.
ModuleConfigModule configuration options.
ModuleHandleModule handle provided to lifecycle hooks.

Type Aliases

Type AliasDescription
FeatureImportUI feature lazy import type. The import should return a module with a default export containing FeatureOptions.
FeatureRegistryRegistry of UI features keyed by route/id.
ServiceClassConstructor type for service classes.

Functions

FunctionDescription
registerModuleRegister a module with its services and lifecycle hooks.
sortModulesByDependenciesSort modules by dependencies using topological sort. Throws if circular dependencies are detected.