aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/quests/arcs.lua
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/core/quests/arcs.lua')
-rw-r--r--gamemode/core/quests/arcs.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/gamemode/core/quests/arcs.lua b/gamemode/core/quests/arcs.lua
new file mode 100644
index 0000000..26c60ab
--- /dev/null
+++ b/gamemode/core/quests/arcs.lua
@@ -0,0 +1,52 @@
+
+local log = nrequire("log.lua")
+local fun = nrequire("fn.lua")
+local a = {}
+
+local arcs = {}
+local arc_required_fields = {
+ "Name",
+ "Init",
+ "Serialize",
+ "DeSerialize"
+}
+
+function a.RegisterArc(tbl)
+ for k,v in pairs(arc_required_fields) do
+ assert(tbl[v],"Attempted to register an arc, which didn't have a required field:" .. v)
+ end
+ if arcs[tbl.Name] ~= nil then
+ log.warn("Attempted to register and arc named " .. tbl.Name .. " when another arc by that name already exists. Overwriteing...")
+ end
+ arcs[tbl.Name] = tbl
+ log.debug("Registered new arc type:" .. tbl.Name)
+end
+
+local function MakeArcBase(name)
+ log.debug("Making arc:" .. name)
+ assert(arcs[name] ~= nil, "Attempted to make an unknown arc type:\"" .. name .. "\". Known arc types are:" .. table.concat(table.GetKeys(arcs),"\n\t"))
+ local arc_m = {
+ __index = arcs[name]
+ }
+ arcbase = {}
+ setmetatable(arcbase,arc_m)
+ return arcbase
+end
+
+function a.MakeArc(name, ...)
+ local arc = MakeArcBase(name)
+ arc:Init(...)
+ return arc
+end
+
+function a.MakeArcWithData(name,data)
+ local arc = MakeArcBase(name)
+ arc:DeSerialize(data)
+ return arc
+end
+
+concommand.Add("artery_printquestarcs",function(ply,cmd,args)
+ PrintTable(arcs)
+end)
+
+return a