mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-17 06:08:06 +02:00
actually apply alternate_text texts
This commit is contained in:
parent
3d4141e786
commit
577ea356aa
@ -182,7 +182,8 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id)
|
||||
yl_speak_up.speak_to[pname].o_id = nil
|
||||
yl_speak_up.speak_to[pname].a_id = nil
|
||||
yl_speak_up.show_fs(player, "talk", {n_id = n_id,
|
||||
d_id = this_action.a_on_failure})
|
||||
d_id = this_action.a_on_failure,
|
||||
alternate_text = this_action.alternate_text})
|
||||
return
|
||||
else
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, "Action "..
|
||||
@ -211,7 +212,8 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id)
|
||||
"Doing effects/results now.")
|
||||
-- execute all effects/results
|
||||
local effects = dialog.n_dialogs[d_id].d_options[o_id].o_results
|
||||
local target_dialog = yl_speak_up.execute_all_relevant_effects(player, effects, o_id, true)
|
||||
local res = yl_speak_up.execute_all_relevant_effects(player, effects, o_id, true)
|
||||
local target_dialog = res.next_dialog
|
||||
yl_speak_up.speak_to[pname].o_id = nil
|
||||
yl_speak_up.speak_to[pname].a_id = nil
|
||||
if(not(target_dialog)
|
||||
@ -220,7 +222,8 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id)
|
||||
target_dialog = d_id
|
||||
end
|
||||
-- the function above returns a target dialog; show that to the player
|
||||
yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = target_dialog})
|
||||
yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = target_dialog,
|
||||
alternate_text = res.alternate_text})
|
||||
end
|
||||
|
||||
|
||||
|
@ -230,7 +230,7 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
|
||||
if(not(effects)) then
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, "No effects given.")
|
||||
-- no effects? Then...return to the start dialog
|
||||
return ""
|
||||
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!
|
||||
@ -244,6 +244,8 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
|
||||
else
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, "Not executing effects because in edit mode.")
|
||||
end
|
||||
-- failed actions may set an alternate text
|
||||
local alternate_text = nil
|
||||
local last_result = action_was_successful
|
||||
local res = true
|
||||
for i, k in ipairs(sorted_key_list) do
|
||||
@ -258,6 +260,7 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
|
||||
if(not(res)) then
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id)..
|
||||
" -> Effect failed to execute.")
|
||||
alternate_text = r.alternate_text
|
||||
end
|
||||
else
|
||||
-- in edit mode: assume that the effect was successful
|
||||
@ -266,19 +269,20 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
|
||||
-- "dialog" gives us the normal target_dialog
|
||||
if(r.r_type and r.r_type == "dialog") then
|
||||
target_dialog = r.r_value
|
||||
alternate_text = r.alternate_text
|
||||
-- "on_failure" gives an alternate target dialog if the action
|
||||
-- or last effect failed
|
||||
elseif(r.r_type and r.r_type == "on_failure" and r.r_value and not(last_result)) then
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, "Aborted executing effects at "..
|
||||
tostring(r.r_id)..". New target dialog: "..tostring(r.r_value)..".")
|
||||
-- we also stop execution here
|
||||
return r.r_value
|
||||
return {next_dialog = r.r_value, alternate_text = r.alternate_text}
|
||||
end
|
||||
last_result = res
|
||||
end
|
||||
-- all preconditions are true
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, "Finished executing effects.")
|
||||
return target_dialog
|
||||
return {next_dialog = target_dialog, alternate_text = alternate_text}
|
||||
end
|
||||
|
||||
|
||||
|
@ -725,7 +725,7 @@ end
|
||||
|
||||
-- talk
|
||||
|
||||
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id)
|
||||
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text)
|
||||
local pname = player:get_player_name()
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local context_d_id = yl_speak_up.speak_to[pname].d_id
|
||||
@ -922,9 +922,12 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id)
|
||||
table.insert(formspec, minetest.formspec_escape(active_dialog.d_text))
|
||||
table.insert(formspec, "]")
|
||||
else
|
||||
if(alternate_text) then
|
||||
alternate_text = string.gsub(alternate_text, "%$TEXT%$", active_dialog.d_text)
|
||||
end
|
||||
-- replace $NPC_NAME$ etc.
|
||||
local t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
active_dialog.d_text, dialog, pname))
|
||||
(alternate_text or active_dialog.d_text), dialog, pname))
|
||||
table.insert(formspec, "hypertext[0.2,5;19.6,17.8;d_text;<normal>")
|
||||
table.insert(formspec, t .. "\n</normal>")
|
||||
table.insert(formspec, "]")
|
||||
|
@ -211,7 +211,7 @@ yl_speak_up.show_fs = function(player, fs_name, param)
|
||||
param = {}
|
||||
end
|
||||
minetest.show_formspec(pname, "yl_speak_up:talk",
|
||||
yl_speak_up.get_fs_talkdialog(player, param.n_id, param.d_id))
|
||||
yl_speak_up.get_fs_talkdialog(player, param.n_id, param.d_id, param.alternate_text))
|
||||
|
||||
elseif(fs_name == "fashion") then
|
||||
minetest.show_formspec(pname, "yl_speak_up:fashion",
|
||||
|
Loading…
Reference in New Issue
Block a user