2015-02-19 16:47:50 +01:00
|
|
|
-- reading previous quests
|
|
|
|
local file = io.open(minetest.get_worldpath().."/quests", "r")
|
|
|
|
if file then
|
|
|
|
print "Reading quests..."
|
|
|
|
quests = minetest.deserialize(file:read("*all"))
|
|
|
|
file:close()
|
|
|
|
end
|
2015-02-21 14:46:27 +01:00
|
|
|
quests = quests or {}
|
2015-02-28 11:48:27 +01:00
|
|
|
quests.registered_quests = {}
|
|
|
|
quests.active_quests = quests.active_quests or {}
|
2015-02-21 14:46:27 +01:00
|
|
|
quests.successfull_quests = quests.successfull_quests or {}
|
|
|
|
quests.failed_quests = quests.failed_quests or {}
|
|
|
|
quests.hud = quests.hud or {}
|
|
|
|
|
|
|
|
|
2015-02-19 16:47:50 +01:00
|
|
|
quests.formspec_lists = {}
|
2015-03-02 20:32:42 +01:00
|
|
|
function quests.round(num, n)
|
2015-02-20 16:21:10 +01:00
|
|
|
local mult = 10^(n or 0)
|
|
|
|
return math.floor(num * mult + .5) / mult
|
|
|
|
end
|
|
|
|
|
2015-02-28 11:48:27 +01:00
|
|
|
|
2015-03-02 20:32:42 +01:00
|
|
|
dofile(minetest.get_modpath("quests") .. "/core.lua")
|
|
|
|
dofile(minetest.get_modpath("quests") .. "/hud.lua")
|
|
|
|
dofile(minetest.get_modpath("quests") .. "/formspecs.lua")
|
2015-02-19 16:47:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- write the quests to file
|
|
|
|
minetest.register_on_shutdown(function()
|
|
|
|
print "Writing quests to file"
|
2015-02-28 19:01:22 +01:00
|
|
|
for playername, quest in pairs(quests.active_quests) do
|
|
|
|
for questname, questspecs in pairs(quest) do
|
|
|
|
if (questspecs.finished) then
|
|
|
|
quests.active_quests[playername][questname] = nil -- make sure no finished quests are saved as unfinished
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-02-19 16:47:50 +01:00
|
|
|
local file = io.open(minetest.get_worldpath().."/quests", "w")
|
|
|
|
if (file) then
|
2015-02-28 11:48:27 +01:00
|
|
|
file:write(minetest.serialize({ --registered_quests = quests.registered_quests,
|
|
|
|
active_quests = quests.active_quests,
|
2015-02-21 14:46:27 +01:00
|
|
|
successfull_quests = quests.successfull_quests,
|
|
|
|
failed_quests = quests.failed_quests,
|
|
|
|
hud = quests.hud}))
|
2015-02-19 16:47:50 +01:00
|
|
|
file:close()
|
|
|
|
end
|
|
|
|
end)
|