preparations for add_generic_dialogs

This commit is contained in:
Sokomine 2022-04-22 03:45:52 +02:00
parent 282ae84c81
commit 3c7ece2f77
7 changed files with 36 additions and 14 deletions

8
add_generic_dialogs.lua Normal file
View File

@ -0,0 +1,8 @@
yl_speak_up.add_generic_dialogs = function(dialog, n_id, player)
if(not(player)) then
return dialog
end
-- TODO: extend the dialog with generic dialog texts
return dialog
end

View File

@ -356,7 +356,7 @@ function yl_speak_up.fashion(player, obj)
yl_speak_up.speak_to[pname].textures = t
yl_speak_up.speak_to[pname].skins = textures2skin(t)
local dialog = yl_speak_up.load_dialog(n_id)
local dialog = yl_speak_up.load_dialog(n_id, false)
if next(dialog) then
yl_speak_up.speak_to[pname].n_npc = dialog.n_npc
else

View File

@ -19,7 +19,7 @@ yl_speak_up.fs_get_list_of_usage_of_variable = function(var_name, pname, check_p
local count_changed = 0
for i, n_id in ipairs(npc_list) do
-- the NPC may not even be loaded
local dialog = yl_speak_up.load_dialog(n_id)
local dialog = yl_speak_up.load_dialog(n_id, false)
if(dialog and dialog.n_dialogs) then
for d_id, d in pairs(dialog.n_dialogs) do
if(d and d.d_options) then

View File

@ -41,7 +41,7 @@ yl_speak_up.input_save_or_discard_changes = function(player, formname, fields)
-- if we just reload the old state, they would both get lost
local target_dialog_data = yl_speak_up.speak_to[pname].dialog.n_dialogs[ target_dialog ]
-- actually restore the old state and discard the changes by loading the dialog anew
yl_speak_up.speak_to[pname].dialog = yl_speak_up.load_dialog(n_id)
yl_speak_up.speak_to[pname].dialog = yl_speak_up.load_dialog(n_id, false)
-- clear list of changes
yl_speak_up.npc_was_changed[ n_id ] = {}
local dialog = yl_speak_up.speak_to[pname].dialog

View File

@ -136,12 +136,13 @@ yl_speak_up.save_dialog = function(n_id, dialog)
end
yl_speak_up.load_dialog = function(n_id) -- returns the saved dialog
-- if a player is supplied: include generic dialogs
yl_speak_up.load_dialog = function(n_id, player) -- returns the saved dialog
local p = save_path(n_id)
local file, err = io.open(p, "r")
if err then
return {}
return yl_speak_up.add_generic_dialogs({}, n_id, player)
end
io.input(file)
local content = io.read()
@ -152,13 +153,13 @@ yl_speak_up.load_dialog = function(n_id) -- returns the saved dialog
dialog = {}
end
return dialog
return yl_speak_up.add_generic_dialogs(dialog, n_id, player)
end
-- used by staff and input_inital_config
yl_speak_up.fields_to_dialog = function(pname, fields)
local n_id = yl_speak_up.speak_to[pname].n_id
local dialog = yl_speak_up.load_dialog(n_id)
local dialog = yl_speak_up.load_dialog(n_id, false)
local save_d_id = ""
if next(dialog) == nil then -- No file found. Let's create the basic values
@ -205,7 +206,7 @@ yl_speak_up.delete_dialog = function(n_id, d_id)
return false
end -- We don't delete "New dialog"
local dialog = yl_speak_up.load_dialog(n_id)
local dialog = yl_speak_up.load_dialog(n_id, false)
dialog.n_dialogs[d_id] = nil
@ -352,7 +353,9 @@ end
-- identify multiple results that lead to target dialogs
yl_speak_up.check_for_disambigous_results = function(n_id, pname)
local errors_found = false
local dialog = yl_speak_up.load_dialog(n_id)
-- this is only checked when trying to edit this npc;
-- let's stick to check the dialogs of this one without generic dialogs
local dialog = yl_speak_up.load_dialog(n_id, false)
-- nothing defined yet - nothing to repair
if(not(dialog.n_dialogs)) then
return
@ -427,10 +430,19 @@ function yl_speak_up.talk(self, clicker)
yl_speak_up.speak_to[pname] = {}
yl_speak_up.speak_to[pname].n_id = n_id -- Memorize which player talks to which NPC
yl_speak_up.speak_to[pname].dialog = yl_speak_up.load_dialog(n_id) -- Load the dialog and see what we can do with it
yl_speak_up.speak_to[pname].textures = self.yl_speak_up.textures
yl_speak_up.speak_to[pname].option_index = 1
-- the object itself may be needed in load_dialog for adding generic dialogs
yl_speak_up.speak_to[pname].obj = self.object
-- Load the dialog and see what we can do with it
-- this inculdes generic dialog parts;
-- make sure this is never true in edit mode (because in edit mode we want to
-- edit this particular NPC without generic parts)
local player = clicker
if(yl_speak_up.edit_mode[pname] == n_id) then
player = nil
end
yl_speak_up.speak_to[pname].dialog = yl_speak_up.load_dialog(n_id, clicker)
-- is this player explicitly allowed to edit this npc?
if(yl_speak_up.speak_to[pname].dialog

View File

@ -28,6 +28,8 @@ yl_speak_up.custom_server_functions = {}
dofile(modpath .. "config.lua")
dofile(modpath .. "privs.lua")
-- add generic dialogs
dofile(modpath .. "add_generic_dialogs.lua")
-- react to right-click etc.
dofile(modpath .. "interface_mobs_api.lua")
-- handle on_player_receive_fields and showing of formspecs

View File

@ -142,7 +142,7 @@ local function delete_option(n_id, d_id, o_id)
return false
end -- We don't delete "New option"
local dialog = yl_speak_up.load_dialog(n_id)
local dialog = yl_speak_up.load_dialog(n_id, false)
dialog.n_dialogs[d_id].d_options[o_id] = nil
@ -159,7 +159,7 @@ end
-- dialog
yl_speak_up.get_fs_setdialog = function(clicker, n_id, d_id)
local dialog = yl_speak_up.load_dialog(n_id)
local dialog = yl_speak_up.load_dialog(n_id, false)
local items = yl_speak_up.text_new_dialog_id
local count = 1
@ -236,7 +236,7 @@ end
-- options
yl_speak_up.get_fs_optiondialog = function(player, n_id, d_id, o_id, p_id, r_id)
local dialog = yl_speak_up.load_dialog(n_id)
local dialog = yl_speak_up.load_dialog(n_id, false)
local pname = player:get_player_name()
if next(dialog) == nil or d_id == yl_speak_up.text_new_dialog_id or dialog.n_dialogs == nil then -- file does not exist or the user sent the New dialog
@ -756,7 +756,7 @@ function yl_speak_up.config(clicker, npc)
yl_speak_up.speak_to[pname] = {}
yl_speak_up.speak_to[pname].n_id = n_id -- Memorize which player talks to which NPC
yl_speak_up.speak_to[pname].d_id = yl_speak_up.text_new_dialog_id -- The only d_id we can rely on existing
yl_speak_up.speak_to[pname].dialog = yl_speak_up.load_dialog(n_id) -- Load the dialog and see what we can do with it
yl_speak_up.speak_to[pname].dialog = yl_speak_up.load_dialog(n_id, false) -- Load the dialog and see what we can do with it
yl_speak_up.speak_to[pname].obj = npc
-- find out who owns the npc while we still have easy access to the luaentity