Implementation:AIScientists Dev WorldSeed ui config
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Configuration |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete reactive singleton UI config loader with scene type registry and rule matching, providing zero-hardcoded entity types, provided by the WorldSeed frontend.
Description
The uiConfig singleton loads `.ui.json` config files per scene ID and exposes rule-matching methods. `load(sceneId)` fetches `/configs/{sceneId}.ui.json` and populates `rules`, `events`, `eventDefaults`, `layout`, and `assetPack`. On failure, it falls back to `DEFAULT_CONFIG` (degraded mode: agents get avatar with `locate_by`, everything else gets a card). `findRule(entity)` matches by `id` and `type` against config rules. `getSceneType` maps scene names to `SceneType` (container/agent/item/free/hidden) via `SCENE_TYPES`. `getEventStyle`/`getEventEffect` look up event bubble/effect styles. `assetUrl`/`vignetteUrl`/`avatarUrl` build asset paths.
Usage
Import `uiConfig` from layout, map, and overlay modules. Call `uiConfig.load(sceneId)` before rendering entities. Use `getBind`/`getSceneType`/`getEventStyle` for entity classification and event rendering.
Code Reference
Source Location
- Repository: WorldSeed
- File: frontend/src/lib/ui-config.ts
Signature
export const uiConfig: {
rules: UIRule[];
events: UIEventStyle[];
layout: Record<string, { x: number; y: number; w: number; h: number; rotation?: number; z?: number }>;
loaded: boolean;
load(sceneId: string): Promise<boolean>;
findRule(entity: any): UIRule;
getBind(entity: any): Record<string, any>;
getSceneName(entity: any): string;
getSceneType(entity: any): SceneType;
getEventStyle(eventType: string): string;
assetUrl(entity: any): string;
avatarUrl(entity: any): string;
};
Import
import { uiConfig } from '@/lib/ui-config';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| sceneId | string | Yes (load) │ Scene ID to load config for | |
| entity | any | Yes (rule lookups) │ Entity with id and type | |
| eventType | string | Yes (event lookups) │ Event type to match |
Outputs
| Name | Type | Description |
|---|---|---|
| load returns | Promise<boolean> │ True on success (always, even degraded) | |
| getBind returns | Record<string, any> │ Bind config (locate_by, connections, etc.) | |
| getSceneType returns | SceneType │ Role + assetDir for rendering |
Usage Examples
import { uiConfig } from '@/lib/ui-config';
// Load config when run starts
await uiConfig.load('teahouse');
// Classify an entity
const bind = uiConfig.getBind(entity);
const sceneType = uiConfig.getSceneType(entity);
// sceneType = { role: 'container', assetDir: 'entities' }
// Get event bubble style
const bubble = uiConfig.getEventStyle('god_announce');
// 'speech'