do not return nil from get_compass_meta_pos, add is_set instead

This commit is contained in:
whosit 2021-05-17 21:23:15 +03:00
parent e14d942193
commit bc9040d551

View File

@ -32,13 +32,7 @@ end
local function get_compass_meta_pos(meta)
local pos_str = meta:get_string("waypoint_compass:position")
if pos_str == "" then
-- FIXME This is probably bad.
return nil
else
return minetest.deserialize(meta:get_string("waypoint_compass:position"))
end
return minetest.deserialize(meta:get_string("waypoint_compass:position"))
end
@ -47,6 +41,12 @@ 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
@ -118,7 +118,7 @@ end
local function show_hud_waypoint(player, compass_item_meta)
local player_name = player:get_player_name()
local waypoint_pos = get_compass_meta_pos(compass_item_meta)
if waypoint_pos == nil then
if not get_compass_meta_is_set(compass_item_meta) then
-- do not show unset compass position
return
end
@ -155,8 +155,11 @@ local function update_hud_waypoint(player, itemstack, force)
local meta = itemstack:get_meta()
local waypoint_pos = get_compass_meta_pos(meta)
-- remove different waypoint if it exists
if player_waypoints[player_name] and waypoint_pos and
((player_waypoints[player_name].pos ~= waypoint_pos) or force) then
if player_waypoints[player_name] and
(player_waypoints[player_name].pos ~= waypoint_pos
or force
or not get_compass_meta_is_set(meta)) then
hide_hud_waypoint(player)
end
-- show new waypoint