Skip to content

Commit 1c570cb

Browse files
Wuzzy2est31
authored andcommittedNov 5, 2016
Separate optional from required mod dependencies in main menu (#4721)
* Separate optional from require dep's in main menu * Simplify modmgr mod dependency listing code
1 parent 66bb295 commit 1c570cb

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed
 

‎builtin/mainmenu/dlg_config_world.lua

+10-5
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ local function get_formspec(data)
4747
if mod == nil then
4848
mod = {name=""}
4949
end
50+
51+
local hard_deps, soft_deps = modmgr.get_dependencies(mod.path)
5052

5153
retval = retval ..
5254
"label[0,0.7;" .. fgettext("Mod:") .. "]" ..
5355
"label[0.75,0.7;" .. mod.name .. "]" ..
54-
"label[0,1.25;" .. fgettext("Depends:") .. "]" ..
55-
"textlist[0,1.75;5,4.25;world_config_depends;" ..
56-
modmgr.get_dependencies(mod.path) .. ";0]" ..
56+
"label[0,1.25;" .. fgettext("Dependencies:") .. "]" ..
57+
"textlist[0,1.75;5,2.125;world_config_depends;" ..
58+
hard_deps .. ";0]" ..
59+
"label[0,3.875;" .. fgettext("Optional dependencies:") .. "]" ..
60+
"textlist[0,4.375;5,1.8;world_config_optdepends;" ..
61+
soft_deps .. ";0]" ..
5762
"button[3.25,7;2.5,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
5863
"button[5.75,7;2.5,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
5964

@@ -86,11 +91,11 @@ local function get_formspec(data)
8691
if enabled_all then
8792
retval = retval ..
8893
"button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]" ..
89-
"textlist[5.5,0.75;5.75,5.25;world_config_modlist;"
94+
"textlist[5.5,0.75;5.75,5.4;world_config_modlist;"
9095
else
9196
retval = retval ..
9297
"button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]" ..
93-
"textlist[5.5,0.75;5.75,5.25;world_config_modlist;"
98+
"textlist[5.5,0.75;5.75,5.4;world_config_modlist;"
9499
end
95100
retval = retval .. modmgr.render_modlist(data.list)
96101
retval = retval .. ";" .. data.selected_mod .."]"

‎builtin/mainmenu/modmgr.lua

+11-6
Original file line numberDiff line numberDiff line change
@@ -284,27 +284,32 @@ end
284284

285285
--------------------------------------------------------------------------------
286286
function modmgr.get_dependencies(modfolder)
287-
local toadd = ""
287+
local toadd_hard = ""
288+
local toadd_soft = ""
288289
if modfolder ~= nil then
289290
local filename = modfolder ..
290291
DIR_DELIM .. "depends.txt"
291292

293+
local hard_dependencies = {}
294+
local soft_dependencies = {}
292295
local dependencyfile = io.open(filename,"r")
293-
294296
if dependencyfile then
295297
local dependency = dependencyfile:read("*l")
296298
while dependency do
297-
if toadd ~= "" then
298-
toadd = toadd .. ","
299+
if string.sub(dependency, -1, -1) == "?" then
300+
table.insert(soft_dependencies, string.sub(dependency, 1, -2))
301+
else
302+
table.insert(hard_dependencies, dependency)
299303
end
300-
toadd = toadd .. dependency
301304
dependency = dependencyfile:read()
302305
end
303306
dependencyfile:close()
304307
end
308+
toadd_hard = table.concat(hard_dependencies, ",")
309+
toadd_soft = table.concat(soft_dependencies, ",")
305310
end
306311

307-
return toadd
312+
return toadd_hard, toadd_soft
308313
end
309314

310315
--------------------------------------------------------------------------------

‎builtin/mainmenu/tab_mods.lua

+18-6
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,24 @@ local function get_formspec(tabview, name, tabdata)
9898
.. fgettext("Uninstall selected modpack") .. "]"
9999
else
100100
--show dependencies
101-
102-
retval = retval .. "," .. fgettext("Depends:") .. ","
103-
104-
local toadd = modmgr.get_dependencies(selected_mod.path)
105-
106-
retval = retval .. toadd .. ";0]"
101+
local toadd_hard, toadd_soft = modmgr.get_dependencies(selected_mod.path)
102+
if toadd_hard == "" and toadd_soft == "" then
103+
retval = retval .. "," .. fgettext("No dependencies.")
104+
else
105+
if toadd_hard ~= "" then
106+
retval = retval .. "," .. fgettext("Dependencies:") .. ","
107+
retval = retval .. toadd_hard
108+
end
109+
if toadd_soft ~= "" then
110+
if toadd_hard ~= "" then
111+
retval = retval .. ","
112+
end
113+
retval = retval .. "," .. fgettext("Optional dependencies:") .. ","
114+
retval = retval .. toadd_soft
115+
end
116+
end
117+
118+
retval = retval .. ";0]"
107119

108120
retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
109121
.. fgettext("Uninstall selected mod") .. "]"

0 commit comments

Comments
 (0)
Please sign in to comment.