Compare commits
3 Commits
aa575ae02b
...
f4299c2cda
Author | SHA1 | Date |
---|---|---|
whosit | f4299c2cda | |
whosit | bc8166e365 | |
whosit | 3f30011448 |
65
init.lua
65
init.lua
|
@ -16,23 +16,19 @@ 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
|
||||
|
||||
|
||||
local function set_compass_meta_label(meta, label)
|
||||
meta:set_string("waypoint_compass:label", label)
|
||||
if label == "" 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
|
||||
local function get_compass_meta_owner(meta)
|
||||
return meta:get_string("waypoint_compass:owner")
|
||||
end
|
||||
|
||||
|
||||
|
@ -41,12 +37,37 @@ local function get_compass_meta_label(meta)
|
|||
end
|
||||
|
||||
|
||||
local function update_compass_meta_label(meta)
|
||||
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)
|
||||
meta:set_string("waypoint_compass:label", label)
|
||||
update_compass_meta_label(meta)
|
||||
end
|
||||
|
||||
|
||||
local function set_compass_meta_pos(meta, pos)
|
||||
local pos_str = minetest.pos_to_string(pos)
|
||||
meta:set_string("waypoint_compass:position", pos_str)
|
||||
if get_compass_meta_label(meta) == "" then
|
||||
meta:set_string("description", string.format("Waypoint compass to %s", minetest.pos_to_string(pos)))
|
||||
end
|
||||
update_compass_meta_label(meta)
|
||||
end
|
||||
|
||||
|
||||
|
@ -57,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
|
||||
|
@ -75,13 +90,10 @@ end
|
|||
|
||||
local function set_compass_meta_owner(meta, player_name)
|
||||
meta:set_string("waypoint_compass:owner", player_name)
|
||||
update_compass_meta_label(meta)
|
||||
end
|
||||
|
||||
|
||||
local function get_compass_meta_owner(meta)
|
||||
return meta:get_string("waypoint_compass:owner")
|
||||
end
|
||||
|
||||
|
||||
local function set_waypoint_at_pointed_place(itemstack, pointed_thing)
|
||||
if pointed_thing and pointed_thing.type == "node" then
|
||||
|
@ -427,6 +439,9 @@ local function waypoint_compass_copy_meta(itemstack, player, old_craft_grid, cra
|
|||
end
|
||||
local copymeta = original:get_meta():to_table()
|
||||
itemstack:get_meta():from_table(copymeta)
|
||||
set_compass_meta_owner(itemstack:get_meta(),
|
||||
(player and player:get_player_name()) or
|
||||
original:get_meta():get_string("waypoint_compass:owner"))
|
||||
-- put the compass with metadata back in the craft grid
|
||||
craft_inv:set_stack("craft", index, original)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue