turned into function: yl_speak_up.export_to_simple_dialogs_language(

This commit is contained in:
Sokomine 2024-03-22 17:20:02 +01:00
parent cfb673993f
commit 507123660f

View File

@ -19,6 +19,42 @@ yl_speak_up.get_dialog_list_for_export = function(dialog)
end
yl_speak_up.export_to_simple_dialogs_language = function(dialog, n_id)
local d_liste = yl_speak_up.get_dialog_list_for_export(dialog)
local tmp = {}
for i, d_id in ipairs(d_liste) do
table.insert(tmp, "===")
-- TODO: use labels here when available
table.insert(tmp, tostring(d_id))
table.insert(tmp, "\n")
-- :, > and = are not allowed as line start in simple dialogs
-- just add a leading blank so that any :, > and = at the start are covered
table.insert(tmp, " ")
local t = dialog.n_dialogs[d_id].d_text or ""
t = string.gsub(t, "\n([:>=])", "\n %1")
table.insert(tmp, t)
table.insert(tmp, "\n")
for o_id, o_data in pairs(dialog.n_dialogs[d_id].d_options or {}) do
local target_dialog = nil
for r_id, r_data in pairs(o_data.o_results) do
if(r_data.r_type and r_data.r_type == "dialog") then
target_dialog = r_data.r_value
end
end
table.insert(tmp, ">")
table.insert(tmp, target_dialog or "d_1")
table.insert(tmp, ":")
table.insert(tmp, o_data.o_text_when_prerequisites_met)
table.insert(tmp, "\n")
end
table.insert(tmp, "\n")
end
return table.concat(tmp, "")
end
yl_speak_up.input_export = function(player, formname, fields)
if(fields and fields.back) then
return yl_speak_up.show_fs(player, "talk")
@ -202,38 +238,7 @@ yl_speak_up.get_fs_export = function(player, param)
"this mod here. It only covers the raw dialogs. If a dialog line starts with "..
"\":\", \">\" or \"=\", a \" \" is added before that letter because such a "..
"line start would not be allowed in \"simple_dialogs\"."
local d_liste = yl_speak_up.get_dialog_list_for_export(dialog)
local tmp = {}
for i, d_id in ipairs(d_liste) do
table.insert(tmp, "===")
-- TODO: use labels here when available
table.insert(tmp, tostring(d_id))
table.insert(tmp, "\n")
-- :, > and = are not allowed as line start in simple dialogs
-- just add a leading blank so that any :, > and = at the start are covered
table.insert(tmp, " ")
local t = dialog.n_dialogs[d_id].d_text or ""
t = string.gsub(t, "\n([:>=])", "\n %1")
table.insert(tmp, t)
table.insert(tmp, "\n")
for o_id, o_data in pairs(dialog.n_dialogs[d_id].d_options or {}) do
local target_dialog = nil
for r_id, r_data in pairs(o_data.o_results) do
if(r_data.r_type and r_data.r_type == "dialog") then
target_dialog = r_data.r_value
end
end
table.insert(tmp, ">")
table.insert(tmp, target_dialog or "d_1")
table.insert(tmp, ":")
table.insert(tmp, o_data.o_text_when_prerequisites_met)
table.insert(tmp, "\n")
end
table.insert(tmp, "\n")
end
content = table.concat(tmp, "")
content = yl_speak_up.export_to_simple_dialogs_language(dialog, n_id)
else
b2 = "label[5.0,17.6;This is export in .json format]"
explanation = "Mark the text in the above window with your mouse and paste it into "..