|
9 | 9 | from typing import TYPE_CHECKING |
10 | 10 |
|
11 | 11 | from stories.anything.npcs.npc_defs import RoamingMob |
12 | | -from tale import lang |
| 12 | +from tale import lang, parse_utils |
13 | 13 | from tale.base import Door, Exit, Location |
14 | 14 | from tale.coord import Coord |
15 | 15 | from tale.dungeon.dungeon_generator import ItemPopulator, Layout, LayoutGenerator, MobPopulator |
@@ -201,27 +201,29 @@ def _connect_locations(self, layout: Layout) -> None: |
201 | 201 | for connection in connections: |
202 | 202 | cell_location = self._grid.get(connection.coord.as_tuple(), None) |
203 | 203 | parent_location = self._grid.get(connection.other.as_tuple(), None) |
| 204 | + direction = parse_utils.direction_from_coordinates(connection.other.subtract(connection.coord)) |
| 205 | + reverse_direction = parse_utils.opposite_direction(direction) |
204 | 206 |
|
205 | 207 | if not cell_location or not parent_location: |
206 | 208 | continue |
207 | 209 |
|
208 | 210 | # Skip if already connected |
209 | | - if cell_location.exits.get(parent_location.name, None): |
| 211 | + if cell_location.exits.get(parent_location.name, None) or cell_location.exits.get(direction, None): |
210 | 212 | continue |
211 | | - elif parent_location.exits.get(cell_location.name, None): |
| 213 | + elif parent_location.exits.get(cell_location.name, None) or parent_location.exits.get(reverse_direction, None): |
212 | 214 | continue |
213 | 215 |
|
214 | 216 | # Create connection |
215 | 217 | if connection.door: |
216 | 218 | Door.connect( |
217 | | - cell_location, parent_location.name, '', None, |
218 | | - parent_location, cell_location.name, '', None, |
| 219 | + cell_location, [parent_location.name, direction], '', None, |
| 220 | + parent_location, [cell_location.name, reverse_direction], '', None, |
219 | 221 | opened=False, locked=connection.locked, key_code=connection.key_code |
220 | 222 | ) |
221 | 223 | else: |
222 | 224 | Exit.connect( |
223 | | - cell_location, parent_location.name, '', None, |
224 | | - parent_location, cell_location.name, '', None |
| 225 | + cell_location, [parent_location.name, direction], '', None, |
| 226 | + parent_location, [cell_location.name, reverse_direction], '', None |
225 | 227 | ) |
226 | 228 |
|
227 | 229 | def _spawn_gold(self, zone: Zone): |
|
0 commit comments