Signs: update and improve
This commit is contained in:
parent
da31e7c91c
commit
11bc97381f
@ -8,9 +8,9 @@ if translator and not minetest.is_singleplayer() then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local vadd = vector.add
|
|
||||||
local floor, pi = math.floor, math.pi
|
local floor, pi = math.floor, math.pi
|
||||||
local find = string.find
|
local vadd = vector.add
|
||||||
|
local objects_inside_radius = minetest.get_objects_inside_radius
|
||||||
local b = "blank.png"
|
local b = "blank.png"
|
||||||
|
|
||||||
-- Cyrillic transliteration library
|
-- Cyrillic transliteration library
|
||||||
@ -67,10 +67,6 @@ local wrap_chars = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local function generate_sign_texture(str)
|
local function generate_sign_texture(str)
|
||||||
if not str or str == "" then
|
|
||||||
return b
|
|
||||||
end
|
|
||||||
|
|
||||||
local row = 0
|
local row = 0
|
||||||
local texture = "[combine:" .. 16 * 20 .. "x100"
|
local texture = "[combine:" .. 16 * 20 .. "x100"
|
||||||
local result = {}
|
local result = {}
|
||||||
@ -221,7 +217,7 @@ local function place(itemstack, placer, pointed_thing)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function destruct(pos)
|
local function destruct(pos)
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
for _, obj in pairs(objects_inside_radius(pos, 0.5)) do
|
||||||
local ent = obj:get_luaentity()
|
local ent = obj:get_luaentity()
|
||||||
if ent and ent.name == "signs:sign_text" then
|
if ent and ent.name == "signs:sign_text" then
|
||||||
obj:remove()
|
obj:remove()
|
||||||
@ -232,7 +228,7 @@ end
|
|||||||
local function check_text(pos)
|
local function check_text(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local text = meta:get_string("sign_text")
|
local text = meta:get_string("sign_text")
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
local objects = objects_inside_radius(pos, 0.5)
|
||||||
|
|
||||||
if text and text ~= "" then
|
if text and text ~= "" then
|
||||||
local count = 0
|
local count = 0
|
||||||
@ -266,6 +262,12 @@ local function check_text(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Remove old on_construct fs
|
||||||
|
local fs = meta:get_string("formspec")
|
||||||
|
if fs and fs ~= "" then
|
||||||
|
meta:set_string("")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function edit_text(pos, _, clicker)
|
local function edit_text(pos, _, clicker)
|
||||||
@ -292,13 +294,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local text = fields.Dtext
|
local text = fields.Dtext
|
||||||
local pos = fields.spos
|
local pos = fields.spos and minetest.string_to_pos(fields.spos)
|
||||||
|
|
||||||
if not text or not pos then
|
if not text or not pos then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
pos = minetest.string_to_pos(fields.spos)
|
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
if minetest.is_protected(pos, player:get_player_name()) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -307,7 +308,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
local p2 = node.param2
|
local p2 = node.param2
|
||||||
local sign_pos = sign_positions
|
local sign_pos = sign_positions
|
||||||
|
|
||||||
if find(node.name, "wall") then
|
if node.name:find("wall") then
|
||||||
p2 = p2 - 2
|
p2 = p2 - 2
|
||||||
sign_pos = wall_sign_positions
|
sign_pos = wall_sign_positions
|
||||||
end
|
end
|
||||||
@ -316,7 +317,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local sign
|
local sign
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
for _, obj in pairs(objects_inside_radius(pos, 0.5)) do
|
||||||
local ent = obj:get_luaentity()
|
local ent = obj:get_luaentity()
|
||||||
if ent and ent.name == "signs:sign_text" then
|
if ent and ent.name == "signs:sign_text" then
|
||||||
sign = obj
|
sign = obj
|
||||||
@ -333,14 +334,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Serialization longer values may cause a crash
|
local texture = b
|
||||||
-- because we are serializing the texture too
|
if text ~= "" then
|
||||||
text = text:sub(1, 256)
|
-- Serialization longer values may cause a crash
|
||||||
|
-- because we are serializing the texture too
|
||||||
|
text = text:sub(1, 256)
|
||||||
|
|
||||||
|
texture = generate_sign_texture(text)
|
||||||
|
sign:set_properties({
|
||||||
|
textures = {texture, b}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
local texture = generate_sign_texture(text)
|
|
||||||
sign:set_properties({
|
|
||||||
textures = {texture, b}
|
|
||||||
})
|
|
||||||
sign:set_yaw(sign_pos[p2][2])
|
sign:set_yaw(sign_pos[p2][2])
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -353,7 +358,12 @@ end)
|
|||||||
-- Sign nodes
|
-- Sign nodes
|
||||||
minetest.register_node("signs:sign", {
|
minetest.register_node("signs:sign", {
|
||||||
description = S"Sign",
|
description = S"Sign",
|
||||||
tiles = {"signs_wood.png"},
|
tiles = {
|
||||||
|
"signs_top.png", "signs_top.png", "signs_top.png",
|
||||||
|
"signs_top.png", "signs_sign.png", "signs_sign.png"
|
||||||
|
},
|
||||||
|
inventory_image = "signs_item.png",
|
||||||
|
wield_image = "signs_item.png",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -375,7 +385,7 @@ minetest.register_node("signs:sign", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("signs:wall_sign", {
|
minetest.register_node("signs:wall_sign", {
|
||||||
tiles = {"signs_wood.png"},
|
tiles = {"signs_wall_sign.png"},
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "wallmounted",
|
paramtype2 = "wallmounted",
|
||||||
|
BIN
files/signs/textures/signs_item.png
Normal file
BIN
files/signs/textures/signs_item.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
files/signs/textures/signs_sign.png
Normal file
BIN
files/signs/textures/signs_sign.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
files/signs/textures/signs_top.png
Normal file
BIN
files/signs/textures/signs_top.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 966 B |
BIN
files/signs/textures/signs_wall_sign.png
Normal file
BIN
files/signs/textures/signs_wall_sign.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Loading…
x
Reference in New Issue
Block a user