moved fs_edit_general.lua to api/; renamed most get_fs_ functions there to get_sub_fs_ and main function to build_fs_ for more clarity

This commit is contained in:
Sokomine 2023-12-18 05:15:04 +01:00
parent 536ad045f6
commit 3ae305dcc9
5 changed files with 49 additions and 49 deletions

View File

@ -686,7 +686,7 @@ end
-- These two functions
-- * yl_speak_up.input_fs_edit_option_related and
-- * yl_speak_up.get_fs_edit_option_related
-- * yl_speak_up.build_fs_edit_option_related
-- are very similar for preconditions and effects. Therefore they're called here
-- with a lot of parameters. fs_edit_preconditions.lua and fs_edit_effects.lua
-- contain only wrappers.
@ -1154,7 +1154,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
end
yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
yl_speak_up.build_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,
@ -1349,34 +1349,34 @@ 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 what_type == "state" and id_prefix ~= "a_") then
return yl_speak_up.get_fs_edit_option_p_and_e_state(
return yl_speak_up.get_sub_fs_edit_option_p_and_e_state(
pname, dialog, formspec, data, id_prefix, save_button, e,
text_variable, text_select_value, text_select_operator,
values_operator, check_operator, get_sorted_player_var_list_function )
-- "the value of a property of the NPC (for generic NPC)"
elseif(data.what and what_type == "property" and id_prefix ~= "a_") then
return yl_speak_up.get_fs_edit_option_p_and_e_property(
return yl_speak_up.get_sub_fs_edit_option_p_and_e_property(
pname, dialog, formspec, data, id_prefix, save_button, e,
text_select_operator, values_operator, check_operator)
-- "something that has to be calculated or evaluated (=call a function)"
elseif(data.what and what_type == "evaluate") then
return yl_speak_up.get_fs_edit_option_p_and_e_evaluate(
return yl_speak_up.get_sub_fs_edit_option_p_and_e_evaluate(
pname, dialog, formspec, data, id_prefix, save_button, e,
text_select_operator, values_operator, check_operator)
-- "a block somewhere", -- 3
-- (block is the third offered option in both preconditions and effects list)
elseif(data.what and what_type == "block" and id_prefix ~= "a_") then
return yl_speak_up.get_fs_edit_option_p_and_e_block(
return yl_speak_up.get_sub_fs_edit_option_p_and_e_block(
pname, dialog, formspec, data, id_prefix, save_button, e,
text_block_position, values_block, check_block)
-- "a trade", -- 4
-- (trade - only for preconditions; effects have something else here)
elseif(data.what and id_prefix == "p_" and what_type == "trade") then
return yl_speak_up.get_fs_edit_option_precondition_trade(
return yl_speak_up.get_sub_fs_edit_option_precondition_trade(
pname, dialog, formspec, data, id_prefix, save_button, e,
values_trade, check_trade)
@ -1392,57 +1392,57 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
and (what_type == "put_into_block_inv" or what_type == "take_from_block_inv"))) then
-- the inventory of a block needs more input options (in particular block selection)
data.what_type = what_type
return yl_speak_up.get_fs_edit_option_precondition_inv(
return yl_speak_up.get_sub_fs_edit_option_precondition_inv(
pname, dialog, formspec, data, id_prefix, save_button, e,
values_inv, check_inv, values_block)
elseif(data.what and id_prefix == "r_" and what_type == "deal_with_offered_item") then
return yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item(
return yl_speak_up.get_sub_fs_edit_option_effect_deal_with_offered_item(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9
-- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10
elseif(data.what and id_prefix == "r_" and (what_type == "give_item" or what_type=="take_item")) then
return yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item(
return yl_speak_up.get_sub_fs_edit_option_effect_give_item_or_take_item(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11
elseif(data.what and id_prefix == "r_" and what_type == "move") then
return yl_speak_up.get_fs_edit_option_effect_move(
return yl_speak_up.get_sub_fs_edit_option_effect_move(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "execute Lua code (requires npc_master priv)", -- precondition: 8; effect: 12
elseif((data.what and id_prefix == "p_" and what_type == "function")
or (data.what and id_prefix == "r_" and what_type == "function")) then
return yl_speak_up.get_fs_edit_option_p_and_e_function(
return yl_speak_up.get_sub_fs_edit_option_p_and_e_function(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "NPC crafts something", -- 6
-- (craft - only for effects - not for preconditions)
elseif(data.what and id_prefix == "r_" and what_type == "craft") then
return yl_speak_up.get_fs_edit_option_effect_craft(
return yl_speak_up.get_sub_fs_edit_option_effect_craft(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "go to other dialog if the *previous* effect failed", -- 5
-- (on_failure - only for effects - not for preconditions)
elseif(data.what and id_prefix == "r_" and what_type == "on_failure") then
return yl_speak_up.get_fs_edit_option_effect_on_failure(
return yl_speak_up.get_sub_fs_edit_option_effect_on_failure(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "send a chat message to all players" -- 8
elseif(data.what and id_prefix == "r_" and what_type == "chat_all") then
return yl_speak_up.get_fs_edit_option_effect_chat_all(
return yl_speak_up.get_sub_fs_edit_option_effect_chat_all(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "Normal trade - one item(stack) for another item(stack).", -- 3
elseif(data.what and id_prefix == "a_" and what_type == "trade") then
return yl_speak_up.get_fs_edit_option_action_trade(
return yl_speak_up.get_sub_fs_edit_option_action_trade(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "The NPC gives something to the player (i.e. a quest item).", -- 4
-- (only for actions)
elseif(data.what and id_prefix == "a_" and what_type == "npc_gives") then
return yl_speak_up.get_fs_edit_option_action_npc_gives(
return yl_speak_up.get_sub_fs_edit_option_action_npc_gives(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
@ -1450,13 +1450,13 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
-- "an item the player offered/gave to the NPC", (as precondition)
elseif(data.what and ((id_prefix == "a_" and what_type == "npc_wants")
or (id_prefix == "p_" and what_type == "player_offered_item"))) then
return yl_speak_up.get_fs_edit_option_action_npc_wants_or_accepts(
return yl_speak_up.get_sub_fs_edit_option_action_npc_wants_or_accepts(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "The player has to manually enter a password or passphrase or some other text.", -- 6
-- (only for actions)
elseif(data.what and id_prefix == "a_" and what_type == "text_input") then
return yl_speak_up.get_fs_edit_option_action_text_input(
return yl_speak_up.get_sub_fs_edit_option_action_text_input(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "Call custom functions that are supposed to be overridden by the server.", -- 7
@ -1465,13 +1465,13 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
and ((id_prefix == "a_" and what_type == "custom")
or (id_prefix == "p_" and what_type == "custom")
or (id_prefix == "r_" and what_type == "custom"))) then
return yl_speak_up.get_fs_edit_option_all_custom(
return yl_speak_up.get_sub_fs_edit_option_all_custom(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "The preconditions of another dialog option are fulfilled/not fulfilled.", -- 10
-- precondition: 9
elseif(data.what and id_prefix == "p_" and what_type == "other") then
return yl_speak_up.get_fs_other_option_preconditions(
return yl_speak_up.get_sub_fs_other_option_preconditions(
pname, dialog, formspec, data, id_prefix, save_button, e)
end
-- create a new precondition, action or effect
@ -1484,7 +1484,7 @@ end
-- helper function for "state", "property" and "evaluate";
-- shows dropdown for operator and input field for comparison value var_cmp_value
yl_speak_up.get_fs_operator_based_comparison = function(data, id_prefix, save_button, e,
yl_speak_up.get_sub_fs_operator_based_comparison = function(data, id_prefix, save_button, e,
values_operator, check_operator,
what_is_this, text_what_is_this,
text_select_operator, text_select_value)
@ -1527,7 +1527,7 @@ end
-- "an internal state (i.e. of a quest)", -- 2
-- (state is the second offered option in both preconditions and effects list)
yl_speak_up.get_fs_edit_option_p_and_e_state = function(
yl_speak_up.get_sub_fs_edit_option_p_and_e_state = function(
pname, dialog, formspec, data, id_prefix, save_button, e,
text_variable, text_select_value, text_select_operator,
values_operator, check_operator, get_sorted_player_var_list_function )
@ -1544,7 +1544,7 @@ yl_speak_up.get_fs_edit_option_p_and_e_state = function(
data.variable = 0
end
return formspec..
yl_speak_up.get_fs_operator_based_comparison(data, id_prefix, save_button, e,
yl_speak_up.get_sub_fs_operator_based_comparison(data, id_prefix, save_button, e,
values_operator, check_operator, "variable", text_variable,
text_select_operator, text_select_value)..
"dropdown[0.2,4.8;6.5,0.6;select_variable;"..
@ -1565,7 +1565,7 @@ end
-- "the value of a property of the NPC (for generic NPC)"
yl_speak_up.get_fs_edit_option_p_and_e_property = function(
yl_speak_up.get_sub_fs_edit_option_p_and_e_property = function(
pname, dialog, formspec, data, id_prefix, save_button, e,
text_select_operator, values_operator, check_operator)
if(e) then
@ -1586,7 +1586,7 @@ yl_speak_up.get_fs_edit_option_p_and_e_property = function(
end
-- the list of available variables needs to be extended with the ones
return formspec..
yl_speak_up.get_fs_operator_based_comparison(data, id_prefix, save_button, e,
yl_speak_up.get_sub_fs_operator_based_comparison(data, id_prefix, save_button, e,
values_operator, operator_list, "property",
"The NPC shall have the following property:",
text_select_operator, text_compare_with)..
@ -1602,7 +1602,7 @@ end
-- "something that has to be calculated or evaluated (=call a function)"
yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
yl_speak_up.get_sub_fs_edit_option_p_and_e_evaluate = function(
pname, dialog, formspec, data, id_prefix, save_button, e,
text_select_operator, values_operator, check_operator)
local fun_list = {}
@ -1666,7 +1666,7 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
local explanation = ""
local dlength = "6.5"
if(id_prefix == "p_") then
text_operator_and_comparison = yl_speak_up.get_fs_operator_based_comparison(
text_operator_and_comparison = yl_speak_up.get_sub_fs_operator_based_comparison(
data, id_prefix, save_button, e,
values_operator, operator_list, "function",
"Execute and evaluate the following function:",
@ -1713,7 +1713,7 @@ end
-- helper function for:
-- yl_speak_up.get_fs_edit_option_p_and_e_block
-- yl_speak_up.get_sub_fs_edit_option_p_and_e_block
yl_speak_up.get_block_pos_info = function(pname, data, id_prefix, e, values_block, ignore_protection)
-- are we more intrested in the inventory of the block or in the block itself?
local looking_at_inventory = false
@ -1801,7 +1801,7 @@ end
-- "a block somewhere", -- 3
-- (block is the third offered option in both preconditions and effects list)
yl_speak_up.get_fs_edit_option_p_and_e_block = function(
yl_speak_up.get_sub_fs_edit_option_p_and_e_block = function(
pname, dialog, formspec, data, id_prefix, save_button, e,
text_block_position, values_block, check_block)
@ -1832,7 +1832,7 @@ end
-- "a trade", -- 4
-- (trade - only for preconditions; effects have something else here)
yl_speak_up.get_fs_edit_option_precondition_trade = function(
yl_speak_up.get_sub_fs_edit_option_precondition_trade = function(
pname, dialog, formspec, data, id_prefix, save_button, e,
values_trade, check_trade)
if(e) then
@ -1858,7 +1858,7 @@ end
-- "put item from the NPC's inventory into a chest etc.", -- 4 (effect)
-- "take item from a chest etc. and put it into the NPC's inventory", -- 5 (effect)
-- (inventory - only for preconditions; effects have something else here)
yl_speak_up.get_fs_edit_option_precondition_inv = function(
yl_speak_up.get_sub_fs_edit_option_precondition_inv = function(
pname, dialog, formspec, data, id_prefix, save_button, e,
values_inv, check_inv, values_block)
if(e) then
@ -1929,7 +1929,7 @@ end
-- "an item the player offered to the NPC"
yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item = function(
yl_speak_up.get_sub_fs_edit_option_effect_deal_with_offered_item = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
data.select_deal_with_offered_item = table.indexof(
@ -1952,7 +1952,7 @@ end
-- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9
-- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10
yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function(
yl_speak_up.get_sub_fs_edit_option_effect_give_item_or_take_item = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
data.inv_stack_name = e[ "r_value" ] or ""
@ -1980,7 +1980,7 @@ end
-- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11
yl_speak_up.get_fs_edit_option_effect_move = function(
yl_speak_up.get_sub_fs_edit_option_effect_move = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
if(e[ "r_value"] and type(e[ "r_value" ]) == "string") then
@ -2011,7 +2011,7 @@ end
-- "execute Lua code (requires npc_master priv)", -- precondition: 8; effect: 12
yl_speak_up.get_fs_edit_option_p_and_e_function = function(
yl_speak_up.get_sub_fs_edit_option_p_and_e_function = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
if(e[ id_prefix.."value"] and e[ id_prefix.."value"] ~= "") then
@ -2038,7 +2038,7 @@ end
-- "NPC crafts something", -- 6
-- (craft - only for effects - not for preconditions)
yl_speak_up.get_fs_edit_option_effect_craft = function(
yl_speak_up.get_sub_fs_edit_option_effect_craft = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
-- those items can at least be shown as background images
@ -2074,7 +2074,7 @@ end
-- "go to other dialog if the *previous* effect failed", -- 5
-- (on_failure - only for effects - not for preconditions)
yl_speak_up.get_fs_edit_option_effect_on_failure = function(
yl_speak_up.get_sub_fs_edit_option_effect_on_failure = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
data.on_failure = e[ "r_value" ]
@ -2114,7 +2114,7 @@ end
-- "send a chat message to all players" -- 8
yl_speak_up.get_fs_edit_option_effect_chat_all = function(
yl_speak_up.get_sub_fs_edit_option_effect_chat_all = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
data.chat_msg_text = e[ "r_value" ]
@ -2136,7 +2136,7 @@ end
-- "Normal trade - one item(stack) for another item(stack).", -- 3
yl_speak_up.get_fs_edit_option_action_trade = function(
yl_speak_up.get_sub_fs_edit_option_action_trade = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
data.trade_id = e[ "a_value" ]
@ -2182,7 +2182,7 @@ end
-- "The NPC gives something to the player (i.e. a quest item).", -- 4
-- (only for actions)
yl_speak_up.get_fs_edit_option_action_npc_gives = function(
yl_speak_up.get_sub_fs_edit_option_action_npc_gives = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
local bg_img = ""
if(e) then
@ -2238,7 +2238,7 @@ end
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
-- (only for actions)
-- "an item the player offered/gave to the NPC", (as precondition)
yl_speak_up.get_fs_edit_option_action_npc_wants_or_accepts = function(
yl_speak_up.get_sub_fs_edit_option_action_npc_wants_or_accepts = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
local bg_img = ""
local node_name = ""
@ -2328,7 +2328,7 @@ end
-- "The player has to manually enter a password or passphrase or some other text.", -- 6
-- (only for actions)
yl_speak_up.get_fs_edit_option_action_text_input = function(
yl_speak_up.get_sub_fs_edit_option_action_text_input = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
data.quest_question = e[ "a_question" ]
@ -2371,7 +2371,7 @@ end
-- "Call custom functions that are supposed to be overridden by the server.", -- 7
-- precondition: 9; action: 7; effect: 13
yl_speak_up.get_fs_edit_option_all_custom = function(
yl_speak_up.get_sub_fs_edit_option_all_custom = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then
data.custom_param = e[ id_prefix.."value" ]
@ -2414,7 +2414,7 @@ end
-- "The preconditions of another dialog option are fulfilled/not fulfilled.", -- 10
-- precondition: 10
yl_speak_up.get_fs_other_option_preconditions = function(
yl_speak_up.get_sub_fs_other_option_preconditions = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
local dialog = yl_speak_up.speak_to[pname].dialog
local d_id = yl_speak_up.speak_to[pname].d_id

View File

@ -110,7 +110,7 @@ yl_speak_up.input_fs_edit_actions = function(player, formname, fields)
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,
return yl_speak_up.build_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?",

View File

@ -328,7 +328,7 @@ yl_speak_up.input_fs_edit_effects = function(player, formname, fields)
end
yl_speak_up.get_fs_edit_effects = function(player, table_click_result)
return yl_speak_up.get_fs_edit_option_related(player, table_click_result,
return yl_speak_up.build_fs_edit_option_related(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?",

View File

@ -344,7 +344,7 @@ end
yl_speak_up.get_fs_edit_preconditions = function(player, table_click_result)
return yl_speak_up.get_fs_edit_option_related(player, table_click_result,
return yl_speak_up.build_fs_edit_option_related(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?",

View File

@ -191,7 +191,7 @@ yl_speak_up.reload = function(modpath, log_entry)
-- execute lua code directly (preconditions and effects) - requires priv
dofile(modpath .. "eval_and_execute_function.lua")
-- common functions for editing preconditions and effects
dofile(modpath .. "fs_edit_general.lua")
dofile(modpath .. "api/fs_edit_general.lua")
-- edit preconditions (can be reached through edit options dialog)
dofile(modpath .. "fs/fs_edit_preconditions.lua")
-- edit actions (can be reached through edit options dialog)