forked from whosit/waypoint_compass
do not return nil from get_compass_meta_pos, add is_set instead
This commit is contained in:
parent
e14d942193
commit
bc9040d551
23
init.lua
23
init.lua
@ -32,13 +32,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local function get_compass_meta_pos(meta)
|
local function get_compass_meta_pos(meta)
|
||||||
local pos_str = meta:get_string("waypoint_compass:position")
|
return minetest.deserialize(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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -47,6 +41,12 @@ local function set_compass_meta_color(meta, color)
|
|||||||
end
|
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 function get_compass_meta_color(meta)
|
||||||
local color = meta:get_int("waypoint_compass:color")
|
local color = meta:get_int("waypoint_compass:color")
|
||||||
if color > 0 then
|
if color > 0 then
|
||||||
@ -118,7 +118,7 @@ end
|
|||||||
local function show_hud_waypoint(player, compass_item_meta)
|
local function show_hud_waypoint(player, compass_item_meta)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local waypoint_pos = get_compass_meta_pos(compass_item_meta)
|
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
|
-- do not show unset compass position
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -155,8 +155,11 @@ local function update_hud_waypoint(player, itemstack, force)
|
|||||||
local meta = itemstack:get_meta()
|
local meta = itemstack:get_meta()
|
||||||
local waypoint_pos = get_compass_meta_pos(meta)
|
local waypoint_pos = get_compass_meta_pos(meta)
|
||||||
-- remove different waypoint if it exists
|
-- remove different waypoint if it exists
|
||||||
if player_waypoints[player_name] and waypoint_pos and
|
if player_waypoints[player_name] and
|
||||||
((player_waypoints[player_name].pos ~= waypoint_pos) or force) then
|
(player_waypoints[player_name].pos ~= waypoint_pos
|
||||||
|
or force
|
||||||
|
or not get_compass_meta_is_set(meta)) then
|
||||||
|
|
||||||
hide_hud_waypoint(player)
|
hide_hud_waypoint(player)
|
||||||
end
|
end
|
||||||
-- show new waypoint
|
-- show new waypoint
|
||||||
|
Loading…
Reference in New Issue
Block a user