clock.module
README.md
clock
The city's day: hours that pass, and the moments other systems wait for.
local Clock = require("metropolisGame.logic.clock")
local clock = Clock.new({ dayMinutes = 36, start = 5.5, dawn = 6, dusk = 20, blend = 1 }, hub?)
clock:tick(dt) -- real seconds; returns the hours crossed this tick, e.g. { 6 } (empty most ticks)
clock.hour clock.day -- 0..24 and days since the start (0-based)
clock:weekday() -- 1..7 (day 0 is weekday 1)
clock:phase() -- "dawn" | "day" | "dusk" | "night"
clock:isNight() clock:text() -> "06:15"
clock:skipTo(22) -- rest until an hour (crosses the hours between; returns them)
clock:set(hour) -- a mission sets the scene (no hours are "crossed")
clock:secondsUntil(6) -- real seconds until an hour next comes round
clock:serialise() clock:restore(data)
Several players, one clock (the shared-anchor model): nobody ticks. The clock's owner publishes an ANCHOR record
and every peer computes the hour from it and a timeline they all agree on, so nothing drifts:
local record = clock:anchor(sharedNow) -- { t0, total0, dayMinutes } for the host to sync (owner only)
clock:follow(record, sharedNow) -- every peer, every tick: advances to where the record says (hours
-- crossed fire as usual); returns the hours crossed
clock.moved -- true after skipTo / set / restore: the owner publishes a new anchor
Hub events: "hour" { hour, day }, "dayPassed" { day } (at midnight).
The interface is documented in the header of init.luau; this file repeats it for the asset browser.