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:
parent
6cfaaf0bf9
commit
8075892e0e
12 changed files with 445 additions and 0 deletions
41
packages/ludic.inventory/README.md
Normal file
41
packages/ludic.inventory/README.md
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# 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`](../ludic.base/README.md) and nothing else.
|
||||
|
||||
```ludic
|
||||
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
|
||||
|
||||
```ludic
|
||||
property PackRules {
|
||||
stack_limit: fn(int) -> int # how many of a kind fit (unbound: no limit)
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| `inv_bind(r)`, `inv_config(keys)` | the port, 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
|
||||
|
||||
```bash
|
||||
ludic build packages/ludic.inventory/tests/inventory_test.ludic --headless -o /tmp/inventory_test && /tmp/inventory_test
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue