Skip to content

Commit 4242782

Browse files
committedAug 19, 2013
World config dialog: Use engine determined path for game mods
1 parent 8548bb7 commit 4242782

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed
 

‎builtin/gamemgr.lua

+28-15
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,35 @@ function gamemgr.delete_mod(gamespec,modindex)
155155
end
156156

157157
--------------------------------------------------------------------------------
158-
function gamemgr.get_game_mods(gamespec)
158+
function gamemgr.find_by_gameid(gameid)
159+
for i=1,#gamemgr.games,1 do
160+
if gamemgr.games[i].id == gameid then
161+
return gamemgr.games[i], i
162+
end
163+
end
164+
return nil, nil
165+
end
159166

160-
local retval = ""
161-
162-
if gamespec.gamemods_path ~= nil and
167+
--------------------------------------------------------------------------------
168+
function gamemgr.get_game_mods(gamespec, retval)
169+
if gamespec ~= nil and
170+
gamespec.gamemods_path ~= nil and
163171
gamespec.gamemods_path ~= "" then
164-
local game_mods = {}
165-
get_mods(gamespec.gamemods_path,game_mods)
166-
167-
for i=1,#game_mods,1 do
168-
if retval ~= "" then
169-
retval = retval..","
170-
end
171-
retval = retval .. game_mods[i].name
172-
end
172+
get_mods(gamespec.gamemods_path, retval)
173173
end
174+
end
175+
176+
--------------------------------------------------------------------------------
177+
function gamemgr.get_game_modlist(gamespec)
178+
local retval = ""
179+
local game_mods = {}
180+
gamemgr.get_game_mods(gamespec, game_mods)
181+
for i=1,#game_mods,1 do
182+
if retval ~= "" then
183+
retval = retval..","
184+
end
185+
retval = retval .. game_mods[i].name
186+
end
174187
return retval
175188
end
176189

@@ -220,7 +233,7 @@ function gamemgr.tab()
220233
"label[6,1.4;" .. fgettext("Mods:") .."]" ..
221234
"button[9.7,1.5;2,0.2;btn_game_mgr_edit_game;" .. fgettext("edit game") .. "]" ..
222235
"textlist[6,2;5.5,3.3;game_mgr_modlist;"
223-
.. gamemgr.get_game_mods(current_game) ..";0]" ..
236+
.. gamemgr.get_game_modlist(current_game) ..";0]" ..
224237
"button[1,4.75;3.2,0.5;btn_game_mgr_new_game;" .. fgettext("new game") .. "]"
225238
end
226239
return retval
@@ -243,7 +256,7 @@ function gamemgr.dialog_edit_game()
243256

244257
retval = retval ..
245258
"textlist[0.5,0.5;4.5,4.3;mods_current;"
246-
.. gamemgr.get_game_mods(current_game) ..";0]"
259+
.. gamemgr.get_game_modlist(current_game) ..";0]"
247260

248261

249262
retval = retval ..

‎builtin/mainmenu.lua

+5-7
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,11 @@ function menu.update_last_game()
237237
if current_world == nil then
238238
return
239239
end
240-
241-
for i=1,#gamemgr.games,1 do
242-
if gamemgr.games[i].id == current_world.gameid then
243-
menu.last_game = i
244-
engine.setting_set("main_menu_last_game_idx",menu.last_game)
245-
break
246-
end
240+
241+
local gamespec, i = gamemgr.find_by_gameid(current_world.gameid)
242+
if i ~= nil then
243+
menu.last_game = i
244+
engine.setting_set("main_menu_last_game_idx",menu.last_game)
247245
end
248246
end
249247

‎builtin/modmgr.lua

+4-9
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,8 @@ function modmgr.get_worldconfig(worldpath)
529529
end
530530

531531
--read gamemods
532-
local gamemodpath = engine.get_gamepath() .. DIR_DELIM .. worldconfig.id .. DIR_DELIM .. "mods"
533-
534-
get_mods(gamemodpath,worldconfig.game_mods)
532+
local gamespec = gamemgr.find_by_gameid(worldconfig.id)
533+
gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
535534

536535
return worldconfig
537536
end
@@ -871,12 +870,8 @@ function modmgr.preparemodlist(data)
871870
end
872871

873872
--read game mods
874-
if data.gameid ~= nil and
875-
data.gameid ~= "" then
876-
local gamemodpath = engine.get_gamepath() .. DIR_DELIM .. data.gameid .. DIR_DELIM .. "mods"
877-
878-
get_mods(gamemodpath,game_mods)
879-
end
873+
local gamespec = gamemgr.find_by_gameid(data.gameid)
874+
gamemgr.get_game_mods(gamespec, game_mods)
880875

881876
for i=1,#game_mods,1 do
882877
game_mods[i].typ = "game_mod"

0 commit comments

Comments
 (0)
Please sign in to comment.