moved '/npc_talk force_edit' into editor/ part

This commit is contained in:
Sokomine 2024-02-07 20:28:25 +01:00
parent 8dbaaf21d5
commit 596d521345
7 changed files with 87 additions and 47 deletions

View File

@ -1,5 +1,8 @@
-- Implementation of chat commands that were registered in register_once
-- this is a way to provide additional help if a mod adds further commands (like the editor)
yl_speak_up.add_to_command_help_text = ""
-- general function for handling talking to the NPC
yl_speak_up.command_npc_talk = function(pname, param)
if(not(pname)) then
@ -23,10 +26,6 @@ yl_speak_up.command_npc_talk = function(pname, param)
elseif(cmd and cmd == "debug") then
-- implemented in npc_talk_debug.lua:
return yl_speak_up.command_npc_talk_debug(pname, rest)
-- activates edit mode when talking to an NPC; but only if the player can edit that NPC
elseif(cmd and cmd == "force_edit") then
-- implemented in functions.lua:
return yl_speak_up.command_npc_talk_force_edit(pname, rest)
-- managing generic NPC requires npc_talk_admin priv
elseif(cmd and cmd == "generic") then
@ -69,11 +68,11 @@ yl_speak_up.command_npc_talk = function(pname, param)
" version show human-readable version information\n"..
" list shows a list of NPC that you can edit\n"..
" debug debug a particular NPC\n"..
" force_edit forces edit mode for any NPC you talk to\n"..
" generic [requores npc_talk_admin priv] list, add or remove NPC as generic NPC\n"..
" force_restore_npc [requires npc_talk_admin priv] restore NPC that got lost\n"..
" privs [requires privs priv] list, grant or revoke privs for an NPC\n"..
-- reload is fully handled in register_once
"Note: /npc_talk_reload [requires privs priv] reloads the code of the mod without server "..
"restart.")
"restart."..
yl_speak_up.add_to_command_help_text)
end

View File

@ -0,0 +1,28 @@
-- Implementation of chat commands that were registered in register_once
-- (here: only add those additional things needed for edit mode)
local old_command_npc_talk = yl_speak_up.command_npc_talk
yl_speak_up.command_npc_talk = function(pname, param)
if(not(pname)) then
return
end
-- activates edit mode when talking to an NPC; but only if the player can edit that NPC
if(param and param == "force_edit") then
-- implemented in functions.lua:
return yl_speak_up.command_npc_talk_force_edit(pname, rest)
end
-- not perfect - but at least some help
if(param
and (param == "help force_edit"
or param == "? force_edit"
or param == "force_edit help")) then
minetest.chat_send_player(pname,
"Toggles force edit mode. This is helpful if you cut yourself out "..
"of editing an NPC by breaking it. From now on all NPC you will talk to "..
"will already be in edit mode (provided you are allowed to edit them)."..
"\nIssuing the command again ends force edit mode.")
return
end
return old_command_npc_talk(pname, param)
end

View File

@ -0,0 +1,24 @@
-- allow to enter force edit mode (useful when an NPC was broken)
yl_speak_up.force_edit_mode = {}
-- command to enter force edit mode
yl_speak_up.command_npc_talk_force_edit = function(pname, param)
if(not(pname)) then
return
end
if(yl_speak_up.force_edit_mode[pname]) then
yl_speak_up.force_edit_mode[pname] = nil
minetest.chat_send_player(pname,
"Ending force edit mode for NPC. From now on talks "..
"will no longer start in edit mode.")
else
yl_speak_up.force_edit_mode[pname] = true
minetest.chat_send_player(pname,
"STARTING force edit mode for NPC. From now on talks "..
"with NPC will always start in edit mode provided "..
"you are allowed to edit this NPC.\n"..
"In order to end force edit mode, give the command "..
"/npc_talk_force_edit a second time.")
end
end

View File

@ -6,8 +6,16 @@ yl_speak_up.in_edit_mode = function(pname)
and (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id)
end
local modname = minetest.get_current_modname()
-- TODO: adjust to new mod name and paths
local modpath = minetest.get_modpath(modname)..DIR_DELIM.."editor"..DIR_DELIM
-- this is a way to provide additional help if a mod adds further commands (like the editor)
yl_speak_up.add_to_command_help_text = yl_speak_up.add_to_command_help_text..
"\nAdditional commands provided by "..tostring(modname)..":\n"..
" force_edit forces edit mode for any NPC you talk to\n"
local modpath = minetest.get_modpath("yl_speak_up")..DIR_DELIM.."editor"..DIR_DELIM
-- overrides of functions fo fs/fs_talkdialog.lua when in edit_mode (or for entering/leaving it)
dofile(modpath .. "fs/fs_talkdialog_edit_mode.lua")
@ -128,6 +136,10 @@ local modpath = minetest.get_modpath("yl_speak_up")..DIR_DELIM.."editor"..DIR_DE
dofile(modpath .. "fs/fs_properties.lua")
-- -- the main functionality of the mod
-- dofile(modpath .. "functions.lua")
-- /npc_talk force_edit (when talking to an NPC in the normal way fails):
dofile(modpath .. "command_force_edit_mode.lua")
-- add the force_edit option to the chat commands
dofile(modpath .. "chat_commands_in_edit_mode.lua")
-- -- implementation of the chat commands registered in register_once.lua:
-- dofile(modpath .. "chat_commands.lua")
-- creating and maintaining quests

View File

@ -665,3 +665,20 @@ yl_speak_up.get_fs_talkdialog_add_edit_and_command_buttons = function(
return {h = h, formspec = formspec}
end
-- apply force_edit_mode if necessary
local old_get_fs_talkdialog = yl_speak_up.get_fs_talkdialog
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, recursion_depth)
if(not(player)) then
return
end
local pname = player:get_player_name()
-- are we in force edit mode, and can the player edit this NPC?
if(yl_speak_up.force_edit_mode[pname]
-- not already in edit mode?
and (not(yl_speak_up.edit_mode[pname]) or yl_speak_up.edit_mode[pname] ~= n_id)
and yl_speak_up.may_edit_npc(player, n_id)) then
yl_speak_up.edit_mode[pname] = n_id
end
return old_get_fs_talkdialog(player, n_id, d_id, alternate_text, recursion_depth)
end

View File

@ -513,29 +513,6 @@ yl_speak_up.check_for_disambigous_results = function(n_id, pname)
end
-- allow to enter force edit mode (useful when an NPC was broken)
yl_speak_up.force_edit_mode = {}
-- command to enter force edit mode
yl_speak_up.command_npc_talk_force_edit = function(pname, param)
if(not(pname)) then
return
end
if(yl_speak_up.force_edit_mode[pname]) then
yl_speak_up.force_edit_mode[pname] = nil
minetest.chat_send_player(pname,
"Ending force edit mode for NPC. From now on talks "..
"will no longer start in edit mode.")
else
yl_speak_up.force_edit_mode[pname] = true
minetest.chat_send_player(pname,
"STARTING force edit mode for NPC. From now on talks "..
"with NPC will always start in edit mode provided "..
"you are allowed to edit this NPC.\n"..
"In order to end force edit mode, give the command "..
"/npc_talk_force_edit a second time.")
end
end
-- Make the NPC talk
-- assign n_ID
@ -657,12 +634,6 @@ function yl_speak_up.talk(self, clicker)
yl_speak_up.speak_to[pname].may_edit_this_npc = true
end
-- are we in force edit mode, and can the player edit this NPC?
if(yl_speak_up.force_edit_mode[pname]
and yl_speak_up.may_edit_npc(clicker, n_id)) then
yl_speak_up.edit_mode[pname] = n_id
end
local dialog = yl_speak_up.speak_to[pname].dialog
if(not(dialog.trades)) then
dialog.trades = {}

View File

@ -159,17 +159,6 @@ minetest.register_chatcommand( 'npc_talk_reload', {
-- most of the files of this mod can be reloaded without the server having to
-- be restarted;
-- handled in init.lua
minetest.register_chatcommand( 'npc_talk_force_edit', {
description = "Toggles force edit mode. This is helpful if you cut yourself out "..
"of editing an NPC by breaking it. From now on all NPC you will talk to "..
"will already be in edit mode (provided you are allowed to edit them)."..
"\nIssuing the command again ends force edit mode.",
privs = {npc_talk_owner = true},
func = function(pname, param)
return yl_speak_up.command_npc_talk_force_edit(pname, param)
end,
})
-- a general command that may branch off and/or offer help
minetest.register_chatcommand( 'npc_talk', {