-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroom.lua
142 lines (120 loc) · 2.57 KB
/
room.lua
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
local Util = require "util"
local info = Util.info
local format = string.format
local Room = {}
Room.__index = Room
function Room.new()
local ret = setmetatable({}, Room)
ret.name = nil
ret.id = nil
ret.exits = {}
ret.pos = {}
ret.moving = false
ret.label = " "
return ret
end
function Room.load(obj)
local ret = setmetatable({}, Room)
ret.name = obj.name
ret.id = obj.id
ret.exits = obj.exits
ret.pos = obj.pos
ret.moving = obj.moving or false
ret.label = obj.label or " "
return ret
end
function Room:save()
return {
name=self.name,
id=self.id,
exits=self.exits,
moving=self.moving,
pos=self.pos,
label=self.label,
}
end
function Room:set_name(name)
info("ROOM", format("Setting name '%s'", name))
self.name = name
end
function Room:get_name()
return self.name
end
function Room:set_id(id)
info("ROOM", format("Setting id '%s'", id))
self.id = id
end
function Room:get_id()
return self.id
end
function Room:set_label(label)
info("ROOM", format("Setting label '%s'", label))
self.label = label
end
function Room:remove_label()
self.label = " "
end
function Room:add_exit(dir, area, pos)
local ndir = Util.parse_exit(dir)
if not self.exits[ndir] then
info("ROOM", format("Adding exit '%s'", ndir))
self.exits[ndir] = {}
end
self.exits[ndir].area=area
self.exits[ndir].pos=pos
end
function Room:add_exit_cmd(dir, cmd)
local ndir = Util.parse_exit(dir)
info("ROOM", format("Setting command '%s' for '%s'", cmd, ndir))
if not self.exits[ndir] then
self.exits[ndir] = {}
end
self.exits[ndir].cmd=cmd
end
function Room:get_exit_cmd(dir)
local ndir = Util.parse_exit(dir)
if self.exits[ndir] then
if self.exits[ndir].cmd then
return self.exits[ndir].cmd, true
else
return ndir, false
end
end
return dir, false
end
function Room:set_exit_door(dir, door)
local ndir = Util.parse_exit(dir)
info("ROOM", format("Marking '%s' as door", ndir))
if not self.exits[ndir] then
self.exits[ndir] = {}
end
self.exits[ndir].door = door
end
function Room:is_exit_door(dir)
local ndir = Util.parse_exit(dir)
if self.exits[ndir] then
return self.exits[ndir].door
end
return false
end
function Room:set_moving(moving)
info("ROOM", "Marking room as 'moving'")
self.moving = moving
end
function Room:is_moving()
return self.moving or false
end
function Room:add_undiscovered_exit(dir)
local ndir = Util.parse_exit(dir)
if not self.exits[ndir] then
self.exits[ndir] = {}
end
end
function Room:rename_area(old_name, new_name)
for _,exit in pairs(self.exits) do
if exit.area == old_name then
exit.area = new_name
end
end
end
return Room