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
| Interface | Description |
|---|---|
| HudDefinition | HUD feature definition. |
| Module | Module handle returned by registerModule. This is what gets exported from each module and imported by the runtime. |
| ModuleConfig | Module configuration options. |
| ModuleHandle | Module handle provided to lifecycle hooks. |
| PageDefinition | Page feature definition. |
Type Aliases
| Type Alias | Description |
|---|---|
| HudPosition | Grid position for HUD features. |
| ServiceClass | Constructor type for service classes. |
Functions
| Function | Description |
|---|---|
| registerModule | Register a module with its services and lifecycle hooks. |
| sortModulesByDependencies | Sort modules by dependencies using topological sort. Throws if circular dependencies are detected. |