ludic/packages/ludic.hints/mute.ludic
Orkuncakilkaya 9c24d707bc ludic.settings: the store filled into a kept object in place; texts read from a file kept apart from it
settings_fill_json(v) writes every saved setting into an object the caller keeps, making a Value
only for a key seen the first time (value_set_str / value_set_int): Maroon Lake's Settings pages
rebuilt the whole tree on every change and dropped the old one. A text read from a file is interned,
and so is a muted card's key ludic.hints does not know, so the parsed tree can be let go whole.

Test: the store filled into a kept object changes its Values in place (6 tests pass).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 12:22:07 +03:00

53 lines
1.9 KiB
Text

# mute.ludic - the cards a player has said they know, kept BY KEY: a card added, removed or moved in
# the registry leaves every other mute where it was, and a key this build does not know is carried
export function hints_muted(hints_st: HintsState, id: int) -> bool {
if id < 0 or id >= HINT_COUNT { return false }
return hints_st.hn_mute[id]
}
export function hints_mute(hints_st: mut HintsState, id: int, on: bool) -> void {
if id < 0 or id >= HINT_COUNT { return }
hints_st.hn_mute[id] = on
}
export function hints_mute_count(hints_st: HintsState) -> int {
var n = 0
for i in 0 .. HINT_COUNT { if hints_st.hn_mute[i] { n += 1 } }
return n
}
# every muted card given back, from the next pass
export function hints_unmute_all(hints_st: mut HintsState) -> void {
for i in 0 .. HINT_COUNT { hints_st.hn_mute[i] = false }
hints_st.hn_foreign = new []string
hints_st.hn_t = 0.0
hn_fact(hints_st, HINTS_F_UNMUTED, -1)
}
# the mutes as a list of keys, for wherever the game keeps the player's own choices
export function hints_mutes_save(hints_st: HintsState) -> Val {
let l = Value.list()
for i in 0 .. HINT_COUNT { if hints_st.hn_mute[i] { Value.add(l, Value.str(Hints[i].key)) } }
for i in 0 .. len(hints_st.hn_foreign) { Value.add(l, Value.str(hints_st.hn_foreign[i])) }
return l
}
# a list of keys read back; anything that is not a list is no mutes
export function hints_mutes_load(hints_st: mut HintsState, l: Val) -> void {
hints_st.hn_mute = hn_mutes()
if l == null or Value.kind(l) != 5 { return }
for i in 0 .. Value.count(l) {
let e = Value.at(l, i)
if Value.kind(e) != 4 { continue }
let k = Value.as_str(e)
let id = hints_find(k)
if id >= 0 { hints_st.hn_mute[id] = true } else { push(hints_st.hn_foreign, intern(k)) } # the tree is let go
}
}
function hn_mutes() -> []bool {
let out = new []bool
for i in 0 .. HINT_COUNT { push(out, false) }
return out
}