aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/quests/arcs.lua
blob: 26c60abeefc50545c0b18bce462ce5e73f7fbd16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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