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
|
local world = require("world")
local net = require("net")
world.locations = world.locations or {}
local loc = {}
local required_fields = {
name = "string",
desc = "string",
goto_txt = "string",
go = "table",
settle_txt = "string"
}
local location_base = {
get_desc = function(self)
local houses = net.ask_for_homes(self.name,1)
self.last_houses = houses
local sb = {self.desc}
for k,v in pairs(houses) do
print("Adding ", v)
sb[#sb + 1] = string.format("%s is here",v)
end
return table.concat(sb,"\n")
end,
houses = {},
is_location = true
}
local location_m = {__index = location_base}
function loc.add_location(tbl)
print("Added location:",tbl.name)
assert(type(tbl) == "table","Tried to register a location that was not a table")
for k,v in pairs(required_fields) do
assertf(tbl[k],"Tried to register a location without a %s field",k)
assertf(type(tbl[k]) == v,"Tried to register a location with a %s field that should have been a %s, but was a %s",k,v,type(tbl[k]))
end
assert(world.locations[tbl.name] == nil)
setmetatable(tbl,location_m)
world.locations[tbl.name] = tbl
end
return loc
|