ludic/packages/ludic.clock/state.ludic
Orkuncakilkaya 63e29f024c refactor(packages): the mechanic packages use ludic_base only, and ask through ports
ludic.clock, .effects, .inventory, .wallet, .weather and .tracks say
'uses ludic_base' (ludic.base uses nothing). ClockWorld, PackRules,
WeatherWorld and TracksWorld are export ports whose defaults are the old
fallbacks; clock_bind, inv_bind, weather_bind and tracks_bind are gone,
and the tests bind their fakes. The base README's toy does the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 05:36:11 +03:00

58 lines
1.9 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
# (unbound: this machine runs it, nobody rests, and a seed of 1)
export port ClockWorld {
owns_world: fn() -> bool = fn ck_owns_alone
rest_scale: fn() -> float = fn ck_no_rest
seed: fn() -> int = fn ck_seed_one
}
function ck_owns_alone() -> bool { return true }
function ck_no_rest() -> float { return 1.0 }
function ck_seed_one() -> int { return 1 }
# 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_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
# 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 { return ClockWorld.owns_world() }
function ck_rest() -> float { return ClockWorld.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
}