add a location logger
this is handy in my more complicated mapgens to find examples of things generated "in the wild".
This commit is contained in:
parent
5fe751ea81
commit
4e226f1237
2
init.lua
2
init.lua
@ -15,7 +15,7 @@ dofile(MP.."/lines.lua")
|
|||||||
dofile(MP.."/place_schematic.lua")
|
dofile(MP.."/place_schematic.lua")
|
||||||
dofile(MP.."/noise_manager.lua")
|
dofile(MP.."/noise_manager.lua")
|
||||||
dofile(MP.."/metrics.lua")
|
dofile(MP.."/metrics.lua")
|
||||||
|
dofile(MP.."/log_location.lua")
|
||||||
|
|
||||||
local map_data = {}
|
local map_data = {}
|
||||||
local map_param2_data = {}
|
local map_param2_data = {}
|
||||||
|
108
log_location.lua
Normal file
108
log_location.lua
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
if not minetest.settings:get_bool("mapgen_helper_log_locations", false) then
|
||||||
|
mapgen_helper.log_first_location = function()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
mapgen_helper.log_location_enabled = true
|
||||||
|
|
||||||
|
local worldpath = minetest.get_worldpath()
|
||||||
|
local locations = {}
|
||||||
|
|
||||||
|
local save_data = function()
|
||||||
|
local file = io.open(worldpath.."/mapgen_helper_test_locations.json", "w")
|
||||||
|
if file then
|
||||||
|
local data = {}
|
||||||
|
data.locations = locations
|
||||||
|
file:write(minetest.serialize(data))
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local read_data = function()
|
||||||
|
local file = io.open(worldpath.."/mapgen_helper_test_locations.json", "r")
|
||||||
|
if file then
|
||||||
|
local data = minetest.deserialize(file:read("*all"))
|
||||||
|
locations = data.locations or {}
|
||||||
|
file:close()
|
||||||
|
else
|
||||||
|
locations = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
read_data()
|
||||||
|
|
||||||
|
mapgen_helper.log_first_location = function(name, pos, desc, notes)
|
||||||
|
if not locations[name] then
|
||||||
|
locations[name] = {pos=pos, desc=desc, notes=notes}
|
||||||
|
minetest.log("info", "[mapgen_helper] recorded location " .. name .. " at " .. minetest.pos_to_string(pos) .. " with desc '" .. (desc or "") .. "'")
|
||||||
|
save_data()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("mapgen_helper_loc", {
|
||||||
|
params = "[location name]",
|
||||||
|
description = "sends the player to the named test location, or lists recorded locations if no parameter is given",
|
||||||
|
privs = {server=true},
|
||||||
|
func = function(name, param)
|
||||||
|
if not param or param == "" then
|
||||||
|
minetest.chat_send_all("test locations available:")
|
||||||
|
local names = {}
|
||||||
|
for name, loc in pairs(locations) do
|
||||||
|
table.insert(names, name)
|
||||||
|
end
|
||||||
|
table.sort(names)
|
||||||
|
for number, name in ipairs(names) do
|
||||||
|
minetest.chat_send_all("\t"..name .. " - " .. (locations[name].desc or ""))
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local loc = locations[param]
|
||||||
|
if not loc then
|
||||||
|
minetest.chat_send_all("test location " .. param .. " not found")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
player:set_pos(loc.pos)
|
||||||
|
if loc.notes then
|
||||||
|
minetest.chat_send_player(name, loc.notes)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
local tour_index = 0
|
||||||
|
minetest.register_chatcommand("mapgen_helper_tour", {
|
||||||
|
params = "<next|prev>",
|
||||||
|
description = "cycles through the various recorded mapgen test locations, forward or backward",
|
||||||
|
privs = {server=true},
|
||||||
|
func = function(name, param)
|
||||||
|
local names = {}
|
||||||
|
for name, loc in pairs(locations) do
|
||||||
|
table.insert(names, name)
|
||||||
|
end
|
||||||
|
table.sort(names)
|
||||||
|
if param == "prev" then
|
||||||
|
tour_index = tour_index - 1
|
||||||
|
if tour_index < 1 then
|
||||||
|
tour_index = #names
|
||||||
|
end
|
||||||
|
else
|
||||||
|
tour_index = tour_index + 1
|
||||||
|
if tour_index > #names then
|
||||||
|
tour_index = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local loc = locations[names[tour_index]]
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
player:set_pos(loc.pos)
|
||||||
|
minetest.chat_send_player(name, "Teleport to test location " .. names[tour_index])
|
||||||
|
if loc.notes then
|
||||||
|
minetest.chat_send_player(name, loc.notes)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_on_shutdown(function()
|
||||||
|
save_data()
|
||||||
|
end)
|
@ -1,5 +1,3 @@
|
|||||||
local worldpath = minetest.get_worldpath()
|
|
||||||
|
|
||||||
if not minetest.settings:get_bool("mapgen_helper_record_time", false) then
|
if not minetest.settings:get_bool("mapgen_helper_record_time", false) then
|
||||||
mapgen_helper.record_time = function()
|
mapgen_helper.record_time = function()
|
||||||
return
|
return
|
||||||
@ -7,6 +5,8 @@ if not minetest.settings:get_bool("mapgen_helper_record_time", false) then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local worldpath = minetest.get_worldpath()
|
||||||
|
|
||||||
local persist = minetest.settings:get_bool("mapgen_helper_persist_recorded_time", false)
|
local persist = minetest.settings:get_bool("mapgen_helper_persist_recorded_time", false)
|
||||||
local filename = "mapgen_helper_metrics.lua"
|
local filename = "mapgen_helper_metrics.lua"
|
||||||
local filename_old = "mapgen_helper_metrics_old.lua"
|
local filename_old = "mapgen_helper_metrics_old.lua"
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
mapgen_helper_record_time (Enable time-taken logging) bool false
|
mapgen_helper_record_time (Enable time-taken logging) bool false
|
||||||
mapgen_helper_persist_recorded_time (Persist time-taken logging between server sessions) bool false
|
mapgen_helper_persist_recorded_time (Persist time-taken logging between server sessions) bool false
|
||||||
mapgen_helper_record_time_resolution (Resolution of time-taken histogram) float 0.1
|
mapgen_helper_record_time_resolution (Resolution of time-taken histogram) float 0.1
|
||||||
|
mapgen_helper_log_locations (Enable location logging) bool false
|
Loading…
x
Reference in New Issue
Block a user