Add map metadata export

This commit is contained in:
rubenwardy 2017-12-27 16:01:14 +00:00
parent d5c2454471
commit b4ed07cee3
3 changed files with 26 additions and 14 deletions

View file

@ -59,7 +59,8 @@ local maptitle = "Untitled Map " .. randint
local mapauthor = nil local mapauthor = nil
local center_barrier_rot = 1 local center_barrier_rot = 1
local function show_gui(name) local function show_gui(name)
local author = mapauthor or name mapauthor = mapauthor or name
local formspec = { local formspec = {
"size[8,9.5]", "size[8,9.5]",
"bgcolor[#080808BB;true]", "bgcolor[#080808BB;true]",
@ -86,7 +87,7 @@ local function show_gui(name)
"label[0,5.5;3. Meta Data]", "label[0,5.5;3. Meta Data]",
"field[0.4,6.5;7.5,1;title;Title;" , minetest.formspec_escape(maptitle), "]", "field[0.4,6.5;7.5,1;title;Title;" , minetest.formspec_escape(maptitle), "]",
"field[0.4,7.8;3.75,1;name;File Name;" , minetest.formspec_escape(mapname), "]", "field[0.4,7.8;3.75,1;name;File Name;" , minetest.formspec_escape(mapname), "]",
"field[4.15,7.8;3.75,1;author;Author;", minetest.formspec_escape(author), "]", "field[4.15,7.8;3.75,1;author;Author;", minetest.formspec_escape(mapauthor), "]",
"button_exit[0.8,8.8;3,1;close;Close]", "button_exit[0.8,8.8;3,1;close;Close]",
"button_exit[3.8,8.8;3,1;export;Export]", "button_exit[3.8,8.8;3,1;export;Export]",
@ -122,6 +123,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
center.r = tonumber(fields.posr) center.r = tonumber(fields.posr)
center.h = tonumber(fields.posh) center.h = tonumber(fields.posh)
barrier_r = tonumber(fields.barrier_r) barrier_r = tonumber(fields.barrier_r)
maptitle = fields.title
mapauthor = fields.author
mapname = fields.name
end end
if fields.center_barrier_rot and fields.center_barrier_rot ~= "" then if fields.center_barrier_rot and fields.center_barrier_rot ~= "" then
@ -177,15 +181,23 @@ 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...")
minetest.after(0.1, function() local path = minetest.get_worldpath() .. "/schems/"
local path = minetest.get_worldpath() .. "/schems" minetest.mkdir(path)
minetest.mkdir(path)
local filepath = path .. "/" .. mapname .. ".mts" local meta = Settings(path .. mapname .. ".conf")
meta:set("name", maptitle)
meta:set("author", mapauthor)
meta:set("rotation", center_barrier_rot == 0 and "x" or "z")
meta:set("r", center.r)
meta:set("h", center.h)
meta:write()
minetest.after(0.1, function()
local filepath = path .. mapname .. ".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
minetest.chat_send_all("Exported to " .. filepath) minetest.chat_send_all("Exported " .. mapname .. " to " .. path)
minetest.close_formspec(player_name, "") minetest.close_formspec(player_name, "")
else else
minetest.chat_send_all("Failed!") minetest.chat_send_all("Failed!")

View file

@ -1,11 +1,11 @@
name = The Bridge name = The Bridge
author = rubenwardy author = rubenwardy
rotation = x rotation = x
r = 110 r = 115
h = 220 h = 140
team.1 = red team.1 = red
team.1.color = red team.1.color = red
team.1.pos = -57,-60,94 team.1.pos = -57,-20,94
team.2 = blue team.2 = blue
team.2.color = blue team.2.color = blue
team.2.pos = -74,-56,-70 team.2.pos = -74,-16,-70

View file

@ -7,7 +7,7 @@ function ctf_map.place_map(map)
local h = map.h local h = map.h
minetest.emerge_area({ x = -r, y = -h / 2, z = -r }, { x = r, y = h / 2, z = r }) minetest.emerge_area({ x = -r, y = -h / 2, z = -r }, { x = r, y = h / 2, z = r })
local res = minetest.place_schematic({ x = -r - 5, y = -h / 2, z = -r - 5 }, local res = minetest.place_schematic({ x = -r, y = -h / 2, z = -r },
minetest.get_modpath("ctf_map") .. "/maps/" .. map.schematic, map.rotation == "z" and "0" or "90") minetest.get_modpath("ctf_map") .. "/maps/" .. map.schematic, map.rotation == "z" and "0" or "90")
if res ~= nil then if res ~= nil then
@ -35,9 +35,9 @@ function ctf_match.load_map_meta(name)
local i = 1 local i = 1
while meta:get("team." .. i) do while meta:get("team." .. i) do
local tname = meta:get("team." .. i) local tname = meta:get("team." .. i)
local tcolor = meta:get("team." .. i .. ".color") local tcolor = meta:get("team." .. i .. ".color")
local tpos = minetest.string_to_pos(meta:get("team." .. i .. ".pos")) local tpos = minetest.string_to_pos(meta:get("team." .. i .. ".pos"))
map.teams[tname] = { map.teams[tname] = {
color = tcolor, color = tcolor,