Skip to content

Commit a755a00

Browse files
committed
Reformat code
1 parent 39aa5f2 commit a755a00

File tree

7 files changed

+113
-77
lines changed

7 files changed

+113
-77
lines changed

src/floors/floor.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ def to_json(self, indent: int):
7373
current_index: int = 0
7474
max_index: int = len(self._rooms)
7575
json_string = (
76-
"{\n"
77-
+ f'{indent_s}"_seed": "{self.seed}",\n'
78-
+ indent_s
79-
+ '"_rooms"'
80-
+ ": ["
76+
"{\n"
77+
+ f'{indent_s}"_seed": "{self.seed}",\n'
78+
+ indent_s
79+
+ '"_rooms"'
80+
+ ": ["
8181
)
8282
if len(self._rooms) == 0:
8383
json_string += "]"
@@ -98,7 +98,9 @@ def from_json(cls, json_string: str):
9898
Creates a floor object from a json string.
9999
"""
100100
json_dict = json.loads(json_string)
101-
floor = Floor(json_dict["_height"], json_dict["_width"], json_dict["_floor"]["_seed"])
101+
floor = Floor(
102+
json_dict["_height"], json_dict["_width"], json_dict["_floor"]["_seed"]
103+
)
102104
rooms = json_dict["_floor"]["_rooms"]
103105
for room in rooms:
104106
floor._rooms.append(Room.from_dict(room))
@@ -113,7 +115,7 @@ def add_to_floor_grid(self, x: int, y: int) -> None:
113115
self._floor_grid[y][x] = 1
114116

115117
def add_room(
116-
self, x: int, y: int, room_type: RoomType = RoomType.NORMAL_ROOM
118+
self, x: int, y: int, room_type: RoomType = RoomType.NORMAL_ROOM
117119
) -> None:
118120
"""
119121
Creates and adds a room to the floor.
@@ -126,7 +128,7 @@ def add_room(
126128
self._room_id += 1
127129

128130
def add_room_next_to(
129-
self, room: Room, direction: Direction, room_type: RoomType
131+
self, room: Room, direction: Direction, room_type: RoomType
130132
) -> None:
131133
"""
132134
Creates and adds a room next to a given room.
@@ -262,8 +264,12 @@ def has_boos_room_as_neighbour(self, coordinates: Tuple[int, int]) -> bool:
262264
@return: True if the coordinates have a boss room as neighbour otherwise False
263265
"""
264266
for direction in Direction.main_directions():
265-
new_coordinates = utils.util_functions.add_direction_to_coordinates(direction, coordinates)
266-
if self.is_within_border(new_coordinates) and self.contains_room(new_coordinates):
267+
new_coordinates = utils.util_functions.add_direction_to_coordinates(
268+
direction, coordinates
269+
)
270+
if self.is_within_border(new_coordinates) and self.contains_room(
271+
new_coordinates
272+
):
267273
room = self._get_room(new_coordinates)
268274
if room.get_type() == RoomType.BOSS_ROOM:
269275
return True
@@ -282,8 +288,12 @@ def has_special_room_as_neighbour(self, coordinates: Tuple[int, int]) -> bool:
282288
@return: True if the coordinates have a special room as neighbour otherwise False
283289
"""
284290
for direction in Direction.main_directions():
285-
new_coordinates = utils.util_functions.add_direction_to_coordinates(direction, coordinates)
286-
if self.is_within_border(new_coordinates) and self.contains_room(new_coordinates):
291+
new_coordinates = utils.util_functions.add_direction_to_coordinates(
292+
direction, coordinates
293+
)
294+
if self.is_within_border(new_coordinates) and self.contains_room(
295+
new_coordinates
296+
):
287297
room = self._get_room(new_coordinates)
288298
if room.get_type().is_special():
289299
return True

src/generators/floor_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class FloorManager:
1414
"""
1515
Class to manage the floors of the tkinter generator.
1616
"""
17+
1718
def __init__(self, output_file_name: str) -> None:
1819
"""
1920
Creates a new floor manager.

src/generators/generator.py

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class Generator:
2626
"""
2727

2828
def __init__(
29-
self,
30-
seed: str,
31-
output_file_name: str,
32-
output_file_path: str = "",
33-
stage_id: int = 2,
29+
self,
30+
seed: str,
31+
output_file_name: str,
32+
output_file_path: str = "",
33+
stage_id: int = 2,
3434
):
3535
"""
3636
Creates a new generator with the given arguments.
@@ -53,22 +53,22 @@ def to_json(self, indent: int) -> str:
5353
indent_s = my_globals.BASE_INDENT * indent
5454

5555
j = (
56-
"{\n"
57-
+ indent_s
58-
+ '"_width": '
59-
+ str(my_globals.FLOOR_WIDTH)
60-
+ ",\n"
61-
+ indent_s
62-
+ '"_height": '
63-
+ str(my_globals.FLOOR_HEIGHT)
64-
+ ",\n"
65-
+ indent_s
66-
+ '"_floor": '
67-
+ self._floor.to_json(indent + 1)
68-
+ ",\n"
69-
+ indent_s
70-
+ '"_generated_by": "python"'
71-
+ "\n}"
56+
"{\n"
57+
+ indent_s
58+
+ '"_width": '
59+
+ str(my_globals.FLOOR_WIDTH)
60+
+ ",\n"
61+
+ indent_s
62+
+ '"_height": '
63+
+ str(my_globals.FLOOR_HEIGHT)
64+
+ ",\n"
65+
+ indent_s
66+
+ '"_floor": '
67+
+ self._floor.to_json(indent + 1)
68+
+ ",\n"
69+
+ indent_s
70+
+ '"_generated_by": "python"'
71+
+ "\n}"
7272
)
7373
return j
7474

@@ -78,7 +78,9 @@ def _create_floor(self) -> None:
7878
"""
7979
self._floor = Floor(my_globals.FLOOR_HEIGHT, my_globals.FLOOR_WIDTH, self._seed)
8080

81-
def _add_new_room(self, new_room_tuple: Tuple[int, int], room_tuple_queue: deque) -> bool:
81+
def _add_new_room(
82+
self, new_room_tuple: Tuple[int, int], room_tuple_queue: deque
83+
) -> bool:
8284
"""
8385
Checks if a room can be added at the new position
8486
and if possible adds it to the queue and floor grid.
@@ -87,10 +89,12 @@ def _add_new_room(self, new_room_tuple: Tuple[int, int], room_tuple_queue: deque
8789
@return: True if the position was added to the queue otherwise False
8890
"""
8991
if (
90-
self._floor.is_within_border(new_room_tuple)
91-
and (not self._floor.contains_room(new_room_tuple))
92-
and (self._floor.count_neighbours(new_room_tuple[0], new_room_tuple[1]) <= 1)
93-
and util_functions.place_room()
92+
self._floor.is_within_border(new_room_tuple)
93+
and (not self._floor.contains_room(new_room_tuple))
94+
and (
95+
self._floor.count_neighbours(new_room_tuple[0], new_room_tuple[1]) <= 1
96+
)
97+
and util_functions.place_room()
9498
):
9599
room_tuple_queue.append(new_room_tuple)
96100
self._floor.add_to_floor_grid(*new_room_tuple)
@@ -155,8 +159,8 @@ def mark_dead_ends(self) -> list:
155159
for i in range(len(floor.get_rooms())):
156160
room = floor.get_rooms()[i]
157161
if (
158-
floor.is_dead_end(room[0], room[1])
159-
and room.get_type() == RoomType.NORMAL_ROOM
162+
floor.is_dead_end(room[0], room[1])
163+
and room.get_type() == RoomType.NORMAL_ROOM
160164
):
161165
room.set_type(RoomType.DEAD_END)
162166
dead_end_indices += (i,)
@@ -205,9 +209,9 @@ def add_boss_room(self, dead_end_indices: list, start_room: tuple) -> None:
205209
direction, (boss_room_x, boss_room_y)
206210
)
207211
if (
208-
self._floor.is_within_border(new_boss_tuple)
209-
and floor.count_neighbours(new_boss_tuple[0], new_boss_tuple[1]) == 1
210-
and not self._floor.contains_room(new_boss_tuple)
212+
self._floor.is_within_border(new_boss_tuple)
213+
and floor.count_neighbours(new_boss_tuple[0], new_boss_tuple[1]) == 1
214+
and not self._floor.contains_room(new_boss_tuple)
211215
):
212216
possible_locations.append(direction)
213217

@@ -221,9 +225,9 @@ def add_boss_room(self, dead_end_indices: list, start_room: tuple) -> None:
221225
boss_room_placed = self._place_big_boss_room(possible_locations, boss_room)
222226

223227
if (
224-
not boss_room_placed
225-
and len(possible_locations) >= 1
226-
and random.randint(0, 10) < 5
228+
not boss_room_placed
229+
and len(possible_locations) >= 1
230+
and random.randint(0, 10) < 5
227231
):
228232
# Create a 1 * 2 boss-room
229233
floor.add_room_next_to(boss_room, possible_locations[0], RoomType.BOSS_ROOM)
@@ -249,9 +253,9 @@ def _place_big_boss_room(self, possible_locations: List, boss_room: Room) -> boo
249253
direction[2], (boss_room[0], boss_room[1])
250254
)
251255
if (
252-
direction[0] in possible_locations
253-
and direction[1] in possible_locations
254-
and self._floor.has_no_neighbours(corner)
256+
direction[0] in possible_locations
257+
and direction[1] in possible_locations
258+
and self._floor.has_no_neighbours(corner)
255259
):
256260
self._add_rooms_next_to_room(boss_room, direction)
257261
return True
@@ -272,17 +276,17 @@ def _place_boss_with_teleport_room(self, boss_room) -> None:
272276
boss_room.set_cord(0, my_globals.FLOOR_HEIGHT - 1)
273277

274278
elif self._check_if_not_contains_room_and_has_no_neighbours(
275-
floor.bottom_left()
279+
floor.bottom_left()
276280
):
277281
boss_room.set_cord(my_globals.FLOOR_WIDTH - 1, my_globals.FLOOR_HEIGHT - 1)
278282

279283
elif self._check_if_not_contains_room_and_has_no_neighbours(
280-
floor.bottom_right()
284+
floor.bottom_right()
281285
):
282286
boss_room.set_cord(my_globals.FLOOR_WIDTH - 1, 0)
283287

284288
def _check_if_not_contains_room_and_has_no_neighbours(
285-
self, point: Tuple[int, int]
289+
self, point: Tuple[int, int]
286290
) -> bool:
287291
floor = self._floor
288292
return not floor.contains_room(
@@ -316,9 +320,12 @@ def place_super_secret_room(self) -> None:
316320
neighbour = util_functions.add_direction_to_coordinates(
317321
direction, (room[0], room[1])
318322
)
319-
if (floor.is_within_border(neighbour) and not floor.contains_room(neighbour)
320-
and not floor.has_boos_room_as_neighbour(neighbour)
321-
and floor.count_neighbours(neighbour[0],neighbour[1]) == 1):
323+
if (
324+
floor.is_within_border(neighbour)
325+
and not floor.contains_room(neighbour)
326+
and not floor.has_boos_room_as_neighbour(neighbour)
327+
and floor.count_neighbours(neighbour[0], neighbour[1]) == 1
328+
):
322329
distance = util_functions.calculate_distance(boss_room, neighbour)
323330
if distance < distance_to_boss:
324331
distance_to_boss = distance
@@ -336,12 +343,16 @@ def place_secret_room(self) -> None:
336343
while not secret_room_placed:
337344
for room in reversed(floor.get_rooms()):
338345
# Check all neighbours of the room
339-
secret_room_placed = self._check_directions_for_secret_room(room, neighbour_rooms)
346+
secret_room_placed = self._check_directions_for_secret_room(
347+
room, neighbour_rooms
348+
)
340349
if secret_room_placed:
341350
break
342351
neighbour_rooms -= 1
343352

344-
def _check_directions_for_secret_room(self, room: Room, neighbour_rooms: int) -> bool:
353+
def _check_directions_for_secret_room(
354+
self, room: Room, neighbour_rooms: int
355+
) -> bool:
345356
"""
346357
Checks if a secret room can be placed next to a given room.
347358
@param room: room to check
@@ -358,7 +369,10 @@ def _check_directions_for_secret_room(self, room: Room, neighbour_rooms: int) ->
358369
if floor.has_special_room_as_neighbour(neighbour):
359370
continue
360371
current_neighbour = floor.count_neighbours(neighbour[0], neighbour[1])
361-
if current_neighbour >= neighbour_rooms and not floor.has_boos_room_as_neighbour(neighbour):
372+
if (
373+
current_neighbour >= neighbour_rooms
374+
and not floor.has_boos_room_as_neighbour(neighbour)
375+
):
362376
floor.add_room(neighbour[0], neighbour[1], RoomType.SECRET_ROOM)
363377
return True
364378
return False

src/generators/theme_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ThemeHandler:
99
"""
1010
Class to handle the theme of the application.
1111
"""
12+
1213
def __init__(self, tk: Tk, canvas: Canvas) -> None:
1314
"""
1415
Creates a new theme handler.

src/generators/tkinter_generator.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TkinterGenerator(Generator):
2323
"""
2424

2525
def __init__(
26-
self, seed: str, output_file_name: str, output_file_path: str, stage_id: int = 2
26+
self, seed: str, output_file_name: str, output_file_path: str, stage_id: int = 2
2727
):
2828
"""
2929
Creates a new generator.
@@ -47,14 +47,19 @@ def __init__(
4747
self._menu_bar = tk.Menu(self._tk)
4848
self._theme_handler = ThemeHandler(self._tk, self._canvas)
4949
self._floor_manager = FloorManager(output_file_name)
50-
self._tk.protocol('WM_DELETE_WINDOW', self.quit)
50+
self._tk.protocol("WM_DELETE_WINDOW", self.quit)
5151

5252
def _create_floor(self) -> None:
5353
"""
5454
Creates a new TkinterFloor and appends it to the floor queue.
5555
"""
56-
self._floor = TkinterFloor(my_globals.FLOOR_HEIGHT, my_globals.FLOOR_WIDTH, self._canvas,
57-
my_globals.DEFAULT_FLOOR_NAME + my_globals.JSON_SUFFIX, self._seed)
56+
self._floor = TkinterFloor(
57+
my_globals.FLOOR_HEIGHT,
58+
my_globals.FLOOR_WIDTH,
59+
self._canvas,
60+
my_globals.DEFAULT_FLOOR_NAME + my_globals.JSON_SUFFIX,
61+
self._seed,
62+
)
5863
self._floor_manager.add_new_floor(self._floor, self._canvas)
5964
self._floor = self._floor_manager.get_current_floor()
6065

@@ -107,7 +112,7 @@ def save(self, path: str = "") -> str:
107112
if os.path.exists(path):
108113
# Show dialog for overwriting the file
109114
if messagebox.askyesno(
110-
"File already exists", "Do you want to overwrite the file?"
115+
"File already exists", "Do you want to overwrite the file?"
111116
):
112117
save_file = True
113118
else:
@@ -164,8 +169,7 @@ def add_information_frame(self) -> None:
164169
name_text = ttk.Label(information_frame, text="Floor name: ")
165170
name_text.pack(side=tk.LEFT)
166171
name_label = ttk.Label(
167-
information_frame,
168-
textvariable=self._floor_manager.current_floor_name
172+
information_frame, textvariable=self._floor_manager.current_floor_name
169173
)
170174
name_label.pack(side=tk.LEFT)
171175
path_text = ttk.Label(information_frame, text="Current path: ")
@@ -175,8 +179,7 @@ def add_information_frame(self) -> None:
175179
seed_text = ttk.Label(information_frame, text="Seed: ")
176180
seed_text.pack(side=tk.LEFT, padx=(25, 0))
177181
seed_label = ttk.Label(
178-
information_frame,
179-
textvariable=self._floor_manager.current_floor_seed_var
182+
information_frame, textvariable=self._floor_manager.current_floor_seed_var
180183
)
181184
seed_label.pack(side=tk.LEFT)
182185

@@ -218,7 +221,9 @@ def add_buttons(self) -> None:
218221
# Next seed entry
219222
next_seed_label = ttk.Label(button_frame, text="Next seed: ")
220223
next_seed_label.pack(side=tk.LEFT, padx=10)
221-
next_seed_entry = ttk.Entry(button_frame, textvariable=self._floor_manager.next_seed)
224+
next_seed_entry = ttk.Entry(
225+
button_frame, textvariable=self._floor_manager.next_seed
226+
)
222227
next_seed_entry.bind(
223228
"<Return>", lambda event: self._floor_manager.set_next_seed()
224229
)
@@ -243,7 +248,11 @@ def create_menu_bar(self) -> None:
243248
label="Save As", command=self.save, accelerator="Ctrl+Shift+s"
244249
)
245250
menu_bar.add_command(
246-
label="Switch Theme", command=self._theme_handler.switch_theme, accelerator="Ctrl+t"
251+
label="Switch Theme",
252+
command=self._theme_handler.switch_theme,
253+
accelerator="Ctrl+t",
254+
)
255+
menu_bar.add_command(
256+
label="Legend", command=legend_window.display_legend, accelerator="F1"
247257
)
248-
menu_bar.add_command(label="Legend", command=legend_window.display_legend, accelerator="F1")
249258
menu_bar.add_command(label="Exit", command=self.quit, accelerator="Ctrl+q")

src/rooms/tkinter/legend_window.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ def display_legend():
2121
room_type: RoomType
2222
for room_type in RoomType.get_all():
2323
color: my_globals.Color = room_colors[room_type]
24-
legend_canvas.create_rectangle(10, y_offset, 30, y_offset + 20, fill=util_functions.rgb2hex(*color.value))
25-
legend_canvas.create_text(40, y_offset + 10, anchor=tk.W, text=room_names[room_type])
24+
legend_canvas.create_rectangle(
25+
10, y_offset, 30, y_offset + 20, fill=util_functions.rgb2hex(*color.value)
26+
)
27+
legend_canvas.create_text(
28+
40, y_offset + 10, anchor=tk.W, text=room_names[room_type]
29+
)
2630
y_offset += 30
27-
28-
29-

0 commit comments

Comments
 (0)