Optimise map parsing for more flexibility

This commit is contained in:
ANAND 2019-10-11 19:33:40 +05:30
parent b04f904f8b
commit baa15e39a6

View file

@ -80,9 +80,9 @@ minetest.register_chatcommand("set_next", {
end, end,
}) })
local function load_map_meta(idx, path) local function load_map_meta(idx, path, filename)
minetest.log("info", "load_map_meta: Loading map meta from \"" .. path .. "\"") minetest.log("info", "load_map_meta: Loading map meta from \"" .. path .. filename .. "\"")
local conf_path = mapdir .. path .. ".conf" local conf_path = ctf_map.mapdir .. path .. filename .. ".conf"
local offset = vector.new(600 * idx, 0, 0) local offset = vector.new(600 * idx, 0, 0)
local meta = Settings(conf_path) local meta = Settings(conf_path)
@ -97,6 +97,8 @@ local function load_map_meta(idx, path)
local map = { local map = {
name = meta:get("name"), name = meta:get("name"),
path = path,
filename = filename,
author = meta:get("author"), author = meta:get("author"),
hint = meta:get("hint"), hint = meta:get("hint"),
rotation = meta:get("rotation"), rotation = meta:get("rotation"),
@ -198,7 +200,10 @@ local function load_maps()
local filename = parts[1] local filename = parts[1]
local extension = parts[2] local extension = parts[2]
if extension == "mts" then if extension == "mts" then
files_hash[dir .. "/" .. filename] = true files_hash[#files_hash + 1] = {
subdir = dir .. "/",
filename = filename
}
else else
if extension ~= "conf" and extension ~= "md" and extension ~= "png" if extension ~= "conf" and extension ~= "md" and extension ~= "png"
and files[i] ~= ".git" then and files[i] ~= ".git" then
@ -211,12 +216,13 @@ local function load_maps()
local idx = 1 local idx = 1
ctf_map.available_maps = {} ctf_map.available_maps = {}
for key, _ in pairs(files_hash) do for i, path in pairs(files_hash) do
local conf = Settings(mapdir .. "/" .. key .. ".conf") local conf = Settings(ctf_map.mapdir .. "/" ..
local val = minetest.settings:get("ctf.maps." .. key:gsub("%./", ""):gsub("/", ".")) path.subdir .. path.filename .. ".conf")
local val = minetest.settings:get("ctf.maps." ..
string.gsub(path.subdir .. path.filename, "%./", ""):gsub("/", "."))
if not conf:get_bool("disabled", false) and val ~= "false" then if not conf:get_bool("disabled", false) and val ~= "false" then
local map = load_map_meta(idx, key) local map = load_map_meta(idx, path.subdir, path.filename)
map.path = key
table.insert(ctf_map.available_maps, map) table.insert(ctf_map.available_maps, map)
minetest.log("action", "Found map '" .. map.name .. "'") minetest.log("action", "Found map '" .. map.name .. "'")
minetest.log("info", dump(map)) minetest.log("info", dump(map))