1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-11-17 14:55:13 -05:00

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

View File

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