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>
40 lines
1.6 KiB
Text
40 lines
1.6 KiB
Text
# hold.ludic - a recipe made by holding a button for its `hold` seconds: letting go wastes
|
|
# nothing, and it stops by itself the moment it can no longer be made
|
|
|
|
export function craft_holds(i: int) -> bool { return craft_ok(i) and CraftRecipes[i].hold > 0.0 }
|
|
|
|
# the recipe being held, or -1
|
|
export function craft_holding(crafting_st: CraftingState) -> int { return crafting_st.craft_hold_i }
|
|
|
|
# starts holding one that is made by holding and can be made now
|
|
export function craft_hold_start(crafting_st: mut CraftingState, i: int) -> bool {
|
|
if not craft_holds(i) or not craft_can(i) { return false }
|
|
crafting_st.craft_hold_i = i
|
|
crafting_st.craft_hold_t = 0.0
|
|
return true
|
|
}
|
|
|
|
export function craft_hold_stop(crafting_st: mut CraftingState) -> void {
|
|
crafting_st.craft_hold_i = -1
|
|
crafting_st.craft_hold_t = 0.0
|
|
}
|
|
|
|
# how far through the hold on `i` is, 0 to 1
|
|
export function craft_hold_frac(crafting_st: CraftingState, i: int) -> float {
|
|
if crafting_st.craft_hold_i != i or not craft_holds(i) { return 0.0 }
|
|
return Math.clamp(crafting_st.craft_hold_t / CraftRecipes[i].hold, 0.0, 1.0)
|
|
}
|
|
|
|
# `dt` real seconds of holding; true on the frame it is made
|
|
export function craft_hold_run(crafting_st: mut CraftingState, dt: float) -> bool {
|
|
if crafting_st.craft_hold_i < 0 { return false }
|
|
if not craft_can(crafting_st.craft_hold_i) {
|
|
craft_hold_stop(crafting_st)
|
|
return false
|
|
}
|
|
crafting_st.craft_hold_t = crafting_st.craft_hold_t + dt
|
|
if crafting_st.craft_hold_t <= CraftRecipes[crafting_st.craft_hold_i].hold { return false }
|
|
let i = crafting_st.craft_hold_i
|
|
craft_hold_stop(crafting_st)
|
|
return craft_make(crafting_st, i)
|
|
}
|