support for d_name in export to ink
This commit is contained in:
parent
86e4d9a3fa
commit
443d6568b1
@ -6,6 +6,8 @@ yl_speak_up.export_to_ink = {}
|
|||||||
-- an abbreviation
|
-- an abbreviation
|
||||||
local ink_export = yl_speak_up.export_to_ink
|
local ink_export = yl_speak_up.export_to_ink
|
||||||
|
|
||||||
|
-- use d_name field (name of dialog) instead of n_<id>_d_<id>
|
||||||
|
local use_d_name = true
|
||||||
|
|
||||||
|
|
||||||
-- in order to be able to deal with multiple NPC in ink, we use the NPC id n_id
|
-- in order to be able to deal with multiple NPC in ink, we use the NPC id n_id
|
||||||
@ -55,7 +57,8 @@ end
|
|||||||
-- also, the divert_to target dialog may need to be rewritten
|
-- also, the divert_to target dialog may need to be rewritten
|
||||||
yl_speak_up.export_to_ink.print_choice = function(lines, choice_text, n_id, start_dialog,
|
yl_speak_up.export_to_ink.print_choice = function(lines, choice_text, n_id, start_dialog,
|
||||||
alternate_text, divert_to, only_once, label,
|
alternate_text, divert_to, only_once, label,
|
||||||
precondition_list, effect_list)
|
precondition_list, effect_list,
|
||||||
|
dialog_names)
|
||||||
-- usually, options/answers/choices can be selected multiple times;
|
-- usually, options/answers/choices can be selected multiple times;
|
||||||
-- we support the default ink way of "*" as well (but only until the player stops talking,
|
-- we support the default ink way of "*" as well (but only until the player stops talking,
|
||||||
-- not persistently stored)
|
-- not persistently stored)
|
||||||
@ -114,7 +117,7 @@ yl_speak_up.export_to_ink.print_choice = function(lines, choice_text, n_id, star
|
|||||||
end
|
end
|
||||||
if(not(divert_to) or divert_to == "") then
|
if(not(divert_to) or divert_to == "") then
|
||||||
-- go back to the start dialog (the start dialog may have been changed)
|
-- go back to the start dialog (the start dialog may have been changed)
|
||||||
divert_to = tostring(n_id).."_"..tostring(start_dialog)
|
divert_to = tostring(start_dialog)
|
||||||
elseif(divert_to == "d_end" or divert_to == tostring(n_id).."_d_end") then
|
elseif(divert_to == "d_end" or divert_to == tostring(n_id).."_d_end") then
|
||||||
-- go back to choosing between talking to NPC and end
|
-- go back to choosing between talking to NPC and end
|
||||||
divert_to = tostring(n_id).."_main"
|
divert_to = tostring(n_id).."_main"
|
||||||
@ -122,6 +125,9 @@ yl_speak_up.export_to_ink.print_choice = function(lines, choice_text, n_id, star
|
|||||||
-- make sure it is prefixed with the n_id
|
-- make sure it is prefixed with the n_id
|
||||||
divert_to = tostring(n_id).."_"..tostring(divert_to)
|
divert_to = tostring(n_id).."_"..tostring(divert_to)
|
||||||
end
|
end
|
||||||
|
if(dialog_names and dialog_names[divert_to]) then
|
||||||
|
divert_to = dialog_names[divert_to]
|
||||||
|
end
|
||||||
table.insert(lines, divert_to)
|
table.insert(lines, divert_to)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -130,6 +136,9 @@ end
|
|||||||
-- d: dialog
|
-- d: dialog
|
||||||
yl_speak_up.export_to_ink.print_dialog_knot = function(lines, n_id, d_id, d)
|
yl_speak_up.export_to_ink.print_dialog_knot = function(lines, n_id, d_id, d)
|
||||||
local knot_name = tostring(n_id).."_"..tostring(d_id)
|
local knot_name = tostring(n_id).."_"..tostring(d_id)
|
||||||
|
if(use_d_name) then
|
||||||
|
knot_name = (d.d_name or knot_name)
|
||||||
|
end
|
||||||
ink_export.print_knot_name(lines, knot_name)
|
ink_export.print_knot_name(lines, knot_name)
|
||||||
|
|
||||||
-- many characters at the start of a line have a special meaning;
|
-- many characters at the start of a line have a special meaning;
|
||||||
@ -151,7 +160,7 @@ end
|
|||||||
-- Parameter:
|
-- Parameter:
|
||||||
-- a action
|
-- a action
|
||||||
yl_speak_up.export_to_ink.print_action_knot = function(lines, n_id, d_id, o_id, start_dialog,
|
yl_speak_up.export_to_ink.print_action_knot = function(lines, n_id, d_id, o_id, start_dialog,
|
||||||
a, alternate_text_on_success, next_target)
|
a, alternate_text_on_success, next_target, dialog_names)
|
||||||
local knot_name = tostring(n_id).."_"..tostring(d_id).."_"..tostring(o_id).."_"..tostring(a.a_id)
|
local knot_name = tostring(n_id).."_"..tostring(d_id).."_"..tostring(o_id).."_"..tostring(a.a_id)
|
||||||
ink_export.print_knot_name(lines, knot_name)
|
ink_export.print_knot_name(lines, knot_name)
|
||||||
|
|
||||||
@ -161,13 +170,16 @@ yl_speak_up.export_to_ink.print_action_knot = function(lines, n_id, d_id, o_id,
|
|||||||
table.insert(lines, yl_speak_up.show_action(a))
|
table.insert(lines, yl_speak_up.show_action(a))
|
||||||
|
|
||||||
ink_export.print_choice(lines, "Action was successful", n_id, start_dialog,
|
ink_export.print_choice(lines, "Action was successful", n_id, start_dialog,
|
||||||
alternate_text_on_success, next_target, false, nil)
|
alternate_text_on_success, next_target, false, nil,
|
||||||
|
nil, nil, dialog_names)
|
||||||
|
|
||||||
ink_export.print_choice(lines, "Action failed", n_id, start_dialog,
|
ink_export.print_choice(lines, "Action failed", n_id, start_dialog,
|
||||||
a.alternate_text, a.a_on_failure, false, nil)
|
a.alternate_text, a.a_on_failure, false, nil,
|
||||||
|
nil, nil, dialog_names)
|
||||||
|
|
||||||
ink_export.print_choice(lines, "Back", n_id, start_dialog,
|
ink_export.print_choice(lines, "Back", n_id, start_dialog,
|
||||||
nil, tostring(n_id).."_"..tostring(d_id), false, nil)
|
nil, tostring(n_id).."_"..tostring(d_id), false, nil,
|
||||||
|
nil, nil, dialog_names)
|
||||||
return knot_name
|
return knot_name
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -179,7 +191,8 @@ end
|
|||||||
-- r effect/result
|
-- r effect/result
|
||||||
-- r_prev previous effect
|
-- r_prev previous effect
|
||||||
yl_speak_up.export_to_ink.print_effect_knot = function(lines, n_id, d_id, o_id, start_dialog,
|
yl_speak_up.export_to_ink.print_effect_knot = function(lines, n_id, d_id, o_id, start_dialog,
|
||||||
r, r_prev, alternate_text_on_success, next_target)
|
r, r_prev, alternate_text_on_success, next_target,
|
||||||
|
dialog_names)
|
||||||
local knot_name = tostring(n_id).."_"..tostring(d_id).."_"..tostring(o_id).."_"..tostring(r.r_id)
|
local knot_name = tostring(n_id).."_"..tostring(d_id).."_"..tostring(o_id).."_"..tostring(r.r_id)
|
||||||
ink_export.print_knot_name(lines, knot_name)
|
ink_export.print_knot_name(lines, knot_name)
|
||||||
|
|
||||||
@ -196,10 +209,12 @@ yl_speak_up.export_to_ink.print_effect_knot = function(lines, n_id, d_id, o_id,
|
|||||||
table.insert(lines, yl_speak_up.show_effect(r_prev))
|
table.insert(lines, yl_speak_up.show_effect(r_prev))
|
||||||
|
|
||||||
ink_export.print_choice(lines, "Effect was successful", n_id, start_dialog,
|
ink_export.print_choice(lines, "Effect was successful", n_id, start_dialog,
|
||||||
alternate_text_on_success, next_target, false, nil)
|
alternate_text_on_success, next_target, false, nil,
|
||||||
|
nil, nil, dialog_names)
|
||||||
|
|
||||||
ink_export.print_choice(lines, "Effect failed", n_id, start_dialog,
|
ink_export.print_choice(lines, "Effect failed", n_id, start_dialog,
|
||||||
r.alternate_text, r.r_value, false, nil)
|
r.alternate_text, r.r_value, false, nil,
|
||||||
|
nil, nil, dialog_names)
|
||||||
|
|
||||||
return knot_name
|
return knot_name
|
||||||
end
|
end
|
||||||
@ -248,7 +263,7 @@ yl_speak_up.export_to_ink.print_variables_used = function(lines, dialog, n_id, p
|
|||||||
-- add the variable as a variable to INK
|
-- add the variable as a variable to INK
|
||||||
table.insert(lines, "\nVAR ")
|
table.insert(lines, "\nVAR ")
|
||||||
table.insert(lines, v_name)
|
table.insert(lines, v_name)
|
||||||
table.insert(lines, " = NONE") -- start with undefined/nil (we don't know the stored value)
|
table.insert(lines, " = false") -- start with undefined/nil (we don't know the stored value)
|
||||||
end
|
end
|
||||||
table.insert(lines, "\n")
|
table.insert(lines, "\n")
|
||||||
return vars_used
|
return vars_used
|
||||||
@ -284,14 +299,15 @@ local var_with_operator = function(liste, var_name, op, var_cmp_value, vars_used
|
|||||||
elseif(op=="is_set") then
|
elseif(op=="is_set") then
|
||||||
table.insert(liste, tostring(vars_used[var_name]))
|
table.insert(liste, tostring(vars_used[var_name]))
|
||||||
elseif(op=="is_unset") then
|
elseif(op=="is_unset") then
|
||||||
table.insert(liste, tostring(vars_used[var_name]).." == NONE")
|
table.insert(liste, tostring(vars_used[var_name]).." == false")
|
||||||
end
|
end
|
||||||
-- the following values for op cannot really be checked here and are not printed:
|
-- the following values for op cannot really be checked here and are not printed:
|
||||||
-- "more_than_x_seconds_ago","less_than_x_seconds_ago",
|
-- "more_than_x_seconds_ago","less_than_x_seconds_ago",
|
||||||
-- "quest_step_done", "quest_step_not_done"
|
-- "quest_step_done", "quest_step_not_done"
|
||||||
end
|
end
|
||||||
|
|
||||||
yl_speak_up.export_to_ink.translate_precondition_list = function(dialog, preconditions, vars_used, n_id)
|
yl_speak_up.export_to_ink.translate_precondition_list = function(dialog, preconditions, vars_used, n_id,
|
||||||
|
dialog_names)
|
||||||
-- collect preconditions that may work in ink
|
-- collect preconditions that may work in ink
|
||||||
local liste = {}
|
local liste = {}
|
||||||
-- variables may be used in preconditions
|
-- variables may be used in preconditions
|
||||||
@ -304,7 +320,12 @@ yl_speak_up.export_to_ink.translate_precondition_list = function(dialog, precond
|
|||||||
var_with_operator(liste, p.p_value, p.p_operator, p.p_var_cmp_value, vars_used)
|
var_with_operator(liste, p.p_value, p.p_operator, p.p_var_cmp_value, vars_used)
|
||||||
elseif(p and p.p_type and p.p_type == "evaluate" and p.p_value == "counted_visits_to_option") then
|
elseif(p and p.p_type and p.p_type == "evaluate" and p.p_value == "counted_visits_to_option") then
|
||||||
-- simulate the visit counter that ink has in yl_speak_up
|
-- simulate the visit counter that ink has in yl_speak_up
|
||||||
local tmp_var_name = n_id.."_"..p.p_param1.."_"..p.p_param2
|
local tmp_var_name = n_id.."_"..p.p_param1
|
||||||
|
if(dialog_names[tmp_var_name]) then
|
||||||
|
tmp_var_name = dialog_names[tmp_var_name].."."..tostring(p.p_param2)
|
||||||
|
else
|
||||||
|
tmp_var_name = tmp_var_name.. "_"..tostring(p.p_param2)
|
||||||
|
end
|
||||||
var_with_operator(liste, tmp_var_name, p.p_operator, p.p_var_cmp_value, vars_used)
|
var_with_operator(liste, tmp_var_name, p.p_operator, p.p_var_cmp_value, vars_used)
|
||||||
elseif(p and p.p_type and p.p_type == "true") then
|
elseif(p and p.p_type and p.p_type == "true") then
|
||||||
table.insert(liste, p.p_type)
|
table.insert(liste, p.p_type)
|
||||||
@ -317,14 +338,16 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- small helper function
|
-- small helper function
|
||||||
local set_var_to_value = function(liste, var_name, op, val, vars_used)
|
local set_var_to_value = function(liste, var_name_full, op, val, vars_used)
|
||||||
if(not(vars_used[var_name])) then
|
if(not(vars_used[var_name_full])) then
|
||||||
vars_used[var_name] = var_name
|
vars_used[var_name_full] = var_name_full
|
||||||
end
|
end
|
||||||
|
local var_name = vars_used[var_name_full]
|
||||||
if(op == "set_to") then
|
if(op == "set_to") then
|
||||||
table.insert(liste, tostring(var_name).." = "..tostring(val))
|
table.insert(liste, tostring(var_name).." = "..tostring(val))
|
||||||
elseif(op == "unset") then
|
elseif(op == "unset") then
|
||||||
table.insert(liste, tostring(var_name).." = NONE ")
|
-- TODO: there does not seem to be a none/nil type in the Ink language
|
||||||
|
table.insert(liste, tostring(var_name).." = false ")
|
||||||
elseif(op == "maximum") then
|
elseif(op == "maximum") then
|
||||||
table.insert(liste, tostring(var_name).." = max("..tostring(var_name)..", "..tostring(val))
|
table.insert(liste, tostring(var_name).." = max("..tostring(var_name)..", "..tostring(val))
|
||||||
elseif(op == "minimum") then
|
elseif(op == "minimum") then
|
||||||
@ -359,17 +382,36 @@ yl_speak_up.export_to_ink_language = function(dialog, n_id)
|
|||||||
if(not(start_dialog)) then
|
if(not(start_dialog)) then
|
||||||
start_dialog = "d_1"
|
start_dialog = "d_1"
|
||||||
end
|
end
|
||||||
|
if(use_d_name
|
||||||
|
and dialog.n_dialogs
|
||||||
|
and dialog.n_dialogs[start_dialog]
|
||||||
|
and dialog.n_dialogs[start_dialog].d_name) then
|
||||||
|
start_dialog = dialog.n_dialogs[start_dialog].d_name
|
||||||
|
else
|
||||||
|
start_dialog = tostring(n_id).."_"..tostring(start_dialog)
|
||||||
|
end
|
||||||
|
|
||||||
local main = tostring(n_id).."_main"
|
local main = tostring(n_id).."_main"
|
||||||
local tmp = {"-> ", main,
|
local tmp = {"-> ", main,
|
||||||
"\n=== ", main, " ===",
|
"\n=== ", main, " ===",
|
||||||
"\nWhat do you wish to do?",
|
"\nWhat do you wish to do?",
|
||||||
"\n+ Talk to ", tostring(dialog.n_npc), " -> ", tostring(n_id).."_"..tostring(start_dialog),
|
"\n+ Talk to ", tostring(dialog.n_npc), " -> ", tostring(start_dialog),
|
||||||
"\n+ End -> END"}
|
"\n+ End -> END"}
|
||||||
|
|
||||||
local vars_used = ink_export.print_variables_used(tmp, dialog, n_id, pname)
|
local vars_used = ink_export.print_variables_used(tmp, dialog, n_id, pname)
|
||||||
|
|
||||||
local sorted_d_list = yl_speak_up.sort_keys(dialog.n_dialogs or {}, true)
|
local sorted_d_list = yl_speak_up.sort_keys(dialog.n_dialogs or {}, true)
|
||||||
|
|
||||||
|
-- make use of dialog names if wanted
|
||||||
|
local dialog_names = {}
|
||||||
|
for i, d_id in ipairs(sorted_d_list) do
|
||||||
|
if(use_d_name) then
|
||||||
|
local n = tostring(n_id).."_"..tostring(d_id)
|
||||||
|
local d = dialog.n_dialogs[d_id]
|
||||||
|
dialog_names[n] = (d.d_name or n)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for i, d_id in ipairs(sorted_d_list) do
|
for i, d_id in ipairs(sorted_d_list) do
|
||||||
-- store the knots for actions and effects here:
|
-- store the knots for actions and effects here:
|
||||||
local tmp2 = {}
|
local tmp2 = {}
|
||||||
@ -415,7 +457,8 @@ yl_speak_up.export_to_ink_language = function(dialog, n_id)
|
|||||||
target_dialog = ink_export.print_effect_knot(tmp2,
|
target_dialog = ink_export.print_effect_knot(tmp2,
|
||||||
n_id, d_id, o_id, start_dialog,
|
n_id, d_id, o_id, start_dialog,
|
||||||
r, r_prev,
|
r, r_prev,
|
||||||
alternate_text_on_success, target_dialog)
|
alternate_text_on_success, target_dialog,
|
||||||
|
dialog_names)
|
||||||
-- we have dealt with the alternate text (it will only be shown
|
-- we have dealt with the alternate text (it will only be shown
|
||||||
-- in the last on_failure dialog before we go to the target)
|
-- in the last on_failure dialog before we go to the target)
|
||||||
alternate_text_on_success = ""
|
alternate_text_on_success = ""
|
||||||
@ -435,14 +478,14 @@ yl_speak_up.export_to_ink_language = function(dialog, n_id)
|
|||||||
target_dialog = ink_export.print_action_knot(tmp2,
|
target_dialog = ink_export.print_action_knot(tmp2,
|
||||||
n_id, d_id, o_id, start_dialog,
|
n_id, d_id, o_id, start_dialog,
|
||||||
a,
|
a,
|
||||||
alternate_text_on_success, target_dialog)
|
alternate_text_on_success, target_dialog, dialog_names)
|
||||||
-- has been dealt with
|
-- has been dealt with
|
||||||
alternate_text_on_success = ""
|
alternate_text_on_success = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
-- which preconditions can be translated to ink?
|
-- which preconditions can be translated to ink?
|
||||||
local p_list = ink_export.translate_precondition_list(dialog, o_data.o_prerequisites,
|
local p_list = ink_export.translate_precondition_list(dialog, o_data.o_prerequisites,
|
||||||
vars_used, n_id)
|
vars_used, n_id, dialog_names)
|
||||||
local e_list = ink_export.translate_effect_list(dialog, o_data.o_results,
|
local e_list = ink_export.translate_effect_list(dialog, o_data.o_results,
|
||||||
vars_used, n_id)
|
vars_used, n_id)
|
||||||
|
|
||||||
@ -452,12 +495,12 @@ yl_speak_up.export_to_ink_language = function(dialog, n_id)
|
|||||||
o_data.o_text_when_prerequisites_met, n_id, start_dialog,
|
o_data.o_text_when_prerequisites_met, n_id, start_dialog,
|
||||||
alternate_text_on_success, target_dialog,
|
alternate_text_on_success, target_dialog,
|
||||||
o_data.o_visit_only_once,
|
o_data.o_visit_only_once,
|
||||||
o_id, p_list, e_list)
|
o_id, p_list, e_list, dialog_names)
|
||||||
end -- dealt with the option
|
end -- dealt with the option
|
||||||
table.insert(tmp, "\n")
|
table.insert(tmp, "\n")
|
||||||
-- add way to end talking to the NPC
|
-- add way to end talking to the NPC
|
||||||
ink_export.print_choice(tmp, "Farewell!", n_id, start_dialog,
|
ink_export.print_choice(tmp, "Farewell!", n_id, start_dialog,
|
||||||
nil, tostring(n_id).."_main", false, nil)
|
nil, tostring(n_id).."_main", false, nil, dialog_names)
|
||||||
|
|
||||||
-- add the knots for actions and effects for this dialog and all its options:
|
-- add the knots for actions and effects for this dialog and all its options:
|
||||||
for _, line in ipairs(tmp2) do
|
for _, line in ipairs(tmp2) do
|
||||||
|
Loading…
Reference in New Issue
Block a user