store everything needed to create the fs in context - get rid of context.id
This commit is contained in:
parent
3e918cfeae
commit
78768fc575
@ -12,8 +12,14 @@ predefined (optional): if valid, it will skip the selection formspec and direct
|
||||
context.target = minetest.formspec_escape(params[1])
|
||||
end
|
||||
if params[2] and chat_formspec.predefined[params[2]] then
|
||||
context.id = params[2]
|
||||
chat_formspec.show_predefined(name)
|
||||
local id = params[2]
|
||||
if chat_formspec.predefined[id] then
|
||||
context.fs = chat_formspec.predefined[id].fs
|
||||
context.replacement = chat_formspec.predefined[id].replacement
|
||||
chat_formspec.show_predefined(name)
|
||||
else
|
||||
chat_formspec.show_select_predefined(name)
|
||||
end
|
||||
else
|
||||
chat_formspec.show_select_predefined(name)
|
||||
end
|
||||
|
@ -80,6 +80,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
context.target = fields.target
|
||||
end
|
||||
if fields.back then
|
||||
context.fs = nil
|
||||
context.replacement = nil
|
||||
chat_formspec.show_select_predefined(name)
|
||||
elseif fields.change_text then
|
||||
@ -107,7 +108,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
local context = chat_formspec.get_context(name)
|
||||
if fields.select then
|
||||
context.id = fields.select
|
||||
if chat_formspec.predefined[fields.select] then
|
||||
context.fs = chat_formspec.predefined[fields.select].fs
|
||||
context.replacement = chat_formspec.predefined[fields.select].replacement
|
||||
end
|
||||
end
|
||||
if fields.template then
|
||||
chat_formspec.show_predefined(name)
|
||||
|
20
specs.lua
20
specs.lua
@ -16,7 +16,7 @@ end
|
||||
|
||||
chat_formspec.selection_fs = create_selection_formspec()
|
||||
|
||||
chat_formspec.predefined_template = [[
|
||||
chat_formspec.custom_template = [[
|
||||
formspec_version[6]
|
||||
size[16,12]
|
||||
box[0.8,0.4;14.6,7.7;gray]
|
||||
@ -33,29 +33,17 @@ chat_formspec.predefined_template = [[
|
||||
]]
|
||||
|
||||
function chat_formspec.create_custom_fs(context)
|
||||
if not chat_formspec.predefined[context.id] then return end -- in case someone hacks their client and sends an invalid id in their fs submission
|
||||
local predefined = chat_formspec.predefined[context.id].fs
|
||||
local replacement = context.replacement or chat_formspec.predefined[context.id].replacement
|
||||
local fs = string.format(context.fs, context.sender, context.replacement)
|
||||
local target = context.target or ""
|
||||
local sender = context.sender
|
||||
|
||||
predefined = string.format(predefined, sender, replacement)
|
||||
local fs = string.format(chat_formspec.predefined_template, predefined, replacement, target)
|
||||
return fs
|
||||
return string.format(chat_formspec.custom_template, fs, context.replacement, target)
|
||||
end
|
||||
|
||||
function chat_formspec.create_target_fs(context)
|
||||
if not chat_formspec.predefined[context.id] then return end -- in case someone hacks their client and sends an invalid id in their fs submission
|
||||
local fs = [[formspec_version[2]
|
||||
size[14.6,7.7]
|
||||
set_focus[answer]
|
||||
]]
|
||||
local predefined = chat_formspec.predefined[context.id].fs
|
||||
local replacement = context.replacement or chat_formspec.predefined[context.id].replacement
|
||||
local sender = context.sender
|
||||
|
||||
predefined = string.format(predefined, sender, replacement)
|
||||
fs = fs .. predefined
|
||||
fs = fs .. string.format(context.fs, context.sender, context.replacement)
|
||||
return fs
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user