76 lines
2.4 KiB
Text
76 lines
2.4 KiB
Text
# verbs_ui.ludic - ui_screen, ui_model, ui_tree and ui_override: answered at once, the big ones in a file
|
|
function dl_ui_screen(st: mut DevlinkState, id: int) -> void {
|
|
if dl_bad_args(st, id) { return }
|
|
let s = st.dl_ui
|
|
if DevlinkUi.screen(s) == DL_UNBOUND {
|
|
dl_err(st, id, "unbound", "not offered")
|
|
return
|
|
}
|
|
dl_ok(st, id)
|
|
dl_b(st, 32)
|
|
dl_q(st, s.root)
|
|
dl_b(st, 32)
|
|
dl_q(st, s.components)
|
|
}
|
|
|
|
# a file the game writes: a path with no "..", as a shot's
|
|
function dl_out_path(st: DevlinkState, n: int) -> bool {
|
|
if n < 1 or n > len(st.dl_path) { return false }
|
|
for i in 0 .. n - 1 { if st.dl_str[i] == 46 and st.dl_str[i + 1] == 46 { return false } }
|
|
return true
|
|
}
|
|
# the answer to a member that wrote a file: ok and the path, not offered, or what went wrong
|
|
function dl_wrote(st: mut DevlinkState, id: int, r: int, n: int, why: string) -> void {
|
|
if r == DL_UNBOUND { dl_err(st, id, "unbound", "not offered") }
|
|
else if r < 0 { dl_err(st, id, "failed", why) }
|
|
else {
|
|
dl_ok(st, id)
|
|
dl_b(st, 32)
|
|
dl_q_bytes(st, st.dl_str, n)
|
|
}
|
|
}
|
|
|
|
function dl_ui_model(st: mut DevlinkState, id: int) -> void {
|
|
let nc = dl_quoted(st)
|
|
if st.dl_bad or nc < 1 {
|
|
dl_err(st, id, "bad_args", "a class and a path")
|
|
return
|
|
}
|
|
let cls = dl_text(st, nc)
|
|
let n = dl_quoted(st)
|
|
if dl_bad_args(st, id) { return }
|
|
if not dl_out_path(st, n) {
|
|
dl_err(st, id, "bad_args", "a path without ..")
|
|
return
|
|
}
|
|
dl_wrote(st, id, DevlinkUi.model(cls, dl_text(st, n)), n, "no such instance")
|
|
}
|
|
|
|
function dl_ui_tree(st: mut DevlinkState, id: int) -> void {
|
|
let n = dl_quoted(st)
|
|
if dl_bad_args(st, id) { return }
|
|
if not dl_out_path(st, n) {
|
|
dl_err(st, id, "bad_args", "a path without ..")
|
|
return
|
|
}
|
|
dl_wrote(st, id, DevlinkUi.tree(dl_text(st, n)), n, "not written")
|
|
}
|
|
|
|
# "" for the file clears that path's override; "" "" clears every one
|
|
function dl_ui_override(st: mut DevlinkState, id: int) -> void {
|
|
let np = dl_quoted(st)
|
|
if st.dl_bad {
|
|
dl_err(st, id, "bad_args", "a path and a file")
|
|
return
|
|
}
|
|
let path = dl_text(st, np)
|
|
let nf = dl_quoted(st)
|
|
if dl_bad_args(st, id) { return }
|
|
let file_ok = nf == 0 or dl_out_path(st, nf)
|
|
if not file_ok or (np == 0 and nf > 0) {
|
|
dl_err(st, id, "bad_args", "a file without .., or \"\" \"\" to clear all")
|
|
return
|
|
}
|
|
let r = DevlinkUi.override(path, dl_text(st, nf))
|
|
if r < 0 and r != DL_UNBOUND { dl_err(st, id, "failed", "not overridden") } else { dl_answer(st, id, r) }
|
|
}
|