Implementation:AIScientists Dev WorldSeed map layout
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Layout |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete map layout engine for collage-style zone positioning, entity categorization, and connection line computation, driven entirely by scene type config with zero hardcoded entity types, provided by the WorldSeed frontend.
Description
The map-layout module computes the world map's visual structure. `computeMapData` categorizes entities into zones (containers), items, agents (located within zones), and free entities using UI config bindings. `collageStyle`/`autoLayoutStyle` produce absolute-positioned CSS for each zone — explicit layout config takes priority; otherwise a deterministic hash-based auto-layout places zones in a 3-column staggered grid with jitter. `entityPosInZone` computes grid positions for items within zones using density-aware spacing. `computeConnections` builds line segments between connected zones. `hashStr` provides deterministic random values for stable placement.
Usage
Import this module from `MapView` and overlay components to compute zone positions, entity placement, and connection lines. Call `clearAutoLayoutCache()` when switching runs.
Code Reference
Source Location
- Repository: WorldSeed
- File: frontend/src/lib/map-layout.ts
Signature
export function computeMapData(entities: any[]): MapData;
export function collageStyle(entityId: string, layout: Record<string, any>, index: number): Record<string, any>;
export function autoLayoutStyle(entityId: string, index: number): Record<string, any>;
export function entityPosInZone(entityIndex: number, totalEntities: number, zoneId: string, maxCardW?: number): { left: string; top: string };
export function computeConnections(zones: { entity: any; bind: any }[], layout: Record<string, any>): { x1: number; y1: number; x2: number; y2: number }[];
export function clearAutoLayoutCache(): void;
export function hashStr(s: string): number;
Import
import { computeMapData, collageStyle, entityPosInZone, computeConnections, clearAutoLayoutCache } from '@/lib/map-layout';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| entities | any[] | Yes │ Entity array from world store | |
| layout | Record<string, any> | No │ UI config layout entries | |
| entityId | string | Yes │ Entity ID for deterministic hashing | |
| index | number | Yes │ Fallback grid index |
Outputs
| Name | Type | Description |
|---|---|---|
| computeMapData returns | MapData │ Zones, items (by zone), agents (by zone), free entities | |
| collageStyle returns | CSS props │ Absolute position + rotation + z-index | |
| computeConnections returns | line[] │ x1/y1/x2/y2 segments |
Usage Examples
import { computeMapData, collageStyle, computeConnections } from '@/lib/map-layout';
const mapData = computeMapData(entities);
// mapData.zones = [{ entity, bind }]
// mapData.agents["town"] = [agent1, agent2]
const style = collageStyle(zone.id, uiConfig.layout, 0);
// { position: 'absolute', left: '60px', top: '40px', ... }
const lines = computeConnections(mapData.zones, uiConfig.layout);