wip(0.S2): migrate - a var nothing writes becomes a let; a state is keyed by its module, directory or program, so every program's plan agrees; paths normalized; program states named SceneDemoState / scene_demo_st; the LSP reads state, mut and entry/handler parameters
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3eda72e8c2
commit
5ffe50ed02
463 changed files with 72045 additions and 67421 deletions
|
|
@ -4,54 +4,52 @@
|
|||
import "ludic.ui"
|
||||
program UiKeycap {
|
||||
numbers float
|
||||
state UikeycapState {
|
||||
bind: int = 32
|
||||
pressed: int = 0
|
||||
}
|
||||
view Keys (uikeycap_st: mut UikeycapState) {
|
||||
bind = uikeycap_st.bind
|
||||
pressed = uikeycap_st.pressed
|
||||
on set_bind(v: int) { uikeycap_st.bind = v }
|
||||
on press() { uikeycap_st.pressed = uikeycap_st.pressed + 1 }
|
||||
var bind: int = 32
|
||||
var pressed: int = 0
|
||||
view Keys {
|
||||
bind = bind
|
||||
pressed = pressed
|
||||
on set_bind(v: int) { bind = v }
|
||||
on press() { pressed = pressed + 1 }
|
||||
}
|
||||
const PAGE: string = "<ui><style>.k:capturing { background: #ff0000 }</style><screen name='k'><input type='key' class='k' label='Jump' value='{bind}' on-change='set_bind(event.value)'/><button on-click='press()'>b</button></screen></ui>"
|
||||
function frame(ui_st: mut UiState, x: float, y: float, b: int) -> UiNode {
|
||||
function frame(x: float, y: float, b: int) -> UiNode {
|
||||
let i = new UiInput
|
||||
i.x = x
|
||||
i.y = y
|
||||
i.down = b == 0
|
||||
i.down_right = b == 1
|
||||
i.down_middle = b == 2
|
||||
ui_input(ui_st, i)
|
||||
ui_show(ui_st, "k", view_keys(), 0.0, 0.0, 400.0, 400.0)
|
||||
let r: UiNode = ui_nodes(ui_st, "k", view_keys())
|
||||
ui_place(ui_st, r, 0.0, 0.0, 400.0, 400.0)
|
||||
ui_input(i)
|
||||
ui_show("k", view_keys(), 0.0, 0.0, 400.0, 400.0)
|
||||
let r: UiNode = ui_nodes("k", view_keys())
|
||||
ui_place(r, 0.0, 0.0, 400.0, 400.0)
|
||||
return r
|
||||
}
|
||||
function listen(ui_st: mut UiState, k: UiNode) -> int {
|
||||
frame(ui_st, k.x + 5.0, k.y + 5.0, 0)
|
||||
frame(ui_st, k.x + 5.0, k.y + 5.0, -1)
|
||||
return frame(ui_st, -1.0, -1.0, -1).children[0].bg
|
||||
function listen(k: UiNode) -> int {
|
||||
frame(k.x + 5.0, k.y + 5.0, 0)
|
||||
frame(k.x + 5.0, k.y + 5.0, -1)
|
||||
return frame(-1.0, -1.0, -1).children[0].bg
|
||||
}
|
||||
function take(ui_st: mut UiState, uikeycap_st: UikeycapState, at: UiNode, b: int) -> string {
|
||||
frame(ui_st, at.x + 5.0, at.y + 5.0, b)
|
||||
frame(ui_st, at.x + 5.0, at.y + 5.0, -1)
|
||||
let r = frame(ui_st, -1.0, -1.0, -1)
|
||||
function take(at: UiNode, b: int) -> string {
|
||||
frame(at.x + 5.0, at.y + 5.0, b)
|
||||
frame(at.x + 5.0, at.y + 5.0, -1)
|
||||
let r = frame(-1.0, -1.0, -1)
|
||||
let f = r.children[0]
|
||||
return `{uikeycap_st.bind} {f.children[1].children[0].text} {f.bg}`
|
||||
return `{bind} {f.children[1].children[0].text} {f.bg}`
|
||||
}
|
||||
entry (ui_st: mut UiState, uikeycap_st: UikeycapState) {
|
||||
ui_backend(ui_st, new UiBackend)
|
||||
ui_load_text(ui_st, PAGE, "k.xml")
|
||||
let r = frame(ui_st, -1.0, -1.0, -1)
|
||||
entry {
|
||||
ui_backend(new UiBackend)
|
||||
ui_load_text(PAGE, "k.xml")
|
||||
let r = frame(-1.0, -1.0, -1)
|
||||
let k = r.children[0]
|
||||
let btn = r.children[1]
|
||||
let red = listen(ui_st, k)
|
||||
let right = take(ui_st, uikeycap_st, btn, 1)
|
||||
listen(ui_st, k)
|
||||
let middle = take(ui_st, uikeycap_st, btn, 2)
|
||||
listen(ui_st, k)
|
||||
let left = take(ui_st, uikeycap_st, btn, 0)
|
||||
print(`listening {red} | {right} | {middle} | {left} | pressed {uikeycap_st.pressed}`)
|
||||
let red = listen(k)
|
||||
let right = take(btn, 1)
|
||||
listen(k)
|
||||
let middle = take(btn, 2)
|
||||
listen(k)
|
||||
let left = take(btn, 0)
|
||||
print(`listening {red} | {right} | {middle} | {left} | pressed {pressed}`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue