ludic/packages/ludic.inventory
2026-09-28 20:03:46 +03:00
..
tests refactor(packages): 0.R5 - a question no longer starts its state - 64 lazy starts ('if st.x == null { st.x = ... }' inside a getter) are the state's defaults, gear__ensure is gone, and ludic migrate state --tighten took mut off 208 package parameters: things_all, thing_find, gear_charge, gear_level, jobs_state and the rest read 2026-09-27 00:51:03 +03:00
index.ludic refactor(packages): the mechanic packages use ludic_base only, and ask through ports 2026-09-25 05:36:11 +03:00
package.ludic feat(ludic.inventory, ludic.wallet): the pack and the purse as mechanic packages 2026-09-25 04:29:17 +03:00
README.md refactor(packages): the mechanic packages use ludic_base only, and ask through ports 2026-09-25 05:36:11 +03:00
state.ludic @max on the bounded lists: TextRing's slots, the pack's counts and change ring, the net's fact ring, the compass pools, ludic.ui's memo (its 3/4 of MM_CAP), screen pools, answer and pointer rings; ludic.base's intern test holds the table to its cap now that past it is Mem.over 2026-09-28 16:48:53 +03:00
system.ludic feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune 2026-09-26 04:19:56 +03:00
verbs.ludic ludic.base: a queue's fact records come round again (q_rec / q_ring_add), used by effects, clock, wallet, weather, tracks, needs, fire, settings, update, steps, crafting, shop, gear, hints, session and photo instead of a new record per fact; the minimap's marks cleared and rubbed out in place, its scale steps without a list; the clock's dice seeded again, not made again; once-per-join, per-save and pool-miss paths declared 2026-09-28 20:03:46 +03:00

ludic.inventory

A pack: a count per kind of item. The game names the kinds and says how many of each fit; the package keeps the counts, refuses what does not fit, and reports every change. Uses ludic.base and nothing else.

import "ludic.inventory"

A kind is the game's number for an item (its place in the game's item table). The game hands the package each kind's NAME with inv_config(keys), and the save is by name - {"counts": {"wood": 3}} - so a game can add, remove or reorder its items without a migration; a name the build no longer knows is dropped on load.

The port

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

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
inv_clear() everything gone, silently
inv_count(it), inv_has(it, n), inv_room(it), inv_limit(it), inv_total(), inv_kinds() what the game asks; a kind out of range counts 0 and has no room
inv_changes() -> Queue<ItemChanged> the facts: { item, before, after }, one per change, none for a no-op or a load
inv_system() -> System "inventory", PH_COMMIT: reset, and its save section (inv_save, inv_load)

Tests

ludic build packages/ludic.inventory/tests/inventory_test.ludic --headless -o /tmp/inventory_test && /tmp/inventory_test