-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this is handy in my more complicated mapgens to find examples of things generated "in the wild".
- Loading branch information
Showing
4 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
mapgen_helper_record_time_resolution (Resolution of time-taken histogram) float 0.1 | ||
mapgen_helper_log_locations (Enable location logging) bool false |