split up fs_talkdialog.lua into fs/ and api/

This commit is contained in:
Sokomine 2023-12-18 02:44:43 +01:00
parent 4f15503dfe
commit e9ee295db5
3 changed files with 35 additions and 34 deletions

33
api/api_talk.lua Normal file
View File

@ -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

View File

@ -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

View File

@ -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