diff --git a/changelog.txt b/changelog.txt index 9d64cae8a1..c0c124efa4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -49,6 +49,7 @@ Template for new versions: - `makeown`: set target animals to tame and domesticated - `gui/sandbox`: created citizens can now be useful military squad members - `gui/sandbox`: created undead now have a purple shade (after save and reload) +- `control-panel`: restore non-default values of per-save enabled/disabled settings for repeat-based commands ## Misc Improvements - `gui/unit-info-viewer`: now displays a unit's weight, relative to either dwarves, elephants or cats diff --git a/control-panel.lua b/control-panel.lua index 8062d4ae90..7579db0261 100644 --- a/control-panel.lua +++ b/control-panel.lua @@ -39,10 +39,11 @@ local function apply_fort_loaded_config() apply_autostart_config() dfhack.persistent.saveSiteData(GLOBAL_KEY, {autostart_done=true}) end + local enabled_map = common.get_enabled_map() local enabled_repeats = dfhack.persistent.getSiteData(common.REPEATS_GLOBAL_KEY, {}) for _, data in ipairs(registry.COMMANDS_BY_IDX) do - if data.mode == 'repeat' and enabled_repeats[data.command] ~= false then - common.apply_command(data) + if data.mode == 'repeat' then + common.apply_command(data, enabled_map, enabled_repeats[data.command]) end end end diff --git a/internal/control-panel/common.lua b/internal/control-panel/common.lua index a7b08a0c34..21472c45c1 100644 --- a/internal/control-panel/common.lua +++ b/internal/control-panel/common.lua @@ -53,6 +53,10 @@ end config = config or get_config() +local function munge_repeat_name(name) + return 'control-panel/' .. name +end + local function unmunge_repeat_name(munged_name) if munged_name:startswith('control-panel/') then return munged_name:sub(15) @@ -110,12 +114,15 @@ function get_description(data) return helpdb.is_entry(first_word) and helpdb.get_entry_short_help(first_word) or '' end -local function persist_enabled_repeats() +local function persist_repeats() local cp_repeats = {} - for munged_name in pairs(repeatUtil.repeating) do - local name = unmunge_repeat_name(munged_name) - if name then - cp_repeats[name] = true + for _, data in ipairs(registry.COMMANDS_BY_IDX) do + if data.mode == 'repeat' then + if repeatUtil.repeating[munge_repeat_name(data.command)] then + cp_repeats[data.command] = true + else + cp_repeats[data.command] = false + end end end dfhack.persistent.saveSiteData(REPEATS_GLOBAL_KEY, cp_repeats) @@ -147,7 +154,7 @@ function apply_command(data, enabled_map, enabled) dfhack.run_command{enabled and 'enable' or 'disable', data.command} end elseif data.mode == 'repeat' then - local munged_name = 'control-panel/' .. data.command + local munged_name = munge_repeat_name(data.command) if enabled then local command_str = ('repeat --name %s %s\n'): format(munged_name, table.concat(data.params, ' ')) @@ -155,7 +162,7 @@ function apply_command(data, enabled_map, enabled) else repeatUtil.cancel(munged_name) end - persist_enabled_repeats() + persist_repeats() elseif data.mode == 'run' then if enabled then dfhack.run_command(data.command)