Compare commits

...

4 Commits

Author SHA1 Message Date
ed3a679bca don't emit translation strings to the log (#17)
* don't emit translation strings to the log

* fix luacheck

* don't double-log signs_lib prefix
2022-12-10 14:36:58 -05:00
5ae111e1fa fix unconditional access to default global (#16)
Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2022-11-25 21:33:34 +01:00
aff005e745 handle interactions w/ explosions (#14)
* prevent signs entities from being destroyed

* handle tnt destroying a sign

* remove redundant destructor call
2022-10-26 20:01:27 -04:00
3d0e8d47e6 add setting for custom edit priv (#15)
* add setting for custom edit priv

* fix indent

* hmm maybe now?
2022-10-26 20:00:43 -04:00
5 changed files with 51 additions and 16 deletions

2
API.md
View File

@ -250,7 +250,7 @@ signs_lib.register_sign("basic_signs:sign_wall_glass", {
* `signs_lib.rightclick_sign(pos, node, player, itemstack, pointed_thing)`
Open the default sign formspec, if the player has the `signslib_edit` privilege.
Open the default sign formspec, if the player has the `signslib_edit` privilege. (privilege can be set by `signs_lib.edit_priv` setting)
* `signs_lib.destruct_sign(pos)`

View File

@ -67,3 +67,4 @@ The list of loaded, sign-bearing blocks is created/populated by an LBM (and trim
* `signslib_edit`
Allows to rotate signs and to open (and consequently edit) any default sign formspec.
(privilege can be set by `signs_lib.edit_priv` setting)

61
api.lua
View File

@ -1,6 +1,11 @@
-- signs_lib api, backported from street_signs
local S = signs_lib.S
local has_default_mod = minetest.get_modpath("default")
local function log(level, messagefmt, ...)
minetest.log(level, "[signs_lib] " .. messagefmt:format(...))
end
local function get_sign_formspec() end
@ -21,14 +26,14 @@ signs_lib.standard_xoffs = 4
signs_lib.standard_yoffs = 0
signs_lib.standard_cpl = 35
signs_lib.standard_wood_groups = table.copy(default and minetest.registered_items["default:sign_wall_wood"].groups or {})
signs_lib.standard_wood_groups = table.copy(has_default_mod and minetest.registered_items["default:sign_wall_wood"].groups or {})
signs_lib.standard_wood_groups.attached_node = nil
signs_lib.standard_steel_groups = table.copy(default and minetest.registered_items["default:sign_wall_steel"].groups or {})
signs_lib.standard_steel_groups = table.copy(has_default_mod and minetest.registered_items["default:sign_wall_steel"].groups or {})
signs_lib.standard_steel_groups.attached_node = nil
signs_lib.standard_wood_sign_sounds = table.copy(default and minetest.registered_items["default:sign_wall_wood"].sounds or {})
signs_lib.standard_steel_sign_sounds = table.copy(default and minetest.registered_items["default:sign_wall_steel"].sounds or {})
signs_lib.standard_wood_sign_sounds = table.copy(has_default_mod and minetest.registered_items["default:sign_wall_wood"].sounds or {})
signs_lib.standard_steel_sign_sounds = table.copy(has_default_mod and minetest.registered_items["default:sign_wall_steel"].sounds or {})
signs_lib.default_text_scale = {x=10, y=10}
@ -172,6 +177,9 @@ minetest.register_entity("signs_lib:text", {
self.object:remove()
end
end,
on_blast = function(self, damage)
return false, false, {}
end,
})
function signs_lib.delete_objects(pos)
@ -742,6 +750,15 @@ function signs_lib.destruct_sign(pos)
signs_lib.delete_objects(pos)
end
function signs_lib.blast_sign(pos, intensity)
if signs_lib.can_modify(pos, "") then
local node = minetest.get_node(pos)
local drops = minetest.get_node_drops(node, "tnt:blast")
minetest.remove_node(pos)
return drops
end
end
local function make_infotext(text)
text = trim_input(text)
local lines = signs_lib.split_lines_and_words(text) or {}
@ -803,7 +820,16 @@ end
function signs_lib.can_modify(pos, player)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local playername = player:get_player_name()
local playername
if type(player) == "userdata" then
playername = player:get_player_name()
elseif type(player) == "string" then
playername = player
else
playername = ""
end
if minetest.is_protected(pos, playername) then
minetest.record_protection_violation(pos, playername)
@ -812,7 +838,7 @@ function signs_lib.can_modify(pos, player)
if owner == ""
or playername == owner
or (minetest.check_player_privs(playername, {signslib_edit=true}))
or minetest.get_player_privs(playername)[signs_lib.edit_priv]
or (playername == minetest.settings:get("name")) then
return true
end
@ -951,7 +977,7 @@ function signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locke
end
function signs_lib.register_fence_with_sign()
minetest.log("warning", "[signs_lib] ".."Attempt to call no longer used function signs_lib.register_fence_with_sign()")
log("warning", "Attempt to call no longer used function signs_lib.register_fence_with_sign()")
end
local use_glow = function(pos, node, puncher, pointed_thing)
@ -984,6 +1010,7 @@ function signs_lib.register_sign(name, raw_def)
end
def.after_place_node = raw_def.after_place_node or signs_lib.after_place_node
def.on_blast = raw_def.on_blast or signs_lib.blast_sign
if raw_def.entity_info then
@ -1292,7 +1319,11 @@ minetest.register_chatcommand("regen_signs", {
end
})
minetest.register_privilege("signslib_edit", {})
minetest.register_on_mods_loaded(function()
if not minetest.registered_privileges[signs_lib.edit_priv] then
minetest.register_privilege("signslib_edit", {})
end
end)
@ -1337,11 +1368,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local playername = player:get_player_name()
if fields.text and fields.ok then
minetest.log("action", S("@1 wrote \"@2\" to sign at @3",
log("action", "%s wrote %q to sign at %s",
(playername or ""),
fields.text:gsub('\\', '\\\\'):gsub("\n", "\\n"),
fields.text:gsub("\n", "\\n"),
pos_string
))
)
signs_lib.update_sign(pos, fields)
elseif fields.wide_on or fields.wide_off or fields.uni_on or fields.uni_off then
local node = minetest.get_node(pos)
@ -1365,20 +1396,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
if change_wide then
minetest.log("action", S("@1 flipped the wide-font switch to \"@2\" at @3",
log("action", "%s flipped the wide-font switch to %q at %s",
(playername or ""),
(fields.wide_on and "off" or "on"),
minetest.pos_to_string(pos)
))
)
signs_lib.update_sign(pos, fields)
minetest.show_formspec(playername, "signs_lib:sign", get_sign_formspec(pos, node.name))
end
if change_uni then
minetest.log("action", S("@1 flipped the unicode-font switch to \"@2\" at @3",
log("action", "%s flipped the unicode-font switch to %q at %s",
(playername or ""),
(fields.uni_on and "off" or "on"),
minetest.pos_to_string(pos)
))
)
signs_lib.update_sign(pos, fields)
minetest.show_formspec(playername, "signs_lib:sign", get_sign_formspec(pos, node.name))
end

View File

@ -9,6 +9,8 @@ signs_lib.path = minetest.get_modpath(minetest.get_current_modname())
signs_lib.S = minetest.get_translator(minetest.get_current_modname())
signs_lib.edit_priv = minetest.settings:get("signs_lib.edit_priv") or "signslib_edit"
dofile(signs_lib.path.."/encoding.lua")
dofile(signs_lib.path.."/api.lua")
dofile(signs_lib.path.."/standard_signs.lua")

1
settingstypes.txt Normal file
View File

@ -0,0 +1 @@
signs_lib.edit_priv (Allows to rotate signs and to open (and consequently edit) any default sign formspec) string signslib_edit