some more progress on turning dialogs in alternate texts

This commit is contained in:
Sokomine 2021-07-25 04:30:29 +02:00
parent 972a1e1e61
commit 784ac2af71

View File

@ -379,6 +379,12 @@ yl_speak_up.show_what_points_to_this_dialog = function(player, this_dialog)
r, pname)
table.insert(found, {d_id, o_id, r_id,
"option was selected"})
alternate_dialog = r.r_value
if(r.alternate_text) then
alternate_text =
"Show alternate text: "..
tostring(r.alternate_text)
end
elseif(r and r.r_type and r.r_type == "on_failure"
and r.r_value == this_dialog) then
r_text = r_text..yl_speak_up.print_as_table_effect(
@ -450,50 +456,106 @@ yl_speak_up.show_what_points_to_this_dialog = function(player, this_dialog)
tostring(d_id)).."\" into an alternate text.]")
end
return table.concat(formspec, "\n")
--[[
local formspec = {
"formspec_version[3]",
"size[20,8]",
-- back to the list with that one precondition or effect
"button[0.2,0.2;19.4,0.6;back;Back to dialog "..minetest.formspec_escape(this_dialog).."]",
"button[0.2,7.2;19.4,0.6;back;Back to dialog "..minetest.formspec_escape(this_dialog).."]",
"label[0.2,1.1;Dialog \""..minetest.formspec_escape(this_dialog).."\" "..
"is referenced here:]",
"tablecolumns[color,span=1;text;color,span=1;text]",
"table[1.2,1.4;17.6,5.5;table_of_dialog_uses;"
}
for i, v in ipairs(found) do
local a_or_e = ""
if(v[4] ~= "action failed") then
a_or_e = "effect"
else
a_or_e = "action"
end
table.insert(formspec, "#FFFFFF,"..
minetest.formspec_escape(
"Dialog \""..tostring(v[1]).."\", option \""..tostring(v[2])..
"\", "..tostring(a_or_e).." \""..tostring(v[3]).."\":")..
",#FFFFFF,"..minetest.formspec_escape(v[4])..",")
end
return table.concat(formspec, "").."]"
--]]
end
yl_speak_up.input_fs_show_what_points_to_this_dialog = function(player, formname, fields)
local pname = player:get_player_name()
if(fields.back_from_show_what_points_here) then
if(fields.back_from_show_what_points_here
or not(fields.turn_dialog_into_alternate_text)) then
-- back to the dialog
yl_speak_up.show_fs(player, "talk",
{n_id = yl_speak_up.speak_to[pname].n_id,
d_id = yl_speak_up.speak_to[pname].d_id})
return
end
-- works only in edit mode
-- fields.turn_dialog_into_alternate_text is set
local this_dialog = yl_speak_up.speak_to[pname].d_id
local dialog = yl_speak_up.speak_to[pname].dialog
if(not(dialog)
or not(dialog.n_dialogs)
or not(this_dialog)
or not(dialog.n_dialogs[ this_dialog ])) then
return
end
-- only show this information when editing this npc
if(yl_speak_up.edit_mode[pname] ~= yl_speak_up.speak_to[pname].n_id) then
return
end
local dialog = yl_speak_up.speak_to[pname].dialog
-- TODO. make turn into alternate_text work
minetest.chat_send_player("singleplayer","GREAT! Got input: "..minetest.serialize(fields))
-- find out what needs to be turned into an alternate dialog
local found = {}
-- how many options does the current dialog have?
local count_options = 0
-- iterate over all dialogs
for d_id, d in pairs(dialog.n_dialogs) do
-- the dialog itself may have options that point back to the dialog itself
if(d.d_options) then
-- iterate over all options
for o_id, o in pairs(d.d_options) do
-- this is only possible if there are no options for this dialog
if(d_id == this_dialog) then
count_options = count_options + 1
end
-- preconditions are not relevant;
-- effects are (dialog and on_failure)
if(o.o_results) then
for r_id, r in pairs(o.o_results) do
if(r and r.r_type and r.r_type == "dialog"
and r.r_value == this_dialog) then
table.insert(found, {d_id=d_id, o_id=o_id, id=r_id,
element=r, text="option was selected"})
elseif(r and r.r_type and r.r_type == "on_failure"
and r.r_value == this_dialog) then
table.insert(found, {d_id=d_id, o_id=o_id, id=r_id,
element=r, text="the previous effect failed"})
end
end
end
-- actions may be relevant
if(o.actions) then
for a_id, a in pairs(o.actions) do
if(a and a.a_on_failure
and a.a_on_failure == this_dialog) then
table.insert(found, {d_id=d_id, o_id=o_id, id=a_id,
element=a, text="action failed"})
end
end
end
end
end
end
local error_msg = "This should work."
if(count_options > 0) then
error_msg = "This dialog still has dialog options.\nConversion not possible."
elseif(#found < 1) then
error_msg = "Found no option, action or effect\nthat points to this dialog."
elseif(#found > 1) then
error_msg = "Found more than one option, action\nor effect that points to this dialog."
end
if(error_msg ~= "") then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:show_what_points_to_this_dialog",
formspec = "size[8,2]"..
"label[0.2,0.5;Error: "..error_msg.."]"..
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return
end
-- all fine so far; this is the text we want to set as alternate text
local d_text = dialog.n_dialogs[ this_dialog ].d_text
local f = found[1]
--[[ TODO: implement properly
-- TODO: there may already be alternate texts stored there, which may or may not reference d_text
-- normal switching to the next dialog
if( f.element.r_id and f.element.r_type == "dialog") then
dialog.n_dialogs[ f.d_id ].d_options[ f.o_id ].o_results[ f.id ].alternate_text = d_text
-- the previous effect failed
elseif(f.element.r_id and f.element.r_type == "on_failure") then
dialog.n_dialogs[ f.d_id ].d_options[ f.o_id ].o_results[ f.id ].alternate_text = d_text
-- an action failed
elseif(f.element.a_id) then
dialog.n_dialogs[ f.d_id ].d_options[ f.o_id ].actions[ f.id ].alternate_text = d_text
end
-- TODO: where shall these dialogs point to?
--]]
end