From 5d82cbc32d1a5eb56daa6f4450c1ee9d7e02250a Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 12 Jun 2021 21:17:58 +0200 Subject: [PATCH] added fs_edit_actions.lua and necessary sourroundings --- config.lua | 3 ++ fs_edit_actions.lua | 95 ++++++++++++++++++++++++++++++++++++++ fs_edit_general.lua | 10 ++-- fs_edit_options_dialog.lua | 16 +++++-- init.lua | 2 + show_fs.lua | 8 ++++ 6 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 fs_edit_actions.lua diff --git a/config.lua b/config.lua index 403dcac..58e0de0 100644 --- a/config.lua +++ b/config.lua @@ -32,6 +32,9 @@ yl_speak_up.trade_max_cols = 4 -- how many prerequirements can the player define per dialog option? yl_speak_up.max_prerequirements = 12 +-- how many actions can there be per dialog option? +-- for now, more than one doesn't make sense +yl_speak_up.max_actions = 1 -- how many effects can the player define per dialog option? yl_speak_up.max_result_effects = 6 diff --git a/fs_edit_actions.lua b/fs_edit_actions.lua new file mode 100644 index 0000000..ed64c54 --- /dev/null +++ b/fs_edit_actions.lua @@ -0,0 +1,95 @@ + +-- Which diffrent types of actions are available? +-- -> The following fields are part of an action: +-- a_id the ID/key of the action +-- a_type selected from values_what +-- a_value used to store the subtype of a_type +-- +-- on_failure: TODO - does this make sense here? +-- r_value alternate target dialog if the previous *effect* failed +-- +-- Note: Trades are not stored as actions - they are stored in +-- dialog.trades[ trade_id ] with == " " +-- + +-- some helper lists for creating the formspecs and evaulating +-- the player's answers: + +-- general direction of what could make up an action +local check_what = { + "- please select -", + "No action (default).", -- 2 + "Normal trade - one item(stack) for another item(stack).", -- 3 + "The NPC gives something to the player (i.e. a quest item).", -- 4 + "The player is expected to give something to the NPC (i.e. a quest item).", -- 5 + "The player has to manually enter a password or passphrase or some other text.", -- 6 + "The player has to move virtual items in a virtual inventory to the right position.", -- 7 + "Call custom functions that are supposed to be overridden by the server.", -- 8 +} + +-- how to store these as a_type in the action: +local values_what = {"", "none", "trade", "npc_gives", "npc_wants", "text_input", "puzzle", "custom"} + + +-- returns a human-readable text as description of the action +-- (as shown in the edit options dialog and in the edit effect formspec) +yl_speak_up.show_action = function(a) + if(not(a.a_type) or a.a_type == "" or a.a_type == "none") then + return "(nothing): Nothing to do. No action." + elseif(a.a_type == "trade") then + return "trade:" -- TODO show ation text + elseif(a.a_type == "npc_gives") then + return "npc_gives:" -- TODO show ation text + elseif(a.a_type == "npc_wants") then + return "npc_wants:" -- TODO show ation text + elseif(a.a_type == "text_input") then + return "text_input:" -- TODO show ation text + elseif(a.a_type == "puzzle") then + return "puzzle:" -- TODO show ation text + elseif(a.a_type == "custom") then + return "custom:" -- TODO show ation text + end + -- fallback + return tostring(a.a_value) +end + + +yl_speak_up.execute_all_actions = function(player, actions, o_id) + -- TODO: implement +end + + +yl_speak_up.execute_action = function(player, n_id, o_id, r) + -- TODO: implement. boils down to showing formspecs + -- fallback: unkown type + return false +end + + +-- these are only wrapper functions for those in fs_edit_general.lua + +yl_speak_up.input_fs_edit_actions = function(player, formname, fields) + return yl_speak_up.input_fs_edit_option_related(player, formname, fields, + "a_", "actions", yl_speak_up.max_actions, + "(A)ctions", "tmp_action", + nil, -- unused - no block operations + values_what, {}, {}, {}, {}, + check_what, {}, {}, {}, {}, + nil, -- no variables + "edit_actions" + ) +end + +yl_speak_up.get_fs_edit_actions = function(player, table_click_result) + return yl_speak_up.get_fs_edit_option_related(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?", + check_what, {}, {}, {}, {}, + nil, -- no variables + yl_speak_up.show_action, + "table_of_elements", + nil, nil, nil, -- no variable handling here + nil -- nothing block-related to do here + ) +end diff --git a/fs_edit_general.lua b/fs_edit_general.lua index 5a5f155..3298eda 100644 --- a/fs_edit_general.lua +++ b/fs_edit_general.lua @@ -243,7 +243,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, -- comparison value for a variable (same for both preconditions and effects) elseif(fields.var_cmp_value - and data and data.what and data.what == 2) then + and data and data.what and data.what == 2 and id_prefix ~= "a_") then data.var_cmp_value = fields.var_cmp_value -- text for a chat message @@ -289,14 +289,14 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, return end -- "an internal state (i.e. of a quest)", -- 2 - if(data.what == 2) then + if(data.what == 2 and id_prefix ~= "a_") then v[ id_prefix.."value" ] = "expression" v[ id_prefix.."operator" ] = values_operator[ data.operator ] v[ id_prefix.."var_cmp_value" ] = (data.var_cmp_value or "") v[ id_prefix.."variable" ] = data.variable_name -- "a block somewhere", -- 3 - elseif(data.what == 3) then + elseif(data.what == 3 and id_prefix ~= "a_") then v[ id_prefix.."value" ] = values_block[ data.block ] if(not(data.block_pos) or not(data.node_data) or not(data.node_data.name)) then yl_speak_up.show_fs(player, "msg", { @@ -605,7 +605,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, -- "an internal state (i.e. of a quest)", -- 2 -- (state is the second offered option in both preconditions and effects list) - if(data.what and data.what == 2) then + if(data.what and data.what == 2 and id_prefix ~= "a_") then if(not(data.variable) or data.variable == 1) then data.variable = 1 -- not enough selected yet for saving @@ -642,7 +642,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result, -- "a block somewhere", -- 3 -- (block is the third offered option in both preconditions and effects list) - elseif(data.what and data.what == 3) then + elseif(data.what and data.what == 3 and id_prefix ~= "a_") then local block_pos_str = "- none set -" local node = {name = "- unknown -", param2 = "- unkown -"} if(not(block_pos) and data and data.block_pos) then diff --git a/fs_edit_options_dialog.lua b/fs_edit_options_dialog.lua index 8058bf2..fd6aa3e 100644 --- a/fs_edit_options_dialog.lua +++ b/fs_edit_options_dialog.lua @@ -42,7 +42,7 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields) yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = d_id}) return end - +--[[ -- TODO -- for now, there's only trade as action if(fields.table_of_actions) then local trade_id = tostring(d_id).." "..tostring(o_id) @@ -62,9 +62,9 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields) -- create a new trade for this dialog and option - with ID " " yl_speak_up.show_fs(player, "add_trade_simple", tostring(d_id).." "..tostring(o_id)) return - +--]] -- the player wants to see the previous option/answer - elseif(fields.edit_option_prev) then + if(fields.edit_option_prev) then -- sort all options by o_sort local sorted_list = yl_speak_up.get_sorted_options(n_dialog.d_options, "o_sort") local o_found = o_id @@ -93,6 +93,7 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields) {n_id = n_id, d_id = d_id, o_id = o_found, caller="next option"}) return +--[[ TODO handle elsewhere -- show the trade associated with this dialog and option elseif(fields.effect_show_trade) then -- remember which option was selected @@ -102,6 +103,7 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields) -- show the trade with ID " " yl_speak_up.show_fs(player, "trade_simple", tostring(d_id).." "..tostring(o_id)) return +--]] -- the player clicked on a precondition elseif(fields.table_of_preconditions) then @@ -110,6 +112,13 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields) yl_speak_up.show_fs(player, "edit_preconditions", fields.table_of_preconditions) return + -- the player clicked on an action + elseif(fields.table_of_actions) then + -- remember which option was selected + yl_speak_up.speak_to[pname].o_id = o_id + yl_speak_up.show_fs(player, "edit_actions", fields.table_of_actions) + return + -- the player clicked on an effect elseif(fields.table_of_effects) then -- remember which option was selected @@ -166,6 +175,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id) end local list_of_actions = "" + -- TODO: build the same way as list of preconditions and effects if(dialog.trades and dialog.trades[ tostring(d_id).." "..tostring(o_id) ]) then local tr = dialog.trades[ tostring(d_id).." "..tostring(o_id)] -- show the trade in the result/effects list diff --git a/init.lua b/init.lua index d44186a..a35b103 100644 --- a/init.lua +++ b/init.lua @@ -23,6 +23,8 @@ dofile(modpath .. "show_fs.lua") dofile(modpath .. "fs_edit_general.lua") -- edit preconditions (can be reached through edit options dialog) dofile(modpath .. "fs_edit_preconditions.lua") +-- edit actions (can be reached through edit options dialog) +dofile(modpath .. "fs_edit_actions.lua") -- edit effects (can be reached through edit options dialog) dofile(modpath .. "fs_edit_effects.lua") -- edit options dialog (detailed configuration of options in edit mode) diff --git a/show_fs.lua b/show_fs.lua index 133b049..20251b7 100644 --- a/show_fs.lua +++ b/show_fs.lua @@ -45,6 +45,10 @@ minetest.register_on_player_receive_fields( function(player, formname, fields) elseif formname == "yl_speak_up:edit_preconditions" then yl_speak_up.input_fs_edit_preconditions(player, formname, fields) return true + -- handled in fs_edit_actions.lua + elseif formname == "yl_speak_up:edit_actions" then + yl_speak_up.input_fs_edit_actions(player, formname, fields) + return true -- handled in fs_edit_effects.lua elseif formname == "yl_speak_up:edit_effects" then yl_speak_up.input_fs_edit_effects(player, formname, fields) @@ -142,6 +146,10 @@ yl_speak_up.show_fs = function(player, fs_name, param) minetest.show_formspec(pname, "yl_speak_up:edit_preconditions", yl_speak_up.get_fs_edit_preconditions(player, param)) + elseif(fs_name == "edit_actions") then + minetest.show_formspec(pname, "yl_speak_up:edit_actions", + yl_speak_up.get_fs_edit_actions(player, param)) + elseif(fs_name == "edit_effects") then minetest.show_formspec(pname, "yl_speak_up:edit_effects", yl_speak_up.get_fs_edit_effects(player, param))