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>
52 lines
1.6 KiB
Text
52 lines
1.6 KiB
Text
# system.ludic - the effects as a system: reset, a tick in game hours, and its own save section
|
|
export function effects_reset(effects_st: mut EffectsState) -> void {
|
|
effects_clear(effects_st)
|
|
q_clear(effects_ended(effects_st))
|
|
}
|
|
|
|
function effects_tick(effects_st: mut EffectsState, t: Tick) -> void { effects_run(effects_st, t.hours * 60.0) }
|
|
|
|
export function effects_save(effects_st: mut EffectsState) -> Val {
|
|
let l = Value.list()
|
|
let all = ef_all(effects_st)
|
|
for i in 0 .. len(all) {
|
|
let o = Value.object()
|
|
sv_put_int(o, "k", all[i].kind)
|
|
sv_put_float(o, "m", all[i].mag)
|
|
sv_put_float(o, "t", all[i].left)
|
|
sv_put_float(o, "d", all[i].delay)
|
|
sv_put_bool(o, "b", all[i].bonus)
|
|
sv_put_str(o, "l", all[i].label)
|
|
Value.add(l, o)
|
|
}
|
|
let v = Value.object()
|
|
Value.put(v, "list", l)
|
|
return v
|
|
}
|
|
|
|
export function effects_load(effects_st: mut EffectsState, v: Val, version: int) -> void {
|
|
effects_clear(effects_st)
|
|
if Value.has(v, "list") == 0 { return }
|
|
let l = Value.get(v, "list")
|
|
for i in 0 .. Value.count(l) {
|
|
if len(ef_all(effects_st)) >= effects_st.ef_max { break }
|
|
let o = Value.at(l, i)
|
|
let e = new Effect
|
|
e.kind = sv_int(o, "k", 0)
|
|
e.mag = sv_float(o, "m", 0.0)
|
|
e.left = sv_float(o, "t", 0.0)
|
|
e.delay = sv_float(o, "d", 0.0)
|
|
e.bonus = sv_bool(o, "b", false)
|
|
e.label = sv_str(o, "l", "")
|
|
push(ef_all(effects_st), e)
|
|
}
|
|
}
|
|
|
|
export function effects_system() -> System {
|
|
let s = system_new("effects", PH_SIMULATE)
|
|
s.reset = fn effects_reset
|
|
s.tick = fn effects_tick
|
|
s.save = fn effects_save
|
|
s.load = fn effects_load
|
|
return s
|
|
}
|