Implement easy syntax
This commit is contained in:
parent
68cbca00ee
commit
5cbc680f77
|
@ -0,0 +1,31 @@
|
|||
function chat_formspec.easy_syntax_to_formspec(to_convert)
|
||||
local fs = chat_formspec.template_new
|
||||
to_convert = minetest.formspec_escape(to_convert)
|
||||
local fs_def = string.split(to_convert, "#", false, -1, false)
|
||||
if #fs_def == 1 then -- there were no answer-options provided, so we will create a input field
|
||||
fs = fs .. [[
|
||||
field[0.3,6.4;10.7,0.8;answer;Your answer;]
|
||||
button_exit[11.3,6.4;3,0.8;submit;submit]
|
||||
]]
|
||||
elseif #fs_def == 2 then
|
||||
fs = fs .. string.format("button_exit[5.5,6.4;3,0.8;answer;%s]", fs_def[2])
|
||||
else
|
||||
for i = 2, #fs_def do
|
||||
fs = fs .. string.format("button_exit[%f,6.4;3,0.8;answer;%s]",
|
||||
0.3 + (i-2) * 11 / (#fs_def - 2), fs_def[i])
|
||||
end
|
||||
end
|
||||
return fs, fs_def[1]
|
||||
end
|
||||
|
||||
function chat_formspec.update()
|
||||
for name, def in pairs(chat_formspec.predefined) do
|
||||
if type(def) == "string" then
|
||||
local fs, replacement = chat_formspec.easy_syntax_to_formspec(def)
|
||||
chat_formspec.predefined[name] = {
|
||||
fs = fs,
|
||||
replacement = replacement
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
3
init.lua
3
init.lua
|
@ -6,7 +6,10 @@ chat_formspec.predefined_priv = minetest.settings:get("chat_formspec.predefined_
|
|||
chat_formspec.create_new_priv = minetest.settings:get("chat_formspec.create_new_priv") or "server"
|
||||
|
||||
dofile(modpath .. "/predefined_formspecs.lua")
|
||||
dofile(modpath .. "/helpers.lua")
|
||||
dofile(modpath .. "/specs.lua")
|
||||
dofile(modpath .. "/show-receive.lua")
|
||||
dofile(modpath .. "/chatcommands.lua")
|
||||
|
||||
-- update the predefined formspecs (bc I am lazy and use the easy syntax to create the predefined formspecs too)
|
||||
chat_formspec.update()
|
||||
|
|
|
@ -1,32 +1,17 @@
|
|||
chat_formspec.predefined = {
|
||||
replant_farm = {
|
||||
fs = [[
|
||||
field[0.3,6.4;10.7,0.8;answer;Your answer;]
|
||||
button_exit[11.3,6.4;3,0.8;submit;submit]
|
||||
button[11.3,0.3;3,0.8;chat_help;How to chat?]
|
||||
label[0.4,0.7;I (%s) tried to contact you via chat already\, but you did not respond]
|
||||
textarea[0.4,1.6;13.8,4.2;;;%s]
|
||||
button[11.3,4.5;3,0.8;replant_help;how to replant?]
|
||||
]],
|
||||
replacement = [[The public farm is meant for all players. Therefore it is needed that everyone replants \
|
||||
what he takes. Please do so too! Otherwise we will unfortunately have to resort to other means.]]
|
||||
},
|
||||
default = {
|
||||
fs = [[
|
||||
field[0.3,6.4;10.7,0.8;answer;Your answer;]
|
||||
button_exit[11.3,6.4;3,0.8;submit;submit]
|
||||
button[11.3,0.3;3,0.8;chat_help;How to chat?]
|
||||
label[0.4,0.7;I (%s) tried to contact you via chat already\, but you did not respond]
|
||||
textarea[0.4,1.6;13.8,4.2;;;%s]
|
||||
]],
|
||||
replacement = [[You have shown behavior about which we have some questions for reasons of moderation.\
|
||||
It would be nice if you could answer them. Otherwise we will unfortunately have to resort to other means.]]
|
||||
}
|
||||
replant_farm = "The public farm is meant for all players. Therefore it is needed that everyone replants " ..
|
||||
"what he takes. Please do so too! Otherwise we will unfortunately have to resort to other means." ..
|
||||
"#I will do" ..
|
||||
"#I won't do" ..
|
||||
"#How to replant?",
|
||||
|
||||
default = "You have shown behavior about which we have some questions for reasons of moderation. " ..
|
||||
"It would be nice if you could answer them. Otherwise we will unfortunately have to resort to other means.#",
|
||||
test = "test :-) #OK"
|
||||
}
|
||||
|
||||
chat_formspec.template_new = [[
|
||||
button[11.3,0.3;3,0.8;chat_help;How to chat?]
|
||||
label[0.4,0.7;We tried to contact you via chat already\, but you did not respond]
|
||||
textarea[0.4,1.6;13.8,4.2;;;%s
|
||||
%s]
|
||||
label[0.4,0.7;I (%s) tried to contact you via chat already\, but you did not respond]
|
||||
textarea[0.4,1.6;13.8,4.2;;;%s]
|
||||
]]
|
Reference in New Issue