don't show label/owner if position is not set

This commit is contained in:
whosit 2023-05-12 17:10:46 +03:00
parent bc8166e365
commit f4299c2cda

View File

@ -16,6 +16,12 @@ local player_waypoints = {} -- store a current player waypoint to see if it need
local compass_dialog_context = {} -- store a compass item that player is editing via dialog
local function get_compass_meta_is_set(meta)
local pos_str = meta:get_string("waypoint_compass:position")
return pos_str ~= ""
end
local function get_compass_meta_pos(meta)
return minetest.string_to_pos(meta:get_string("waypoint_compass:position"))
end
@ -32,21 +38,24 @@ end
local function update_compass_meta_label(meta)
local label = get_compass_meta_label(meta)
local owner = get_compass_meta_owner(meta) --or "no owner"
if label == "" then
local pos = get_compass_meta_pos(meta)
if pos then
meta:set_string("description", string.format("Waypoint compass to %s [%s]",
minetest.pos_to_string(pos),
owner))
else
meta:set_string("description", DEFAULT_DESCRIPTION)
end
else
meta:set_string("description", string.format("Waypoint compass to \"%s\" [%s]", label, owner))
if get_compass_meta_is_set(meta) then
local label = get_compass_meta_label(meta)
local owner = get_compass_meta_owner(meta) -- or "no owner"
if label == "" then
local pos = get_compass_meta_pos(meta)
if pos then
meta:set_string("description", string.format("Waypoint compass to %s [%s]",
minetest.pos_to_string(pos),
owner))
return
end
else
meta:set_string("description", string.format("Waypoint compass to \"%s\" [%s]", label, owner))
return
end
end
meta:set_string("description", DEFAULT_DESCRIPTION)
end
local function set_compass_meta_label(meta, label)
@ -69,12 +78,6 @@ local function set_compass_meta_color(meta, color)
end
local function get_compass_meta_is_set(meta)
local pos_str = meta:get_string("waypoint_compass:position")
return pos_str ~= ""
end
local function get_compass_meta_color(meta)
local color = meta:get_int("waypoint_compass:color")
if color > 0 then