add special handling of label string
This commit is contained in:
parent
ac0f1a299b
commit
f521c193dc
40
init.lua
40
init.lua
@ -16,26 +16,37 @@ 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_pos(meta)
|
||||
return minetest.string_to_pos(meta:get_string("waypoint_compass:position"))
|
||||
end
|
||||
|
||||
|
||||
local function set_compass_meta_label(meta, label)
|
||||
meta:set_string("description", string.format("Waypoint compass to \"%s\"", label))
|
||||
meta:set_string("waypoint_compass:label", label)
|
||||
if label == "coords" then
|
||||
local pos = get_compass_meta_pos(meta)
|
||||
if pos then
|
||||
meta:set_string("description", string.format("Waypoint compass to %s", minetest.pos_to_string(pos)))
|
||||
else
|
||||
meta:set_string("description", DEFAULT_DESCRIPTION)
|
||||
end
|
||||
else
|
||||
meta:set_string("description", string.format("Waypoint compass to \"%s\"", label))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function get_compass_meta_label(meta)
|
||||
local label = meta:get_string("waypoint_compass:label")
|
||||
return label ~= "" and label or "destination"
|
||||
return meta:get_string("waypoint_compass:label")
|
||||
end
|
||||
|
||||
|
||||
local function set_compass_meta_pos(meta, pos)
|
||||
local pos_str = minetest.serialize(pos)
|
||||
local pos_str = minetest.pos_to_string(pos)
|
||||
meta:set_string("waypoint_compass:position", pos_str)
|
||||
end
|
||||
|
||||
|
||||
local function get_compass_meta_pos(meta)
|
||||
return minetest.deserialize(meta:get_string("waypoint_compass:position"))
|
||||
if get_compass_meta_label(meta) == "coords" then
|
||||
meta:set_string("description", string.format("Waypoint compass to %s", minetest.pos_to_string(pos)))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -92,15 +103,18 @@ 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 not get_compass_meta_is_set(compass_item_meta) then
|
||||
-- do not show unset compass position
|
||||
return
|
||||
end
|
||||
|
||||
-- Show this waypoint
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
local waypoint_pos = get_compass_meta_pos(compass_item_meta)
|
||||
local waypoint_name = get_compass_meta_label(compass_item_meta)
|
||||
-- show coords instead of name
|
||||
if waypoint_name == "coords" and waypoint_pos then
|
||||
waypoint_name = minetest.pos_to_string(waypoint_pos)
|
||||
end
|
||||
local waypoint_color = get_compass_meta_color(compass_item_meta)
|
||||
local hexcolor = ("#%06X"):format(waypoint_color)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user