Add validation to map detection, to fix some issues
This commit is contained in:
parent
696a44d3d9
commit
e6e9760320
1 changed files with 23 additions and 4 deletions
|
@ -49,9 +49,20 @@ local function search_for_maps()
|
||||||
local dirs = minetest.get_dir_list(mapdir, true)
|
local dirs = minetest.get_dir_list(mapdir, true)
|
||||||
table.insert(dirs, ".")
|
table.insert(dirs, ".")
|
||||||
for _, dir in pairs(dirs) do
|
for _, dir in pairs(dirs) do
|
||||||
local files = minetest.get_dir_list(mapdir .. dir, false)
|
if dir ~= ".git" then
|
||||||
for i=1, #files do
|
local files = minetest.get_dir_list(mapdir .. dir, false)
|
||||||
files_hash[dir .. "/" .. files[i]:split(".")[1]] = true
|
for i=1, #files do
|
||||||
|
local parts = files[i]:split(".")
|
||||||
|
local filename = parts[1]
|
||||||
|
local extension = parts[2]
|
||||||
|
if extension == "mts" then
|
||||||
|
files_hash[dir .. "/" .. filename] = true
|
||||||
|
else
|
||||||
|
if extension ~= "conf" and extension ~= "md" then
|
||||||
|
error("Map extension is not '.mts': " .. files[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,6 +70,9 @@ local function search_for_maps()
|
||||||
for key, _ in pairs(files_hash) do
|
for key, _ in pairs(files_hash) do
|
||||||
table.insert(ctf_map.available_maps, key)
|
table.insert(ctf_map.available_maps, key)
|
||||||
end
|
end
|
||||||
|
if next(ctf_map.available_maps) == nil then
|
||||||
|
error("No maps found in directory " .. mapdir)
|
||||||
|
end
|
||||||
return ctf_map.available_maps
|
return ctf_map.available_maps
|
||||||
end
|
end
|
||||||
print(dump(search_for_maps()))
|
print(dump(search_for_maps()))
|
||||||
|
@ -112,7 +126,12 @@ end
|
||||||
|
|
||||||
function ctf_match.load_map_meta(idx, name)
|
function ctf_match.load_map_meta(idx, name)
|
||||||
local offset = vector.new(600 * idx, 0, 0)
|
local offset = vector.new(600 * idx, 0, 0)
|
||||||
local meta = Settings(mapdir .. name .. ".conf")
|
local conf_path = mapdir .. name .. ".conf"
|
||||||
|
local meta = Settings(conf_path)
|
||||||
|
|
||||||
|
if meta:get("r") == nil then
|
||||||
|
error("Map was not properly configured " .. conf_path)
|
||||||
|
end
|
||||||
|
|
||||||
local initial_stuff = meta:get("initial_stuff")
|
local initial_stuff = meta:get("initial_stuff")
|
||||||
local map = {
|
local map = {
|
||||||
|
|
Loading…
Reference in a new issue