feat(packages): ludic.crafting - recipes as an open registry, can / take / refund / make through a pack port, stations through a port, the hold-to-make, a Crafted fact
A recipe is `def CraftRecipes key { out, n, ins: [...], ns: [...], station, minutes, hold,
group, learned }`. The pack is the CraftPack port (count, take, add, room, and `leaves`: what
an item leaves once used, so water gives back its bottle); stations are CraftStations (ready,
start), unbound meaning hands only. craft_make hands a click recipe over or starts a timed one
at its station, refunding when the station refuses; the hold runs from the screen that shows it.
Uses ludic.base only; ten tests with a fake pack and fake stations.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7f8a7ea7ed
commit
cc9cec922a
9 changed files with 475 additions and 0 deletions
42
packages/ludic.crafting/hold.ludic
Normal file
42
packages/ludic.crafting/hold.ludic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# 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
|
||||
var cr_hold: int = -1
|
||||
var cr_hold_t: float = 0.0
|
||||
|
||||
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() -> int { return cr_hold }
|
||||
|
||||
# starts holding one that is made by holding and can be made now
|
||||
export function craft_hold_start(i: int) -> bool {
|
||||
if not craft_holds(i) or not craft_can(i) { return false }
|
||||
cr_hold = i
|
||||
cr_hold_t = 0.0
|
||||
return true
|
||||
}
|
||||
|
||||
export function craft_hold_stop() -> void {
|
||||
cr_hold = -1
|
||||
cr_hold_t = 0.0
|
||||
}
|
||||
|
||||
# how far through the hold on `i` is, 0 to 1
|
||||
export function craft_hold_frac(i: int) -> float {
|
||||
if cr_hold != i or not craft_holds(i) { return 0.0 }
|
||||
return Math.clamp(cr_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(dt: float) -> bool {
|
||||
if cr_hold < 0 { return false }
|
||||
if not craft_can(cr_hold) {
|
||||
craft_hold_stop()
|
||||
return false
|
||||
}
|
||||
cr_hold_t = cr_hold_t + dt
|
||||
if cr_hold_t <= CraftRecipes[cr_hold].hold { return false }
|
||||
let i = cr_hold
|
||||
craft_hold_stop()
|
||||
return craft_make(i)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue