summaryrefslogtreecommitdiff
path: root/objects/room.lua
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-03-07 00:04:53 +0800
committerEltrac <hi@guhub.cn>2025-03-07 00:04:53 +0800
commit1693be759251b7b294d4c54379e1f513ef012a92 (patch)
tree345ec7436ac321e254f28c60a21a359b9b126268 /objects/room.lua
parent29f5a0cdbaee7de2d5b738061c2a82cb1885b1b0 (diff)
refactor: clearer logic on map generation and room connection
Diffstat (limited to 'objects/room.lua')
-rw-r--r--objects/room.lua23
1 files changed, 8 insertions, 15 deletions
diff --git a/objects/room.lua b/objects/room.lua
index 1477911..3176e0c 100644
--- a/objects/room.lua
+++ b/objects/room.lua
@@ -172,23 +172,16 @@ function Room:connect(anotherRoom, way)
return false
end
- if type(way) == "number" then
- -- if number (Direction enums)
- way = Ways[way]
- elseif not way then
- -- if no way set, randomly choose a doorless direction
- way = Ways[utils.any(self:getDoorlessDirections())]
- end
+ -- determine directions
+ -- if not specified, choose randomly
+ local directions = Way[way or Ways[way or utils.any(self:getDoorlessDirections())]]
+ if not directions then return false end
-- connect room with determined direction
- local door1, door2
- if Way[way] then
- local dir1, dir2 = Way[way][1], Way[way][2]
- door1 = Door:new(dir1, self, anotherRoom)
- door2 = Door:new(dir2, anotherRoom, self)
- self:addDoor(door1)
- anotherRoom:addDoor(door2)
- end
+ 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
end