interfaces.module
README.md
interfaces
Everything the game needs from the scene, as thirteen narrow interfaces, with a
checker the host runs once at start so a missing function is an error with a name on it and not a nil call
three minutes into play.
The game's rules (logic.game, logic.session) are engine-free and are fed plain data. `logic.driver` is the
engine-free half of the host: every tick it reads these interfaces, builds each player's frame, runs the game,
moves the Wardens, flies nothing itself (paint in the air is logic.gunplay, through `physics`), and turns hub
events into animation, sound, camera and UI calls. A scene supplies one small adapter per interface;
`metropolisGame.fake.world` supplies all thirteen over a simulated city, for tests.
They are cut where the published kits the project adopts already end (s3/notes/kits-scout.md), so each adapter
is thin: vehicles = vehiclesKit (seats, ownership, cameras) with aiDrivers driving the Wardens' cars; fx.shot =
projectileKit (a shot is replayed from its launch, not pushed every frame); interact = interactKit (the kit owns
"press E", prompts and holds; it TELLS the game what was used); dialogue = dialogueKit; save.player = saveKit
(flat keys); clock = the shared-anchor model of worldClockKit; input glyphs = controlsKit.
local Interfaces = require("metropolisGame.interfaces")
local ok, missing = Interfaces.checkAll(host) -- false, { "actors.play", ... }
Interfaces.check("actors", host.actors) Interfaces.describe("vehicles") Interfaces.names()
Interfaces.ACTIONS -- the input action names the game reads (the host's input maps bind them)
Interfaces.GESTURES -- the gestures the game asks actors to play
Interfaces.SOUNDS -- the audio events the game raises
Interfaces.SHOTS -- the staged camera shots it asks for
Conventions for every interface: positions are world metres, +x east, +z south, +y up (the engine's frame);
`{ x, y, z }` tables or engine vectors both work wherever a position is taken (fields x, y, z are read);
ids are strings the host chooses and keeps stable while the thing exists; nothing here yields.
city the generated city as the game reads it (the host adapts cityGen.query)
districtAt(x, z) -> districtId | nil one of content.districts' ids
place(id) -> { x, y, z, fx?, fz? } | nil where a place of content.places really is
walls() -> { { id, district, x, y, z, nx, nz, width, height } } paintable walls (the middle of each wall's foot,
its outward normal on the ground plane, its clear size)
roadGraph() -> { nodes = { [id] = { x, z } }, edges = { { id, a, b, class, bridge?, name? } } }
roadAt(x, z) -> { class, edge, fx, fz } | nil the road under a point (class: highway, boulevard, avenue,
street, lane, alley, stairs, path, pedestrian, track)
route(from, to, mode, avoid?) -> { { x, z } } | nil mode "car" | "foot"; avoid(edgeId) -> true to keep off an edge
fixtures(x, z, radius) -> { { id, kind, x, y, z, fx, fz, relay? } } fixed observers and relays near a point:
kind camera | curtain | lamp | callbox | doorman | searchlight
hideSpots(x, z, radius) -> { { id, kind, x, z } } doorways, bins, hedges, stalls, laundry lines
groundAt(x, z) -> y
actors people: the players' bodies, Wardens, security, passers-by, contacts
spawn(kind, at, opts) -> id kind: warden | security | watchman | inspector | plain | informer |
neighbour | guests | crew | rival | repair_crew | warden_off_duty | ...
at = { x, y, z, yaw? }; opts = { id?, count?, walks_to?, leaves?, stays? }
despawn(id)
pose(id) -> { x, y, z, fx, fz, speed, vx, vz, onGround } | nil
move(id, intent) intent = { mode, x, z, speed, hold } (pursuitKit pursuer): the host
writes its mover (CharacterController bus: Pursuer.characterBus)
play(id, gesture, opts?) one of Interfaces.GESTURES
ambient(x, z, radius) -> { { id, x, y, z, fx, fz, seed, atRelay?, relay? } } passers-by near a point (the host's
crowd); seed is a stable number the game deals their sympathies from
playerActor(playerId) -> id the body of a player
state(playerId) -> { hidden, concealment = { tag }, jacket, stand, mounted, blocked, facts = {} } what only the
body knows: in a hide spot, in a crowd, how high its feet are
above the street, why its hands are busy (blocked = "swimming" |
"climbing" | nil), extra mission facts (on_roof, aboard:tram, load)
teleport(id, at) the released stand on the steps of a post
vehicles everything with wheels (the host adapts vehiclesKit: spawn, of, enter, exit, setIntent, info)
spawn(type, at, opts) -> id type: a content.vehicles id; opts = { id?, colour?, plate?, state? }
despawn(id)
pose(id) -> { x, y, z, fx, fz, speed } | nil speed = forward metres a second
info(id) -> { type, colour, plate, state, driver = actorId | nil } state: parked | locked | occupied | lent | service
nearest(x, z, radius) -> id | nil the vehicle a player could take the wheel of
enter(id, actorId) -> boolean exit(actorId) -> boolean for AI crews and forced exits (an arrest); players
take a wheel through `interact`
driving(actorId) -> vehicleId | nil the vehicle an actor is at the wheel of now. The kit decides who
gets a seat; the driver notices the change and tells the session
drive(id, intent) AI driving: intent = { mode, x, z, speed, hold, ram?, slot?, path? }
(pursuitKit pursuer / vehiclePursuit). With aiDrivers: setPath(path
or the point), speedLimit = speed, driving = not hold. Without:
Pursuer.vehicleBus(intent, ...) gives throttle, steer, brake
setLook(id, { colour?, plate? })
stop(id, seconds) the driver cannot see: brake to a halt for that long
slide(id, seconds) its tyres are in paint: grip falls for that long
physics queries only (the same shape paintKit's ballistics take)
raycast(origin, dir, distance, exclude?) -> { x, y, z, nx, ny, nz, distance, kind, target?, part?, lx?, ly?, lz? } | nil
overlap(centre, radius) -> { { target, kind, part?, x, y, z } }
lineOfSight(from, to, exclude?) -> boolean
fx what paint looks like
splats(delta) paintKit splats' drain(): { added, changed, removed }
shot(shot) a projectile was launched: { id, x, y, z, vx, vy, vz, gravity, range,
pigment | hostile, arm }. Its flight is deterministic: replay it
(projectileKit PK.fire with logic = false)
shotEnd(id, hit | nil) it ended: on something (hit = { x, y, z, nx, ny, nz, kind, target }) or spent
mural(siteId, canvas) a canvas changed (draw fill / pigment)
effect(name, at, opts) a one-off: "muzzle", "burst", "slick", "smoke", "wash_hit", "wipe" ...
colour(drain) 0..1 how grey the player's picture is
audio events by name (Interfaces.SOUNDS), spoken lines by catalog key
play(event, at?, opts?) say(lineKey, speakerId?, opts?) radio(lineKey) music(state)
camera
aim(playerId) -> { origin = { x, y, z }, dir = { x, y, z }, site?, u?, v?, distance?, target?, yaw }
the reticle's ray, what it is on (a mural site with the point on it,
or a thing), and the camera's yaw in degrees
shot(name, subjects, seconds) a staged shot (Interfaces.SHOTS)
mode(playerId, name) "foot" | "aim" | "scope" | "vehicle" | "menu"
shake(playerId, amount)
input actions by name (Interfaces.ACTIONS), per player
held(playerId, action) -> boolean pressed(playerId, action) -> boolean (true on the tick it went down)
axis(playerId, action) -> number
glyph(playerId, action) -> any | nil (optional) what to draw for the control now in hand (controlsKit)
interact the things a player can use (interactKit: Interactable + its owner-decided request path)
offer(id, spec) make something usable: spec = { kind, at = { x, y, z } | nil, entity = id | nil,
range, hold (seconds, 0 = press), label = { key, values }, player = id | nil }
kinds: talk | shop | rest | garage | pick_up | hand_over | sketch | stash |
wardrobe | arrange. When a player uses it the host calls
driver:interacted(playerId, id)
withdraw(id)
dialogue conversations (dialogueKit; its presentation is metropolisUi's)
start(playerId, conversation, ctx) conversation: a content.talk id; ctx = { who, trust, band, facts, options? }.
The host reports picks with driver:choose(playerId, option) and
anything a line emits with driver:event(playerId, name, payload)
stop(playerId)
save the stores (logic.save's accessors: get(path, default), set(path, value), getTree(prefix))
world() -> accessor the shared store (runtime_data.world): needs getTree (a leaf per wall)
player(playerId) -> accessor | nil one player's own (runtime_data.player(id), or saveKit: get / set by
key are enough, getTree is not used; its migrations may stay off, the
tree carries its own version and logic.save migrates it)
clock
now() -> seconds monotonic time (for autosave cadence only)
shared() -> seconds | nil (optional, several players) a timeline every peer agrees on. With it the
game clock runs on an ANCHOR record, not on dt: every peer computes the same hour
anchor(record?) -> record | nil (optional) read, or as the clock's owner write, the synced anchor record
{ t0, total0, dayMinutes }
owner() -> boolean (optional) whether this peer may write the anchor
ui metropolisUi's app
setHud(playerId, view) show(playerId, screen, data) hide(playerId, screen) notify(playerId, note)
banner(playerId, data)
The interface is documented in the header of init.luau; this file repeats it for the asset browser.