Improve directory structure of maps

- Each map will have its own sub-dir, containing
  - `map.conf` (used to be `<map_name>.conf`)
  - `map.mts` (used to be `<map_name>.mts`)
  - `screenshot.png` (used to be `<map_name>.png`)
  - `skybox_<n>.png` (used to be `<map_name>_skybox_<n>.png`)
- The `ctf_map` post-processing actions for maps has been moved into a dedicated shell script `setup_maps.sh`. This script appropriately renames all the textures to while copying them over to the mod's textures/ sub-dir. e.g.
  - `cool_map/screenshot.png` ---> `cool_map.png`
  - `awesome_map/skybox_2.png` ---> `awesome_map_skybox_2.png`
This commit is contained in:
ANAND 2019-07-07 13:54:50 +05:30
parent 739eac1d10
commit cbee83a2ac
5 changed files with 73 additions and 79 deletions

View file

@ -371,7 +371,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
we_select(player_name) we_select(player_name)
show_progress_formspec(player_name, "Exporting...") show_progress_formspec(player_name, "Exporting...")
local path = minetest.get_worldpath() .. "/schems/" local path = minetest.get_worldpath() .. "/schems/" .. config.mapname .. "/"
minetest.mkdir(path) minetest.mkdir(path)
-- Reset mod_storage -- Reset mod_storage
@ -384,7 +384,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
storage:set_string("barrier_r", "") storage:set_string("barrier_r", "")
-- Write to .conf -- Write to .conf
local meta = Settings(path .. config.mapname .. ".conf") local meta = Settings(path .. "map.conf")
meta:set("name", config.maptitle) meta:set("name", config.maptitle)
meta:set("author", config.mapauthor) meta:set("author", config.mapauthor)
if config.mapinitial ~= "" then if config.mapinitial ~= "" then
@ -410,7 +410,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
meta:write() meta:write()
minetest.after(0.1, function() minetest.after(0.1, function()
local filepath = path .. config.mapname .. ".mts" local filepath = path .. "map.mts"
if minetest.create_schematic(worldedit.pos1[player_name], if minetest.create_schematic(worldedit.pos1[player_name],
worldedit.pos2[player_name], worldedit.prob_list[player_name], worldedit.pos2[player_name], worldedit.prob_list[player_name],
filepath) then filepath) then

View file

@ -59,7 +59,7 @@ function ctf_map.get_idx_and_map(param)
param = param:lower():trim() param = param:lower():trim()
for i, map in pairs(ctf_map.available_maps) do for i, map in pairs(ctf_map.available_maps) do
if map.name:lower():find(param, 1, true) or if map.name:lower():find(param, 1, true) or
map.path:lower():find(param, 1, true) then map.dirname:lower():find(param, 1, true) then
return i, map return i, map
end end
end end
@ -80,40 +80,34 @@ minetest.register_chatcommand("set_next", {
end, end,
}) })
local function load_map_meta(idx, path, filename) local function load_map_meta(idx, dirname, meta)
minetest.log("info", "load_map_meta: Loading map meta from \"" .. path .. filename .. "\"")
local conf_path = ctf_map.mapdir .. path .. filename .. ".conf"
local offset = vector.new(600 * idx, 0, 0)
local meta = Settings(conf_path)
if not meta:get("r") then if not meta:get("r") then
error("Map was not properly configured " .. conf_path) error("Map was not properly configured: " .. dirname .. "/map.conf")
end end
local offset = vector.new(600 * idx, 0, 0)
local initial_stuff = meta:get("initial_stuff") local initial_stuff = meta:get("initial_stuff")
local treasures = meta:get("treasures") local treasures = meta:get("treasures")
local start_time = meta:get("start_time") local start_time = meta:get("start_time")
local time_speed = meta:get("time_speed") local time_speed = meta:get("time_speed")
local map = { local map = {
dirname = dirname,
r = tonumber(meta:get("r")),
h = tonumber(meta:get("h")),
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"),
screenshot = meta:get("screenshot"),
skybox = ctf_map.skybox_exists(path, filename),
license = meta:get("license"), license = meta:get("license"),
others = meta:get("others"), others = meta:get("others"),
base_node = meta:get("base_node"), base_node = meta:get("base_node"),
schematic = path .. filename .. ".mts",
initial_stuff = initial_stuff and initial_stuff:split(","), initial_stuff = initial_stuff and initial_stuff:split(","),
treasures = treasures and treasures:split(";"), treasures = treasures and treasures:split(";"),
start_time = start_time and tonumber(start_time), start_time = start_time and tonumber(start_time),
time_speed = time_speed and tonumber(time_speed), time_speed = time_speed and tonumber(time_speed),
r = tonumber(meta:get("r")), skybox = ctf_map.skybox_exists(dirname),
h = tonumber(meta:get("h")),
offset = offset, offset = offset,
teams = {}, teams = {},
chests = {} chests = {}
@ -141,7 +135,7 @@ local function load_map_meta(idx, path, filename)
-- Read custom chest zones from config -- Read custom chest zones from config
i = 1 i = 1
minetest.log("info", "Parsing chest zones of " .. map.name .. "...") minetest.log("verbose", "Parsing chest zones of " .. map.name .. "...")
while meta:get("chests." .. i .. ".from") do while meta:get("chests." .. i .. ".from") do
local from = minetest.string_to_pos(meta:get("chests." .. i .. ".from")) local from = minetest.string_to_pos(meta:get("chests." .. i .. ".from"))
local to = minetest.string_to_pos(meta:get("chests." .. i .. ".to")) local to = minetest.string_to_pos(meta:get("chests." .. i .. ".to"))
@ -154,8 +148,6 @@ local function load_map_meta(idx, path, filename)
n = tonumber(meta:get("chests." .. i .. ".n") or "23"), n = tonumber(meta:get("chests." .. i .. ".n") or "23"),
} }
minetest.log("info", dump(map.chests[i]))
i = i + 1 i = i + 1
end end
@ -189,46 +181,22 @@ local function load_map_meta(idx, path, filename)
end end
local function load_maps() local function load_maps()
local files_hash = {}
local dirs = minetest.get_dir_list(ctf_map.mapdir, true)
table.insert(dirs, ".")
for _, dir in pairs(dirs) do
if dir ~= ".git" then
local files = minetest.get_dir_list(ctf_map.mapdir .. dir, false)
for i = 1, #files do
local parts = files[i]:split(".")
local filename = parts[1]
local extension = parts[2]
if extension == "mts" then
files_hash[#files_hash + 1] = {
subdir = dir .. "/",
filename = filename
}
else
if extension ~= "conf" and extension ~= "md" and extension ~= "png"
and files[i] ~= ".git" then
error("Map extension is not '.mts': " .. files[i])
end
end
end
end
end
local idx = 1 local idx = 1
ctf_map.available_maps = {} ctf_map.available_maps = {}
for i, path in pairs(files_hash) do for _, dirname in pairs(minetest.get_dir_list(ctf_map.mapdir, true)) do
local conf = Settings(ctf_map.mapdir .. "/" .. if dirname ~= ".git" then
path.subdir .. path.filename .. ".conf") local conf = Settings(ctf_map.mapdir .. "/" .. dirname .. "/map.conf")
local val = minetest.settings:get("ctf.maps." .. local val = minetest.settings:get("ctf_map." ..
string.gsub(path.subdir .. path.filename, "%./", ""):gsub("/", ".")) string.gsub(dirname, "%./", ""):gsub("/", "."))
if not conf:get_bool("disabled", false) and val ~= "false" then
local map = load_map_meta(idx, path.subdir, path.filename)
table.insert(ctf_map.available_maps, map)
minetest.log("action", "Found map '" .. map.name .. "'") -- If map isn't disabled, load map meta
minetest.log("info", dump(map)) if not conf:get_bool("disabled", false) and val ~= "false" then
local map = load_map_meta(idx, dirname, conf)
ctf_map.available_maps[idx] = map
idx = idx + 1 idx = idx + 1
minetest.log("info", "Loaded map '" .. map.name .. "'")
end
end end
end end
if not next(ctf_map.available_maps) then if not next(ctf_map.available_maps) then
@ -242,12 +210,12 @@ load_maps()
minetest.register_chatcommand("maps_reload", { minetest.register_chatcommand("maps_reload", {
privs = { ctf_admin = true }, privs = { ctf_admin = true },
func = function(name, param) func = function(name, param)
local maps = load_maps()
next_idx = nil next_idx = nil
local maps = load_maps()
local ret = #maps .. " maps found:\n" local ret = #maps .. " maps found:\n"
for i = 1, #maps do for i = 1, #maps do
ret = ret .. " * " .. ctf_map.available_maps[i].name ret = ret .. " * " .. maps[i].name
if i ~= #maps then if i ~= #maps then
ret = ret .. "\n" ret = ret .. "\n"
end end
@ -259,7 +227,7 @@ minetest.register_chatcommand("maps_reload", {
local function place_map(map) local function place_map(map)
ctf_map.emerge_with_callbacks(nil, map.pos1, map.pos2, function() ctf_map.emerge_with_callbacks(nil, map.pos1, map.pos2, function()
local schempath = ctf_map.mapdir .. map.schematic local schempath = ctf_map.mapdir .. map.dirname .. "/map.mts"
local res = minetest.place_schematic(map.pos1, schempath, local res = minetest.place_schematic(map.pos1, schempath,
map.rotation == "z" and "0" or "90") map.rotation == "z" and "0" or "90")
@ -271,7 +239,7 @@ local function place_map(map)
local seed = minetest.get_mapgen_setting("seed") local seed = minetest.get_mapgen_setting("seed")
for _, chestzone in pairs(ctf_map.map.chests) do for _, chestzone in pairs(ctf_map.map.chests) do
minetest.log("info", "Placing " .. chestzone.n .. " chests from " .. minetest.log("verbose", "Placing " .. chestzone.n .. " chests from " ..
minetest.pos_to_string(chestzone.from) .. " to ".. minetest.pos_to_string(chestzone.from) .. " to "..
minetest.pos_to_string(chestzone.to)) minetest.pos_to_string(chestzone.to))
place_chests(chestzone.from, chestzone.to, seed, chestzone.n) place_chests(chestzone.from, chestzone.to, seed, chestzone.n)
@ -352,14 +320,14 @@ ctf_match.register_on_new_match(function()
if b_stack:get_name() == t_stack:get_name() and if b_stack:get_name() == t_stack:get_name() and
t_stack:get_count() == 1 then t_stack:get_count() == 1 then
is_valid = false is_valid = false
minetest.log("action", minetest.log("info",
"ctf_map: Omitting treasure - " .. def[1]) "ctf_map: Omitting treasure - " .. def[1])
break break
end end
end end
if is_valid then if is_valid then
minetest.log("action", minetest.log("info",
"ctf_map: Registering treasure - " .. def[1]) "ctf_map: Registering treasure - " .. def[1])
treasurer.register_treasure(def[1], def[2], def[3], def[4]) treasurer.register_treasure(def[1], def[2], def[3], def[4])
end end

View file

@ -12,20 +12,20 @@ function ctf_map.update_time()
minetest.settings:set("time_speed", BASE_TIME_SPEED * mult) minetest.settings:set("time_speed", BASE_TIME_SPEED * mult)
end end
function ctf_map.skybox_exists(subdir, filename) function ctf_map.skybox_exists(subdir)
return ctf_map.file_exists(subdir, { return ctf_map.file_exists(subdir, {
filename .. "_skybox_1.png", "skybox_1.png",
filename .. "_skybox_2.png", "skybox_2.png",
filename .. "_skybox_3.png", "skybox_3.png",
filename .. "_skybox_4.png", "skybox_4.png",
filename .. "_skybox_5.png", "skybox_5.png",
filename .. "_skybox_6.png" "skybox_6.png"
}) })
end end
function ctf_map.set_skybox(player) function ctf_map.set_skybox(player)
if ctf_map.map.skybox then if ctf_map.map.skybox then
local prefix = ctf_map.map.filename .. "_skybox_" local prefix = ctf_map.map.dirname .. "_skybox_"
local skybox_textures = { local skybox_textures = {
prefix .. "1.png", -- up prefix .. "1.png", -- up
prefix .. "2.png", -- down prefix .. "2.png", -- down

17
setup_maps.sh Executable file
View file

@ -0,0 +1,17 @@
cd mods/ctf/ctf_map/maps/
# Copy textures from map sub-dirs to ctf_map/textures
for f in *; do
if [ -d ${f} ]; then
# Screenshot
cp ${f}/screenshot.png ../textures/${f}.png
# Skybox textures
cp ${f}/skybox_1.png ../textures/${f}_skybox_1.png
cp ${f}/skybox_2.png ../textures/${f}_skybox_2.png
cp ${f}/skybox_3.png ../textures/${f}_skybox_3.png
cp ${f}/skybox_4.png ../textures/${f}_skybox_4.png
cp ${f}/skybox_5.png ../textures/${f}_skybox_5.png
cp ${f}/skybox_6.png ../textures/${f}_skybox_6.png
fi
done

View file

@ -1,8 +1,17 @@
git pull && # Update capturetheflag
cd mods/crafting && git pull
git pull origin master &&
cd ../ctf/ctf_map/maps && # Update crafting submodule
git pull origin master && cd mods/crafting
cp ./*.png ../textures/ && git pull origin master
cd ../../../.. &&
# Update maps submodule
cd ../ctf/ctf_map/maps
git pull origin master
# Run post-processing actions for maps
cd ../../../..
./setup_maps.sh
# Run build.sh
./build.sh ../games/capturetheflag ./build.sh ../games/capturetheflag