Use the Settings Lua interface to read world.mt

This commit is contained in:
PilzAdam 2013-09-10 21:09:21 +02:00
parent dd5c451e03
commit 214da7bef9
1 changed files with 46 additions and 72 deletions

View File

@ -498,36 +498,18 @@ function modmgr.get_worldconfig(worldpath)
local filename = worldpath .. local filename = worldpath ..
DIR_DELIM .. "world.mt" DIR_DELIM .. "world.mt"
local worldfile = io.open(filename,"r") local worldfile = Settings(filename)
local worldconfig = {} local worldconfig = {}
worldconfig.global_mods = {} worldconfig.global_mods = {}
worldconfig.game_mods = {} worldconfig.game_mods = {}
if worldfile then for key,value in pairs(worldfile:to_table()) do
local dependency = worldfile:read("*l") if key == "gameid" then
while dependency do worldconfig.id = value
local parts = dependency:split("=") else
worldconfig.global_mods[key] = engine.is_yes(value)
local key = parts[1]:trim()
if key == "gameid" then
worldconfig.id = parts[2]:trim()
elseif key == "backend" then
worldconfig.backend = parts[2]:trim()
else
local key = parts[1]:trim():sub(10)
if parts[2]:trim() == "true" then
worldconfig.global_mods[key] = true
else
worldconfig.global_mods[key] = false
end
end
dependency = worldfile:read("*l")
end end
worldfile:close()
else
print("Modmgr: " .. filename .. " not found")
end end
--read gamemods --read gamemods
@ -728,28 +710,33 @@ function modmgr.handle_configure_world_buttons(fields)
local filename = worldspec.path .. local filename = worldspec.path ..
DIR_DELIM .. "world.mt" DIR_DELIM .. "world.mt"
local worldfile = io.open(filename,"w") local worldfile = Settings(filename)
local mods = worldfile:to_table()
if worldfile then local rawlist = filterlist.get_raw_list(modmgr.modlist)
worldfile:write("gameid = " .. modmgr.worldconfig.id .. "\nbackend = " .. modmgr.worldconfig.backend .. "\n")
local rawlist = filterlist.get_raw_list(modmgr.modlist) local i,mod
for i,mod in ipairs(rawlist) do
for i=1,#rawlist,1 do if not mod.is_modpack and
mod.typ ~= "game_mod" then
if not rawlist[i].is_modpack and if mod.enabled then
rawlist[i].typ ~= "game_mod" then worldfile:set("load_mod_"..mod.name, "true")
if rawlist[i].enabled then else
worldfile:write("load_mod_" .. rawlist[i].name .. " = true" .. "\n") worldfile:set("load_mod_"..mod.name, "false")
else
worldfile:write("load_mod_" .. rawlist[i].name .. " = false" .. "\n")
end
end end
mods["load_mod_"..mod.name] = nil
end end
end
worldfile:close() -- Remove mods that are not present anymore
else for key,value in pairs(mods) do
print("failed to open world config file") if key:sub(1,9) == "load_mod_" then
worldfile:remove(key)
end
end
if not worldfile:write() then
print("failed to write world config file")
end end
modmgr.modlist = nil modmgr.modlist = nil
@ -888,37 +875,24 @@ function modmgr.preparemodlist(data)
local filename = data.worldpath .. local filename = data.worldpath ..
DIR_DELIM .. "world.mt" DIR_DELIM .. "world.mt"
local worldfile = io.open(filename,"r") local worldfile = Settings(filename)
if worldfile then
local dependency = worldfile:read("*l")
while dependency do
local parts = dependency:split("=")
local key = parts[1]:trim() for key,value in pairs(worldfile:to_table()) do
if key:sub(1, 9) == "load_mod_" then
if key ~= "gameid" then key = key:sub(10)
local key = parts[1]:trim():sub(10) local element = nil
local element = nil for i=1,#retval,1 do
for i=1,#retval,1 do if retval[i].name == key then
if retval[i].name == key then element = retval[i]
element = retval[i] break
break
end
end
if element ~= nil then
if parts[2]:trim() == "true" then
element.enabled = true
else
element.enabled = false
end
else
print("Mod: " .. key .. " " .. dump(parts[2]) .. " but not found")
end end
end end
dependency = worldfile:read("*l") if element ~= nil then
element.enabled = engine.is_yes(value)
else
print("Mod: " .. key .. " " .. dump(value) .. " but not found")
end
end end
worldfile:close()
end end
return retval return retval