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>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-29 12:22:07 +03:00
parent 1667d7f16e
commit 9c24d707bc
3 changed files with 33 additions and 2 deletions

View file

@ -35,6 +35,21 @@ program SettingsTest {
expect_eq(fs[1].id, TOY_LANG)
}
test "the store filled into a kept object changes its Values in place" (settings_st: mut SettingsState) {
declare(settings_st)
let o = Value.object()
settings_fill_json(settings_st, o)
let q = Value.get(o, "shadow_q")
let l = Value.get(o, "lang")
settings_set_int(settings_st, TOY_SHADOW_Q, 3)
settings_set_text(settings_st, TOY_LANG, "tr")
settings_fill_json(settings_st, o)
expect(Value.get(o, "shadow_q") == q)
expect(Value.get(o, "lang") == l)
expect_eq(Value.as_int(q), 3)
expect(Value.as_str(l) == "tr")
}
test "a value out of range is the default" (settings_st: mut SettingsState) {
declare(settings_st)
settings_set_int(settings_st, TOY_SHADOW_Q, 9)