further prepared connection of npc and quest steps
This commit is contained in:
parent
b7423b0d81
commit
861c44024a
@ -9,6 +9,14 @@ local grey_if_zero = function(fs, n)
|
||||
end
|
||||
|
||||
|
||||
-- small helper function
|
||||
local show_error_fs = function(player, text)
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:add_quest_steps",
|
||||
formspec = yl_speak_up.get_fs_quest_edit_error(text, "back_from_error_msg")})
|
||||
end
|
||||
|
||||
|
||||
-- find out in how many quest steps this NPC or location is used;
|
||||
-- ID can either be n_<ID> or a location p_(x,y,z)
|
||||
yl_speak_up.count_used_in_quest_steps = function(id, step_data)
|
||||
@ -113,10 +121,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
|
||||
end
|
||||
local res = yl_speak_up.player_is_working_on_quest(player)
|
||||
if(res.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(res.error_msg, "back")})
|
||||
return
|
||||
return show_error_fs(player, res.error_msg)
|
||||
end
|
||||
local pname = res.pname
|
||||
local q_id = res.q_id
|
||||
@ -147,11 +152,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
|
||||
-- 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
|
||||
return show_error_fs(player, "This is not an NPC ID. They have the form n_<id>.")
|
||||
end
|
||||
-- only npcs that are not yet added (and we store IDs without n_ prefix)
|
||||
local id = tonumber(string.sub(npc_id, 3))
|
||||
@ -173,10 +174,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
|
||||
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
|
||||
return show_error_fs(player, error_msg)
|
||||
end
|
||||
-- only locations that are not yet added
|
||||
if(table.indexof(res.quest.locations or {}, location_id) == -1) then
|
||||
@ -189,15 +187,9 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
|
||||
-- create a new quest step
|
||||
local new_step = fields.add_element_name:trim()
|
||||
-- a new one shall be created
|
||||
local res2 = yl_speak_up.quest_step_add_quest_step(pname, q_id, new_step)
|
||||
if(res2 ~= "OK") then
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:add_quest_steps",
|
||||
formspec = "size[9,2]"..
|
||||
"label[0.2,0.0;Error:\n"..
|
||||
minetest.formspec_escape(minetest.wrap_text(res2,80)).."]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
||||
return res2
|
||||
local msg = yl_speak_up.quest_step_add_quest_step(pname, q_id, new_step)
|
||||
if(msg ~= "OK") then
|
||||
return show_error_fs(player, msg)
|
||||
end
|
||||
-- this will also be set if the quest step exists already; this is fine so far
|
||||
work_step = new_step
|
||||
@ -267,13 +259,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
|
||||
-- *can* it be removed, or is it needed somewhere?
|
||||
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",
|
||||
formspec = "size[9,2]"..
|
||||
"label[0.2,0.0;Error:\n"..
|
||||
"This NPC is needed for setting a quest step.]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
||||
return
|
||||
return show_error_fs(player, "This NPC is needed for setting a quest step.")
|
||||
end
|
||||
table.remove(yl_speak_up.quests[q_id].npcs, selected.row - 1)
|
||||
end
|
||||
@ -288,13 +274,7 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
|
||||
-- *can* it be removed, or is it needed somewhere?
|
||||
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",
|
||||
formspec = "size[9,2]"..
|
||||
"label[0.2,0.0;Error:\n"..
|
||||
"This location is needed for setting a quest step.]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
||||
return
|
||||
return show_error_fs(player, "This location is needed for setting a quest step.")
|
||||
end
|
||||
table.remove(yl_speak_up.quests[q_id].locations, selected.row - 1)
|
||||
end
|
||||
@ -302,13 +282,28 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
|
||||
return yl_speak_up.show_fs(player, "add_quest_steps")
|
||||
end
|
||||
|
||||
if(mode == "embedded_select") then
|
||||
return yl_speak_up.show_fs(player, "manage_quest_steps", work_step)
|
||||
end
|
||||
if(not(work_step)) then
|
||||
return -- TODO
|
||||
end
|
||||
if(not(current_step) or not(step_data[current_step])) then
|
||||
elseif(mode == "embedded_select") then
|
||||
yl_speak_up.speak_to[t.pname].quest_step = work_step
|
||||
return yl_speak_up.show_fs(player, "manage_quest_steps", work_step)
|
||||
elseif(mode == "assign_quest_step") then
|
||||
-- TODO: what if there's already a step assigned?
|
||||
-- actually add the step
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local d_id = yl_speak_up.speak_to[pname].d_id
|
||||
local o_id = yl_speak_up.speak_to[pname].o_id
|
||||
-- this saves the quest data as well if needed
|
||||
local msg = yl_speak_up.quest_step_add_where(pname, q_id, work_step,
|
||||
{n_id = n_id, d_id = d_id, o_id = o_id})
|
||||
if(msg ~= "OK") then
|
||||
return show_error_fs(player, msg)
|
||||
end
|
||||
-- TODO: the NPC needs to be saved as well
|
||||
-- show the newly created or selected step
|
||||
yl_speak_up.speak_to[pname].quest_step = work_step
|
||||
return yl_speak_up.show_fs(player, "manage_quest_steps", work_step)
|
||||
elseif(not(current_step) or not(step_data[current_step])) then
|
||||
return yl_speak_up.show_fs(player, "manage_quests")
|
||||
end
|
||||
|
||||
|
@ -36,11 +36,11 @@ end
|
||||
|
||||
-- show the error message created above
|
||||
yl_speak_up.get_fs_quest_edit_error = function(error_msg, back_button_name)
|
||||
return "size[9,3]"..
|
||||
return "size[10,3]"..
|
||||
"label[0.2,0.5;Error:]"..
|
||||
"label[0.5,1.0;"..minetest.colorize("#FFFF00",
|
||||
minetest.formspec_escape(
|
||||
minetest.wrap_text(tostring(error_msg), 40)))..
|
||||
minetest.wrap_text(tostring(error_msg), 80)))..
|
||||
"]button[3.5,2.0;2,0.9;"..tostring(back_button_name)..";Back]"
|
||||
end
|
||||
|
||||
|
@ -962,7 +962,7 @@ end
|
||||
|
||||
-- turn a location {n_id=.., d_id=.., c_id=..} or position into a uniq string
|
||||
yl_speak_up.get_location_id = function(loc)
|
||||
if(not(loc)) then
|
||||
if(not(loc) or type(loc) ~= "table") then
|
||||
return nil
|
||||
end
|
||||
if(loc.is_block and loc.n_id and loc.d_id and loc.o_id) then
|
||||
@ -985,14 +985,14 @@ yl_speak_up.quest_step_add_where = function(pname, q_id, quest_step_name, new_lo
|
||||
if(error_msg ~= "OK") then
|
||||
return error_msg
|
||||
end
|
||||
local quest_step = yl_speak_up.quests[q_id].step_data[quest_step_name]
|
||||
if(not(quest_step)) then
|
||||
local step_data = yl_speak_up.quests[q_id].step_data[quest_step_name]
|
||||
if(not(step_data)) then
|
||||
return "Quest step \""..tostring(quest_step_name).."\" does not exist."
|
||||
end
|
||||
if(not(step_data.where)) then
|
||||
step_data.where = {}
|
||||
end
|
||||
local new_loc_id = yl_speak_up.get_location_id(loc)
|
||||
local new_loc_id = yl_speak_up.get_location_id(new_location)
|
||||
if(not(new_loc_id)) then
|
||||
return "Failed to create location ID for this location."
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user