Skip to content

core/universe/contract.ts ​

Generated from the exports of core/universe/contract.ts · npm run docs:gen

The universe contract: what a universe folder (universes/<id>/) must provide, and how the core reads it. A universe gives words, colours, texts and a renderer. It never changes the state, the quests or the rules.

Standards that cite this file: alta.universe/0.1: universe packs

Exports ​

Term interface ​

ts
interface Term { label: string; gloss?: string }

UniverseManifest interface ​

ts
interface UniverseManifest {
  id: string;
  /** Position in the switcher; the lowest opens first. */
  order: number;
  name: string;
  tagline: string;
  version: string;
  languages: string[];
  fonts: { display: string; body: string };
  /** Words that only this universe uses. The core, the content and the client must never contain them (tested). */
  distinctive: string[];
}

Vocabulary interface ​

ts
interface Vocabulary {
  kinds: Record<EntityKind, Term>;
  roles: Record<AgentRole, Term & { creature: string }>;
  /** Name of the player's avatar when it has no name yet, and of a level and of xp. */
  avatar: Term;
  level: Term;
  xp: Term;
  /** The edge of the world where devices and accounts sit, and the whole world. */
  edge: Term;
  world: Term;
}

Palette type ​

ts
type Palette = Record<"bg" | "bg2" | "ink" | "muted" | "accent" | "ok" | "warn" | "bad" | "mock" | "panel" | "panelInk" | "line", string>;

Copy type ​

ts
type Copy = Record<string, string | string[]>;

Camera interface ​

ts
interface Camera { x: number; y: number; w: number; h: number; zoom: number }

Draw interface ​

ts
interface Draw {
  ctx: CanvasRenderingContext2D;
  /** Seconds since start. */
  t: number;
  palette: Palette;
}

Renderer interface ​

ts
interface Renderer {
  /** Draws the ground of the world, in world coordinates (the camera transform is already applied). */
  background(d: Draw, cam: Camera, layout: Layout, world: WorldState): void;
  link(d: Draw, a: Placed, b: Placed, kind: "flow" | "cycle" | "control"): void;
  /** Draws one entity at (p.x, p.y). `pulse` is 0..1, the phase of its rhythm for automations. */
  entity(d: Draw, p: Placed, focus: boolean, pulse: number): void;
  avatar(d: Draw, x: number, y: number, facing: number, moving: boolean): void;
  /** Optional layer above everything (light, fog, particles), in world coordinates. */
  foreground?(d: Draw, cam: Camera, layout: Layout): void;
}

Universe interface ​

ts
interface Universe {
  manifest: UniverseManifest;
  vocabulary: Vocabulary;
  palette: Palette;
  copy: Record<string, Copy>;
  renderer: Renderer;
  /** Optional stylesheet for the interface, applied only while the universe is active. */
  skin?: string;
  /** Optional guided onboarding of this world (alta.onboarding/0.1, see core/onboarding). */
  onboarding?: unknown;
  /** Optional scenes of this world (alta.cinematics/0.1, see core/cinematics). */
  cinematics?: unknown;
}

UniverseError class ​

ts
class UniverseError extends Error { … }

checkUniverse function ​

Checks a universe against the contract; returns the list of problems (empty when it holds).

ts
function checkUniverse(u: Universe): string[]

text function ​

A text of the active universe, else the neutral text, else the key itself (visible, so a gap is never hidden).

ts
function text(key: string, universe: Copy | undefined, neutral: Copy, vars: Record<string, string> = {}): string

The standard, the SDK and the CLI are Apache-2.0; Alta System OS and Alta World are FSL-1.1-ALv2.