1
0
mirror of https://github.com/mt-mods/signs_lib.git synced 2025-06-28 22:06:20 +02:00

Compare commits

..

3 Commits

Author SHA1 Message Date
dfa47c2519 add protection and ownership checks to default metal sign 2019-05-25 04:45:30 -04:00
34a7242616 add protection checks to all rotate functions
add ownership check to rotation of locked sign
2019-05-25 04:38:17 -04:00
c199a33bb8 Cache character textures 2018-11-21 18:49:13 -06:00

121
init.lua
View File

@ -26,6 +26,9 @@ signs_lib.gettext = S
-- text encoding -- text encoding
dofile(signs_lib.path .. "/encoding.lua"); dofile(signs_lib.path .. "/encoding.lua");
-- Initialize character texture cache
local ctexcache = {}
local wall_dir_change = { local wall_dir_change = {
[0] = 4, [0] = 4,
@ -38,6 +41,11 @@ local wall_dir_change = {
} }
signs_lib.wallmounted_rotate = function(pos, node, user, mode) signs_lib.wallmounted_rotate = function(pos, node, user, mode)
if minetest.is_protected(pos, user:get_player_name()) then
minetest.record_protection_violation(pos,
sender:get_player_name())
return false
end
if mode ~= screwdriver.ROTATE_FACE then return false end if mode ~= screwdriver.ROTATE_FACE then return false end
minetest.swap_node(pos, { name = node.name, param2 = wall_dir_change[node.param2 % 6] }) minetest.swap_node(pos, { name = node.name, param2 = wall_dir_change[node.param2 % 6] })
signs_lib.update_sign(pos,nil,nil,node) signs_lib.update_sign(pos,nil,nil,node)
@ -45,6 +53,11 @@ signs_lib.wallmounted_rotate = function(pos, node, user, mode)
end end
signs_lib.facedir_rotate = function(pos, node, user, mode) signs_lib.facedir_rotate = function(pos, node, user, mode)
if minetest.is_protected(pos, user:get_player_name()) then
minetest.record_protection_violation(pos,
sender:get_player_name())
return false
end
if mode ~= screwdriver.ROTATE_FACE then return false end if mode ~= screwdriver.ROTATE_FACE then return false end
local newparam2 = (node.param2 %8) + 1 local newparam2 = (node.param2 %8) + 1
if newparam2 == 5 then if newparam2 == 5 then
@ -58,6 +71,11 @@ signs_lib.facedir_rotate = function(pos, node, user, mode)
end end
signs_lib.facedir_rotate_simple = function(pos, node, user, mode) signs_lib.facedir_rotate_simple = function(pos, node, user, mode)
if minetest.is_protected(pos, user:get_player_name()) then
minetest.record_protection_violation(pos,
sender:get_player_name())
return false
end
if mode ~= screwdriver.ROTATE_FACE then return false end if mode ~= screwdriver.ROTATE_FACE then return false end
local newparam2 = (node.param2 %8) + 1 local newparam2 = (node.param2 %8) + 1
if newparam2 > 3 then newparam2 = 0 end if newparam2 > 3 then newparam2 = 0 end
@ -362,14 +380,19 @@ end
-- make char texture file name -- make char texture file name
-- if texture file does not exist use fallback texture instead -- if texture file does not exist use fallback texture instead
local function char_tex(font_name, ch) local function char_tex(font_name, ch)
local c = ch:byte() if ctexcache[font_name..ch] then
local exists, tex = file_exists(CHAR_PATH:format(font_name, c)) return ctexcache[font_name..ch], true
if exists and c ~= 14 then
tex = CHAR_FILE:format(font_name, c)
else else
tex = CHAR_FILE:format(font_name, 0x0) local c = ch:byte()
local exists, tex = file_exists(CHAR_PATH:format(font_name, c))
if exists and c ~= 14 then
tex = CHAR_FILE:format(font_name, c)
else
tex = CHAR_FILE:format(font_name, 0x0)
end
ctexcache[font_name..ch] = tex
return tex, exists
end end
return tex, exists
end end
local function make_line_texture(line, lineno, pos) local function make_line_texture(line, lineno, pos)
@ -884,43 +907,65 @@ minetest.register_node(":locked_sign:sign_wall_locked", {
return pname == owner or pname == minetest.settings:get("name") return pname == owner or pname == minetest.settings:get("name")
or minetest.check_player_privs(pname, {sign_editor=true}) or minetest.check_player_privs(pname, {sign_editor=true})
end, end,
on_rotate = signs_lib.wallmounted_rotate on_rotate = function(pos, node, user, mode)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if owner == user:get_player_name() then
signs_lib.wallmounted_rotate(pos, node, user, mode)
else
return false
end
end
}) })
-- default metal sign, if defined -- default metal sign, if defined
if minetest.registered_nodes["default:sign_wall_steel"] then minetest.register_node(":"..default_sign_metal, {
minetest.register_node(":"..default_sign_metal, { description = S("Sign"),
description = S("Sign"), inventory_image = default_sign_metal_image,
inventory_image = default_sign_metal_image, wield_image = default_sign_metal_image,
wield_image = default_sign_metal_image, node_placement_prediction = "",
node_placement_prediction = "", sunlight_propagates = true,
sunlight_propagates = true, paramtype = "light",
paramtype = "light", paramtype2 = "wallmounted",
paramtype2 = "wallmounted", drawtype = "nodebox",
drawtype = "nodebox", node_box = signs_lib.regular_wall_sign_model.nodebox,
node_box = signs_lib.regular_wall_sign_model.nodebox, tiles = {"signs_wall_sign_metal.png"},
tiles = {"signs_wall_sign_metal.png"}, groups = sign_groups,
groups = sign_groups,
on_place = function(itemstack, placer, pointed_thing)
return 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)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local pname = sender:get_player_name() or ""
if pname ~= owner and pname ~= minetest.settings:get("name")
and not minetest.check_player_privs(pname, {sign_editor=true}) then
return
end
signs_lib.receive_fields(pos, formname, fields, sender, true)
end,
on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos,nil,nil,node)
end,
on_rotate = function(pos, node, user, mode)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if owner == user:get_player_name() then
signs_lib.wallmounted_rotate(pos, node, user, mode)
else
return false
end
end
})
on_place = function(itemstack, placer, pointed_thing)
return 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,nil,nil,node)
end,
on_rotate = signs_lib.wallmounted_rotate
})
end
-- metal, colored signs -- metal, colored signs
if enable_colored_metal_signs then if enable_colored_metal_signs then