diff --git a/init.lua b/init.lua index 2754b9b..52ebde1 100644 --- a/init.lua +++ b/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"), diff --git a/map_api.lua b/map_api.lua index e9d31d8..09f3e84 100644 --- a/map_api.lua +++ b/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 diff --git a/map_formspec.lua b/map_formspec.lua index a507a59..5e4aeaf 100644 --- a/map_formspec.lua +++ b/map_formspec.lua @@ -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