mirror of
https://github.com/chenasraf/aardwolf.git
synced 2026-05-18 01:39:06 +00:00
feat: mark outside exits
This commit is contained in:
5
Makefile
5
Makefile
@@ -1,6 +1,11 @@
|
||||
MUSHDIR=$(HOME)/Library/Application Support/CrossOver/Bottles/MushClient/drive_c/users/crossover/MUSHclient
|
||||
PLUGDIR=$(MUSHDIR)/worlds/plugins
|
||||
|
||||
.PHONY: copydb
|
||||
copydb:
|
||||
cp "$(MUSHDIR)/Aardwolf.db" "MapGenerator/Aardwolf.db"
|
||||
@echo "Aardwolf.db copied to MapGenerator."
|
||||
|
||||
.PHONY: install/spellbook
|
||||
install/spellbook:
|
||||
cp "./Spellbook/Spellbook.xml" "$(PLUGDIR)"
|
||||
|
||||
@@ -33,8 +33,10 @@ class GraphRenderer:
|
||||
# Draw rectangular nodes
|
||||
ax = plt.gca()
|
||||
for node, (x, y) in pos.items():
|
||||
room = next((r for r in self.rooms if r.uid == node), None)
|
||||
color = 'lightblue' if not room.data.get('outside', False) else 'lightcoral'
|
||||
rect = Rectangle((x - rect_width / 2, y - rect_height / 2), rect_width, rect_height,
|
||||
facecolor="skyblue", edgecolor="black")
|
||||
facecolor=color, edgecolor="black")
|
||||
ax.add_patch(rect)
|
||||
label = labels.get(node, node)
|
||||
ax.text(x, y, label, verticalalignment='center', horizontalalignment='center', fontsize=10)
|
||||
@@ -1,13 +1,15 @@
|
||||
from room import Room
|
||||
|
||||
class PositionCalculator:
|
||||
compass_directions = {
|
||||
'n': (0, 1),
|
||||
's': (0, -1),
|
||||
'e': (1, 0),
|
||||
'w': (-1, 0),
|
||||
'ne': (1, 1),
|
||||
'nw': (-1, 1),
|
||||
'se': (1, -1),
|
||||
'sw': (-1, -1),
|
||||
'n': (0, 1), # Move up
|
||||
's': (0, -1), # Move down
|
||||
'e': (1, 0), # Move right
|
||||
'w': (-1, 0), # Move left
|
||||
'ne': (1, 1), # Diagonal top-right
|
||||
'nw': (-1, 1), # Diagonal top-left
|
||||
'se': (1, -1), # Diagonal bottom-right
|
||||
'sw': (-1, -1) # Diagonal bottom-left
|
||||
}
|
||||
|
||||
def __init__(self, rooms, exits):
|
||||
@@ -33,10 +35,16 @@ class PositionCalculator:
|
||||
next_room_uid = exit.to_room
|
||||
# Search for the next room to position it nearby in the grid
|
||||
next_room = next((r for r in self.rooms if r.uid == next_room_uid), None)
|
||||
if not next_room:
|
||||
print(f"Warning: Room with UID '{next_room_uid}' not found.")
|
||||
continue
|
||||
|
||||
if not next_room:
|
||||
print(f"Warning: Room with UID '{next_room_uid}' not found. Adding a stub room.")
|
||||
# Create a stub room with some default properties
|
||||
stub_room = Room(uid=next_room_uid, name=f"Outside ({next_room_uid})",
|
||||
area=0, notes="This is a placeholder room", data={"outside": True})
|
||||
self.rooms.append(stub_room)
|
||||
next_room = stub_room
|
||||
|
||||
# If the room is not in the visited set, continue positioning
|
||||
if next_room.uid not in visited:
|
||||
offset = self.direction_to_offset(direction)
|
||||
next_position = (position[0] + offset[0], position[1] + offset[1])
|
||||
@@ -49,19 +57,64 @@ class PositionCalculator:
|
||||
self._place_room(start_room, (0, 0), set())
|
||||
|
||||
def ensure_no_collisions(self):
|
||||
"""Ensure there are no missing positions, using a structured grid."""
|
||||
"""Ensure there are no missing positions, using row/column shifting to manage collisions."""
|
||||
missing_positions = [room.uid for room in self.rooms if room.uid not in self.positions]
|
||||
if missing_positions:
|
||||
print(f"Missing positions: {missing_positions}")
|
||||
|
||||
for room_uid in missing_positions:
|
||||
existing_rooms = self.positions.values()
|
||||
for x, y in existing_rooms:
|
||||
placed = False
|
||||
# Attempt to find a free space around existing placed rooms
|
||||
for (x, y) in self.positions.values():
|
||||
free_position = self.find_free_position((x, y))
|
||||
if free_position:
|
||||
print(f"Placing Room '{room_uid}' at position {free_position}")
|
||||
self.positions[room_uid] = free_position
|
||||
self.grid[free_position] = room_uid
|
||||
placed = True
|
||||
break
|
||||
|
||||
# If no free space, we need to shift rows/columns to make space
|
||||
if not placed:
|
||||
first_existing_room_pos = next(iter(self.positions.values())) # Get any position from placed rooms
|
||||
print(f"Shifting grid to make room for Room '{room_uid}'...")
|
||||
self._shift_grid(room_uid, first_existing_room_pos)
|
||||
|
||||
def _shift_grid(self, room_uid, conflict_position):
|
||||
"""Shift an entire row/column in the grid to create space."""
|
||||
# Let's focus on shifting rows first (you can expand to columns similarly)
|
||||
x, y = conflict_position
|
||||
|
||||
# Decide based on whether there is more space up or down the grid
|
||||
if (x, y + 1) not in self.grid: # Try shifting down
|
||||
self._shift_row(y, 1) # Shift all rooms at y or below by 1 unit downwards
|
||||
new_position = (x, y + 1)
|
||||
elif (x, y - 1) not in self.grid: # Try shifting up
|
||||
self._shift_row(y, -1) # Shift all rooms at y or above by 1 unit upwards
|
||||
new_position = (x, y - 1)
|
||||
else:
|
||||
new_position = None # In case shifting is impossible (fallback)
|
||||
|
||||
if new_position is not None:
|
||||
print(f"Room '{room_uid}' moved to: {new_position}")
|
||||
self.positions[room_uid] = new_position
|
||||
self.grid[new_position] = room_uid
|
||||
else:
|
||||
print(f"Warning: Room '{room_uid}' could not find space after row shifting!")
|
||||
|
||||
def _shift_row(self, y, shift_val):
|
||||
"""Helper function to shift a row of rooms up or down in the grid."""
|
||||
# Gather all rooms in the row to be shifted
|
||||
row_rooms = {(x, ry): node for (x, ry), node in list(self.grid.items()) if ry >= y} if shift_val > 0 \
|
||||
else {(x, ry): node for (x, ry), node in list(self.grid.items()) if ry <= y}
|
||||
|
||||
# Shift each room in the row by the shift_val
|
||||
for (x, old_y), node in row_rooms.items():
|
||||
new_position = (x, old_y + shift_val)
|
||||
self.grid[new_position] = node
|
||||
self.positions[node] = new_position
|
||||
del self.grid[(x, old_y)] # Clear the old position in the grid
|
||||
|
||||
def find_free_position(self, position):
|
||||
"""Find the first available adjacent position."""
|
||||
for direction, (dx, dy) in self.compass_directions.items():
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from parser import MapParser
|
||||
from graph_generator import GraphGenerator
|
||||
from position_calculator import PositionCalculator
|
||||
from graph_renderer import GraphRenderer
|
||||
import os
|
||||
import json
|
||||
|
||||
@@ -24,7 +25,13 @@ if __name__ == "__main__":
|
||||
)
|
||||
)
|
||||
print(f"Saved {cache_file}")
|
||||
gr = GraphGenerator(rooms, exits)
|
||||
gr.generate_graph()
|
||||
gr.draw_graph()
|
||||
|
||||
calculator = PositionCalculator(rooms, exits)
|
||||
calculator.assign_positions()
|
||||
calculator.ensure_no_collisions()
|
||||
positions = calculator.get_positions()
|
||||
|
||||
renderer = GraphRenderer(rooms, exits, positions)
|
||||
renderer.generate_graph()
|
||||
renderer.draw_graph()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user