added get list of writable variables, some documentation and yl_speak_up.show_effect to fs_edit_effects.lua

This commit is contained in:
Sokomine 2021-06-09 00:43:37 +02:00
parent 967e7c6eb4
commit fab84ca4a0
3 changed files with 108 additions and 9 deletions

View File

@ -1,4 +1,33 @@
-- Which diffrent types of effects are available?
-- -> The following fields are part of an effect/result:
-- r_id the ID/key of the effect/result
-- r_type selected from values_what; the staffs allow to use other
-- types like "function" or "give_item" etc. - but that is not
-- supported here (cannot be edited or created; only be shown)
-- r_value used to store the subtype of r_type
--
-- a state/variable:
-- r_variable name of a variable the player has *write* access to;
-- dropdown list with allowed options
-- r_operator selected from values_operator
-- r_var_cmp_value can be set freely by the player (the variable will be
-- set to this value)
--
-- a block in the world:
-- r_pos a position in the world; determined by asking the player
-- to punch the block
-- r_node (follows from r_pos)
-- r_param2 (follows from r_pos)
--
-- a craft receipe: TODO
--
-- on_failure: TODO
--
-- Unlike in preconditions, trade (the trade action already happened) and
-- inventory actions are not supported as effects.
--
-- some helper lists for creating the formspecs and evaulating
-- the player's answers:
@ -39,6 +68,77 @@ local check_operator = {
-- how to store these as r_value (the actual variable is stored in r_variable, and the value in r_new_value):
local values_operator = {"", "set_to", "unset"}
-- get the list of variables the player has *write* access to
yl_speak_up.get_sorted_player_var_list_write_access = function(pname)
local var_list = {}
-- some values - like hour of day or HP of the player - can be read in
-- a precondition but not be modified
-- get the list of variables the player can *write*
local tmp = yl_speak_up.get_quest_variables_with_write_access(pname)
-- sort that list (the dropdown formspec element returns just an index)
table.sort(tmp)
for i, v in ipairs(tmp) do
table.insert(var_list, v)
end
return var_list
end
-- returns a human-readable text as description of the effects
-- (as shown in the edit options dialog and in the edit effect formspec)
yl_speak_up.show_effect = function(r)
if(not(r.r_type) or r.r_type == "") then
return "(nothing): Nothing to do. No effect."
elseif(r.r_type == "give_item") then
return "give_item: Add \""..tostring(r.r_value).."\" to the player's inventory."
elseif(r.r_type == "take_item") then
return "take_item: Take \""..tostring(r.r_value).."\" from the player's inventory."
elseif(r.r_type == "move") then
return "move: Move the player to "..tostring(r.r_value).."."
elseif(r.r_type == "function") then
return "function: execute \""..tostring(r.r_value).."\"."
elseif(r.r_type == "trade") then
return "trade: obsolete (now defined as an action)"
elseif(r.r_type == "dialog") then
return "Switch to dialog \""..tostring(r.r_value).."\"."
elseif(r.r_type == "state") then
if(not(r.r_operator)) then
return "Error: Operator not defined."
elseif(r.r_operator == "set_to") then
return "set VARIABLE[ "..tostring(r.r_variable).." ] to value \""..
tostring(r.r_var_cmp_value).."\""
elseif(r.r_operator == "unset") then
return "discard VARIABLE[ "..tostring(r.r_variable).." ] (unset)"
else
return "ERROR: Wrong operator \""..tostring(r.r_operator).."\" for "..
"VARIABLE[ "..tostring(r.r_variable).." ]"
end
elseif(r.r_type == "block") then
if(not(r.r_pos) or type(r.r_pos) ~= "table"
or not(r.r_pos.x) or not(r.r_pos.y) or not(r.r_pos.z)) then
return "ERROR: r.r_pos is "..minetest.serialize(r.r_pos)
elseif(r.r_value == "place") then
return "Place \""..tostring(r.r_node).."\" with param2: "..tostring(r.r_param2)..
" at "..minetest.pos_to_string(p.p_pos).."."
elseif(r.r_value == "dig") then
return "Dig the block at "..minetest.pos_to_string(r.r_pos).."."
elseif(r.r_value == "punch") then
return "Punch the block at "..minetest.pos_to_string(r.r_pos).."."
elseif(r.r_value == "right-click") then
return "Right-click the block at "..minetest.pos_to_string(r.r_pos).."."
else
return "ERROR: Don't know what to do with the block at "..
minetest.pos_to_string(r.r_pos)..": \""..tostring(r.r_value).."\"?"
end
elseif(r.r_type == "craft") then
return "TODO. Crafting is not yet supported."
end
-- fallback
return tostring(r.r_value)
end
-- these are only wrapper functions for those in fs_edit_general.lua
yl_speak_up.input_fs_edit_effects = function(player, formname, fields)
@ -48,9 +148,8 @@ yl_speak_up.input_fs_edit_effects = function(player, formname, fields)
"Please punch the block you want to manipulate in your effect!",
values_what, values_operator, values_block, {}, {},
check_what, check_operator, check_block, {}, {},
-- TODO: this needs to be implemented
-- player variables with write access
get_sorted_player_var_list,
yl_speak_up.get_sorted_player_var_list_write_access,
"edit_effects"
)
end
@ -61,11 +160,9 @@ yl_speak_up.get_fs_edit_effects = function(player, table_click_result)
"(Ef)fect", "tmp_result",
"What do you want to change with this effect?",
check_what, check_operator, check_block, {}, {},
-- TODO: this needs to be implemented
-- player variables with write access
get_sorted_player_var_list,
-- TODO: the show_result function needs to be implemented
yl_speak_up.show_result,
yl_speak_up.get_sorted_player_var_list_write_access,
yl_speak_up.show_effect,
"table_of_elements",
"Change the value of the following variable:", "What to do:", "New value:",
"The NPC shall do something to the block at the following position:"

View File

@ -192,14 +192,16 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id)
list_of_effects = list_of_effects..
minetest.formspec_escape(v.r_id)..",#999999,"..
minetest.formspec_escape(v.r_type)..","..
minetest.formspec_escape(v.r_value)..","
minetest.formspec_escape(
yl_speak_up.show_effect(v))..","
-- there may be more than one in the data structure
target_dialog = v.r_value
elseif v.r_type ~= "dialog" then
list_of_effects = list_of_effects..
minetest.formspec_escape(v.r_id)..",#FFFF00,"..
minetest.formspec_escape(v.r_type)..","..
minetest.formspec_escape(v.r_value)..","
minetest.formspec_escape(
yl_speak_up.show_effect(v))..","
end
count_effects = count_effects + 1
end

View File

@ -130,7 +130,7 @@ yl_speak_up.show_precondition = function(p)
if(not(p.p_type) or p.p_type == "") then
return "(nothing): Always true."
elseif(p.p_type == "item") then
return "item: The player has "..tostring(p.p_value).." in his inventory."
return "item: The player has \""..tostring(p.p_value).."\" in his inventory."
elseif(p.p_type == "quest") then
return "quest: Always false."
elseif(p.p_type == "auto") then