A ClockWorld port (owns_world, rest_scale, seed), verbs to set and advance it, clock_new_day, a DayTurned queue (stayed up past midnight, or slept), a calendar whose month, year and season are pure functions of the day, and a System (PH_INPUT) with its own save section. Nine test blocks in tests/clock_test.ludic with fakes for the port. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
2 KiB
Text
63 lines
2 KiB
Text
# state.ludic - the clock's port, its facts, and what it holds
|
|
# what the clock asks the world: whether this machine runs it, how much the rest speeds it (1 when
|
|
# nobody rests), and a seed for a new trip's moon
|
|
export property ClockWorld {
|
|
owns_world: fn() -> bool = null
|
|
rest_scale: fn() -> float = null
|
|
seed: fn() -> int = null
|
|
}
|
|
|
|
# how a day turned: the hour ran past midnight, or a verb turned it (a night slept, a collapse)
|
|
export const DAY_STAYED_UP: int = 0
|
|
export const DAY_SLEPT: int = 1
|
|
|
|
export property DayTurned {
|
|
day: int = 0
|
|
how: int = 0
|
|
}
|
|
|
|
var ck_world: ClockWorld = null
|
|
var ck_day: int = 1
|
|
var ck_hours: float = 0.0
|
|
var ck_moon: float = 0.0
|
|
var ck_scale: float = 60.0 # game seconds per real second
|
|
var ck_start_hours: float = 8.0
|
|
var ck_night_from: float = 20.0
|
|
var ck_night_to: float = 6.0
|
|
var ck_moon_days: float = 29.5
|
|
var ck_moon_lo: float = 0.0
|
|
var ck_moon_hi: float = 1.0
|
|
var ck_dice: Rng = null
|
|
var ck_days: Queue<DayTurned> = null
|
|
|
|
export function clock_bind(w: ClockWorld) -> void { ck_world = w }
|
|
|
|
# the facts: each day that turned, in order; the game drains it and runs its morning
|
|
export function clock_days() -> Queue<DayTurned> {
|
|
if ck_days == null { ck_days = queue_new("clock.days") }
|
|
return ck_days
|
|
}
|
|
|
|
function ck_owns() -> bool {
|
|
if ck_world == null or ck_world.owns_world == null { return true }
|
|
return ck_world.owns_world()
|
|
}
|
|
|
|
function ck_rest() -> float {
|
|
if ck_world == null or ck_world.rest_scale == null { return 1.0 }
|
|
return ck_world.rest_scale()
|
|
}
|
|
|
|
# when a trip starts, when the night is, and how long the moon's month is
|
|
export function clock_config(start_hours: float, night_from: float, night_to: float) -> void {
|
|
ck_start_hours = start_hours
|
|
ck_night_from = night_from
|
|
ck_night_to = night_to
|
|
}
|
|
|
|
# a new trip's moon falls in [lo, hi) of its month; the month is `days` long
|
|
export function clock_config_moon(days: float, lo: float, hi: float) -> void {
|
|
ck_moon_days = days
|
|
ck_moon_lo = lo
|
|
ck_moon_hi = hi
|
|
}
|