From a85f0629c50ed4b72002dd9f33f69b74a2cf0485 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 12 Jan 2025 22:28:19 +0100 Subject: [PATCH] ink import: sort dialogs according to order given in ink; sort existing but not imported dialogs in after that --- functions_dialogs.lua | 13 +++++++++---- import_from_ink.lua | 9 ++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/functions_dialogs.lua b/functions_dialogs.lua index ee23a9a..3b57d69 100644 --- a/functions_dialogs.lua +++ b/functions_dialogs.lua @@ -228,6 +228,9 @@ yl_speak_up.update_dialog = function(log, dialog, dialog_name, dialog_text) for i, o_id in ipairs(d_data.d_tmp_sorted_option_list or {}) do d_data.d_options[o_id].o_tmp_needs_update = true end + -- mark this dialog as having received an update (meaning we won't have to update d_sort after + -- all dialogs have been updated) + d_data.d_tmp_has_been_updated = true return d_id end @@ -302,7 +305,7 @@ end -- make sure only one dialog has d_sort set to 0 (and is thus the start dialog) -yl_speak_up.update_start_dialog = function(log, dialog, start_dialog_name) +yl_speak_up.update_start_dialog = function(log, dialog, start_dialog_name, start_with_d_sort) local start_d_id = yl_speak_up.d_name_to_d_id(dialog, start_dialog_name) if(not(start_d_id)) then return @@ -315,10 +318,12 @@ yl_speak_up.update_start_dialog = function(log, dialog, start_dialog_name) d.d_sort = 0 -- the start dialog certainly is *a* start dialog (with the buttons) d.is_a_start_dialog = true - elseif(not(d.d_sort) or d.d_sort == 0) then - -- all other dialogs are not *the* start dialog - d.d_sort = d.d_sort or tonumber(string.sub(d_id, 3)) or 1 + elseif(not(d.d_tmp_has_been_updated)) then + -- sort this dialog behind the others + d.d_sort = start_with_d_sort + start_with_d_sort = start_with_d_sort + 1 end + d.d_tmp_has_been_updated = nil end end diff --git a/import_from_ink.lua b/import_from_ink.lua index c5ba066..2a5c8fb 100644 --- a/import_from_ink.lua +++ b/import_from_ink.lua @@ -889,12 +889,19 @@ parse_ink.import_dialogs = function(dialog, dialogs, actions, effects, start_dia end end -- we need to add the dialogs as such first so that target_dialog will work + local d_sort = 1 for i, d_name in ipairs(dialog_list) do local dialog_knot = dialogs[d_name] local dialog_name = parse_ink.strip_prefix(d_name, prefix) local d_id = yl_speak_up.update_dialog(log, dialog, dialog_name, dialog_knot.text) dialog_knot.d_id = d_id + + -- adjust d_sort so that it is the same order as in the import + if(d_id and dialog.n_dialogs[d_id] and d_name ~= start_dialog) then + dialog.n_dialogs[d_id].d_sort = d_sort + d_sort = d_sort + 1 + end end -- now we can add the options @@ -977,7 +984,7 @@ parse_ink.import_dialogs = function(dialog, dialogs, actions, effects, start_dia end -- make sure the right start dialog is set - yl_speak_up.update_start_dialog(log, dialog, parse_ink.strip_prefix(start_dialog, prefix)) + yl_speak_up.update_start_dialog(log, dialog, parse_ink.strip_prefix(start_dialog, prefix), d_sort) return dialog end