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/core/spawning/spawn.service";
 
export default registerModule({
    name: "spawning",
    services: [SpawnService],
    dependencies: ["characters"],
});

Then in the runtime:

// runtime/client/main.ts
import spawningModule from "@modules/core/spawning/module";
import needsModule from "@modules/core/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
HudDefinitionHUD feature definition.
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.
PageDefinitionPage feature definition.

Type Aliases

Type AliasDescription
HudPositionGrid position for HUD features.
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.