add npcs and locations via add field to lists

This commit is contained in:
Sokomine 2023-09-30 21:03:44 +02:00
parent 13abe1687a
commit 78f26d42a1

View File

@ -140,6 +140,52 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
-- has a quest step be selected?
local work_step = nil
if(fields.add_element and fields.add_element_name) then
if( mode and mode == "manage_quest_npcs") then
-- manually entered an NPC ID
local npc_id = fields.add_element_name or ""
-- just check if it is *potentially* an NPC ID; that way NPC the quest
-- creator has no write access to can be added
if(string.sub(npc_id, 1, 2) ~= "n_"
or not(tonumber(string.sub(npc_id, 3)))) then
local error_msg = "This is not an NPC ID. They have the form n_<id>."
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:add_quest_steps",
formspec = yl_speak_up.get_fs_quest_edit_error(error_msg, "back_from_error_msg")})
return
end
-- only npcs that are not yet added (and we store IDs without n_ prefix)
local id = tonumber(string.sub(npc_id, 3))
if(id and table.indexof(res.quest.npcs or {}, id) == -1) then
table.insert(yl_speak_up.quests[q_id].npcs, id)
yl_speak_up.save_quest(q_id)
end
return yl_speak_up.show_fs(player, "add_quest_steps")
elseif(mode and mode == "manage_quest_locations") then
-- manually entered a quest location
local location_id = fields.add_element_name or ""
local d = yl_speak_up.player_vars["$NPC_META_DATA$"][location_id]
local error_msg = ""
-- the owner is not checked; that way, locations can be added where the
-- quest onwer does not (yet) have write access
if(string.sub(location_id, 1, 1) ~= "p") then
error_msg = "This is not a location ID."
elseif(not(d)) then
error_msg = "Location not found."
end
if(error_msg ~= "") then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:add_quest_steps",
formspec = yl_speak_up.get_fs_quest_edit_error(error_msg, "back_from_error_msg")})
return
end
-- only locations that are not yet added
if(table.indexof(res.quest.locations or {}, location_id) == -1) then
table.insert(yl_speak_up.quests[q_id].locations, location_id)
yl_speak_up.save_quest(q_id)
end
return yl_speak_up.show_fs(player, "add_quest_steps")
end
-- create a new quest step
local new_step = fields.add_element_name:trim()
-- a new one shall be created
@ -219,7 +265,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
local liste = (res.quest.npcs or {})
if(selected and selected.row and selected.row > 1 and selected.row <= #liste + 1) then
-- *can* it be removed, or is it needed somewhere?
local full_id = "n_"..tostring(liste[selected_row - 1])
local full_id = "n_"..tostring(liste[selected.row - 1])
if(yl_speak_up.count_used_in_quest_steps(full_id, step_data) > 0) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:add_quest_steps",
@ -240,7 +286,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
local liste = (res.quest.locations or {})
if(selected and selected.row and selected.row > 1 and selected.row <= #liste + 1) then
-- *can* it be removed, or is it needed somewhere?
local full_id = liste[selected_row - 1]
local full_id = liste[selected.row - 1]
if(yl_speak_up.count_used_in_quest_steps(full_id, step_data) > 0) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:add_quest_steps",