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>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 05:36:11 +03:00
parent f4062010e9
commit 63e29f024c
31 changed files with 130 additions and 149 deletions

View file

@ -20,7 +20,7 @@ good as walking a trail.
## The port
```ludic
property TracksWorld {
export port TracksWorld { # every member has a default, so any may be left out
now: fn() -> float # game hours counted from the start of the trip (unbound: 0)
skill: fn() -> int # the reader's tier; at tracks_config_reading's name_at it names the animal
bearing: fn(float) -> string # a yaw in words, "" for none (a reader with no compass)
@ -28,11 +28,17 @@ property TracksWorld {
}
```
The game fills it once, where it is put together - a declaration, not a call:
```ludic
bind TracksWorld { now: fn rt_trip_hours, skill: fn track_skill, bearing: fn track_bearing, placed: fn track_mark_placed }
```
## API
| | |
| --- | --- |
| `tracks_bind(w)`, `tracks_config(kinds, cap)`, `tracks_config_reading(name_at, fresh, recent)` | the port; how many kinds and how many prints of each; the skill that names the animal and the ages (hours) under which a print is fresh or recent |
| `bind TracksWorld { ... }`, `tracks_config(kinds, cap)`, `tracks_config_reading(name_at, fresh, recent)` | the port; how many kinds and how many prints of each; the skill that names the animal and the ages (hours) under which a print is fresh or recent |
| `tracks_leave(kind, x, z, yaw, sp, legend) -> int`, `tracks_leave_at(..., made)` | a print, now or at another machine's time; returns its ring index |
| `tracks_clear()` | the ground forgets every print (a new world); the reader keeps what it learned |
| `tracks_nearest(x, z, r) -> int` | the nearest print within `r`, as a slot (`kind * cap + index`), or -1 |

View file

@ -22,16 +22,13 @@ export function tracks_config_reading(name_at: int, fresh: float, recent: float)
}
function tk_now() -> float {
if tk_world == null or tk_world.now == null { return 0.0 }
return tk_world.now()
return TracksWorld.now()
}
function tk_named() -> bool {
if tk_world == null or tk_world.skill == null { return true }
return tk_world.skill() >= tk_name_at
return TracksWorld.skill() >= tk_name_at
}
function tk_bearing(yaw: float) -> string {
if tk_world == null or tk_world.bearing == null { return "" }
return tk_world.bearing(yaw)
return TracksWorld.bearing(yaw)
}

View file

@ -1,6 +1,6 @@
# ludic.tracks - a ring of prints per kind, each remembering who left it, which way it went and
# when; reading one is a fact on a queue, and the game draws them through a hook
module ludic_tracks
module ludic_tracks uses ludic_base
numbers float
import "ludic.base"
import "state.ludic"

View file

@ -19,7 +19,7 @@ export function tracks_leave_at(kind: int, x: float, z: float, yaw: float, sp: i
t.legend = legend
t.made = made
t.read = false
if tk_world != null and tk_world.placed != null { tk_world.placed(kind, i) }
TracksWorld.placed(kind, i)
return i
}

View file

@ -1,12 +1,16 @@
# state.ludic - the port, the prints, the facts, and what the reader has learned
# what the tracks ask the world. Any field may be left null: the time is then 0, the reader
# can name every animal, no bearing is given, and nothing is drawn.
export property TracksWorld {
now: fn() -> float = null # game hours, counted from the start of the trip
skill: fn() -> int = null # how well the reader reads (the game's tiers)
bearing: fn(float) -> string = null # a yaw in words ("north-west"), "" for none
placed: fn(int, int) -> void = null # a print was put down at (kind, ring index): draw it
# what the tracks ask the world. Any member may be left out of the bind: the time is then 0,
# the reader can name every animal, no bearing is given, and nothing is drawn.
export port TracksWorld {
now: fn() -> float = fn tk_time_zero # game hours, counted from the start of the trip
skill: fn() -> int = fn tk_every_skill # how well the reader reads (the game's tiers)
bearing: fn(float) -> string = fn tk_no_bearing # a yaw in words ("north-west"), "" for none
placed: fn(int, int) -> void = fn tk_not_drawn # a print was put down at (kind, ring index): draw it
}
function tk_time_zero() -> float { return 0.0 }
function tk_every_skill() -> int { return 2147483647 }
function tk_no_bearing(yaw: float) -> string { return "" }
function tk_not_drawn(kind: int, i: int) -> void { }
# where a sign came from
export const TRACK_PRINT: int = 0 # a print in a ring, read with tracks_read
@ -43,7 +47,6 @@ export property TrackRead {
first: bool = false
}
var tk_world: TracksWorld = null
var tk_kinds: int = 0
var tk_cap: int = 0
var tk_ring: []Track = null # kinds x cap, kind-major
@ -57,7 +60,6 @@ var tk_yaw: float = 0.0 # the heading of the last sign read
var tk_has_yaw: bool = false
var tk_reads: Queue<TrackRead> = null
export function tracks_bind(w: TracksWorld) -> void { tk_world = w }
# the facts: every sign read, oldest first
export function tracks_reads() -> Queue<TrackRead> {

View file

@ -21,17 +21,13 @@ program TracksTest {
placed_last = i
}
bind TracksWorld { now: fn fake_now, skill: fn fake_skill, bearing: fn fake_bearing, placed: fn fake_placed }
function fresh() -> void {
now = 10.0
skill = 1
placed_n = 0
placed_last = -1
let w = new TracksWorld
w.now = fn fake_now
w.skill = fn fake_skill
w.bearing = fn fake_bearing
w.placed = fn fake_placed
tracks_bind(w)
tracks_config(3, 4)
tracks_config_reading(1, 0.5, 2.5)
tracks_reset()