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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 01:29:32 +03:00
parent 63c30b9ebe
commit 9e4f4edb92
21 changed files with 98 additions and 163 deletions

View file

@ -1,8 +1,7 @@
# ludic.settings/file.ludic - the store as a JSON object, by key: a switch is 0 or 1, a whole number
# is itself, a float is thousandths (sv_put_float), text is a string. A key the file lacks keeps
# what the store holds, and a key the store does not know is ignored.
export function settings_to_json(settings_st: mut SettingsState) -> Val {
sg_init(settings_st)
export function settings_to_json(settings_st: SettingsState) -> Val {
let v = Value.object()
for i in 0 .. len(settings_st.sg_defs) { settings_put(settings_st, v, i) }
return v
@ -23,7 +22,6 @@ export function settings_put(settings_st: SettingsState, v: Val, id: int) -> voi
# every key `v` names, held to its range; quiet, since a load is applied whole by its caller
export function settings_from_json(settings_st: mut SettingsState, v: Val) -> void {
sg_init(settings_st)
if v == null { return }
for i in 0 .. len(settings_st.sg_defs) { sg_read(settings_st, v, i) }
}

View file

@ -1,7 +1,6 @@
# ludic.settings/rules.ludic - the whole store at once: every setting to its default, every one
# held to its range, and the rescue set. None of these is news: whoever calls them applies it all
export function settings_reset_all(settings_st: mut SettingsState) -> void {
sg_init(settings_st)
for i in 0 .. len(settings_st.sg_defs) {
settings_st.sg_num[i] = settings_st.sg_defs[i].num
settings_st.sg_text[i] = settings_st.sg_defs[i].text
@ -11,14 +10,12 @@ export function settings_reset_all(settings_st: mut SettingsState) -> void {
# a hand-edited file, or one from a build with more choices, never hands the game a value it has
# no case for
export function settings_clamp_all(settings_st: mut SettingsState) -> void {
sg_init(settings_st)
for i in 0 .. len(settings_st.sg_defs) { settings_st.sg_num[i] = settings_held(settings_st, i, settings_st.sg_num[i]) }
}
# the values every machine can run: each setting marked `rescue` back to its default, and the
# rest (keys, language, volume) left the player's
export function settings_rescue(settings_st: mut SettingsState) -> void {
sg_init(settings_st)
for i in 0 .. len(settings_st.sg_defs) {
if settings_st.sg_defs[i].rescue {
settings_st.sg_num[i] = settings_st.sg_defs[i].num

View file

@ -1,18 +1,12 @@
# ludic.settings/store.ludic - the values, by id (a setting's place in the order it was added),
# and the verbs: nothing else holds a setting, and every set that changes one is a fact
export state SettingsState {
sg_defs: []SettingDef = null
sg_num: []float = null
sg_text: []string = null
sg_defs: []SettingDef = new []SettingDef
sg_num: []float = new []float
sg_text: []string = new []string
sg_changes: Queue<SettingChanged> = sg_changes__new()
}
function sg_init(settings_st: mut SettingsState) -> void {
if settings_st.sg_defs != null { return }
settings_st.sg_defs = new []SettingDef
settings_st.sg_num = new []float
settings_st.sg_text = new []string
}
export function settings_changes(settings_st: SettingsState) -> Queue<SettingChanged> {
return settings_st.sg_changes
@ -28,23 +22,20 @@ export function settings_clear(settings_st: mut SettingsState) -> void {
# a setting, at its default; its id is its place in the order added
export function settings_add(settings_st: mut SettingsState, d: SettingDef) -> int {
sg_init(settings_st)
push(settings_st.sg_defs, d)
push(settings_st.sg_num, d.num)
push(settings_st.sg_text, d.text)
return len(settings_st.sg_defs) - 1
}
export function settings_count(settings_st: mut SettingsState) -> int {
sg_init(settings_st)
export function settings_count(settings_st: SettingsState) -> int {
return len(settings_st.sg_defs)
}
export function settings_def(settings_st: SettingsState, id: int) -> SettingDef { return settings_st.sg_defs[id] }
# the id of `key`, or -1
export function settings_id_of(settings_st: mut SettingsState, key: string) -> int {
sg_init(settings_st)
export function settings_id_of(settings_st: SettingsState, key: string) -> int {
for i in 0 .. len(settings_st.sg_defs) { if settings_st.sg_defs[i].key == key { return i } }
return -1
}