Add marker registration function and support for multi-detail markers
This commit is contained in:
parent
23da5f8900
commit
26e4377cf9
1
init.lua
1
init.lua
|
@ -8,6 +8,7 @@ _cartographer = {
|
|||
CHUNK_SIZE = 16,
|
||||
|
||||
biome_lookup = {},
|
||||
marker_lookup = {},
|
||||
maps = minetest.deserialize(mod_storage:get_string("maps")) or {},
|
||||
next_map_id = mod_storage:get_int("next_map_id"),
|
||||
|
||||
|
|
27
map_api.lua
27
map_api.lua
|
@ -134,6 +134,19 @@ function cartographer.register_biome(name, textures, min_height, max_height)
|
|||
};
|
||||
end
|
||||
|
||||
-- Register a marker with textures to display
|
||||
-- id: A string containing the id of the marker
|
||||
-- name: A string containing the displayedname of the marker
|
||||
-- textures: A table of texture names.
|
||||
-- These should correspond with detail levels,
|
||||
-- any detail level past the length of the table will return the last texture
|
||||
function cartographer.register_marker(id, name, textures)
|
||||
_cartographer.marker_lookup[id] = {
|
||||
name = name,
|
||||
textures = textures,
|
||||
};
|
||||
end
|
||||
|
||||
function cartographer.is_filled(map, x, z)
|
||||
if map == nil then
|
||||
return false;
|
||||
|
@ -157,3 +170,17 @@ function cartographer.get_biome_texture(name, height, detail)
|
|||
|
||||
return nil;
|
||||
end
|
||||
|
||||
-- Get the texture name (minus extension) for the given marker and detail level.
|
||||
-- id: A string containing the marker id
|
||||
-- detail: The detail level
|
||||
-- Returns a string with a texture name, or nil if no matching marker was found.
|
||||
function cartographer.get_marker_texture(id, detail)
|
||||
local marker = _cartographer.marker_lookup[id];
|
||||
|
||||
if marker then
|
||||
return marker.textures[math.min(detail, #marker.textures)];
|
||||
end
|
||||
|
||||
return nil;
|
||||
end
|
||||
|
|
|
@ -51,7 +51,7 @@ local function generate_map(data, x, y, w, h, player_x, player_y, detail, map_sc
|
|||
end
|
||||
|
||||
if get_marker then
|
||||
local marker = get_marker(user, i, j);
|
||||
local marker = cartographer.get_marker_texture(get_marker(user, i, j), detail);
|
||||
if marker then
|
||||
str = str..tile:format(fx, fy - (height * 0.05), scale, scale, marker .. ".png")
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user