diff --git a/api/api_talk.lua b/api/api_talk.lua new file mode 100644 index 0000000..22cbe13 --- /dev/null +++ b/api/api_talk.lua @@ -0,0 +1,33 @@ + +yl_speak_up.stop_talking = function(pname) + if(not(pname)) then + return + end + yl_speak_up.edit_mode[pname] = nil + yl_speak_up.speak_to[pname] = nil + minetest.close_formspec(pname, "yl_speak_up:talk") +end + + +-- helper function for +-- yl_speak_up.get_fs_talkdialog and +-- yl_speak_up.check_and_add_as_generic_dialog +-- find the dialog with d_sort == 0 or lowest number +yl_speak_up.get_start_dialog_id = function(dialog) + if(not(dialog) or not(dialog.n_dialogs)) then + return nil + end + -- Find the dialog with d_sort = 0 or alternatively with the lowest number + local lowest_sort = nil + local d_id = nil + for k, v in pairs(dialog.n_dialogs) do + local nr = tonumber(v.d_sort) + if(not(lowest_sort) or (nr and nr >= 0 and nr < lowest_sort)) then + lowest_sort = nr + d_id = k + end + end + return d_id +end + + diff --git a/fs_talkdialog.lua b/fs/fs_talkdialog.lua similarity index 98% rename from fs_talkdialog.lua rename to fs/fs_talkdialog.lua index 37323ae..4dd8470 100644 --- a/fs_talkdialog.lua +++ b/fs/fs_talkdialog.lua @@ -1,14 +1,4 @@ -- This is the main talkdialog the NPC shows when right-clicked. - -yl_speak_up.stop_talking = function(pname) - if(not(pname)) then - return - end - yl_speak_up.edit_mode[pname] = nil - yl_speak_up.speak_to[pname] = nil - minetest.close_formspec(pname, "yl_speak_up:talk") -end - yl_speak_up.input_talk = function(player, formname, fields) if formname ~= "yl_speak_up:talk" then return @@ -328,29 +318,6 @@ yl_speak_up.input_talk = function(player, formname, fields) end --- helper function for --- yl_speak_up.get_fs_talkdialog and --- yl_speak_up.check_and_add_as_generic_dialog --- find the dialog with d_sort == 0 or lowest number -yl_speak_up.get_start_dialog_id = function(dialog) - if(not(dialog) or not(dialog.n_dialogs)) then - return nil - end - -- Find the dialog with d_sort = 0 or alternatively with the lowest number - local lowest_sort = nil - local d_id = nil - for k, v in pairs(dialog.n_dialogs) do - local nr = tonumber(v.d_sort) - if(not(lowest_sort) or (nr and nr >= 0 and nr < lowest_sort)) then - lowest_sort = nr - d_id = k - end - end - return d_id -end - - - -- helper function for yl_speak_up.get_fs_talkdialog: -- shows the text the NPC "speaks" and adds edit and navigation buttons diff --git a/init.lua b/init.lua index ad60b93..74706eb 100644 --- a/init.lua +++ b/init.lua @@ -155,7 +155,8 @@ yl_speak_up.reload = function(modpath, log_entry) -- general decoration part for main formspec, trade window etc. dofile(modpath .. "fs_decorated.lua") -- the formspec and input handling for the main dialog - dofile(modpath .. "fs_talkdialog.lua") + dofile(modpath .. "api/api_talk.lua") + dofile(modpath .. "fs/fs_talkdialog.lua") -- ask if the player wants to save, discard or go back in edit mode dofile(modpath .. "fs/fs_save_or_discard_or_back.lua") -- the player wants to change something regarding the dialog