ludic/packages/ludic.settings
2026-09-30 00:29:03 +03:00
..
tests ludic.settings: the store filled into a kept object in place; texts read from a file kept apart from it 2026-09-29 12:22:07 +03:00
defs.ludic packages: the registry text a game fills is keys (Maroon Lake's phase 26.4) - ThingKind.name, GearKind blurb/howto/names, HintCard's words, JobDef title/text/how, NpcLine and NpcChoice text, WeatherKind.name are @Text Key fields (a compiled row that leaves one out takes its derived key, the English is the game's en.po); what a package hands back as text is the key's marked text, "" for none; NpcName.name, NpcChoice.line and SettingDef.text are not text and lose @Text; ludic.i18n's tr/trf/trn/key_text say @alloc_ok (tr is a cast); the packages' tests with key literals (built, not run); changes/text-keys-data.md 2026-09-30 00:29:03 +03:00
file.ludic ludic.settings: the store filled into a kept object in place; texts read from a file kept apart from it 2026-09-29 12:22:07 +03:00
index.ludic feat(packages): ludic.settings - a settings store as data: typed reads and writes by id, clamping, rescue values, per-key persistence, a fact per change 2026-09-25 05:51:04 +03:00
package.ludic feat(packages): ludic.settings - a settings store as data: typed reads and writes by id, clamping, rescue values, per-key persistence, a fact per change 2026-09-25 05:51:04 +03:00
README.md feat(packages): ludic.settings - a settings store as data: typed reads and writes by id, clamping, rescue values, per-key persistence, a fact per change 2026-09-25 05:51:04 +03:00
rules.ludic refactor(packages): 0.R5 - jobs, session, settings, hints and net make their tables when the state is made, not on the first question (jobs__ensure, session__init and ply_init, sg_init, hn_mute_ensure, net__init gone); their questions read 2026-09-27 01:29:32 +03:00
store.ludic ludic.base: a queue's fact records come round again (q_rec / q_ring_add), used by effects, clock, wallet, weather, tracks, needs, fire, settings, update, steps, crafting, shop, gear, hints, session and photo instead of a new record per fact; the minimap's marks cleared and rubbed out in place, its scale steps without a list; the clock's dice seeded again, not made again; once-per-join, per-save and pool-miss paths declared 2026-09-28 20:03:46 +03:00

ludic.settings

A game's settings as data, in one store with one owner. The game declares them - usually as a registry of SettingDef read from a .lres - and everything else reads and writes them through the store's verbs. A change is a SettingChanged fact the game drains to apply it. Uses ludic.base and nothing else.

import "ludic.settings"
export registry Settings of SettingDef as SET from "assets/data/settings.lres"
for i in 0 .. SET_COUNT { settings_add(Settings[i]) }       # SET_* is each setting's id
# settings.lres - the entry's name is the key in the file
bloom { kind: SETTING_BOOL, num: 1.0 }
shadow_q { kind: SETTING_INT, num: 2.0, lo: 0.0, hi: 3.0, rescue: true }
rscale { kind: SETTING_FLOAT, num: 0.78, lo: 0.5, hi: 1.0, rescue: true }
lang { kind: SETTING_TEXT, text: "en" }

API

SettingDef { key, kind, num, text, lo, hi, rescue, saved } a setting: SETTING_BOOL / _INT / _FLOAT / _TEXT, its default (num or text), its range (hi < lo is none), whether a rescue start puts it back, whether it is written
settings_add(d) -> int, settings_clear(), settings_count(), settings_def(id), settings_id_of(key) -> int the table; an id is the place a setting was added
settings_get_bool / _int / _float / _text(id) the value
settings_set_bool / _int / _float / _text(id, v), settings_set_value(id, Val) a change, held to the range (outside it is the default) and reported
settings_changes() -> Queue<SettingChanged> the facts: { id, key }, one per change
settings_reset_all(), settings_clamp_all(), settings_rescue(), settings_is_safe(id) the whole store at once, quietly: defaults, ranges, the rescue set
settings_to_json() -> Val, settings_put(v, id), settings_from_json(v) the file, by key: a switch is 0/1, a float thousandths; a key the file lacks keeps the store's value

Tests

ludic build packages/ludic.settings/tests/settings_test.ludic --headless -o /tmp/settings_test && /tmp/settings_test