made functions in functions_dialog.lua only optionally dependant on pname

This commit is contained in:
Sokomine 2025-01-01 18:24:38 +01:00
parent c4ebef21f0
commit 4cf06da1e4

View File

@ -64,6 +64,8 @@ end
-- the option to override next_id and provide a value is needed when a new dialog was
-- added, then edited, and then discarded; it's still needed after that, but has to
-- be reset to empty state (wasn't stored before)
-- Note: pname is only passed to yl_speak_up.add_new_option - which is only used if
-- dialog_text is empty (and only for logging)
yl_speak_up.add_new_dialog = function(dialog, pname, next_id, dialog_text)
if(not(next_id)) then
next_id = yl_speak_up.find_next_id(dialog.n_dialogs)
@ -99,6 +101,7 @@ end
-- option_text (optional) the text that shall be shown as option/answer
-- target_dialog (optional) the target dialog where the player will end up when choosing
-- this option/answer
-- Note: pname is only used for logging (and for changing o_sort)
yl_speak_up.add_new_option = function(dialog, pname, next_id, d_id, option_text, target_dialog)
if(not(dialog) or not(dialog.n_dialogs) or not(dialog.n_dialogs[d_id])) then
return nil
@ -127,18 +130,25 @@ yl_speak_up.add_new_option = function(dialog, pname, next_id, d_id, option_text,
o_text_when_prerequisites_not_met = "",
o_text_when_prerequisites_met = (option_text or ""),
}
-- necessary in order for it to work
local s = yl_speak_up.sanitize_sort(dialog.n_dialogs[d_id].d_options, yl_speak_up.speak_to[pname].o_sort)
dialog.n_dialogs[d_id].d_options[future_o_id].o_sort = s
-- log only in edit mode
local n_id = yl_speak_up.speak_to[pname].n_id
-- would be too difficult to add an exception for edit_mode here; thus, we do it directly here:
if(yl_speak_up.npc_was_changed
and yl_speak_up.npc_was_changed[n_id]) then
table.insert(yl_speak_up.npc_was_changed[ n_id ],
"Dialog "..d_id..": Added new option/answer "..future_o_id..".")
local start_with_o_sort = nil
if(pname and pname ~= "") then
-- log only in edit mode
local n_id = yl_speak_up.speak_to[pname].n_id
-- would be too difficult to add an exception for edit_mode here; thus, we do it directly here:
if(yl_speak_up.npc_was_changed
and yl_speak_up.npc_was_changed[n_id]) then
table.insert(yl_speak_up.npc_was_changed[ n_id ],
"Dialog "..d_id..": Added new option/answer "..future_o_id..".")
end
start_with_o_sort = yl_speak_up.speak_to[pname].o_sort
end
-- necessary in order for it to work
local new_o_sort = yl_speak_up.sanitize_sort(dialog.n_dialogs[d_id].d_options, start_with_o_sort)
dialog.n_dialogs[d_id].d_options[future_o_id].o_sort = new_o_sort
-- letting d_got_item point back to itself is not a good idea because the
-- NPC will then end up in a loop; plus the d_got_item dialog is intended for
-- automatic processing, not for showing to the player