added yl_speak_up.get_fs_operator_based_comparison for operator + value entry for preconditions and effects

This commit is contained in:
Sokomine 2022-06-24 23:26:47 +02:00
parent 98c63c83bd
commit adb5c5573f

View File

@ -1514,23 +1514,18 @@ end
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- begin of formspecs for types of preconditions, actions and effects -- begin of formspecs for types of preconditions, actions and effects
-- "an internal state (i.e. of a quest)", -- 2 -- helper function for "state", "property" and "evaluate";
-- (state is the second offered option in both preconditions and effects list) -- shows dropdown for operator and input field for comparison value var_cmp_value
yl_speak_up.get_fs_edit_option_p_and_e_state = function( yl_speak_up.get_fs_operator_based_comparison = function(data, id_prefix, save_button, e,
pname, dialog, formspec, data, id_prefix, save_button, e, values_operator, check_operator,
text_variable, text_select_value, text_select_operator, what_is_this, text_what_is_this,
values_operator, check_operator, get_sorted_player_var_list_function ) text_select_operator, text_select_value)
local var_list = get_sorted_player_var_list_function(pname)
if(e) then if(e) then
data.operator = math.max(1,table.indexof(values_operator, e[ id_prefix.."operator" ])) data.operator = math.max(1,table.indexof(values_operator, e[ id_prefix.."operator" ]))
data.var_cmp_value = e[ id_prefix.."var_cmp_value" ] data.var_cmp_value = e[ id_prefix.."var_cmp_value" ]
data.variable_name = yl_speak_up.strip_pname_from_var(e[ id_prefix.."variable" ], pname)
data.variable = table.indexof(var_list, e[ id_prefix.."variable"])
end end
local var_list_stripped = yl_speak_up.strip_pname_from_varlist(var_list, pname) if(not(data[what_is_this]) or data[what_is_this] == "" or tostring(data[what_is_this]) == -1
if(not(data.variable) or data.variable < 1) then or tostring(data[what_is_this]) == "0") then
data.variable = 0
-- not enough selected yet for saving -- not enough selected yet for saving
save_button = "" save_button = ""
elseif(not(data.operator) or data.operator == 1) then elseif(not(data.operator) or data.operator == 1) then
@ -1550,18 +1545,43 @@ yl_speak_up.get_fs_edit_option_p_and_e_state = function(
-- the list of available variables needs to be extended with the ones -- the list of available variables needs to be extended with the ones
-- the player has read access to, and the order has to be constant -- the player has read access to, and the order has to be constant
-- (because dropdown just returns an index) -- (because dropdown just returns an index)
return formspec.. return "label[0.2,3.3;"..text_what_is_this.."]"..
"label[0.2,3.3;"..text_variable.."]".. "label[0.2,4.3;Name of "..what_is_this..":]"..
"label[0.2,4.3;Name of variable:]"..
"dropdown[0.2,4.8;6.5,0.6;select_variable;"..
"- please select -"..var_list_stripped..";"..
tostring(data.variable + 1)..";]"..
"label[7.0,4.3;"..text_select_operator.."]".. "label[7.0,4.3;"..text_select_operator.."]"..
"dropdown[7.0,4.8;4.5,0.6;select_operator;".. "dropdown[7.0,4.8;4.5,0.6;select_operator;"..
table.concat(check_operator, ",")..";".. table.concat(check_operator, ",")..";"..
tostring(data.operator)..";]".. tostring(data.operator)..";]"..
"label[11.7,4.3;"..text_select_value.."]".. "label[11.7,4.3;"..text_select_value.."]"..
field_for_value.. field_for_value..
save_button
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(
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 list of available variables needs to be extended with the ones
-- the player has read access to, and the order has to be constant
-- (because dropdown just returns an index)
local var_list = get_sorted_player_var_list_function(pname)
local var_list_stripped = yl_speak_up.strip_pname_from_varlist(var_list, pname)
if(e) then
data.variable_name = yl_speak_up.strip_pname_from_var(e[ id_prefix.."variable" ], pname)
data.variable = table.indexof(var_list, e[ id_prefix.."variable"])
end
if(not(data.variable) or data.variable < 1) then
data.variable = 0
end
return formspec..
yl_speak_up.get_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;"..
"- please select -"..var_list_stripped..";"..
tostring(data.variable + 1)..";]"..
"button[0.2,6.0;4.0,0.6;manage_variables;Manage variables]".. "button[0.2,6.0;4.0,0.6;manage_variables;Manage variables]"..
"button[4.7,6.0;6.5,0.6;show_var_usage_edit_element;Show where this variable is used]".. "button[4.7,6.0;6.5,0.6;show_var_usage_edit_element;Show where this variable is used]"..
"hypertext[1.2,7.0;16.0,2.5;some_text;<normal>".. "hypertext[1.2,7.0;16.0,2.5;some_text;<normal>"..
@ -1572,8 +1592,7 @@ yl_speak_up.get_fs_edit_option_p_and_e_state = function(
"than x seconds ago\" or \"less than x seconds ago\". This can be ".. "than x seconds ago\" or \"less than x seconds ago\". This can be "..
"useful for prevending your NPC from handing out the same quest item again ".. "useful for prevending your NPC from handing out the same quest item again "..
"too quickly (players are inventive and may use your quest item for their ".. "too quickly (players are inventive and may use your quest item for their "..
"own needs).\n</normal>]".. "own needs).\n</normal>]"
save_button
end end
@ -1582,27 +1601,8 @@ yl_speak_up.get_fs_edit_option_p_and_e_property = function(
pname, dialog, formspec, data, id_prefix, save_button, e, pname, dialog, formspec, data, id_prefix, save_button, e,
text_select_operator, values_operator, check_operator) text_select_operator, values_operator, check_operator)
if(e) then if(e) 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.property = e[ id_prefix.."value"] data.property = e[ id_prefix.."value"]
end end
if(not(data.property) or data.property == "") then
-- not enough selected yet for saving
save_button = ""
elseif(not(data.operator) or data.operator == 1) then
data.operator = 1
save_button = ""
end
local field_for_value = "field[11.7,4.8;7.5,0.6;var_cmp_value;;"..
minetest.formspec_escape(data.var_cmp_value or "- enter value -").."]"
-- do not show value input field for unary operators
-- (unary operators are diffrent for prerequirements and effects)
if(not(data.operator)
or (id_prefix == "p_" and (data.operator == 1 or (data.operator>=8 and data.operator<11)))
-- "unset", "set_to_current_time"
or (id_prefix == "r_" and (data.operator == 3 or data.operator == 4))) then
field_for_value = "label[11.7,5.1;- not used for this operator -]"
end
local operator_list = {} local operator_list = {}
for i, v in ipairs(check_operator) do for i, v in ipairs(check_operator) do
v2 = values_operator[i] v2 = values_operator[i]
@ -1618,21 +1618,16 @@ yl_speak_up.get_fs_edit_option_p_and_e_property = function(
end end
-- the list of available variables needs to be extended with the ones -- the list of available variables needs to be extended with the ones
return formspec.. return formspec..
"label[0.2,3.3;The NPC shall have the following property:]".. yl_speak_up.get_fs_operator_based_comparison(data, id_prefix, save_button, e,
"label[0.2,4.3;Name of property:]".. values_operator, operator_list, "property",
"The NPC shall have the following property:",
text_select_operator, text_compare_with)..
"field[1.0,4.8;5.0,0.6;property;;".. "field[1.0,4.8;5.0,0.6;property;;"..
minetest.formspec_escape(data.property or "- enter name -").."]".. minetest.formspec_escape(data.property or "- enter name -").."]"..
"label[7.0,4.3;"..text_select_operator.."]"..
"dropdown[7.0,4.8;4.5,0.6;select_operator;"..
table.concat(operator_list, ",")..";"..
tostring(data.operator)..";]"..
"label[11.7,4.3;"..text_compare_with..":]"..
field_for_value..
"hypertext[1.2,7.0;16.0,2.5;some_text;<normal>".. "hypertext[1.2,7.0;16.0,2.5;some_text;<normal>"..
"<b>Note:</b> Properties are useful for NPC that have a generic ".. "<b>Note:</b> Properties are useful for NPC that have a generic "..
"behaviour and may vary their behaviour slightly.\n".. "behaviour and may vary their behaviour slightly.\n"..
"</normal>]".. "</normal>]"
save_button
end end
@ -1640,8 +1635,36 @@ end
yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function( yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
pname, dialog, formspec, data, id_prefix, save_button, e, pname, dialog, formspec, data, id_prefix, save_button, e,
text_select_operator, values_operator, check_operator) text_select_operator, values_operator, check_operator)
-- TODO: actually implement if(e) then
return formspec data.function_name = e[ id_prefix.."value"]
-- TODO: p_param1 .. p_param9
end
local operator_list = {}
for i, v in ipairs(check_operator) do
v2 = values_operator[i]
if( v2 ~= "quest_step_done" and v2 ~= "quest_step_not_done"
and v2 ~= "true_for_param" and v2 ~= "false_for_param") then
table.insert(operator_list, v)
end
end
local text_operator_and_comparison = ""
if(id_prefix ~= "r_") then
text_operator_and_comparison = yl_speak_up.get_fs_operator_based_comparison(
data, id_prefix, save_button, e,
values_operator, operator_list, "function",
"Execute and evaluate the following function:",
text_select_operator, "Compare the return value with this value:")
end
-- the list of available variables needs to be extended with the ones
return formspec..
text_operator_and_comparison..
-- TODO: rather a dropdown...
"field[1.0,4.8;5.0,0.6;property;;"..
minetest.formspec_escape(data.property or "- enter name -").."]"..
"hypertext[1.2,7.0;16.0,2.5;some_text;<normal>"..
"<b>Note:</b> Functions are called with parameters which are passed on to them. "..
"The function then calculates a result. This can be compared to a given value."..
"</normal>]"
end end