ludic.ui: a select matches a number as a number (its text was made every frame per select); the fired-event queue's lists made with room; ludic.inventory: the counts made at full length at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d483c9283c
commit
bd2d62ddca
5 changed files with 57 additions and 10 deletions
|
|
@ -40,10 +40,16 @@ export function inv_set(inventory_st: mut InventoryState, it: int, n: int) -> vo
|
||||||
|
|
||||||
# everything gone, silently: a new trip, or before a load
|
# everything gone, silently: a new trip, or before a load
|
||||||
export function inv_clear(inventory_st: mut InventoryState) -> void {
|
export function inv_clear(inventory_st: mut InventoryState) -> void {
|
||||||
if inventory_st.iv_counts == null {
|
if inventory_st.iv_counts == null { inventory_st.iv_counts = iv_counts__new(inv_kinds(inventory_st)) }
|
||||||
@alloc_ok("once: the counts are made the first time the pack is cleared")
|
|
||||||
inventory_st.iv_counts = new []int
|
|
||||||
}
|
|
||||||
List.clear(inventory_st.iv_counts)
|
List.clear(inventory_st.iv_counts)
|
||||||
for i in 0 .. inv_kinds(inventory_st) { kept_push(inventory_st.iv_counts, 0) }
|
for i in 0 .. inv_kinds(inventory_st) { kept_push(inventory_st.iv_counts, 0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# the counts made at their full length at once: a list grown a push at a time in play is a new block
|
||||||
|
@alloc_ok("once: the counts are made the first time the pack is cleared")
|
||||||
|
function iv_counts__new(n: int) -> []int {
|
||||||
|
let xs = new []int
|
||||||
|
for i in 0 .. n { push(xs, 0) }
|
||||||
|
List.clear(xs)
|
||||||
|
return xs
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,12 +147,12 @@ export state UiState {
|
||||||
lc_prev_unmounts: []UiAct = new []UiAct
|
lc_prev_unmounts: []UiAct = new []UiAct
|
||||||
lc_prev_envs: []UiEnv = new []UiEnv
|
lc_prev_envs: []UiEnv = new []UiEnv
|
||||||
nt_list: []UiNative = new []UiNative
|
nt_list: []UiNative = new []UiNative
|
||||||
nt_sp_nodes: []UiNode = new []UiNode # native.ludic: the queue's spare, swapped while it runs
|
nt_sp_nodes: []UiNode = nt_nodes__new() # native.ludic: the queue's spare, swapped while it runs;
|
||||||
nt_sp_names: []string = new []string
|
nt_sp_names: []string = nt_names__new() # each list is made with room for a busy frame's events
|
||||||
nt_sp_vals: []Val = new []Val
|
nt_sp_vals: []Val = nt_vals__new()
|
||||||
nt_q_nodes: []UiNode = new []UiNode
|
nt_q_nodes: []UiNode = nt_nodes__new()
|
||||||
nt_q_names: []string = new []string
|
nt_q_names: []string = nt_names__new()
|
||||||
nt_q_vals: []Val = new []Val
|
nt_q_vals: []Val = nt_vals__new()
|
||||||
fr_hover: []string = new []string
|
fr_hover: []string = new []string
|
||||||
fr_hover_sp: []string = new []string
|
fr_hover_sp: []string = new []string
|
||||||
fr_press_key: string = ""
|
fr_press_key: string = ""
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,8 @@ function ct_build_select(ui_st: mut UiState, n: UiNode) -> void {
|
||||||
}
|
}
|
||||||
# which option the select's value names: an option's value="...", else its place
|
# which option the select's value names: an option's value="...", else its place
|
||||||
function ct_option_at(n: UiNode, opts: []UiNode) -> int {
|
function ct_option_at(n: UiNode, opts: []UiNode) -> int {
|
||||||
|
let nv = ui_attr(n, "value")
|
||||||
|
if ct_numeric(nv) { return ct_option_num(nv, opts) }
|
||||||
let v = ui_attr_text(n, "value")
|
let v = ui_attr_text(n, "value")
|
||||||
for i in 0 .. len(opts) {
|
for i in 0 .. len(opts) {
|
||||||
let ov = ui_attr_text(opts[i], "value")
|
let ov = ui_attr_text(opts[i], "value")
|
||||||
|
|
@ -96,3 +98,17 @@ function ct_field_text(ui_st: mut UiState, n: UiNode) -> string {
|
||||||
if t == "number" { return ct_num_shown(ui_st, n) }
|
if t == "number" { return ct_num_shown(ui_st, n) }
|
||||||
return ui_attr_text(n, "value")
|
return ui_attr_text(n, "value")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# a number held by a select (the usual case: a setting's value) matched as a number: its text was
|
||||||
|
# made every frame for every select on screen. An option with no value of its own is its index
|
||||||
|
function ct_numeric(v: Val) -> bool { return Value.kind(v) == 1 or Value.kind(v) == 7 }
|
||||||
|
function ct_option_num(nv: Val, opts: []UiNode) -> int {
|
||||||
|
let x = Value.as_float(nv)
|
||||||
|
for i in 0 .. len(opts) {
|
||||||
|
let ov = ui_attr(opts[i], "value")
|
||||||
|
if Value.kind(ov) == 0 and x == float(i) { return i }
|
||||||
|
if ct_numeric(ov) and Value.as_float(ov) == x { return i }
|
||||||
|
if Value.kind(ov) == 4 and el_num(Value.as_str(ov)) == x and len(Value.as_str(ov)) > 0 { return i }
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import "env.ludic"
|
||||||
import "eval.ludic"
|
import "eval.ludic"
|
||||||
import "act.ludic"
|
import "act.ludic"
|
||||||
import "native.ludic"
|
import "native.ludic"
|
||||||
|
import "native_room.ludic"
|
||||||
import "controls.ludic"
|
import "controls.ludic"
|
||||||
import "controls_build.ludic"
|
import "controls_build.ludic"
|
||||||
import "controls_parts.ludic"
|
import "controls_parts.ludic"
|
||||||
|
|
|
||||||
24
packages/ludic.ui/native_room.ludic
Normal file
24
packages/ludic.ui/native_room.ludic
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
# native_room.ludic - the fired-event queue's lists made with room already: a list's first growth
|
||||||
|
# is made at start rather than in the frame that first fires an event
|
||||||
|
const NT_ROOM: int = 32
|
||||||
|
@alloc_ok("once: made with the state")
|
||||||
|
function nt_nodes__new() -> []UiNode {
|
||||||
|
let xs = new []UiNode
|
||||||
|
for i in 0 .. NT_ROOM { push(xs, null) }
|
||||||
|
List.clear(xs)
|
||||||
|
return xs
|
||||||
|
}
|
||||||
|
@alloc_ok("once: made with the state")
|
||||||
|
function nt_names__new() -> []string {
|
||||||
|
let xs = new []string
|
||||||
|
for i in 0 .. NT_ROOM { push(xs, "") }
|
||||||
|
List.clear(xs)
|
||||||
|
return xs
|
||||||
|
}
|
||||||
|
@alloc_ok("once: made with the state")
|
||||||
|
function nt_vals__new() -> []Val {
|
||||||
|
let xs = new []Val
|
||||||
|
for i in 0 .. NT_ROOM { push(xs, null) }
|
||||||
|
List.clear(xs)
|
||||||
|
return xs
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue