1
0
mirror of https://github.com/pyrollo/display_modpack.git synced 2025-07-15 14:30:27 +02:00

Seperate signs API from signs definitions

Change modnames from *_lib to *_api
This commit is contained in:
Thomas--S
2018-02-01 16:54:55 +01:00
parent 2acccd7261
commit f3970f641e
43 changed files with 831 additions and 327 deletions

View File

@ -21,113 +21,40 @@
local S = signs.intllib
local F = function(...) return minetest.formspec_escape(S(...)) end
function signs.set_display_text(pos,text)
local meta = minetest.get_meta(pos)
meta:set_string("display_text", text)
meta:set_string("infotext", "\""..text.."\"")
display_lib.update_entities(pos)
--Backwards compatibility functions
signs.set_display_text = function(...)
minetest.log("warning", "signs.set_display_text() is deprecated, please use signs_api.set_display_text() instead.")
return signs_api.set_display_text(...)
end
function signs.set_formspec(pos)
local meta = minetest.get_meta(pos)
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
if ndef and ndef.display_entities and ndef.display_entities["signs:display_text"] then
local maxlines = ndef.display_entities["signs:display_text"].maxlines
local formspec
if maxlines == 1 then
formspec = "size[6,3]"..
default.gui_bg .. default.gui_bg_img .. default.gui_slots ..
"field[0.5,0.7;5.5,1;display_text;"..F("Text")..";${display_text}]"..
"button_exit[2,2;2,1;ok;"..F("Write").."]"
else
local extralabel = ""
if maxlines then
extralabel = F(" (first %s lines only)"):format(maxlines)
end
formspec = "size[6,4]"..
default.gui_bg .. default.gui_bg_img .. default.gui_slots ..
"textarea[0.5,0.7;5.5,2;display_text;"..F("Text")..""..extralabel..";${display_text}]"..
"button_exit[2,3;2,1;ok;"..F("Write").."]"
end
meta:set_string("formspec", formspec)
end
signs.set_formspec = function(...)
minetest.log("warning", "signs.set_formspec() is deprecated, please use signs_api.set_formspec() instead.")
return signs_api.set_formspec(...)
end
function signs.on_receive_fields(pos, formname, fields, player)
if not minetest.is_protected(pos, player:get_player_name()) then
if fields and (fields.ok or fields.key_enter) then
signs.set_display_text(pos, fields.display_text)
end
end
signs.on_receive_fields = function(...)
minetest.log("warning", "signs.on_receive_fields() is deprecated, please use signs_api.on_receive_fields() instead.")
return signs_api.on_receive_fields(...)
end
-- On place callback for direction signs
-- (chooses which sign according to look direction)
function signs.on_place_direction(itemstack, placer, pointed_thing)
local name = itemstack:get_name()
local ndef = minetest.registered_nodes[name]
local bdir = {x = pointed_thing.under.x - pointed_thing.above.x,
y = pointed_thing.under.y - pointed_thing.above.y,
z = pointed_thing.under.z - pointed_thing.above.z}
local pdir = placer:get_look_dir()
local ndir, test
if ndef.paramtype2 == "facedir" then
if bdir.x == 0 and bdir.z == 0 then
-- Ceiling or floor pointed (facedir chosen from player dir)
ndir = minetest.dir_to_facedir({x=pdir.x, y=0, z=pdir.z})
else
-- Wall pointed
ndir = minetest.dir_to_facedir(bdir)
end
test = {[0]=-pdir.x, pdir.z, pdir.x, -pdir.z}
end
if ndef.paramtype2 == "wallmounted" then
ndir = minetest.dir_to_wallmounted(bdir)
if ndir == 0 or ndir == 1 then
-- Ceiling or floor
ndir = minetest.dir_to_wallmounted({x=pdir.x, y=0, z=pdir.z})
end
test = {0, pdir.z, -pdir.z, -pdir.x, pdir.x}
end
-- Only for direction signs
if ndef.signs_other_dir then
if test[ndir] > 0 then
itemstack:set_name(ndef.signs_other_dir)
end
itemstack = minetest.item_place(itemstack, placer, pointed_thing, ndir)
itemstack:set_name(name)
return itemstack
else
return minetest.item_place(itemstack, placer, pointed_thing, ndir)
end
signs.on_place_direction = function(...)
minetest.log("warning", "signs.on_place_direction() is deprecated, please use signs_api.on_place_direction() instead.")
return signs_api.on_place_direction(...)
end
-- Handles screwdriver rotation. Direction is affected for direction signs
function signs.on_rotate(pos, node, player, mode, new_param2)
if mode == 2 then
local ndef = minetest.registered_nodes[node.name]
if ndef.signs_other_dir then
minetest.swap_node(pos, {name = ndef.signs_other_dir,
param1 = node.param1, param2 = node.param2})
display_lib.update_entities(pos)
end
else
display_lib.on_rotate(pos, node, user, mode, new_param2)
end
return false;
signs.on_rotate = function(...)
minetest.log("warning", "signs.on_rotate() is deprecated, please use signs_api.on_rotate() instead.")
return signs_api.on_rotate(...)
end
signs.register_sign = function(...)
minetest.log("warning", "signs.register_sign() is deprecated, please use signs_api.register_sign() instead.")
return signs_api.register_sign(...)
end
-- Generic callback for show_formspec displayed formspecs of "sign" mod
minetest.register_on_player_receive_fields(function(player, formname, fields)
@ -142,59 +69,3 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end
end)
function signs.register_sign(mod, name, model)
-- Default fields
local fields = {
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {-model.width/2, -model.height/2, 0.5,
model.width/2, model.height/2, 0.5 - model.depth},
},
groups = {choppy=2, dig_immediate=2, not_blocking_trains = 1, display_lib_node = 1},
sounds = default.node_sound_defaults(),
display_entities = {
["signs:display_text"] = {
on_display_update = font_lib.on_display_update,
depth = 0.5 - display_lib.entity_spacing - model.depth,
size = { x = model.width, y = model.height },
resolution = { x = 64, y = 64 },
maxlines = 1,
},
},
on_place = display_lib.on_place,
on_construct = function(pos)
signs.set_formspec(pos)
display_lib.on_construct(pos)
end,
on_destruct = display_lib.on_destruct,
on_rotate = signs.on_rotate,
on_receive_fields = signs.on_receive_fields,
on_punch = function(pos, node, player, pointed_thing) display_lib.update_entities(pos) end,
}
-- Node fields override
for key, value in pairs(model.node_fields) do
if key == "groups" then
for key2, value2 in pairs(value) do
fields[key][key2] = value2
end
else
fields[key] = value
end
end
if not fields.wield_image then fields.wield_image = fields.inventory_image end
-- Entity fields override
for key, value in pairs(model.entity_fields) do
fields.display_entities["signs:display_text"][key] = value
end
minetest.register_node(mod..":"..name, fields)
end

View File

@ -43,9 +43,9 @@ local function compatibility_check_1(pos, node)
node.name = convert_nodes[node.name]
if node.name then
node.param2 = wallmounted_to_facedir[node.param2]
display_lib.on_destruct(pos)
display_api.on_destruct(pos)
minetest.swap_node(pos, node)
display_lib.on_construct(pos)
display_api.on_construct(pos)
end
end
@ -76,7 +76,7 @@ local function compatibility_check_2(pos, node)
end
end
-- Create new entity
display_lib.update_entities(pos)
display_api.update_entities(pos)
end
minetest.register_lbm({ name = "signs:conpatibility_2",

View File

@ -1,4 +1,5 @@
default
intllib?
display_lib
font_lib
display_api
font_api
signs_api

View File

@ -28,7 +28,7 @@ local function display_poster(pos, node, player)
local def = minetest.registered_nodes[node.name].display_entities["signs:display_text"]
-- Title texture
local titletexture = font_lib.make_multiline_texture(
local titletexture = font_api.make_multiline_texture(
def.font_name, meta:get_string("display_text"),
116, 12, def.maxlines, def.valign, def.color)
@ -61,9 +61,9 @@ local function edit_poster(pos, node, player)
"size[6.5,7.5]"..
default.gui_bg .. default.gui_bg_img .. default.gui_slots ..
"field[0.5,0.7;6,1;display_text;"..F("Title")..";"..
minetest.formspec_escape(meta:get_string("display_text")).."]"..
minetest.formspec_escape(meta:get_string("display_text")).."]"..
"textarea[0.5,1.7;6,6;text;"..F("Text")..";"..
minetest.formspec_escape(meta:get_string("text")).."]"..
minetest.formspec_escape(meta:get_string("text")).."]"..
"button_exit[2.25,7;2,1;write;"..F("Write").."]"
minetest.show_formspec(player:get_player_name(),
node.name.."@"..minetest.pos_to_string(pos)..":edit",
@ -87,14 +87,14 @@ local function on_receive_fields_poster(pos, formname, fields, player)
meta:set_string("text", fields.text)
meta:set_string("infotext", "\""..fields.display_text
.."\"\n"..S("(right-click to read more text)"))
display_lib.update_entities(pos)
display_api.update_entities(pos)
display_poster(pos, node, player)
end
end
end
-- Text entity for all signs
display_lib.register_display_entity("signs:display_text")
display_api.register_display_entity("signs:display_text")
-- Sign models and registration
local models = {
@ -103,7 +103,7 @@ local models = {
width = 14/16,
height = 7/16,
entity_fields = {
right = -3/32,
right = -3/32,
size = { x = 12/16, y = 6/16 },
resolution = { x = 9, y = 5 },
maxlines = 2,
@ -113,8 +113,8 @@ local models = {
description = S("Wooden direction sign"),
tiles = { "signs_wooden_direction.png" },
inventory_image = "signs_wooden_inventory.png",
signs_other_dir = 'signs:wooden_left_sign',
on_place = signs.on_place_direction,
signs_other_dir = 'signs:wooden_left_sign',
on_place = signs_api.on_place_direction,
drawtype = "mesh",
mesh = "signs_dir_right.obj",
selection_box = { type="fixed", fixed = {-0.5, -7/32, 0.5, 7/16, 7/32, 7/16}},
@ -126,7 +126,7 @@ local models = {
width = 14/16,
height = 7/16,
entity_fields = {
right = 3/32,
right = 3/32,
size = { x = 12/16, y = 6/16 },
resolution = { x = 9, y = 5 },
maxlines = 2,
@ -136,7 +136,7 @@ local models = {
description = S("Wooden direction sign"),
tiles = { "signs_wooden_direction.png" },
inventory_image = "signs_wooden_inventory.png",
signs_other_dir = 'signs:wooden_right_sign',
signs_other_dir = 'signs:wooden_right_sign',
drawtype = "mesh",
mesh = "signs_dir_left.obj",
selection_box = { type="fixed", fixed = {-7/16, -7/32, 0.5, 0.5, 7/32, 7/16}},
@ -158,10 +158,10 @@ local models = {
node_fields = {
description = S("Poster"),
tiles = { "signs_poster_sides.png", "signs_poster_sides.png",
"signs_poster_sides.png", "signs_poster_sides.png",
"signs_poster_sides.png", "signs_poster.png" },
"signs_poster_sides.png", "signs_poster_sides.png",
"signs_poster_sides.png", "signs_poster.png" },
inventory_image = "signs_poster_inventory.png",
on_construct = display_lib.on_construct,
on_construct = display_api.on_construct,
on_rightclick = display_poster,
on_receive_fields = on_receive_fields_poster,
},
@ -171,6 +171,6 @@ local models = {
-- Node registration
for name, model in pairs(models)
do
signs.register_sign("signs", name, model)
signs_api.register_sign("signs", name, model)
end