added dry_run_no_exec parameter to execute_all_relevant_effects so that the function can work properly in edit_mode

This commit is contained in:
Sokomine 2024-02-07 22:12:18 +01:00
parent c2728f853b
commit 21c8f1149d
3 changed files with 16 additions and 5 deletions

View File

@ -79,8 +79,10 @@ yl_speak_up.add_to_command_help_text = yl_speak_up.add_to_command_help_text..
-- dofile(modpath .. "exec_eval_preconditions.lua")
-- dofile(modpath .. "exec_actions.lua")
-- dofile(modpath .. "exec_apply_effects.lua")
-- in edit mode we need a more complex reaction to inventory changes
-- in edit_mode we need a more complex reaction to inventory changes
dofile(modpath .. "exec_actions_action_inv_changed.lua")
-- in edit_mode: effects are not executed
dofile(modpath .. "exec_all_relevant_effects.lua")
-- some helper functions for formatting text for a formspec talbe
dofile(modpath .. "print_as_table.lua")
-- -- create i.e. a dropdown list of player names

View File

@ -0,0 +1,9 @@
local old_execute_all_relevant_effects = yl_speak_up.execute_all_relevant_effects
yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, action_was_successful, d_option,
dry_run_no_exec) -- dry_run_no_exec for edit_mode
-- if in edit mode: do a dry run - do *not* execute the effects
local edit_mode = (player and yl_speak_up.in_edit_mode(player:get_player_name()))
-- we pass this as an additional parameter so that it doesn't have to be re-evaluated for each effect
return old_execute_all_relevant_effects(player, effects, o_id, action_was_successful, d_option, edit_mode)
end

View File

@ -44,7 +44,8 @@ end
-- was encountered after an unsuccessful action *or* right after an
-- effect that returned false.
-- Note: In edit mode, effects will *not* be executed.
yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, action_was_successful, d_option)
yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, action_was_successful, d_option,
dry_run_no_exec) -- dry_run_no_exec for edit_mode
local target_dialog = ""
local pname = player:get_player_name()
local n_id = yl_speak_up.speak_to[pname].n_id
@ -62,13 +63,12 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
-- no effects? Then...return to the start dialog
return {next_dialog = "", alternate_text = nil}
end
local edit_mode = (yl_speak_up.edit_mode[pname] == n_id)
-- Important: the list of effects is *sorted* here. The order remains constant!
local sorted_key_list = yl_speak_up.sort_keys(effects)
if(not(sorted_key_list) or #sorted_key_list < 1) then
yl_speak_up.debug_msg(player, n_id, o_id, "Error: No effects found. At least one of "..
"type \"dialog\" is necessary.")
elseif(not(edit_mode)) then
elseif(not(dry_run_no_exec)) then
yl_speak_up.debug_msg(player, n_id, o_id, "Executing effects: "..
table.concat(sorted_key_list, ", ")..".")
else
@ -86,7 +86,7 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
yl_speak_up.debug_msg(player, n_id, o_id, "..executing "..
tostring(r.r_id)..": "..yl_speak_up.show_effect(r, pname))
-- do not execute effects in edit mode
if(not(edit_mode)) then
if(not(dry_run_no_exec)) then
if(not(no_log)) then
yl_speak_up.debug_msg(player, n_id, o_id,
"Executing effect "..tostring(r.r_id)..".")