Add per-map skybox support
The skybox textures have to follow this naming convention to be auto-detected by `ctf_map`: `<mapname>_skybox_<1-6>.png`
This commit is contained in:
parent
baa15e39a6
commit
179c993ee7
4 changed files with 84 additions and 24 deletions
|
@ -6,6 +6,21 @@ function ctf_map.get_team_relative_z(player)
|
||||||
return (tname == "red" and 1 or -1) * player:get_pos().z
|
return (tname == "red" and 1 or -1) * player:get_pos().z
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Convenience function to check whether a file (or multiple files) exists in mapdir
|
||||||
|
function ctf_map.file_exists(subdir, target)
|
||||||
|
local list = minetest.get_dir_list(ctf_map.mapdir .. subdir, false)
|
||||||
|
if type(target) == "string" then
|
||||||
|
return table.indexof(list, target) ~= 1
|
||||||
|
elseif type(target) == "table" then
|
||||||
|
for _, filename in pairs(target) do
|
||||||
|
if table.indexof(list, filename) == -1 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Overridden by server mods
|
-- Overridden by server mods
|
||||||
function ctf_map.can_cross(player)
|
function ctf_map.can_cross(player)
|
||||||
return false
|
return false
|
||||||
|
@ -20,7 +35,7 @@ if minetest.get_modpath("ctf") then
|
||||||
dofile(modpath .. "/base.lua")
|
dofile(modpath .. "/base.lua")
|
||||||
dofile(modpath .. "/chest.lua")
|
dofile(modpath .. "/chest.lua")
|
||||||
dofile(modpath .. "/give_initial_stuff.lua")
|
dofile(modpath .. "/give_initial_stuff.lua")
|
||||||
dofile(modpath .. "/time.lua")
|
dofile(modpath .. "/time_sky.lua")
|
||||||
dofile(modpath .. "/schem_map.lua")
|
dofile(modpath .. "/schem_map.lua")
|
||||||
dofile(modpath .. "/maps_catalog.lua")
|
dofile(modpath .. "/maps_catalog.lua")
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ minetest.register_alias_force("default:stone_with_gold", "default:stone")
|
||||||
|
|
||||||
|
|
||||||
local max_r = 120
|
local max_r = 120
|
||||||
local mapdir = minetest.get_modpath("ctf_map") .. "/maps/"
|
ctf_map.mapdir = minetest.get_modpath("ctf_map") .. "/maps/"
|
||||||
ctf_map.map = nil
|
ctf_map.map = nil
|
||||||
|
|
||||||
-- Modify server status message to include map info
|
-- Modify server status message to include map info
|
||||||
|
@ -103,10 +103,11 @@ local function load_map_meta(idx, path, filename)
|
||||||
hint = meta:get("hint"),
|
hint = meta:get("hint"),
|
||||||
rotation = meta:get("rotation"),
|
rotation = meta:get("rotation"),
|
||||||
screenshot = meta:get("screenshot"),
|
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 .. ".mts",
|
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),
|
||||||
|
@ -190,11 +191,11 @@ end
|
||||||
local function load_maps()
|
local function load_maps()
|
||||||
local files_hash = {}
|
local files_hash = {}
|
||||||
|
|
||||||
local dirs = minetest.get_dir_list(mapdir, true)
|
local dirs = minetest.get_dir_list(ctf_map.mapdir, true)
|
||||||
table.insert(dirs, ".")
|
table.insert(dirs, ".")
|
||||||
for _, dir in pairs(dirs) do
|
for _, dir in pairs(dirs) do
|
||||||
if dir ~= ".git" then
|
if dir ~= ".git" then
|
||||||
local files = minetest.get_dir_list(mapdir .. dir, false)
|
local files = minetest.get_dir_list(ctf_map.mapdir .. dir, false)
|
||||||
for i = 1, #files do
|
for i = 1, #files do
|
||||||
local parts = files[i]:split(".")
|
local parts = files[i]:split(".")
|
||||||
local filename = parts[1]
|
local filename = parts[1]
|
||||||
|
@ -224,13 +225,14 @@ local function load_maps()
|
||||||
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, path.subdir, path.filename)
|
local map = load_map_meta(idx, path.subdir, path.filename)
|
||||||
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))
|
||||||
idx = idx + 1
|
idx = idx + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not next(ctf_map.available_maps) then
|
if not next(ctf_map.available_maps) then
|
||||||
error("No maps found in directory " .. mapdir)
|
error("No maps found in directory " .. ctf_map.mapdir)
|
||||||
end
|
end
|
||||||
return ctf_map.available_maps
|
return ctf_map.available_maps
|
||||||
end
|
end
|
||||||
|
@ -248,7 +250,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 = mapdir .. map.schematic
|
local schempath = ctf_map.mapdir .. map.schematic
|
||||||
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")
|
||||||
|
|
||||||
|
@ -356,11 +358,14 @@ ctf_match.register_on_new_match(function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Place map
|
||||||
|
place_map(ctf_map.map)
|
||||||
|
|
||||||
-- Update time speed
|
-- Update time speed
|
||||||
ctf_map.update_time()
|
ctf_map.update_time()
|
||||||
|
|
||||||
-- Place map
|
-- Update players' skyboxes last
|
||||||
place_map(ctf_map.map)
|
ctf_map.set_skybox_all()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function ctf_match.create_teams()
|
function ctf_match.create_teams()
|
||||||
|
@ -387,3 +392,9 @@ function ctf_match.create_teams()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
if ctf_map.map then
|
||||||
|
ctf_map.set_skybox(player)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
local BASE_TIME_SPEED = 72
|
|
||||||
|
|
||||||
function ctf_map.update_time()
|
|
||||||
local time = ctf_map.map.start_time
|
|
||||||
local mult = ctf_map.map.time_speed or 1
|
|
||||||
if time then
|
|
||||||
minetest.set_timeofday(time)
|
|
||||||
else
|
|
||||||
minetest.set_timeofday(0.4)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.settings:set("time_speed", BASE_TIME_SPEED * mult)
|
|
||||||
end
|
|
47
mods/ctf/ctf_map/time_sky.lua
Normal file
47
mods/ctf/ctf_map/time_sky.lua
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
local BASE_TIME_SPEED = 72
|
||||||
|
|
||||||
|
function ctf_map.update_time()
|
||||||
|
local time = ctf_map.map.start_time
|
||||||
|
local mult = ctf_map.map.time_speed or 1
|
||||||
|
if time then
|
||||||
|
minetest.set_timeofday(time)
|
||||||
|
else
|
||||||
|
minetest.set_timeofday(0.4)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.settings:set("time_speed", BASE_TIME_SPEED * mult)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ctf_map.skybox_exists(subdir, filename)
|
||||||
|
return ctf_map.file_exists(subdir, {
|
||||||
|
filename .. "_skybox_1.png",
|
||||||
|
filename .. "_skybox_2.png",
|
||||||
|
filename .. "_skybox_3.png",
|
||||||
|
filename .. "_skybox_4.png",
|
||||||
|
filename .. "_skybox_5.png",
|
||||||
|
filename .. "_skybox_6.png"
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
function ctf_map.set_skybox(player)
|
||||||
|
if ctf_map.map.skybox then
|
||||||
|
local prefix = ctf_map.map.filename .. "_skybox_"
|
||||||
|
local skybox_textures = {
|
||||||
|
prefix .. "1.png", -- up
|
||||||
|
prefix .. "2.png", -- down
|
||||||
|
prefix .. "3.png", -- east
|
||||||
|
prefix .. "4.png", -- west
|
||||||
|
prefix .. "5.png", -- south
|
||||||
|
prefix .. "6.png" -- north
|
||||||
|
}
|
||||||
|
player:set_sky(0xFFFFFFFF, "skybox", skybox_textures, false)
|
||||||
|
else
|
||||||
|
player:set_sky(0xFFFFFFFF, "regular", {}, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ctf_map.set_skybox_all()
|
||||||
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
|
ctf_map.set_skybox(player)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue