functionalize the code for determining the type of sign

to be placed and the on_receive_fields calls, expose them in the API.
This commit is contained in:
Vanessa Ezekowitz 2014-06-23 06:27:25 -04:00
parent 16d4329f67
commit 9021760e7e

View File

@ -449,21 +449,9 @@ signs_lib.update_sign = function(pos, fields)
text:setyaw(sign_info.yaw)
end
minetest.register_node(":default:sign_wall", {
description = S("Sign"),
inventory_image = "default_sign_wall.png",
wield_image = "default_sign_wall.png",
node_placement_prediction = "",
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
drawtype = "nodebox",
node_box = {type = "fixed", fixed = {-0.45, -0.15, 0.4, 0.45, 0.45, 0.498}},
selection_box = {type = "fixed", fixed = {-0.45, -0.15, 0.4, 0.45, 0.45, 0.498}},
tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
groups = sign_groups,
-- What kind of sign do we need to place, anyway?
on_place = function(itemstack, placer, pointed_thing)
function signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
local name
name = minetest.get_node(pointed_thing.under).name
if fences_with_sign[name] then
@ -533,20 +521,14 @@ minetest.register_node(":default:sign_wall", {
z = above.z + sign_info.delta.z}, "signs:text")
text:setyaw(sign_info.yaw)
if not signs_lib.expect_infinite_stacks then
itemstack:take_item()
end
return itemstack
end
end,
on_construct = function(pos)
signs_lib.construct_sign(pos)
end,
on_destruct = function(pos)
signs_lib.destruct_sign(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
end
function signs_lib.receive_fields(pos, formname, fields, sender)
if fields and fields.text then
minetest.log("action", S("%s wrote \"%s\" to sign at %s"):format(
(sender:get_player_name() or ""),
@ -562,6 +544,33 @@ minetest.register_node(":default:sign_wall", {
if fields and fields.text then
signs_lib.update_sign(pos, fields)
end
end
minetest.register_node(":default:sign_wall", {
description = S("Sign"),
inventory_image = "default_sign_wall.png",
wield_image = "default_sign_wall.png",
node_placement_prediction = "",
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
drawtype = "nodebox",
node_box = {type = "fixed", fixed = {-0.45, -0.15, 0.4, 0.45, 0.45, 0.498}},
selection_box = {type = "fixed", fixed = {-0.45, -0.15, 0.4, 0.45, 0.45, 0.498}},
tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
groups = sign_groups,
on_place = function(itemstack, placer, pointed_thing)
signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
end,
on_construct = function(pos)
signs_lib.construct_sign(pos)
end,
on_destruct = function(pos)
signs_lib.destruct_sign(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
signs_lib.receive_fields(pos, formname, fields, sender)
end,
on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos)
@ -589,21 +598,7 @@ minetest.register_node(":signs:sign_yard", {
signs_lib.destruct_sign(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
if fields and fields.text then
minetest.log("action", S("%s wrote \"%s\" to sign at %s"):format(
(sender:get_player_name() or ""),
fields.text,
minetest.pos_to_string(pos)
))
end
if minetest.is_protected(pos, sender:get_player_name()) then
minetest.record_protection_violation(pos,
sender:get_player_name())
return
end
if fields and fields.text then
signs_lib.update_sign(pos, fields)
end
signs_lib.receive_fields(pos, formname, fields, sender)
end,
on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos)
@ -641,21 +636,7 @@ minetest.register_node(":signs:sign_hanging", {
signs_lib.destruct_sign(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
if fields and fields.text then
minetest.log("action", S("%s wrote \"%s\" to sign at %s"):format(
(sender:get_player_name() or ""),
fields.text,
minetest.pos_to_string(pos)
))
end
if minetest.is_protected(pos, sender:get_player_name()) then
minetest.record_protection_violation(pos,
sender:get_player_name())
return
end
if fields and fields.text then
signs_lib.update_sign(pos, fields)
end
signs_lib.receive_fields(pos, formname, fields, sender)
end,
on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos)
@ -772,22 +753,8 @@ function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
def_sign.on_destruct = function(pos, ...)
signs_lib.destruct_sign(pos)
end
def_sign.on_receive_fields = function(pos, formname, fields, sender, ...)
if fields and fields.text then
minetest.log("action", S("%s wrote \"%s\" to sign at %s"):format(
(sender:get_player_name() or ""),
fields.text,
minetest.pos_to_string(pos)
))
end
if minetest.is_protected(pos, sender:get_player_name()) then
minetest.record_protection_violation(pos,
sender:get_player_name())
return
end
if fields and fields.text then
signs_lib.update_sign(pos, fields)
end
def_sign.on_receive_fields = function(pos, formname, fields, sender)
signs_lib.receive_fields(pos, formname, fields, sender)
end
def_sign.on_punch = function(pos, node, puncher, ...)
signs_lib.update_sign(pos)