From ce7877bc2bcb4d25f0b6de49fb3fbcf42805f3e4 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Mon, 7 Jun 2021 21:34:36 +0200 Subject: [PATCH] make delete precondition work --- fs_edit_preconditions.lua | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/fs_edit_preconditions.lua b/fs_edit_preconditions.lua index aa7e934..e79323a 100644 --- a/fs_edit_preconditions.lua +++ b/fs_edit_preconditions.lua @@ -319,7 +319,33 @@ yl_speak_up.input_fs_edit_preconditions = function(player, formname, fields) return end - -- TODO: make delete work + -- delete precondition + if(fields.delete_prereq) then + local dialog = yl_speak_up.speak_to[pname].dialog + if(dialog and dialog.n_dialogs + and p_id + and dialog.n_dialogs[d_id] + and dialog.n_dialogs[d_id].d_options + and dialog.n_dialogs[d_id].d_options[o_id]) then + -- actually delete the prerequirement + dialog.n_dialogs[d_id].d_options[o_id].o_prerequisites[ p_id ] = nil + -- record this as a change, but do not save do disk yet + table.insert(yl_speak_up.npc_was_changed[ n_id ], + "Dialog "..tostring(d_id)..": ".."Pre(C)ondition "..tostring(p_id).. + " deleted for option "..tostring(o_id)..".") + -- TODO: when trying to save: save to disk as well? + -- show the new/changed precondition + -- go back to the edit option dialog (after all we just deleted the prerequirement) + yl_speak_up.show_fs(player, "msg", { + input_to = "yl_speak_up:edit_preconditions", + formspec = "size[6,2]".. + "label[0.2,0.5;Pre(C)ondition \"".. + minetest.formspec_escape(tostring(p_id)).. + "\" has been deleted.]".. + "button[1.5,1.5;2,0.9;back_from_delete_precondition;Back]"}) + return + end + end if(fields.select_block_pos) then minetest.chat_send_player(pname,