Add height mode to map api, and scale in map command
This commit is contained in:
parent
e6035d9e2b
commit
777f09fbe7
21
commands.lua
21
commands.lua
@ -1,22 +1,29 @@
|
||||
local MAXINT = 2147483647;
|
||||
|
||||
-- /map <detail> -- Displays a regional map around the player
|
||||
-- /map <detail> <scale> -- Displays a regional map around the player
|
||||
-- (Optional)detail: Specifies the map's detail level. Defaults to the highest
|
||||
-- available detail.
|
||||
-- (Optional)scale: Specifies the map's scale. Defaults to 1.
|
||||
minetest.register_chatcommand("map", {
|
||||
params = "[<detail>]",
|
||||
func = function(name, detail)
|
||||
params = "[<detail>] [<scale>]",
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name);
|
||||
local pos = player:get_pos();
|
||||
|
||||
local player_x, player_z = cartographer.to_map_coordinates(nil, pos.x, pos.z);
|
||||
|
||||
if detail == "" then
|
||||
detail = MAXINT;
|
||||
local detail, scale = param:match("(%d*) (%d*)");
|
||||
|
||||
if detail then
|
||||
detail = tonumber(detail);
|
||||
end
|
||||
|
||||
minetest.sound_play("cartographer_open_map", { to_player=name }, true);
|
||||
minetest.show_formspec(name, "map", cartographer.get_map_formspec(data, player_x, player_z, 40, 40, detail));
|
||||
if scale then
|
||||
scale = tonumber(scale);
|
||||
end
|
||||
|
||||
cartographer.map_sound("cartographer_open_map", player);
|
||||
minetest.show_formspec(name, "map", cartographer.get_map_formspec(data, math.floor(player_x / scale + 0.5), math.floor(player_z / scale + 0.5), 40, 40, detail or MAXINT, scale or 1, true));
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -58,12 +58,13 @@ end
|
||||
-- player_y: The Y position of the player marker (in map coordinates)
|
||||
-- detail: The detail level
|
||||
-- map_scale: Integer scaling factor for displaying a zoomed-out map
|
||||
-- height_mode: If true, displaces tiles by their height
|
||||
-- (Optional) is_visible: Callback to determine if a tile should be drawn
|
||||
-- (Optional) get_marker: Callback to get the marker for any given tile
|
||||
-- (Optional) user: userdata passed to the is_visible/get_marker callbacks
|
||||
--
|
||||
-- Returns a formspec string
|
||||
local function generate_map(data, x, y, w, h, player_x, player_y, detail, map_scale, is_visible, get_marker, user)
|
||||
local function generate_map(data, x, y, w, h, player_x, player_y, detail, map_scale, height_mode, is_visible, get_marker, user)
|
||||
local str = "";
|
||||
local noise = PerlinNoiseMap(MAP_NOISE, { x=w + 1, y=h + 1, z=1}):get_2d_map({ x=x, y=y});
|
||||
|
||||
@ -88,7 +89,11 @@ local function generate_map(data, x, y, w, h, player_x, player_y, detail, map_sc
|
||||
mod = "^[colorize:white:"..tostring(height * 10)
|
||||
height = height * 0.05;
|
||||
|
||||
if height_mode then
|
||||
str = str .. tile:format(fx, fy - height + TILE_OFFSET, TILE_SIZE, height + 0.01, cartographer.detail_texture(cartographer.skin.cliff_textures, detail) .. ".png");
|
||||
else
|
||||
height = 0;
|
||||
end
|
||||
elseif depth > 0 then
|
||||
mod = "^[colorize:#1f1f34:"..tostring(depth * 10)
|
||||
end
|
||||
@ -127,14 +132,16 @@ end
|
||||
-- w: The width of the map, in map coordinates
|
||||
-- h: The height of the map, in map coordinates
|
||||
-- detail: The detail level of the map
|
||||
-- scale: Integer scaling factor for displaying a zoomed-out map
|
||||
-- height_mode: If true, displaces tiles by their height
|
||||
--
|
||||
-- Returns a formspec string, the width of the formspec, and the height of the
|
||||
-- formspec
|
||||
-- TODO: Remove data argument
|
||||
function cartographer.get_map_formspec(data, x, y, w, h, detail)
|
||||
function cartographer.get_map_formspec(data, x, y, w, h, detail, scale, height_mode)
|
||||
local formspec_width = (w + 1) * TILE_OFFSET + 0.01;
|
||||
local formspec_height = (h + 1) * TILE_OFFSET + 0.01;
|
||||
return map_formspec_prefix:format(formspec_width, formspec_height)..generate_map(data, x - (w * 0.5), y - (h * 0.5), w, h, x, y, detail, 1),
|
||||
return map_formspec_prefix:format(formspec_width, formspec_height)..generate_map(data, x - (w * 0.5), y - (h * 0.5), w, h, x, z, detail, scale, height_mode),
|
||||
formspec_width,
|
||||
formspec_height;
|
||||
end
|
||||
@ -144,14 +151,15 @@ end
|
||||
-- map: The map to use
|
||||
-- x: The X position of the player marker, in map coordinates
|
||||
-- y: The Y position of the player marker, in map coordinates
|
||||
-- height_mode: If true, displaces tiles by their height
|
||||
--
|
||||
-- Returns a formspec string, the width of the formspec, and the height of the
|
||||
-- formspec
|
||||
-- TODO: Remove data argument
|
||||
function cartographer.get_map_formspec_map(data, map, x, y)
|
||||
function cartographer.get_map_formspec_map(data, map, x, y, height_mode)
|
||||
local formspec_width = (map.w + 1) * TILE_OFFSET + 0.01;
|
||||
local formspec_height = (map.h + 1) * TILE_OFFSET + 0.01;
|
||||
return map_formspec_prefix:format(formspec_width, formspec_height)..generate_map(data, map.x, map.z, map.w, map.h, x, y, map.detail, map.scale, cartographer.is_filled, cartographer.get_marker, map),
|
||||
return map_formspec_prefix:format(formspec_width, formspec_height)..generate_map(data, map.x, map.z, map.w, map.h, x, y, map.detail, map.scale, height_mode, cartographer.is_filled, cartographer.get_marker, map),
|
||||
formspec_width,
|
||||
formspec_height;
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user