ludic/packages/ludic.inventory/system.ludic
Orkuncakilkaya 71735b10a2 feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune
ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v),
q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding
facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)).

ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no
longer uses, nor anything it calls, and the argument that fills it - including an argument for a
parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is
told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would
make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 04:19:56 +03:00

32 lines
1.1 KiB
Text

# system.ludic - the pack as a system: reset and its own save section, each count under its
# kind's name, so kinds can be added or reordered without a migration
export function inv_reset(inventory_st: mut InventoryState) -> void {
inv_clear(inventory_st)
q_clear(inv_changes(inventory_st))
}
export function inv_save(inventory_st: InventoryState) -> Val {
let counts = Value.object()
for i in 0 .. inv_kinds(inventory_st) {
if inventory_st.iv_counts[i] != 0 { sv_put_int(counts, inventory_st.iv_keys[i], inventory_st.iv_counts[i]) }
}
let v = Value.object()
Value.put(v, "counts", counts)
return v
}
# a name this build does not know is dropped
export function inv_load(inventory_st: mut InventoryState, v: Val, version: int) -> void {
inv_clear(inventory_st)
if Value.has(v, "counts") == 0 { return }
let counts = Value.get(v, "counts")
for i in 0 .. inv_kinds(inventory_st) { inventory_st.iv_counts[i] = Math.max(sv_int(counts, inventory_st.iv_keys[i], 0), 0) }
}
export function inv_system() -> System {
let s = system_new("inventory", PH_COMMIT)
s.reset = fn inv_reset
s.save = fn inv_save
s.load = fn inv_load
return s
}