mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-16 21:58:05 +02:00
prepared show_fs.lua for beeing more universal by adding register_fs function
This commit is contained in:
parent
03da9151c4
commit
12fc39b3d0
31
show_fs.lua
31
show_fs.lua
@ -1,8 +1,33 @@
|
||||
|
||||
-- allow show_fs to be extended more easily;
|
||||
-- key: formname without yl_speak_up: prefix
|
||||
yl_speak_up.registered_forms_get_fs = {}
|
||||
yl_speak_up.registered_forms_input_handler = {}
|
||||
|
||||
yl_speak_up.register_fs = function(formname, fun_input_handler, fun_get_fs)
|
||||
yl_speak_up.registered_forms_input_handler[formname] = fun_input_handler
|
||||
yl_speak_up.registered_forms_get_fs[formname] = fun_get_fs
|
||||
end
|
||||
|
||||
|
||||
-- route player input to the right functions;
|
||||
-- return true when the right function has been found
|
||||
-- called in minetest.register_on_player_receive_fields
|
||||
yl_speak_up.input_handler = function(player, formname, fields)
|
||||
if(not(formname)) then
|
||||
return false
|
||||
end
|
||||
-- cut off the leading "yl_speak_up:" prefix
|
||||
local fs_name = string.sub(formname, 13)
|
||||
if(fs_name and fs_name ~= "") then
|
||||
local fun = yl_speak_up.registered_forms_input_handler[fs_name]
|
||||
if(fun) then
|
||||
fun(player, formname, fields)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if formname == "yl_speak_up:optiondialog" then
|
||||
yl_speak_up.input_optiondialog(player, formname, fields)
|
||||
return true
|
||||
@ -248,6 +273,12 @@ yl_speak_up.show_fs = function(player, fs_name, param)
|
||||
yl_speak_up.speak_to[pname].last_fs_param = param
|
||||
end
|
||||
|
||||
local fun = yl_speak_up.registered_forms_get_fs[formname]
|
||||
if(fun) then
|
||||
yl_speak_up.show_fs_ver(pname, "yl_speak_up:"..formname, fun(player, param))
|
||||
return true
|
||||
end
|
||||
|
||||
-- this is here mostly to fascilitate debugging - so that really all calls to
|
||||
-- minetest.show_formspec are routed through here
|
||||
if(fs_name == "msg") then
|
||||
|
Loading…
Reference in New Issue
Block a user