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

@ -16,16 +16,18 @@ longer knows is dropped on load.
## The port
```ludic
property PackRules {
stack_limit: fn(int) -> int # how many of a kind fit (unbound: no limit)
export port PackRules {
stack_limit: fn(int) -> int = ... # how many of a kind fit (unbound: no limit)
}
```
The game fills it once, where it is put together: `bind PackRules { stack_limit: fn gear_stack }`.
## API
| | |
| --- | --- |
| `inv_bind(r)`, `inv_config(keys)` | the port, and the kinds by name (the pack starts empty) |
| `bind PackRules { ... }`, `inv_config(keys)` | the port (a declaration), and the kinds by name (the pack starts empty) |
| `inv_add(it, n) -> int` | as many of `n` as there is room for; returns how many went in |
| `inv_take(it, n) -> bool` | all `n` or none |
| `inv_set(it, n)` | a count outright, room or not (a starting kit, a correction, the network's word); never below 0 |

View file

@ -1,6 +1,6 @@
# ludic.inventory - one pack of counts by item kind: the game names the kinds (so the save is by
# name, never by position) and answers how many of one fit; every change is a fact on a queue
module ludic_inventory
module ludic_inventory uses ludic_base
numbers float
import "ludic.base"
import "state.ludic"

View file

@ -1,8 +1,9 @@
# state.ludic - the pack's port, its facts, and its counts
# what the pack asks the game: how many of a kind fit (unbound: no limit)
export property PackRules {
stack_limit: fn(int) -> int = null
export port PackRules {
stack_limit: fn(int) -> int = fn iv_no_limit
}
function iv_no_limit(it: int) -> int { return 2147483647 }
# a count changed, however: added, taken, or set outright
export property ItemChanged {
@ -11,13 +12,10 @@ export property ItemChanged {
after: int = 0
}
var iv_rules: PackRules = null
var iv_keys: []string = null
var iv_counts: []int = null
var iv_changes: Queue<ItemChanged> = null
export function inv_bind(r: PackRules) -> void { iv_rules = r }
# the kinds, by the name each is saved under; the pack starts empty
export function inv_config(keys: []string) -> void {
iv_keys = keys
@ -42,8 +40,7 @@ export function inv_count(it: int) -> int {
}
export function inv_limit(it: int) -> int {
if iv_rules == null or iv_rules.stack_limit == null { return 2147483647 }
return iv_rules.stack_limit(it)
return PackRules.stack_limit(it)
}
# how many more fit

View file

@ -21,10 +21,9 @@ program InventoryTest {
return k
}
bind PackRules { stack_limit: fn limit }
function fresh() -> void {
let r = new PackRules
r.stack_limit = fn limit
inv_bind(r)
inv_config(names("wood", "rod", "fish"))
inv_reset()
}