diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-09 13:18:56 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-09 13:18:56 +0800 |
| commit | baf72ec03652ef5eb182d4a6088268f32508b8bb (patch) | |
| tree | a639f63a6880f5867511d749f9a357aeadff484e /objects/room.lua | |
| parent | d7b96e9d44599705da14058f23586c6f5be66d1d (diff) | |
refactor: create door instance automatically when adding door
Diffstat (limited to 'objects/room.lua')
| -rw-r--r-- | objects/room.lua | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/objects/room.lua b/objects/room.lua index 1abe18d..165a97b 100644 --- a/objects/room.lua +++ b/objects/room.lua @@ -153,12 +153,16 @@ end -- control functions -function Room:addDoor(door) - if self:hasDoor(door.location) then +function Room:addDoor(location, to) + if self:hasDoor(location) then print("door location unavailable") return false end - self.doors[door.location] = door + + local door = Door:new(location, self, to) + self.doors[location] = door + + return door end function Room:connect(anotherRoom, way) @@ -180,12 +184,8 @@ function Room:connect(anotherRoom, way) if not directions then return false end -- connect room with determined direction - local door1 = Door:new(directions[1], self, anotherRoom) - local door2 = Door:new(directions[2], anotherRoom, self) - self:addDoor(door1) - anotherRoom:addDoor(door2) - - return door1, door2 + return self:addDoor(directions[1], anotherRoom), + anotherRoom:addDoor(directions[2], self) end -- initializers |
