partial ink import implemented

This commit is contained in:
Sokomine 2025-01-09 23:20:49 +01:00
parent 7e5fc745c0
commit 799233c8a2

View File

@ -48,8 +48,52 @@ yl_speak_up.input_export = function(player, formname, fields)
return yl_speak_up.show_fs(player, "export", "show_simple_dialogs")
elseif(fields and (fields.import or fields.back_from_error_msg)) then
return yl_speak_up.show_fs(player, "export", "import")
elseif(fields and fields.really_import and fields.new_dialog_input
and string.sub(fields.new_dialog_input, 1, 3) == "-> ") then
local pname = player:get_player_name()
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
return
end
local n_id = yl_speak_up.speak_to[pname].n_id
-- can the player edit this npc?
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
return yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:export",
formspec = yl_speak_up.build_fs_quest_edit_error(
"You do not own this NPC and are not allowed to edit it!",
"back_from_error_msg")})
end
-- import in ink format
local dialog = yl_speak_up.speak_to[pname].dialog
local log = {}
local log_level = 1
yl_speak_up.parse_ink.import_from_ink(dialog, fields.new_dialog_input, log_level, log)
-- save the changed dialog
yl_speak_up.save_dialog(n_id, dialog)
for i_, t_ in ipairs(log) do
minetest.chat_send_player(pname, t_)
end
-- log the change
return yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:export",
formspec = "size[10,3]"..
"label[0.5,1.0;Partially imported dialog data in ink format "..
" successfully.]"..
"button[3.5,2.0;2,0.9;back_from_error_msg;Back]"
})
elseif(fields and fields.really_import and fields.new_dialog_input) then
-- importing requires the "privs" priv
-- can that possibly be json format?
if(not(string.sub(fields.new_dialog_input, 1, 1) == "{")) then
return yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:export",
formspec = yl_speak_up.build_fs_quest_edit_error(
"This does not seem to be in .json format. Please make sure "..
"your import starts with a \"{\"!",
"back_from_error_msg")})
end
-- importing in .json format requires the "privs" priv
-- and it imports more information like npc name
if(not(minetest.check_player_privs(player, {privs=true}))) then
return yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:export",
@ -127,7 +171,7 @@ yl_speak_up.input_export = function(player, formname, fields)
-- save it
yl_speak_up.save_dialog(n_id, new_dialog)
-- log the change
yl_speak_up.log_change(pname, n_id, "Imported new dialog.")
yl_speak_up.log_change(pname, n_id, "Imported new dialog in .json format (complete).")
return yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:export",
formspec = "size[10,3]"..