added yl_speak_up.strip_generic_dialogs
This commit is contained in:
parent
df621c7435
commit
2460714a6b
@ -1,4 +1,4 @@
|
||||
-- the command to add new generic dialogs can be found in command_npc_talk_generic.lua
|
||||
-- the command to add new generic dialogs is implemented in yl_speak_up.command_npc_talk_generic
|
||||
|
||||
-- this table holds all generic dialogs with indices
|
||||
-- generic_dialog[n_id][d_id_n_id]
|
||||
@ -156,6 +156,8 @@ yl_speak_up.generic_dialog_rewrite_options = function(n_id, dialog_name, append_
|
||||
|
||||
-- adjust o_id
|
||||
o.o_id = o_id..append_str
|
||||
-- mark this option as generic
|
||||
o.is_generic = append_str
|
||||
-- the options of the first dialog need to be renamed to r.r_id_n_id to avoid duplicates
|
||||
new_options[o_id..append_str] = o
|
||||
-- TODO: there may be preconditions refering this option which also might need changing
|
||||
@ -414,7 +416,33 @@ yl_speak_up.check_and_add_as_generic_dialog = function(dialog, n_id)
|
||||
end
|
||||
|
||||
|
||||
-- if a dialog has just been loaded (or is about to be saved),
|
||||
-- generic dialogs must not be contained in it;
|
||||
-- returns the cleaned up dialog;
|
||||
-- used by yl_speak_up.add_generic_dialogs (see function below)
|
||||
-- and in yl_speak_up.save_dialog in functions.lua
|
||||
yl_speak_up.strip_generic_dialogs = function(dialog)
|
||||
if(not(dialog) or not(dialog.n_dialogs)) then
|
||||
return dialog
|
||||
end
|
||||
for d_id, d_data in pairs(dialog.n_dialogs) do
|
||||
if(d_data and d_data.is_generic) then
|
||||
-- delete those dialogs that were mistakingly included by previous bugs
|
||||
dialog.n_dialogs[d_id] = nil
|
||||
elseif(d_data and dialog.n_dialogs[d_id].d_options) then
|
||||
for o_id, o_data in pairs(dialog.n_dialogs[d_id].d_options) do
|
||||
if(o_data and o_data.is_generic) then
|
||||
dialog.n_dialogs[d_id].d_options[o_id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return dialog
|
||||
end
|
||||
|
||||
|
||||
yl_speak_up.add_generic_dialogs = function(dialog, current_n_id, player)
|
||||
dialog = yl_speak_up.strip_generic_dialogs(dialog)
|
||||
if(not(player) or not(current_n_id)) then
|
||||
return dialog
|
||||
end
|
||||
|
@ -115,6 +115,8 @@ yl_speak_up.save_dialog = function(n_id, dialog)
|
||||
local p = save_path(n_id)
|
||||
-- save some data (in particular usage of quest variables)
|
||||
yl_speak_up.update_stored_npc_data(n_id, dialog)
|
||||
-- make sure we never store any automaticly added generic dialogs
|
||||
dialog = yl_speak_up.strip_generic_dialogs(dialog)
|
||||
local content = minetest.write_json(dialog)
|
||||
return minetest.safe_file_write(p, content)
|
||||
end
|
||||
@ -510,7 +512,7 @@ function yl_speak_up.talk(self, clicker)
|
||||
-- edit this particular NPC without generic parts)
|
||||
local player = clicker
|
||||
if(yl_speak_up.edit_mode[pname] == n_id) then
|
||||
player = nil
|
||||
player = false
|
||||
end
|
||||
yl_speak_up.speak_to[pname].dialog = yl_speak_up.load_dialog(n_id, player)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user