preparations for adding locations to quests

This commit is contained in:
Sokomine 2023-09-30 12:48:53 +02:00
parent a3c1c5ccfd
commit feae914e85

View File

@ -322,7 +322,8 @@ end
-- lists npc that are either already added or could be added
yl_speak_up.quest_npc_show_table = function(formspec, table_specs, liste, step_data)
-- can also handle locations
yl_speak_up.quest_npc_show_table = function(formspec, table_specs, liste, step_data, is_location_list)
local grey_if_zero = function(fs, n)
if(n and n == 0) then
table.insert(fs, "#444444")
@ -334,20 +335,26 @@ yl_speak_up.quest_npc_show_table = function(formspec, table_specs, liste, step_d
table.insert(formspec, "tablecolumns["..
"color;text,align=right;".. -- used in this many quest steps
"color;text,align=left;".. -- n_id
"color;text,align=left;".. -- n_id (number, for NPC) or p_(-185,3,-146) (for locations)
"color;text,align=left;".. -- owner
"color;text,align=left".. -- name of NPC
"]table[")
table.insert(formspec, table_specs)
table.insert(formspec,"#FFFFFF,Used:,#FFFFFF,n_id:,#FFFFFF,Name")
if(is_location_list) then
table.insert(formspec,"#FFFFFF,Used:,#FFFFFF,PositionID:,#FFFFFF,Name")
else
table.insert(formspec,"#FFFFFF,Used:,#FFFFFF,n_id:,#FFFFFF,Name")
end
table.insert(formspec, minetest.formspec_escape(","))
table.insert(formspec, " description:,#FFFFFF,Owner:,")
local tmp = {}
for i, n_id in ipairs(liste or {}) do
-- TODO: turn this into a function
-- find out in how many quest steps this NPC is used
local used = 0
for s, d in pairs(step_data) do
for loc_id, loc in pairs(d.where or {}) do
-- TODO: needs to be diffrent for locations
if(loc and loc.n_id and loc.n_id == "n_"..n_id) then
used = used + 1
end
@ -356,7 +363,11 @@ yl_speak_up.quest_npc_show_table = function(formspec, table_specs, liste, step_d
grey_if_zero(tmp, used)
-- the n_id of the NPC
table.insert(tmp, "#AAFFAA")
table.insert(tmp, "n_"..minetest.formspec_escape(n_id))
if(is_location_list) then
table.insert(tmp, n_id) -- this already encodes the position
else
table.insert(tmp, "n_"..minetest.formspec_escape(n_id))
end
-- get information from the NPC list (see fs_npc_list.lua)
local owner = "- ? -"
local name = "- ? -"
@ -380,6 +391,26 @@ yl_speak_up.quest_npc_show_table = function(formspec, table_specs, liste, step_d
end
-- returns list of locations that pname can edit and that are not yet part of quest_location_list
yl_speak_up.quest_get_location_candidate_list = function(pname, quest_location_liste)
-- build a list of candidates of locations
local location_list = {}
for n_id, v in pairs(yl_speak_up.player_vars["$NPC_META_DATA$"] or {}) do
-- TODO: better detection would be helpful
if(string.sub(n_id, 1, 1) == "p"
-- only locations that are not yet added
and table.indexof(quest_location_liste or {}, n_id) == -1
-- and only those that the player can edit
and (v.owner == pname or (v.may_edit and v.may_edit[pname]))) then
table.insert(location_list, k)
minetest.chat_send_player("singleplayer", "candidate: "..tostring(n_id))
end
end
table.sort(location_list)
return location_list
end
-- param is unused
yl_speak_up.get_fs_add_quest_steps = function(player, param)
local res = yl_speak_up.player_is_working_on_quest(player)