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
@ -727,29 +709,34 @@ 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")
if worldfile then local worldfile = Settings(filename)
worldfile:write("gameid = " .. modmgr.worldconfig.id .. "\nbackend = " .. modmgr.worldconfig.backend .. "\n") local mods = worldfile:to_table()
local rawlist = filterlist.get_raw_list(modmgr.modlist) local rawlist = filterlist.get_raw_list(modmgr.modlist)
for i=1,#rawlist,1 do local i,mod
for i,mod in ipairs(rawlist) do
if not rawlist[i].is_modpack and if not mod.is_modpack and
rawlist[i].typ ~= "game_mod" then mod.typ ~= "game_mod" then
if rawlist[i].enabled then if mod.enabled then
worldfile:write("load_mod_" .. rawlist[i].name .. " = true" .. "\n") worldfile:set("load_mod_"..mod.name, "true")
else else
worldfile:write("load_mod_" .. rawlist[i].name .. " = false" .. "\n") worldfile:set("load_mod_"..mod.name, "false")
end
end end
mods["load_mod_"..mod.name] = nil
end end
end
worldfile:close()
else -- Remove mods that are not present anymore
print("failed to open world config file") for key,value in pairs(mods) do
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") for key,value in pairs(worldfile:to_table()) do
while dependency do if key:sub(1, 9) == "load_mod_" then
local parts = dependency:split("=") key = key:sub(10)
local element = nil
local key = parts[1]:trim() for i=1,#retval,1 do
if retval[i].name == key then
if key ~= "gameid" then element = retval[i]
local key = parts[1]:trim():sub(10) break
local element = nil
for i=1,#retval,1 do
if retval[i].name == key then
element = retval[i]
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