lua mod refactoring
This commit is contained in:
parent
2b6dcccd9a
commit
462ac0bd6e
@ -27,18 +27,8 @@ minetest.register_node("mapserver:border", {
|
||||
},
|
||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
return player and player:get_player_name() == owner
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name() or "")
|
||||
end,
|
||||
can_dig = mapserver.can_dig,
|
||||
after_place_node = mapserver.after_place_node,
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -52,22 +42,22 @@ minetest.register_node("mapserver:border", {
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local playername = sender:get_player_name()
|
||||
|
||||
if playername == meta:get_string("owner") then
|
||||
-- owner
|
||||
if fields.save then
|
||||
last_name = fields.name
|
||||
meta:set_string("name", fields.name)
|
||||
local index = tonumber(fields.index)
|
||||
if index ~= nil then
|
||||
last_index = index
|
||||
meta:set_int("index", index)
|
||||
end
|
||||
end
|
||||
if not mapserver.can_interact(pos, sender) then
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
if fields.save then
|
||||
last_name = fields.name
|
||||
meta:set_string("name", fields.name)
|
||||
local index = tonumber(fields.index)
|
||||
if index ~= nil then
|
||||
last_index = index
|
||||
meta:set_int("index", index)
|
||||
end
|
||||
end
|
||||
|
||||
update_formspec(meta)
|
||||
end
|
||||
|
28
mapserver_mod/mapserver/common.lua
Normal file
28
mapserver_mod/mapserver/common.lua
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
mapserver.can_dig = function(pos, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
return player and player:get_player_name() == owner
|
||||
end
|
||||
|
||||
mapserver.after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name() or "")
|
||||
end
|
||||
|
||||
mapserver.can_interact = function(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local playername = player:get_player_name()
|
||||
|
||||
if playername == owner then
|
||||
return true
|
||||
end
|
||||
|
||||
if minetest.check_player_privs(playername, {protection_bypass = true}) then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
@ -2,6 +2,7 @@
|
||||
mapserver = {}
|
||||
|
||||
local MP = minetest.get_modpath("mapserver")
|
||||
dofile(MP.."/common.lua")
|
||||
dofile(MP.."/poi.lua")
|
||||
dofile(MP.."/train.lua")
|
||||
dofile(MP.."/label.lua")
|
||||
|
@ -28,18 +28,8 @@ minetest.register_node("mapserver:label", {
|
||||
},
|
||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
return player and player:get_player_name() == owner
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name() or "")
|
||||
end,
|
||||
can_dig = mapserver.can_dig,
|
||||
after_place_node = mapserver.after_place_node,
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -52,18 +42,18 @@ minetest.register_node("mapserver:label", {
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local playername = sender:get_player_name()
|
||||
|
||||
if playername == meta:get_string("owner") then
|
||||
-- owner
|
||||
if fields.save then
|
||||
meta:set_string("text", fields.text)
|
||||
meta:set_string("direction", fields.direction)
|
||||
meta:set_string("size", fields.size)
|
||||
end
|
||||
if not mapserver.can_interact(pos, sender) then
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
if fields.save then
|
||||
meta:set_string("text", fields.text)
|
||||
meta:set_string("direction", fields.direction)
|
||||
meta:set_string("size", fields.size)
|
||||
end
|
||||
|
||||
update_formspec(meta)
|
||||
end
|
||||
|
@ -28,18 +28,8 @@ minetest.register_node("mapserver:poi", {
|
||||
},
|
||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
return player and player:get_player_name() == owner
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name() or "")
|
||||
end,
|
||||
can_dig = mapserver.can_dig,
|
||||
after_place_node = mapserver.after_place_node,
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -52,18 +42,18 @@ minetest.register_node("mapserver:poi", {
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local playername = sender:get_player_name()
|
||||
|
||||
if playername == meta:get_string("owner") then
|
||||
-- owner
|
||||
if fields.save then
|
||||
meta:set_string("name", fields.name)
|
||||
meta:set_string("url", fields.url)
|
||||
meta:set_string("category", fields.category)
|
||||
end
|
||||
if not mapserver.can_interact(pos, sender) then
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
if fields.save then
|
||||
meta:set_string("name", fields.name)
|
||||
meta:set_string("url", fields.url)
|
||||
meta:set_string("category", fields.category)
|
||||
end
|
||||
|
||||
update_formspec(meta)
|
||||
end
|
||||
|
@ -29,18 +29,8 @@ minetest.register_node("mapserver:train", {
|
||||
},
|
||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
return player and player:get_player_name() == owner
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name() or "")
|
||||
end,
|
||||
can_dig = mapserver.can_dig,
|
||||
after_place_node = mapserver.after_place_node,
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -55,23 +45,23 @@ minetest.register_node("mapserver:train", {
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local playername = sender:get_player_name()
|
||||
|
||||
if playername == meta:get_string("owner") then
|
||||
-- owner
|
||||
if fields.save then
|
||||
last_line = fields.line
|
||||
meta:set_string("line", fields.line)
|
||||
meta:set_string("station", fields.station)
|
||||
local index = tonumber(fields.index)
|
||||
if index ~= nil then
|
||||
last_index = index
|
||||
meta:set_int("index", index)
|
||||
end
|
||||
end
|
||||
if not mapserver.can_interact(pos, sender) then
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
if fields.save then
|
||||
last_line = fields.line
|
||||
meta:set_string("line", fields.line)
|
||||
meta:set_string("station", fields.station)
|
||||
local index = tonumber(fields.index)
|
||||
if index ~= nil then
|
||||
last_index = index
|
||||
meta:set_int("index", index)
|
||||
end
|
||||
end
|
||||
|
||||
update_formspec(meta)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user