diff --git a/init.lua b/init.lua index 7488499..55b54a9 100644 --- a/init.lua +++ b/init.lua @@ -15,7 +15,7 @@ dofile(MP.."/lines.lua") dofile(MP.."/place_schematic.lua") dofile(MP.."/noise_manager.lua") dofile(MP.."/metrics.lua") - +dofile(MP.."/log_location.lua") local map_data = {} local map_param2_data = {} diff --git a/log_location.lua b/log_location.lua new file mode 100644 index 0000000..69c1357 --- /dev/null +++ b/log_location.lua @@ -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 = "", + 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) \ No newline at end of file diff --git a/metrics.lua b/metrics.lua index 6c8309b..3e724d2 100644 --- a/metrics.lua +++ b/metrics.lua @@ -1,5 +1,3 @@ -local worldpath = minetest.get_worldpath() - if not minetest.settings:get_bool("mapgen_helper_record_time", false) then mapgen_helper.record_time = function() return @@ -7,6 +5,8 @@ if not minetest.settings:get_bool("mapgen_helper_record_time", false) then return end +local worldpath = minetest.get_worldpath() + local persist = minetest.settings:get_bool("mapgen_helper_persist_recorded_time", false) local filename = "mapgen_helper_metrics.lua" local filename_old = "mapgen_helper_metrics_old.lua" diff --git a/settingtypes.txt b/settingtypes.txt index 3a48c3b..90a406f 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,3 +1,4 @@ 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_record_time_resolution (Resolution of time-taken histogram) float 0.1 \ No newline at end of file +mapgen_helper_record_time_resolution (Resolution of time-taken histogram) float 0.1 +mapgen_helper_log_locations (Enable location logging) bool false \ No newline at end of file