diff --git a/functions.lua b/functions.lua index e7657c9..7773edd 100644 --- a/functions.lua +++ b/functions.lua @@ -1987,12 +1987,13 @@ end -- pname player name -- fields the fields returned from the formspec yl_speak_up.edit_mode_apply_changes = function(pname, fields) + local n_id = yl_speak_up.edit_mode[pname] local d_id = yl_speak_up.speak_to[pname].d_id local dialog = yl_speak_up.speak_to[pname].dialog -- this way we can store the actual changes and present them to the player for saving - if(not(yl_speak_up.npc_was_changed[ yl_speak_up.edit_mode[pname]])) then - yl_speak_up.npc_was_changed[ yl_speak_up.edit_mode[pname]] = {} + if(not(yl_speak_up.npc_was_changed[ n_id ])) then + yl_speak_up.npc_was_changed[ n_id ] = {} end @@ -2004,8 +2005,10 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields) -- detect changes to d_text: text of the dialog (what the npc is saying) if(fields.d_text and dialog.n_dialogs[ d_id ].d_text ~= fields.d_text) then -- store that there have been changes to this npc - table.insert(yl_speak_up.npc_was_changed[ yl_speak_up.edit_mode[pname] ], - "Dialog "..d_id..": d_text (what the NPC says) was changed from \""..tostring( dialog.n_dialogs[ d_id ].d_text).."\" to \""..tostring(fields.d_text).."\".") + table.insert(yl_speak_up.npc_was_changed[ n_id ], + "Dialog "..d_id..": d_text (what the NPC says) was changed from \"".. + tostring( dialog.n_dialogs[ d_id ].d_text).. + "\" to \""..tostring(fields.d_text).."\".") -- actually change the text - but do not save to disk yet dialog.n_dialogs[ d_id ].d_text = fields.d_text -- TODO: option to delete dialogs (when text empty and no options present?) @@ -2020,8 +2023,8 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields) end dialog.n_dialogs[d_id].d_options[future_o_id] = { o_id = future_o_id, - o_hide_when_prerequisites_not_met = false, - o_grey_when_prerequisites_not_met = false, + o_hide_when_prerequisites_not_met = "false", + o_grey_when_prerequisites_not_met = "false", o_sort = -1, o_text_when_prerequisites_not_met = "", o_text_when_prerequisites_met = "", @@ -2029,7 +2032,7 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields) -- necessary in order for it to work local s = 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 - table.insert(yl_speak_up.npc_was_changed[ yl_speak_up.edit_mode[pname] ], + table.insert(yl_speak_up.npc_was_changed[ n_id ], "Dialog "..d_id..": Added new option/answer "..future_o_id..".") end @@ -2042,8 +2045,10 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields) and fields[ "text_option_"..k ] ~= v.o_text_when_prerequisites_met ) then -- TODO: delete option if text is empty -- store that there have been changes to this npc - table.insert(yl_speak_up.npc_was_changed[ yl_speak_up.edit_mode[pname] ], - "Dialog "..d_id..": The text for option "..tostring(k).." was changed from \""..tostring(v.o_text_when_prerequisites_met).."\" to \""..tostring(fields[ "text_option_"..k]).."\".") + table.insert(yl_speak_up.npc_was_changed[ n_id ], + "Dialog "..d_id..": The text for option "..tostring(k).. + " was changed from \""..tostring(v.o_text_when_prerequisites_met).. + "\" to \""..tostring(fields[ "text_option_"..k]).."\".") -- actually change the text of the option dialog.n_dialogs[ d_id ].d_options[ k ].o_text_when_prerequisites_met = fields[ "text_option_"..k ] end @@ -2060,8 +2065,11 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields) fields[ "d_id_"..k ] = yl_speak_up.add_new_dialog(dialog, pname) end -- store that there have been changes to this npc - table.insert(yl_speak_up.npc_was_changed[ yl_speak_up.edit_mode[pname] ], - "Dialog "..d_id..": The target dialog for option "..tostring(k).." was changed from "..tostring(vr.r_value).." to "..tostring(fields[ "d_id_"..k])..".") + table.insert(yl_speak_up.npc_was_changed[ n_id ], + "Dialog "..d_id..": The target dialog for option ".. + tostring(k).." was changed from ".. + tostring(vr.r_value).. + " to "..tostring(fields[ "d_id_"..k])..".") -- actually change the target dialog vr.r_value = fields[ "d_id_"..k ] end @@ -2074,7 +2082,7 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields) fields[ "d_id_"..k ] = yl_speak_up.add_new_dialog(dialog, pname) end -- store that a new option has been added to this dialog - table.insert(yl_speak_up.npc_was_changed[ yl_speak_up.edit_mode[pname] ], + table.insert(yl_speak_up.npc_was_changed[ n_id ], "Dialog "..d_id..": The target dialog for option "..tostring(k).." was changed from -default- to "..tostring(fields[ "d_id_"..k])..".") -- create a new result (first the id, then the actual result) @@ -2201,6 +2209,7 @@ minetest.register_on_player_receive_fields( end -- TODO: change of o_sort, change of target_dialog, button delete, buton add, (button save?) + --yl_speak_up.edit_mode_apply_changes(pname, fields) -- back to the main dialog window? if(fields.show_current_dialog or fields.quit or fields.button_exit or not(d_option)) then