From df9d85a0d1c703d9ec2cbed9d05baebaffc9c2a9 Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 03:25:28 +0800 Subject: [PATCH 01/21] Add flexibility for changing vanilla module versions --- gui/mod-manager.lua | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 7e6b6efe7..183962cdf 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -12,11 +12,45 @@ local widgets = require('gui.widgets') local presets_file = json.open("dfhack-config/mod-manager.json") local GLOBAL_KEY = 'mod-manager' +local vanilla_modules = { + ['vanilla_text'] = true, + ['vanilla_languages'] = true, + ['vanilla_descriptors'] = true, + ['vanilla_materials'] = true, + ['vanilla_environment'] = true, + ['vanilla_plants'] = true, + ['vanilla_items'] = true, + ['vanilla_buildings'] = true, + ['vanilla_bodies'] = true, + ['vanilla_creatures'] = true, + ['vanilla_entities'] = true, + ['vanilla_reactions'] = true, + ['vanilla_interactions'] = true, + ['vanilla_descriptors_graphics'] = true, + ['vanilla_plants_graphics'] = true, + ['vanilla_items_graphics'] = true, + ['vanilla_buildings_graphics'] = true, + ['vanilla_creatures_graphics'] = true, + ['vanilla_interactions_graphics'] = true, + ['vanilla_world_map'] = true, + ['vanilla_interface'] = true, + ['vanilla_music'] = true, +} + +function get_moddable_viewscreen(type) + local vs = nil + if type == 'region' then + vs = dfhack.gui.getViewscreenByType(df.viewscreen_new_regionst, 0) + elseif type == 'arena' then + vs = dfhack.gui.getViewscreenByType(df.viewscreen_new_arenast, 0) + end + return vs +end + -- get_newregion_viewscreen and get_modlist_fields are declared as global functions -- so external tools can call them to get the DF mod list function get_newregion_viewscreen() - local vs = dfhack.gui.getViewscreenByType(df.viewscreen_new_regionst, 0) - return vs + return get_moddable_viewscreen('region') end function get_modlist_fields(kind, viewscreen) @@ -62,7 +96,9 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) local mod_index = nil for i, v in ipairs(from_fields.id) do local version = from_fields.numeric_version[i] - if v.value == mod_id and version == mod_version then + local vanilla = vanilla_modules[mod_id] + -- assuming that vanilla mods will not have multiple possible indices + if v.value == mod_id and (vanilla or version == mod_version) then mod_index = i break end From 3b49b24c6ddedf305d18f5575574504fdee263f6 Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 04:30:15 +0800 Subject: [PATCH 02/21] Add comments --- gui/mod-manager.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 183962cdf..784055c4a 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -12,6 +12,9 @@ local widgets = require('gui.widgets') local presets_file = json.open("dfhack-config/mod-manager.json") local GLOBAL_KEY = 'mod-manager' +-- hardly an elegant solution, but mysteriously, +-- using from_fields.src_dir[i].startswith('data/vanilla') in move_mod_entry() +-- leads to lua complaining that it 'cannot read field string.startswith: not found' local vanilla_modules = { ['vanilla_text'] = true, ['vanilla_languages'] = true, @@ -97,7 +100,7 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) for i, v in ipairs(from_fields.id) do local version = from_fields.numeric_version[i] local vanilla = vanilla_modules[mod_id] - -- assuming that vanilla mods will not have multiple possible indices + -- assumes that vanilla mods will not have multiple possible indices. if v.value == mod_id and (vanilla or version == mod_version) then mod_index = i break From cadf06b017a91d316343bac0a5ef3f50ef26116a Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 16:29:31 +0800 Subject: [PATCH 03/21] Edit vanilla mod identification logic --- gui/mod-manager.lua | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 784055c4a..832a2c148 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -12,34 +12,15 @@ local widgets = require('gui.widgets') local presets_file = json.open("dfhack-config/mod-manager.json") local GLOBAL_KEY = 'mod-manager' --- hardly an elegant solution, but mysteriously, --- using from_fields.src_dir[i].startswith('data/vanilla') in move_mod_entry() --- leads to lua complaining that it 'cannot read field string.startswith: not found' -local vanilla_modules = { - ['vanilla_text'] = true, - ['vanilla_languages'] = true, - ['vanilla_descriptors'] = true, - ['vanilla_materials'] = true, - ['vanilla_environment'] = true, - ['vanilla_plants'] = true, - ['vanilla_items'] = true, - ['vanilla_buildings'] = true, - ['vanilla_bodies'] = true, - ['vanilla_creatures'] = true, - ['vanilla_entities'] = true, - ['vanilla_reactions'] = true, - ['vanilla_interactions'] = true, - ['vanilla_descriptors_graphics'] = true, - ['vanilla_plants_graphics'] = true, - ['vanilla_items_graphics'] = true, - ['vanilla_buildings_graphics'] = true, - ['vanilla_creatures_graphics'] = true, - ['vanilla_interactions_graphics'] = true, - ['vanilla_world_map'] = true, - ['vanilla_interface'] = true, - ['vanilla_music'] = true, -} +-- Shamelessly taken from hack/library/lua/script-manager.lua +function vanilla(dir) + dir = dir.value + dir = dir -- better safe than sorry i guess + return dir:startswith('data/vanilla') +end +-- get_moddable_viewscreen(), get_any_moddable_viewscreen() and get_modlist_fields are declared +-- as global functions so external tools can call them to get the DF mod list function get_moddable_viewscreen(type) local vs = nil if type == 'region' then @@ -99,9 +80,9 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) local mod_index = nil for i, v in ipairs(from_fields.id) do local version = from_fields.numeric_version[i] - local vanilla = vanilla_modules[mod_id] + local src_dir = from_fields.src_dir[i] -- assumes that vanilla mods will not have multiple possible indices. - if v.value == mod_id and (vanilla or version == mod_version) then + if v.value == mod_id and (vanilla(src_dir) or version == mod_version) then mod_index = i break end From f194ffd6c82f144447ceef2ec62b078c27b81fe7 Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 16:29:59 +0800 Subject: [PATCH 04/21] Add support for arena mode --- gui/mod-manager.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 832a2c148..7783fbca4 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -19,7 +19,7 @@ function vanilla(dir) return dir:startswith('data/vanilla') end --- get_moddable_viewscreen(), get_any_moddable_viewscreen() and get_modlist_fields are declared +-- get_moddable_viewscreen(), get_any_moddable_viewscreen() and get_modlist_fields are declared -- as global functions so external tools can call them to get the DF mod list function get_moddable_viewscreen(type) local vs = nil @@ -31,10 +31,12 @@ function get_moddable_viewscreen(type) return vs end --- get_newregion_viewscreen and get_modlist_fields are declared as global functions --- so external tools can call them to get the DF mod list -function get_newregion_viewscreen() - return get_moddable_viewscreen('region') +function get_any_moddable_viewscreen() + local vs = dfhack.gui.getViewscreenByType(df.viewscreen_new_regionst, 0) + if not vs then + vs = dfhack.gui.getViewscreenByType(df.viewscreen_new_arenast, 0) + end + return vs end function get_modlist_fields(kind, viewscreen) @@ -157,7 +159,7 @@ ModmanageMenu.ATTRS { } local function save_new_preset(preset_name) - local viewscreen = get_newregion_viewscreen() + local viewscreen = get_any_moddable_viewscreen() local modlist = get_active_modlist(viewscreen) table.insert(presets_file.data, { name = preset_name, modlist = modlist }) presets_file:write() @@ -177,7 +179,7 @@ local function overwrite_preset(idx) return end - local viewscreen = get_newregion_viewscreen() + local viewscreen = get_any_moddable_viewscreen() local modlist = get_active_modlist(viewscreen) presets_file.data[idx].modlist = modlist presets_file:write() @@ -188,7 +190,7 @@ local function load_preset(idx, unset_default_on_failure) return end - local viewscreen = get_newregion_viewscreen() + local viewscreen = get_any_moddable_viewscreen() local modlist = presets_file.data[idx].modlist local failures = swap_modlist(viewscreen, modlist) @@ -225,7 +227,7 @@ local function load_preset(idx, unset_default_on_failure) table.insert(text, NEWLINE) end dialogs.showMessage("Warning", text) -end + end end local function find_preset_by_name(name) @@ -593,7 +595,7 @@ ModmanageOverlay.ATTRS { desc = "Adds a link to the mod selection screen for accessing the mod manager.", default_pos = { x=5, y=-6 }, version = 2, - viewscreens = { "new_region/Mods" }, + viewscreens = { "new_region/Mods", "new_arena/Mods" }, default_enabled=true, } @@ -656,7 +658,7 @@ notification_timer_fn() local default_applied = false dfhack.onStateChange[GLOBAL_KEY] = function(sc) if sc == SC_VIEWSCREEN_CHANGED then - local vs = get_newregion_viewscreen() + local vs = get_any_moddable_viewscreen() if vs and not default_applied then default_applied = true for i, v in ipairs(presets_file.data) do From d6e12541a4c88b39287f3c325d991aaae92cace6 Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 18:12:00 +0800 Subject: [PATCH 05/21] Add notifications for updated mods --- gui/mod-manager.lua | 99 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 24 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 7783fbca4..16f6aa037 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -13,7 +13,7 @@ local presets_file = json.open("dfhack-config/mod-manager.json") local GLOBAL_KEY = 'mod-manager' -- Shamelessly taken from hack/library/lua/script-manager.lua -function vanilla(dir) +local function vanilla(dir) dir = dir.value dir = dir -- better safe than sorry i guess return dir:startswith('data/vanilla') @@ -75,23 +75,29 @@ function get_modlist_fields(kind, viewscreen) end end +--- @return { success: boolean, version: string } local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) local to_fields = get_modlist_fields(to, viewscreen) local from_fields = get_modlist_fields(from, viewscreen) local mod_index = nil + local loaded_version = nil for i, v in ipairs(from_fields.id) do local version = from_fields.numeric_version[i] local src_dir = from_fields.src_dir[i] + local displayed_version = from_fields.displayed_version[i].value -- assumes that vanilla mods will not have multiple possible indices. if v.value == mod_id and (vanilla(src_dir) or version == mod_version) then + if version ~= mod_version then + loaded_version = displayed_version + end mod_index = i break end end if mod_index == nil then - return false + return { success= false, version= nil } end for k, v in pairs(to_fields) do @@ -106,13 +112,15 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) v:erase(mod_index) end - return true + return { success= true, version= loaded_version } end +--- @return { success: boolean, version: string } local function enable_mod(viewscreen, mod_id, mod_version) return move_mod_entry(viewscreen, "object_load_order", "available", mod_id, mod_version) end +--- @return { success: boolean, version: string } local function disable_mod(viewscreen, mod_id, mod_version) return move_mod_entry(viewscreen, "available", "object_load_order", mod_id, mod_version) end @@ -127,6 +135,7 @@ local function get_active_modlist(viewscreen) return t end +--- @return { failures: [string], changed: [{ id: string, new: string }] } local function swap_modlist(viewscreen, modlist) local current = get_active_modlist(viewscreen) for _, v in ipairs(current) do @@ -134,12 +143,17 @@ local function swap_modlist(viewscreen, modlist) end local failures = {} + local changed = {} for _, v in ipairs(modlist) do - if not enable_mod(viewscreen, v.id, v.version) then + res = enable_mod(viewscreen, v.id, v.version) + if not res.success then table.insert(failures, v.id) end + if res.version then + table.insert(changed, { id= v.id, new= res.version }) + end end - return failures + return { failures= failures, changed= changed } end -------------------- @@ -192,33 +206,53 @@ local function load_preset(idx, unset_default_on_failure) local viewscreen = get_any_moddable_viewscreen() local modlist = presets_file.data[idx].modlist - local failures = swap_modlist(viewscreen, modlist) - - if #failures > 0 then - local text = {} - if unset_default_on_failure then - presets_file.data[idx].default = false - presets_file:write() - - table.insert(text, { - text='Failed to load some mods from your default preset.', - pen=COLOR_LIGHTRED, - }) + local results = swap_modlist(viewscreen, modlist) + local failures = results.failures + local changes = results.changed + local text = {} + + local failed = #failures > 0 + local changed = #changes > 0 + local should_warn = failed or changed + + if should_warn then + if failed then + if unset_default_on_failure then + presets_file.data[idx].default = false + presets_file:write() + + table.insert(text, { + text='Failed to load some mods from your default preset.', + pen=COLOR_LIGHTRED, + }) + table.insert(text, NEWLINE) + table.insert(text, { + text='Preset is being unmarked as the default for safety.', + pen=COLOR_LIGHTRED, + }) + else + table.insert(text, { + text='Failed to load some mods from the preset.', + pen=COLOR_LIGHTRED, + }) + end + end + if failed and changed then table.insert(text, NEWLINE) + end + if changed then table.insert(text, { - text='Preset is being unmarked as the default for safety.', - pen=COLOR_LIGHTRED, - }) - else - table.insert(text, { - text='Failed to load some mods from the preset.', + text='Some vanilla mods have been updated.', pen=COLOR_LIGHTRED, }) end table.insert(text, NEWLINE) - table.insert(text, NEWLINE) table.insert(text, 'Please re-create your preset with mods you currently have installed.') table.insert(text, NEWLINE) + table.insert(text, NEWLINE) + end + + if failed then table.insert(text, 'Here are the mods that failed to load:') table.insert(text, NEWLINE) table.insert(text, NEWLINE) @@ -226,6 +260,23 @@ local function load_preset(idx, unset_default_on_failure) table.insert(text, ('- %s'):format(v)) table.insert(text, NEWLINE) end + end + + if failed and changed then + table.insert(text, NEWLINE) -- just to separate the sections + end + + if changed then + table.insert(text, 'Here are the vanilla mods that have been updated:') + table.insert(text, NEWLINE) + table.insert(text, NEWLINE) + for _, v in ipairs(changes) do + table.insert(text, ('- %s to %s'):format(v.id, v.new)) + table.insert(text, NEWLINE) + end + end + + if should_warn then dialogs.showMessage("Warning", text) end end From a292f126b17d133c97e66b6ccd143b90f924511e Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 18:25:48 +0800 Subject: [PATCH 06/21] Update changelog --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index a937e2fb2..afab6089d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -35,6 +35,7 @@ Template for new versions: ## Fixes - `gui/journal`: fix typo which caused the table of contents to always be regenerated even when not needed - `gui/mod-manager`: gracefully handle mods with missing or broken ``info.txt`` files +- `gui/mod-manager`: gracefully handle vanilla mods with different versions from the user's preset - `uniform-unstick`: resolve overlap with new buttons in 51.13 ## Misc Improvements From 90d437e9a7adad61ec8139df3e730345037d6bdd Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 19:56:56 +0800 Subject: [PATCH 07/21] Refactor warning logic --- gui/mod-manager.lua | 82 ++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 16f6aa037..0c53078ec 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -199,6 +199,44 @@ local function overwrite_preset(idx) presets_file:write() end +local function prepare_warning(text, failed, changed, unset_default_on_failure) + if not failed and not changed then return end + + if failed then + if unset_default_on_failure then + table.insert(text, { + text='Failed to load some mods from your default preset.', + pen=COLOR_LIGHTRED, + }) + table.insert(text, NEWLINE) + table.insert(text, { + text='Preset is being unmarked as the default for safety.', + pen=COLOR_LIGHTRED, + }) + else + table.insert(text, { + text='Failed to load some mods from the preset.', + pen=COLOR_LIGHTRED, + }) + end + end + + if failed and changed then + table.insert(text, NEWLINE) + end + + if changed then + table.insert(text, { + text='Some vanilla mods have been updated.', + pen=COLOR_LIGHTRED, + }) + end + table.insert(text, NEWLINE) + table.insert(text, 'Please re-create your preset with mods you currently have installed.') + table.insert(text, NEWLINE) + table.insert(text, NEWLINE) +end + local function load_preset(idx, unset_default_on_failure) if idx > #presets_file.data then return @@ -213,43 +251,11 @@ local function load_preset(idx, unset_default_on_failure) local failed = #failures > 0 local changed = #changes > 0 - local should_warn = failed or changed - - if should_warn then - if failed then - if unset_default_on_failure then - presets_file.data[idx].default = false - presets_file:write() - - table.insert(text, { - text='Failed to load some mods from your default preset.', - pen=COLOR_LIGHTRED, - }) - table.insert(text, NEWLINE) - table.insert(text, { - text='Preset is being unmarked as the default for safety.', - pen=COLOR_LIGHTRED, - }) - else - table.insert(text, { - text='Failed to load some mods from the preset.', - pen=COLOR_LIGHTRED, - }) - end - end - if failed and changed then - table.insert(text, NEWLINE) - end - if changed then - table.insert(text, { - text='Some vanilla mods have been updated.', - pen=COLOR_LIGHTRED, - }) - end - table.insert(text, NEWLINE) - table.insert(text, 'Please re-create your preset with mods you currently have installed.') - table.insert(text, NEWLINE) - table.insert(text, NEWLINE) + + prepare_warning(text, failed, changed) + if failed and unset_default_on_failure then + presets_file.data[idx].default = false + presets_file:write() end if failed then @@ -276,7 +282,7 @@ local function load_preset(idx, unset_default_on_failure) end end - if should_warn then + if failed or changed then dialogs.showMessage("Warning", text) end end From 3655e85492b9e0fd7a0ae27814d5861a6f6788dd Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 23:11:49 +0800 Subject: [PATCH 08/21] Remove excess locals assignment --- gui/mod-manager.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 0c53078ec..686fc31f2 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -15,7 +15,6 @@ local GLOBAL_KEY = 'mod-manager' -- Shamelessly taken from hack/library/lua/script-manager.lua local function vanilla(dir) dir = dir.value - dir = dir -- better safe than sorry i guess return dir:startswith('data/vanilla') end From 3612f48ed1f749f50aa462d196c940b7982eeb4e Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 23:22:54 +0800 Subject: [PATCH 09/21] Add missing local assignment --- gui/mod-manager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 686fc31f2..350ac3143 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -144,7 +144,7 @@ local function swap_modlist(viewscreen, modlist) local failures = {} local changed = {} for _, v in ipairs(modlist) do - res = enable_mod(viewscreen, v.id, v.version) + local res = enable_mod(viewscreen, v.id, v.version) if not res.success then table.insert(failures, v.id) end From 71c5b15fea8979aa1937c6eaff36c50c66d54070 Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sun, 13 Jul 2025 23:58:29 +0800 Subject: [PATCH 10/21] Add missing changelog entry --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index afab6089d..e5bd22e76 100644 --- a/changelog.txt +++ b/changelog.txt @@ -36,6 +36,7 @@ Template for new versions: - `gui/journal`: fix typo which caused the table of contents to always be regenerated even when not needed - `gui/mod-manager`: gracefully handle mods with missing or broken ``info.txt`` files - `gui/mod-manager`: gracefully handle vanilla mods with different versions from the user's preset +- `gui/mod-manager`: now supports arena mode - `uniform-unstick`: resolve overlap with new buttons in 51.13 ## Misc Improvements From 16ce689f74a5a58d67391e7516ca42664b7914d6 Mon Sep 17 00:00:00 2001 From: yg-ong Date: Thu, 17 Jul 2025 22:53:03 +0800 Subject: [PATCH 11/21] Fix possible fallthrough in swap_modlist --- gui/mod-manager.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 350ac3143..87928b5eb 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -147,8 +147,7 @@ local function swap_modlist(viewscreen, modlist) local res = enable_mod(viewscreen, v.id, v.version) if not res.success then table.insert(failures, v.id) - end - if res.version then + elseif res.version then table.insert(changed, { id= v.id, new= res.version }) end end From 821fef9d916a8bcdd4864a163931749b431114f0 Mon Sep 17 00:00:00 2001 From: Ong Ying Gao <52755148+ong-yinggao98@users.noreply.github.com> Date: Sat, 26 Jul 2025 04:28:42 +0800 Subject: [PATCH 12/21] Update gui/mod-manager.lua Co-authored-by: SilasD --- gui/mod-manager.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 87928b5eb..3a53c19d6 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -134,7 +134,8 @@ local function get_active_modlist(viewscreen) return t end ---- @return { failures: [string], changed: [{ id: string, new: string }] } +--- @return string[] +--- @return { id: string, new: string }[] local function swap_modlist(viewscreen, modlist) local current = get_active_modlist(viewscreen) for _, v in ipairs(current) do From 466c058a71c2d8d45825a87a8137f9b6dba3d80a Mon Sep 17 00:00:00 2001 From: Ong Ying Gao <52755148+ong-yinggao98@users.noreply.github.com> Date: Sat, 26 Jul 2025 04:30:01 +0800 Subject: [PATCH 13/21] Update gui/mod-manager.lua Co-authored-by: SilasD --- gui/mod-manager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 3a53c19d6..48d9606a8 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -152,7 +152,7 @@ local function swap_modlist(viewscreen, modlist) table.insert(changed, { id= v.id, new= res.version }) end end - return { failures= failures, changed= changed } + return failures, changed end -------------------- From 077e3c9c045c3a29d8432ce506090cdc1c55f011 Mon Sep 17 00:00:00 2001 From: Ong Ying Gao <52755148+ong-yinggao98@users.noreply.github.com> Date: Sat, 26 Jul 2025 04:30:28 +0800 Subject: [PATCH 14/21] Update gui/mod-manager.lua Co-authored-by: SilasD --- gui/mod-manager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 48d9606a8..645df30c7 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -243,7 +243,7 @@ local function load_preset(idx, unset_default_on_failure) local viewscreen = get_any_moddable_viewscreen() local modlist = presets_file.data[idx].modlist - local results = swap_modlist(viewscreen, modlist) + local failures, changed = swap_modlist(viewscreen, modlist) local failures = results.failures local changes = results.changed local text = {} From 0fb8e3a2d28237f8fb274f147933f891036d8fca Mon Sep 17 00:00:00 2001 From: Ong Ying Gao <52755148+ong-yinggao98@users.noreply.github.com> Date: Sat, 26 Jul 2025 04:30:39 +0800 Subject: [PATCH 15/21] Update gui/mod-manager.lua Co-authored-by: SilasD --- gui/mod-manager.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 645df30c7..8850e40d4 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -245,7 +245,6 @@ local function load_preset(idx, unset_default_on_failure) local modlist = presets_file.data[idx].modlist local failures, changed = swap_modlist(viewscreen, modlist) local failures = results.failures - local changes = results.changed local text = {} local failed = #failures > 0 From 7127f4b10c1b8315a2f44caf36d431bd456d2bd6 Mon Sep 17 00:00:00 2001 From: Ong Ying Gao <52755148+ong-yinggao98@users.noreply.github.com> Date: Sat, 26 Jul 2025 04:31:34 +0800 Subject: [PATCH 16/21] Update gui/mod-manager.lua Co-authored-by: SilasD --- gui/mod-manager.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 8850e40d4..da844c025 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -74,7 +74,8 @@ function get_modlist_fields(kind, viewscreen) end end ---- @return { success: boolean, version: string } +---@return boolean # true if the mod entry was moved; false if the mod or mod version was not found. +---@return version # string - DISPLAYED_VERSION from the mod's info.txt local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) local to_fields = get_modlist_fields(to, viewscreen) local from_fields = get_modlist_fields(from, viewscreen) From fbb2ae021edc0c8017d016edf83198901f1a4fcc Mon Sep 17 00:00:00 2001 From: Ong Ying Gao <52755148+ong-yinggao98@users.noreply.github.com> Date: Sat, 26 Jul 2025 04:32:00 +0800 Subject: [PATCH 17/21] Update gui/mod-manager.lua Co-authored-by: SilasD --- gui/mod-manager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index da844c025..ac3ce6148 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -112,7 +112,7 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) v:erase(mod_index) end - return { success= true, version= loaded_version } + return true, loaded_version end --- @return { success: boolean, version: string } From ef7986a68e68f900dfdcc2a2dcb2dba5ade391fe Mon Sep 17 00:00:00 2001 From: Ong Ying Gao <52755148+ong-yinggao98@users.noreply.github.com> Date: Sat, 26 Jul 2025 04:32:45 +0800 Subject: [PATCH 18/21] Apply suggestions from code review Co-authored-by: SilasD --- gui/mod-manager.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index ac3ce6148..9bd1778c4 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -115,12 +115,14 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) return true, loaded_version end ---- @return { success: boolean, version: string } +---@return boolean # true if the mod entry was moved; false if the mod or mod version was not found. +---@return version # string - DISPLAYED_VERSION from the mod's info.txt local function enable_mod(viewscreen, mod_id, mod_version) return move_mod_entry(viewscreen, "object_load_order", "available", mod_id, mod_version) end ---- @return { success: boolean, version: string } +---@return boolean # returns true if the mod entry was moved; returns false if the mod or mod version was not found. +---@return version # string - DISPLAYED_VERSION from the mod's info.txt local function disable_mod(viewscreen, mod_id, mod_version) return move_mod_entry(viewscreen, "available", "object_load_order", mod_id, mod_version) end @@ -146,11 +148,11 @@ local function swap_modlist(viewscreen, modlist) local failures = {} local changed = {} for _, v in ipairs(modlist) do - local res = enable_mod(viewscreen, v.id, v.version) - if not res.success then + local success, version = enable_mod(viewscreen, v.id, v.version) + if not success then table.insert(failures, v.id) - elseif res.version then - table.insert(changed, { id= v.id, new= res.version }) + elseif version then + table.insert(changed, { id= v.id, new= version }) end end return failures, changed @@ -245,7 +247,6 @@ local function load_preset(idx, unset_default_on_failure) local viewscreen = get_any_moddable_viewscreen() local modlist = presets_file.data[idx].modlist local failures, changed = swap_modlist(viewscreen, modlist) - local failures = results.failures local text = {} local failed = #failures > 0 From 68f87f6db80ac224218e78b2317bd9820eab6ee5 Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sat, 26 Jul 2025 04:39:04 +0800 Subject: [PATCH 19/21] Remove comment --- gui/mod-manager.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 9bd1778c4..d78f0bc8f 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -12,7 +12,6 @@ local widgets = require('gui.widgets') local presets_file = json.open("dfhack-config/mod-manager.json") local GLOBAL_KEY = 'mod-manager' --- Shamelessly taken from hack/library/lua/script-manager.lua local function vanilla(dir) dir = dir.value return dir:startswith('data/vanilla') @@ -75,7 +74,7 @@ function get_modlist_fields(kind, viewscreen) end ---@return boolean # true if the mod entry was moved; false if the mod or mod version was not found. ----@return version # string - DISPLAYED_VERSION from the mod's info.txt +---@return version # string - DISPLAYED_VERSION from the mod's info.txt local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) local to_fields = get_modlist_fields(to, viewscreen) local from_fields = get_modlist_fields(from, viewscreen) @@ -116,13 +115,13 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) end ---@return boolean # true if the mod entry was moved; false if the mod or mod version was not found. ----@return version # string - DISPLAYED_VERSION from the mod's info.txt +---@return version # string - DISPLAYED_VERSION from the mod's info.txt local function enable_mod(viewscreen, mod_id, mod_version) return move_mod_entry(viewscreen, "object_load_order", "available", mod_id, mod_version) end ---@return boolean # returns true if the mod entry was moved; returns false if the mod or mod version was not found. ----@return version # string - DISPLAYED_VERSION from the mod's info.txt +---@return version # string - DISPLAYED_VERSION from the mod's info.txt local function disable_mod(viewscreen, mod_id, mod_version) return move_mod_entry(viewscreen, "available", "object_load_order", mod_id, mod_version) end From 72b13db868a280e87da4755e6092911e864bec5d Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sat, 26 Jul 2025 05:39:08 +0800 Subject: [PATCH 20/21] Update for 52.02 paths --- gui/mod-manager.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index d78f0bc8f..5e258b470 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -13,7 +13,6 @@ local presets_file = json.open("dfhack-config/mod-manager.json") local GLOBAL_KEY = 'mod-manager' local function vanilla(dir) - dir = dir.value return dir:startswith('data/vanilla') end @@ -245,7 +244,7 @@ local function load_preset(idx, unset_default_on_failure) local viewscreen = get_any_moddable_viewscreen() local modlist = presets_file.data[idx].modlist - local failures, changed = swap_modlist(viewscreen, modlist) + local failures, changes = swap_modlist(viewscreen, modlist) local text = {} local failed = #failures > 0 From 63a64fd83ea96e0233c45f4bc9f88333c0a02d11 Mon Sep 17 00:00:00 2001 From: yg-ong Date: Sat, 26 Jul 2025 18:03:49 +0800 Subject: [PATCH 21/21] Edit docstrings --- gui/mod-manager.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gui/mod-manager.lua b/gui/mod-manager.lua index 5e258b470..12029661b 100644 --- a/gui/mod-manager.lua +++ b/gui/mod-manager.lua @@ -72,8 +72,8 @@ function get_modlist_fields(kind, viewscreen) end end ----@return boolean # true if the mod entry was moved; false if the mod or mod version was not found. ----@return version # string - DISPLAYED_VERSION from the mod's info.txt +---@return boolean # true if the mod entry was moved; false if the mod or mod version was not found. +---@return string|nil # loaded version - DISPLAYED_VERSION from the mod's info.txt local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) local to_fields = get_modlist_fields(to, viewscreen) local from_fields = get_modlist_fields(from, viewscreen) @@ -95,7 +95,7 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) end if mod_index == nil then - return { success= false, version= nil } + return false, nil end for k, v in pairs(to_fields) do @@ -106,21 +106,21 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version) end end - for k, v in pairs(from_fields) do + for _, v in pairs(from_fields) do v:erase(mod_index) end return true, loaded_version end ----@return boolean # true if the mod entry was moved; false if the mod or mod version was not found. ----@return version # string - DISPLAYED_VERSION from the mod's info.txt +---@return boolean # true if the mod entry was moved; false if the mod or mod version was not found. +---@return string|nil # loaded version - DISPLAYED_VERSION from the mod's info.txt local function enable_mod(viewscreen, mod_id, mod_version) return move_mod_entry(viewscreen, "object_load_order", "available", mod_id, mod_version) end ----@return boolean # returns true if the mod entry was moved; returns false if the mod or mod version was not found. ----@return version # string - DISPLAYED_VERSION from the mod's info.txt +---@return boolean # true if the mod entry was moved; false if the mod or mod version was not found. +---@return string|nil # loaded version - DISPLAYED_VERSION from the mod's info.txt local function disable_mod(viewscreen, mod_id, mod_version) return move_mod_entry(viewscreen, "available", "object_load_order", mod_id, mod_version) end