From a44cb0fbddb9a0c385361a42b0702d4415ce2fe3 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 19 Jun 2021 23:42:05 +0200 Subject: [PATCH] allow actual editing of most preconditions, actions and effects --- fs_edit_actions.lua | 1 + fs_edit_effects.lua | 1 + fs_edit_general.lua | 97 +++++++++++++++++++++++++++++++++++++-- fs_edit_preconditions.lua | 1 + 4 files changed, 97 insertions(+), 3 deletions(-) diff --git a/fs_edit_actions.lua b/fs_edit_actions.lua index 860748f..fefc79a 100644 --- a/fs_edit_actions.lua +++ b/fs_edit_actions.lua @@ -659,6 +659,7 @@ yl_speak_up.get_fs_edit_actions = function(player, table_click_result) "a_", "actions", yl_speak_up.max_actions, "(A)ctions", "tmp_action", "What do you want to happen in this (A)ction?", + values_what, {}, {}, {}, {}, check_what, {}, {}, {}, {}, nil, -- no variables yl_speak_up.show_action, diff --git a/fs_edit_effects.lua b/fs_edit_effects.lua index c824657..8f0e735 100644 --- a/fs_edit_effects.lua +++ b/fs_edit_effects.lua @@ -678,6 +678,7 @@ yl_speak_up.get_fs_edit_effects = function(player, table_click_result) "r_", "o_results", yl_speak_up.max_result_effects, "(Ef)fect", "tmp_result", "What do you want to change with this effect?", + values_what, values_operator, values_block, {}, {}, check_what, check_operator, check_block, {}, {}, -- player variables with write access yl_speak_up.get_sorted_player_var_list_write_access, diff --git a/fs_edit_general.lua b/fs_edit_general.lua index 4a56903..edf5717 100644 --- a/fs_edit_general.lua +++ b/fs_edit_general.lua @@ -253,7 +253,8 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, elseif(fields.custom_param and fields.custom_param ~= "- Insert a text that is passed on to your function here -" - and fields.custom_param ~= "") then + and fields.custom_param ~= "" + and data and data.what and data.what == 7 and id_prefix == "a_") then data.custom_param = fields.custom_param elseif(fields.action_item_quest_id @@ -271,13 +272,15 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, data.item_desc = fields.action_item_desc end if(fields.quest_question - and fields.quest_question ~= "") then + and fields.quest_question ~= "" + and data and data.what and data.what == 6 and id_prefix == "a_") then data.quest_question = fields.quest_question end -- quest question and answer can be given with the same press of the save button if(fields.quest_answer and fields.quest_answer ~= "- Insert the correct answer here -" - and fields.quest_answer ~= "") then + and fields.quest_answer ~= "" + and data and data.what and data.what == 6 and id_prefix == "a_") then data.quest_answer = fields.quest_answer end @@ -721,6 +724,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, id_prefix, element_list_name, max_entries_allowed, element_desc, tmp_data_cache, what_do_you_want_txt, + values_what, values_operator, values_block, values_trade, values_inv, check_what, check_operator, check_block, check_trade, check_inv, get_sorted_player_var_list_function, show_element_function, @@ -782,6 +786,8 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, -- store which element we are talking about yl_speak_up.speak_to[pname][ id_prefix.."id" ] = x_id + -- nothing selected yet + yl_speak_up.speak_to[pname][ tmp_data_cache ] = nil -- display the selected element if(x_id ~= "new") then return "formspec_version[3]".. @@ -814,6 +820,91 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, if(not(x_id)) then x_id = "new" end + + -- does the element exist already? if so: use the existing values as presets for data + -- (so that the element can be edited) + -- does kind of the opposite than the saving of values starting in line 323 of this file + if(x_id ~= "new" and data.what == 1 and elements[ x_id ]) then + local e = elements[ x_id ] + data.what = table.indexof(values_what, e[ id_prefix.."type" ]) + if(data.what == -1) then + data.what = 1 + -- a state/variable (precondition + effect) + elseif(data.what == 2 and id_prefix ~= "a_") then + data.operator = math.max(1,table.indexof(values_operator, e[ id_prefix.."operator" ])) + data.var_cmp_value = e[ id_prefix.."var_cmp_value" ] + data.variable_name = e[ id_prefix.."variable" ] + local var_list = get_sorted_player_var_list_function(pname) + data.variable = math.max(1, table.indexof(var_list, e[ id_prefix.."variable"])) + -- a block (precondition + effect) + elseif(data.what == 3 and id_prefix ~= "a_") then + data.block = math.max(1,table.indexof(values_block, e[ id_prefix.."value" ])) + data.node_data = {} + data.node_data.data = e[ id_prefix.."node" ] + data.node_data.param2 = e[ id_prefix.."param2" ] + data.block_pos = {x=e[ id_prefix.."pos" ].x, + y=e[ id_prefix.."pos" ].y, + z=e[ id_prefix.."pos" ].z} + -- the block below was punched + if(id_prefix == "p_" and data.block == 5) then + data.block_pos.y = data.block_pos.y - 1 + end + -- a trade (precondition) + elseif(data.what == 4 and id_prefix == "p_") then + data.trade = math.max(1,table.indexof(values_trade, e[ "p_value" ])) + -- an invenetory (precondition) + elseif((data.what == 5 or data.what == 6) and id_prefix == "p_") then + data.inv = math.max(1,table.indexof(values_inv, e["p_value"])) + data.inv_stack_name = e[ "p_itemstack" ] + -- crafting (effect) + elseif(data.what and id_prefix == "r_" and data.what == 4) then + -- TODO: there really can't be done much in that regard so far + -- v[ "r_value" ] = player_inv:get_stack("craftpreview", 1):to_string() + -- v[ "r_craft_grid"] = {} player_inv:get_stack("craft", i):to_string()) + -- on failure (effect) + elseif(data.what and id_prefix == "r_" and data.what == 5) then + data.on_failure = e[ "r_value" ] + -- send a chat message (effect) + elseif(data.what and id_prefix == "r_" and data.what == 6) then + data.chat_msg_text = e[ "r_value" ] + -- normal trade (action) + elseif(data.what and id_prefix == "a_" and data.what == 3) then + -- TODO: there is no good way to show that in edit mode yet + data.trade_id = e[ "a_value" ] + -- v[ "a_pay" ] = dialog.trades[ data.trade_id ].pay + -- v[ "a_buy" ] = dialog.trades[ data.trade_id ].buy + local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) + data.action_failure_dialog = math.max(1, + table.indexof(sorted_dialog_list, e[ "a_on_failure" ])) + -- npc_gives/npc_wants (action) + elseif(data.what and id_prefix == "a_" and (data.what == 4 or data.what == 5)) then + -- TODO: there is no good way to show that in edit mode yet + local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) + data.action_failure_dialog = math.max(1, + table.indexof(sorted_dialog_list, e[ "a_on_failure" ])) + -- TODO: data.item_string is not really used... + data.item_string = e[ "a_value"] -- stack name and count (as string) + data.item_desc = e[ "a_item_desc" ] + data.item_quest_id = e[ "a_item_quest_id" ] + local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) + data.action_failure_dialog = math.max(1, + table.indexof(sorted_dialog_list, e[ "a_on_failure" ])) + -- entering password (action) + elseif(data.what and id_prefix == "a_" and data.what == 6) then + data.quest_question = e[ "a_question" ] + data.quest_answer = e[ "a_value" ] + local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) + data.action_failure_dialog = math.max(1, + table.indexof(sorted_dialog_list, e[ "a_on_failure" ])) + -- custom function (action) + elseif(data.what and id_prefix == "a_" and data.what == 7) then + data.custom_param = e[ "a_value" ] + local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs) + data.action_failure_dialog = math.max(1, + table.indexof(sorted_dialog_list, e[ "a_on_failure" ])) + end + end + local save_button = "button[5.0,9.8;1,0.7;save_element;Save]" local formspec = "formspec_version[3]".. diff --git a/fs_edit_preconditions.lua b/fs_edit_preconditions.lua index 403f7ea..5c06977 100644 --- a/fs_edit_preconditions.lua +++ b/fs_edit_preconditions.lua @@ -396,6 +396,7 @@ yl_speak_up.get_fs_edit_preconditions = function(player, table_click_result) "p_", "o_prerequisites", yl_speak_up.max_prerequirements, "pre(C)ondition", "tmp_prereq", "What do you want to check in this precondition?", + values_what, values_operator, values_block, values_trade, values_inv, check_what, check_operator, check_block, check_trade, check_inv, -- player variables with read access yl_speak_up.get_sorted_player_var_list_read_access,