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
| Interface | Description |
|---|---|
| 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. |
Type Aliases
| Type Alias | Description |
|---|---|
| FeatureImport | UI feature lazy import type. The import should return a module with a default export containing FeatureOptions. |
| FeatureRegistry | Registry of UI features keyed by route/id. |
| 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. |