feat(ludic.inventory, ludic.wallet): the pack and the purse as mechanic packages

ludic.inventory: counts per item kind, a PackRules port (stack_limit), add
what fits / take all or none / set outright, an ItemChanged queue, and a save
section keyed by item NAME so a game can reorder its items with no migration.
ludic.wallet: earn, spend only what is there, lose down to zero, set, a
MoneyChanged queue and its own save section. Six and five test blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 04:29:17 +03:00
parent 6cfaaf0bf9
commit 8075892e0e
12 changed files with 445 additions and 0 deletions

View file

@ -0,0 +1,38 @@
# verbs.ludic - the only way a count changes, and each change is said once
function iv_change(it: int, after: int) -> void {
let before = iv_counts[it]
if before == after { return }
iv_counts[it] = after
let c = new ItemChanged
c.item = it
c.before = before
c.after = after
q_push(inv_changes(), c)
}
# as many of n as there is room for; returns how many went in
export function inv_add(it: int, n: int) -> int {
if not iv_valid(it) or n <= 0 { return 0 }
let k = Math.min(n, inv_room(it))
if k > 0 { iv_change(it, iv_counts[it] + k) }
return k
}
# all n or none
export function inv_take(it: int, n: int) -> bool {
if not iv_valid(it) or iv_counts[it] < n { return false }
if n > 0 { iv_change(it, iv_counts[it] - n) }
return true
}
# a count outright, room or not (a starting kit, a correction, the network's word); never below 0
export function inv_set(it: int, n: int) -> void {
if not iv_valid(it) { return }
iv_change(it, Math.max(n, 0))
}
# everything gone, silently: a new trip, or before a load
export function inv_clear() -> void {
iv_counts = new []int
for i in 0 .. inv_kinds() { push(iv_counts, 0) }
}