Merge pull request #61 from Thomas--S/protected-button
Allow sharing the button based on protection
This commit is contained in:
commit
019d9c96b5
@ -109,6 +109,7 @@ TA3 Booster=TA3 Gebläse
|
|||||||
|
|
||||||
### button.lua ###
|
### button.lua ###
|
||||||
|
|
||||||
|
Access:=Zugriff:
|
||||||
TA3 Button/Switch=TA3 Taster/Schalter
|
TA3 Button/Switch=TA3 Taster/Schalter
|
||||||
TA4 Button/Switch=TA4 Schalter/Taster
|
TA4 Button/Switch=TA4 Schalter/Taster
|
||||||
|
|
||||||
|
@ -109,6 +109,7 @@ TA3 Booster=
|
|||||||
|
|
||||||
### button.lua ###
|
### button.lua ###
|
||||||
|
|
||||||
|
Access:=
|
||||||
TA3 Button/Switch=
|
TA3 Button/Switch=
|
||||||
TA4 Button/Switch=
|
TA4 Button/Switch=
|
||||||
|
|
||||||
|
@ -56,10 +56,12 @@ local function formspec(meta)
|
|||||||
local numbers = meta:get_string("numbers") or ""
|
local numbers = meta:get_string("numbers") or ""
|
||||||
local idx = meta:get_int("cycle_idx") or 0
|
local idx = meta:get_int("cycle_idx") or 0
|
||||||
if idx == 0 then idx = 1 end
|
if idx == 0 then idx = 1 end
|
||||||
|
local access_idx = meta:get_string("public") == "true" and 3 or meta:get_string("protected") == "true" and 2 or 1
|
||||||
return "size[7.5,6]"..
|
return "size[7.5,6]"..
|
||||||
"dropdown[0.2,0;3;type;switch,button 1s,button 2s,button 4s,button 8s,button 16s,button 32s;"..idx.."]"..
|
"dropdown[0.2,0;3;type;switch,button 1s,button 2s,button 4s,button 8s,button 16s,button 32s;"..idx.."]"..
|
||||||
"field[0.5,2;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
|
"field[0.5,2;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
|
||||||
"checkbox[1,3;public;public;false]"..
|
"label[0.2,3;"..S("Access:").."]"..
|
||||||
|
"dropdown[3,3;4;access;private,protected,public;"..access_idx.."]"..
|
||||||
"button_exit[2,4;3,1;exit;"..S("Save").."]"
|
"button_exit[2,4;3,1;exit;"..S("Save").."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -72,8 +74,17 @@ local function on_receive_fields(pos, formname, fields, player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
meta:set_string("numbers", fields.numbers)
|
meta:set_string("numbers", fields.numbers)
|
||||||
if fields.public then
|
if fields.access == "protected" then
|
||||||
meta:set_string("public", fields.public)
|
meta:set_string("protected", "true")
|
||||||
|
meta:set_string("public", "")
|
||||||
|
end
|
||||||
|
if fields.access == "public" then
|
||||||
|
meta:set_string("public", "true")
|
||||||
|
meta:set_string("protected", "")
|
||||||
|
end
|
||||||
|
if fields.access == "private" then
|
||||||
|
meta:set_string("public", "")
|
||||||
|
meta:set_string("protected", "")
|
||||||
end
|
end
|
||||||
local cycle_time = nil
|
local cycle_time = nil
|
||||||
if fields.type == "switch" then
|
if fields.type == "switch" then
|
||||||
@ -110,12 +121,20 @@ local function on_receive_fields(pos, formname, fields, player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function can_access(pos, player)
|
||||||
|
local meta = M(pos)
|
||||||
|
local public = meta:get_string("public") == "true"
|
||||||
|
local protected = meta:get_string("protected") == "true"
|
||||||
|
local owner = meta:get_string("owner")
|
||||||
|
local name = player:get_player_name()
|
||||||
|
return public or protected and not minetest.is_protected(pos, name) or owner == name
|
||||||
|
end
|
||||||
|
|
||||||
local function on_rightclick_on(pos, node, clicker)
|
local function on_rightclick_on(pos, node, clicker)
|
||||||
local meta = M(pos)
|
local meta = M(pos)
|
||||||
local fixed = meta:get_string("fixed")
|
local fixed = meta:get_string("fixed")
|
||||||
if fixed == "true" then
|
if fixed == "true" then
|
||||||
if meta:get_string("public") == "true" or
|
if can_access(pos, clicker) then
|
||||||
clicker:get_player_name() == meta:get_string("owner") then
|
|
||||||
switch_on(pos)
|
switch_on(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -126,8 +145,7 @@ local function on_rightclick_off(pos, node, clicker)
|
|||||||
local numbers = meta:get_string("numbers")
|
local numbers = meta:get_string("numbers")
|
||||||
local cycle_time = meta:get_int("cycle_time") or 0
|
local cycle_time = meta:get_int("cycle_time") or 0
|
||||||
if numbers ~= "" and numbers ~= nil and cycle_time == 0 then
|
if numbers ~= "" and numbers ~= nil and cycle_time == 0 then
|
||||||
if meta:get_string("public") == "true" or
|
if can_access(pos, clicker) then
|
||||||
clicker:get_player_name() == meta:get_string("owner") then
|
|
||||||
switch_off(pos)
|
switch_off(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user