forked from nalc/homedecor_modpack
make signs_able to display the interact_keyword setting
as used by CWz's mod of the same name Write @KEYWORD (all caps, with the 'at') into the sign's text to display the keyword. Keyword displayed is automatically updated if the 15-second update interval detects that it differs from the minetest.conf setting. The keyword setting is only read at startup.
This commit is contained in:
parent
492f13fd8f
commit
f0a846b200
|
@ -10,6 +10,9 @@
|
||||||
-- { delta = {entity position for 90° yaw}, exact yaw expression }
|
-- { delta = {entity position for 90° yaw}, exact yaw expression }
|
||||||
-- }
|
-- }
|
||||||
|
|
||||||
|
-- CWz's keyword interact mod uses this setting.
|
||||||
|
local keyword = minetest.setting_get("interact_keyword") or "iaccept"
|
||||||
|
|
||||||
signs_lib = {}
|
signs_lib = {}
|
||||||
screwdriver = screwdriver or {}
|
screwdriver = screwdriver or {}
|
||||||
|
|
||||||
|
@ -364,6 +367,7 @@ end
|
||||||
|
|
||||||
local function split_lines_and_words(text)
|
local function split_lines_and_words(text)
|
||||||
if not text then return end
|
if not text then return end
|
||||||
|
text = string.gsub(text, "@KEYWORD", keyword)
|
||||||
local lines = { }
|
local lines = { }
|
||||||
for _, line in ipairs(text:split("\n")) do
|
for _, line in ipairs(text:split("\n")) do
|
||||||
table.insert(lines, line:split(" "))
|
table.insert(lines, line:split(" "))
|
||||||
|
@ -526,9 +530,33 @@ local function make_infotext(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
signs_lib.update_sign = function(pos, fields, owner)
|
signs_lib.update_sign = function(pos, fields, owner)
|
||||||
|
|
||||||
|
-- First, check if the interact keyword from CWz's mod is being set,
|
||||||
|
-- or has been changed since the last restart...
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
local stored_text = meta:get_string("text") or ""
|
||||||
|
|
||||||
|
if fields then -- ...we're editing the sign.
|
||||||
|
if fields.text and string.find(dump(fields.text), "@KEYWORD") then
|
||||||
|
meta:set_string("keyword", keyword)
|
||||||
|
else
|
||||||
|
meta:set_string("keyword", nil)
|
||||||
|
end
|
||||||
|
elseif string.find(dump(stored_text), "@KEYWORD") then -- we need to check if the password is being set/changed
|
||||||
|
|
||||||
|
local stored_keyword = meta:get_string("keyword")
|
||||||
|
if stored_keyword and stored_keyword ~= "" and stored_keyword ~= keyword then
|
||||||
|
signs_lib.destruct_sign(pos)
|
||||||
|
meta:set_string("keyword", keyword)
|
||||||
|
local ownstr = ""
|
||||||
|
if owner then ownstr = "Locked sign, owned by "..owner.."\n" end
|
||||||
|
meta:set_string("infotext", ownstr..string.gsub(make_infotext(stored_text), "@KEYWORD", keyword).." ")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local new
|
local new
|
||||||
|
|
||||||
if fields then
|
if fields then
|
||||||
|
|
||||||
fields.text = trim_input(fields.text)
|
fields.text = trim_input(fields.text)
|
||||||
|
@ -536,8 +564,9 @@ signs_lib.update_sign = function(pos, fields, owner)
|
||||||
local ownstr = ""
|
local ownstr = ""
|
||||||
if owner then ownstr = "Locked sign, owned by "..owner.."\n" end
|
if owner then ownstr = "Locked sign, owned by "..owner.."\n" end
|
||||||
|
|
||||||
meta:set_string("infotext", ownstr..make_infotext(fields.text).." ")
|
meta:set_string("infotext", ownstr..string.gsub(make_infotext(fields.text), "@KEYWORD", keyword).." ")
|
||||||
meta:set_string("text", fields.text)
|
meta:set_string("text", fields.text)
|
||||||
|
|
||||||
meta:set_int("__signslib_new_format", 1)
|
meta:set_int("__signslib_new_format", 1)
|
||||||
new = true
|
new = true
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user