From 2703987b24923681fc77120e5419ca66cd345874 Mon Sep 17 00:00:00 2001 From: Joltras <72395471+Joltras@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:14:08 +0000 Subject: [PATCH 1/6] fix: use consistent import path in legend window --- src/rooms/tkinter/legend_window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rooms/tkinter/legend_window.py b/src/rooms/tkinter/legend_window.py index 3a71fbe..1b3c737 100644 --- a/src/rooms/tkinter/legend_window.py +++ b/src/rooms/tkinter/legend_window.py @@ -4,7 +4,7 @@ import tkinter as tk -import src.utils.globals as my_globals +import utils.globals as my_globals from utils import util_functions from utils.room_type import RoomType, room_colors, room_names From 1893da827cfe8b99f34ef0cb001f91ecd24f1115 Mon Sep 17 00:00:00 2001 From: Joltras <72395471+Joltras@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:14:08 +0000 Subject: [PATCH 2/6] fix: resolve mypy type errors --- src/floors/floor.py | 10 ++++------ src/floors/tkinter_floor.py | 12 ++++++++++-- src/generators/floor_manager.py | 4 +++- src/generators/generator.py | 8 +++----- src/generators/tkinter_generator.py | 2 ++ src/main.py | 5 ++--- src/rooms/room.py | 7 ++++--- src/utils/util_functions.py | 20 ++------------------ 8 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/floors/floor.py b/src/floors/floor.py index c6a9248..8790a3f 100644 --- a/src/floors/floor.py +++ b/src/floors/floor.py @@ -6,7 +6,7 @@ and contains the seed it was created with. """ import json -from typing import List, Tuple, TypeVar, Optional +from typing import List, Tuple, Optional import numpy as np @@ -18,8 +18,6 @@ from rooms.room import Room from rooms.teleport_room import TeleportRoom -T = TypeVar("T", bound=Room) - class Floor: """ @@ -33,7 +31,7 @@ def __init__(self, height: int, width: int, seed: str): @param height: height for the floor @param width: width for the floor """ - self._rooms: List[T] = [] + self._rooms: List[Room] = [] self._floor_grid = np.zeros((height, width)) self._width: int = width self._height: int = height @@ -271,7 +269,7 @@ def has_boos_room_as_neighbour(self, coordinates: Tuple[int, int]) -> bool: new_coordinates ): room = self._get_room(new_coordinates) - if room.get_type() == RoomType.BOSS_ROOM: + if room is not None and room.get_type() == RoomType.BOSS_ROOM: return True return False @@ -295,7 +293,7 @@ def has_special_room_as_neighbour(self, coordinates: Tuple[int, int]) -> bool: new_coordinates ): room = self._get_room(new_coordinates) - if room.get_type().is_special(): + if room is not None and room.get_type().is_special(): return True return False diff --git a/src/floors/tkinter_floor.py b/src/floors/tkinter_floor.py index e8f5379..90718db 100644 --- a/src/floors/tkinter_floor.py +++ b/src/floors/tkinter_floor.py @@ -4,6 +4,7 @@ import threading import time +from typing import List, cast from floors.floor import Floor from rooms.room import Room @@ -67,13 +68,20 @@ def from_floor(cls, floor: Floor, canvas, name: str): ) # pylint: disable=protected-access return tkinter_floor + def _tkinter_rooms(self) -> List[TkinterRoom]: + """ + Returns the rooms of the floor, which are all tkinter rooms. + @return: rooms + """ + return cast(List[TkinterRoom], self._rooms) + def draw(self) -> None: """ Draws the floor with all the rooms on the canvas. """ self.stop_drawing() self._canvas.delete("all") - for room in self._rooms: + for room in self._tkinter_rooms(): room.draw(self._canvas) def draw_thread(self) -> None: @@ -94,7 +102,7 @@ def draw_step_by_step(self) -> None: Draws the floor step by step. """ self._canvas.delete("all") - sorted_rooms = sorted(self._rooms, key=lambda r: r.get_id()) + sorted_rooms = sorted(self._tkinter_rooms(), key=lambda r: r.get_id()) self._is_drawing = True for room in sorted_rooms: if not self._is_drawing: diff --git a/src/generators/floor_manager.py b/src/generators/floor_manager.py index 78c6e1c..7e79225 100644 --- a/src/generators/floor_manager.py +++ b/src/generators/floor_manager.py @@ -5,6 +5,8 @@ import secrets import tkinter as tk from collections import deque +from typing import Deque + from utils import globals as my_globals from floors.tkinter_floor import TkinterFloor @@ -20,7 +22,7 @@ def __init__(self, output_file_name: str) -> None: Creates a new floor manager. @param output_file_name: name of the output file """ - self._floors = deque() + self._floors: Deque[TkinterFloor] = deque() self.current_floor_index = -1 self.current_floor_name = tk.StringVar() self.current_floor_name.set(output_file_name) diff --git a/src/generators/generator.py b/src/generators/generator.py index 0eac0be..5feb9f2 100644 --- a/src/generators/generator.py +++ b/src/generators/generator.py @@ -9,7 +9,7 @@ import random from collections import deque from datetime import datetime -from typing import List, Optional, TypeVar, Tuple +from typing import List, Optional, Tuple from floors.floor import Floor from rooms.room import Room @@ -17,8 +17,6 @@ from utils.direction import Direction from utils.room_type import RoomType -T = TypeVar("T", bound=Floor) - class Generator: """ @@ -45,7 +43,7 @@ def __init__( self._seed = seed self._output_file_name = output_file_name self._output_file_path = output_file_path - self._floor: T = Floor(my_globals.FLOOR_WIDTH, my_globals.FLOOR_HEIGHT, seed) + self._floor: Floor = Floor(my_globals.FLOOR_WIDTH, my_globals.FLOOR_HEIGHT, seed) self._random = random.Random(seed) def to_json(self, indent: int) -> str: @@ -159,7 +157,7 @@ def mark_dead_ends(self) -> list: Searches for dead ends in the floor and marks them ands returns their indices in a list. @return: indices of all dead ends """ - dead_end_indices = [] + dead_end_indices: List[int] = [] floor = self._floor for i in range(len(floor.get_rooms())): room = floor.get_rooms()[i] diff --git a/src/generators/tkinter_generator.py b/src/generators/tkinter_generator.py index 624b463..229a4a9 100644 --- a/src/generators/tkinter_generator.py +++ b/src/generators/tkinter_generator.py @@ -22,6 +22,8 @@ class TkinterGenerator(Generator): Tkinter version of the generator. """ + _floor: TkinterFloor + def __init__( self, seed: str, output_file_name: str, output_file_path: str, stage_id: int = 2 ): diff --git a/src/main.py b/src/main.py index 790995c..e8a297d 100644 --- a/src/main.py +++ b/src/main.py @@ -37,10 +37,9 @@ def main(seed: str, output: str, ui: bool, floor_id): print("No output folder found. Creating specific folder") if ui: - generator = TkinterGenerator( + TkinterGenerator( seed, my_globals.DEFAULT_FLOOR_NAME, output_folder, floor_id - ) - generator.run() + ).run() else: generator = Generator(seed=seed, output_file_name=output, stage_id=floor_id) generator.generate() diff --git a/src/rooms/room.py b/src/rooms/room.py index 22fe0e3..f5ac45d 100644 --- a/src/rooms/room.py +++ b/src/rooms/room.py @@ -4,6 +4,8 @@ A room has a type, coordinates and doors. """ +from typing import List + from utils import globals as my_globals from utils.globals import DoorFace, MAX_DOOR_AMOUNT from utils.room_type import RoomType @@ -27,7 +29,7 @@ def __init__(self, x: int, y: int, room_id: int, room_type: RoomType): self._y: int = y self._id: int = room_id self._type = room_type - self._doors = [] + self._doors: List[DoorFace] = [] def __getitem__(self, index: int) -> int: """ @@ -40,8 +42,7 @@ def __getitem__(self, index: int) -> int: raise ValueError(str(index) + "is not a valid index") if index == 0: return self._x - if index == 1: - return self._y + return self._y def to_json(self, indent: int) -> str: """ diff --git a/src/utils/util_functions.py b/src/utils/util_functions.py index 013be08..9903f48 100644 --- a/src/utils/util_functions.py +++ b/src/utils/util_functions.py @@ -75,24 +75,8 @@ def add_direction_to_coordinates( @param coordinates: start point for the calculation @return: calculated point """ - result = None - if direction is Direction.UP: - result = coordinates[0], coordinates[1] - 1 - if direction is Direction.DOWN: - result = coordinates[0], coordinates[1] + 1 - if direction is Direction.LEFT: - result = coordinates[0] - 1, coordinates[1] - if direction is Direction.RIGHT: - result = coordinates[0] + 1, coordinates[1] - if direction is Direction.UP_LEFT: - result = coordinates[0] - 1, coordinates[1] - 1 - if direction is Direction.UP_RIGHT: - result = coordinates[0] + 1, coordinates[1] - 1 - if direction is Direction.DOWN_LEFT: - result = coordinates[0] - 1, coordinates[1] + 1 - if direction is Direction.DOWN_RIGHT: - result = coordinates[0] + 1, coordinates[1] + 1 - return result + delta_x, delta_y = direction.value + return coordinates[0] + delta_x, coordinates[1] + delta_y json_file_options: dict = { From 1dd0dc12d767fe4e18885e4af4e2562c6084ffbf Mon Sep 17 00:00:00 2001 From: Joltras <72395471+Joltras@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:14:57 +0000 Subject: [PATCH 3/6] chore(ci): run flake8 and mypy --- .flake8 | 2 ++ .github/workflows/ci.yaml | 6 ++++++ pyproject.toml | 5 +++++ test/room_test.py | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..7da1f96 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 100 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ce1ddd0..b41d578 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,3 +38,9 @@ jobs: - name: Run pylint run: pylint src --rcfile=.pylintrc --fail-under=9.5 + + - name: Run flake8 + run: flake8 src test + + - name: Run mypy + run: mypy diff --git a/pyproject.toml b/pyproject.toml index e85ba17..3963431 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,8 @@ [tool.pytest.ini_options] pythonpath = ["src"] testpaths = ["test"] + +[tool.mypy] +mypy_path = "src" +explicit_package_bases = true +files = ["src"] diff --git a/test/room_test.py b/test/room_test.py index 4fa588c..239039e 100644 --- a/test/room_test.py +++ b/test/room_test.py @@ -69,7 +69,7 @@ def test_set_cord(self): def test_get_cord_with_exception(self): with self.assertRaises(ValueError, msg="20 is not a valid index"): - var = self._room[20] + _ = self._room[20] if __name__ == "__main__": From 1a9dee87ef0b1697cfe5a3c0b4a925a5bc894755 Mon Sep 17 00:00:00 2001 From: Joltras <72395471+Joltras@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:15:11 +0000 Subject: [PATCH 4/6] style: format code with black --- src/controller.py | 1 + src/floors/floor.py | 1 + src/generators/generator.py | 4 +++- src/rooms/teleport_room.py | 1 + src/rooms/tkinter/tkinter_room.py | 1 + src/utils/globals.py | 1 + src/utils/util_functions.py | 11 ++++------- test/generator_test.py | 13 ++++++++++--- 8 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/controller.py b/src/controller.py index fdd03cf..6f4718f 100644 --- a/src/controller.py +++ b/src/controller.py @@ -1,6 +1,7 @@ """ This module contains the FastAPI application and the endpoints for the floor generation. """ + import secrets from fastapi import FastAPI, Path diff --git a/src/floors/floor.py b/src/floors/floor.py index 8790a3f..e96ecc9 100644 --- a/src/floors/floor.py +++ b/src/floors/floor.py @@ -5,6 +5,7 @@ It also provides methods to save and load the floor as a json file and contains the seed it was created with. """ + import json from typing import List, Tuple, Optional diff --git a/src/generators/generator.py b/src/generators/generator.py index 5feb9f2..3a01253 100644 --- a/src/generators/generator.py +++ b/src/generators/generator.py @@ -43,7 +43,9 @@ def __init__( self._seed = seed self._output_file_name = output_file_name self._output_file_path = output_file_path - self._floor: Floor = Floor(my_globals.FLOOR_WIDTH, my_globals.FLOOR_HEIGHT, seed) + self._floor: Floor = Floor( + my_globals.FLOOR_WIDTH, my_globals.FLOOR_HEIGHT, seed + ) self._random = random.Random(seed) def to_json(self, indent: int) -> str: diff --git a/src/rooms/teleport_room.py b/src/rooms/teleport_room.py index 8e8659e..d3022b2 100644 --- a/src/rooms/teleport_room.py +++ b/src/rooms/teleport_room.py @@ -1,6 +1,7 @@ """ Teleport room module. """ + from rooms.room import Room from utils.room_type import RoomType diff --git a/src/rooms/tkinter/tkinter_room.py b/src/rooms/tkinter/tkinter_room.py index 661c9e1..724b00c 100644 --- a/src/rooms/tkinter/tkinter_room.py +++ b/src/rooms/tkinter/tkinter_room.py @@ -1,6 +1,7 @@ """ Module for TkinterRoom class. """ + import tkinter as tk from rooms.room import Room from utils import util_functions, globals as my_globals, room_type diff --git a/src/utils/globals.py b/src/utils/globals.py index f14beb9..acf3125 100644 --- a/src/utils/globals.py +++ b/src/utils/globals.py @@ -1,6 +1,7 @@ """ This file contains all the global constants used in the project. """ + import os from enum import Enum diff --git a/src/utils/util_functions.py b/src/utils/util_functions.py index 9903f48..1f75fc0 100644 --- a/src/utils/util_functions.py +++ b/src/utils/util_functions.py @@ -1,6 +1,7 @@ """ This module contains utility functions for the floor generator. """ + import os import random import math @@ -28,11 +29,7 @@ def get_picture_for_room_type(room_type: RoomType): # Join the project root directory with the relative path to get the absolute path image_path = os.path.join(project_root, "resources", "room_icons", image_file) try: - return ImageTk.PhotoImage( - Image.open( - image_path - ).resize((32, 32)) - ) + return ImageTk.PhotoImage(Image.open(image_path).resize((32, 32))) except FileNotFoundError: return None @@ -67,7 +64,7 @@ def rgb2hex(r, g, b): def add_direction_to_coordinates( - direction: Direction, coordinates: Tuple[int, int] + direction: Direction, coordinates: Tuple[int, int] ) -> Tuple[int, int]: """ Calculates the room according to the given room and direction @@ -96,5 +93,5 @@ def calculate_distance(cord1, cord2) -> int: Calculates the distance between two points. """ return (cord1[0] - cord2[0]) * (cord1[0] - cord2[0]) + (cord1[1] - cord2[1]) * ( - cord1[1] - cord2[1] + cord1[1] - cord2[1] ) diff --git a/test/generator_test.py b/test/generator_test.py index de67752..6ca175d 100644 --- a/test/generator_test.py +++ b/test/generator_test.py @@ -1,6 +1,7 @@ """ This file contains the test cases for the generator class. """ + import json import os import random @@ -33,14 +34,18 @@ def _reachable_coordinates(floor): while queue: current = queue.popleft() neighbour_coordinates = [ - (current[0] + dx, current[1] + dy) for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)) + (current[0] + dx, current[1] + dy) + for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)) ] if isinstance(current, TeleportRoom): connected_room = rooms_by_id[current.get_connected_room_id()] neighbour_coordinates.append((connected_room[0], connected_room[1])) for room in rooms: room_coordinates = (room[0], room[1]) - if room_coordinates in neighbour_coordinates and room_coordinates not in seen: + if ( + room_coordinates in neighbour_coordinates + and room_coordinates not in seen + ): seen.add(room_coordinates) queue.append(room) return seen, coordinates @@ -124,7 +129,9 @@ def test_add_special_rooms_assigns_item_and_shop_room(self): self.assertEqual(RoomType.ITEM_ROOM, floor.get_rooms()[1].get_type()) self.assertEqual(RoomType.SHOP_ROOM, floor.get_rooms()[2].get_type()) - def test_add_special_rooms_stops_when_there_are_fewer_dead_ends_than_special_rooms(self): + def test_add_special_rooms_stops_when_there_are_fewer_dead_ends_than_special_rooms( + self, + ): floor = self._generator._floor floor.add_room(2, 2, RoomType.START_ROOM) floor.add_room(1, 2, RoomType.DEAD_END) From b160e27b9a4f7a94c0863696a7097e587cf8fd6e Mon Sep 17 00:00:00 2001 From: Joltras <72395471+Joltras@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:15:12 +0000 Subject: [PATCH 5/6] chore(ci): check formatting with black --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b41d578..791e3b2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -42,5 +42,8 @@ jobs: - name: Run flake8 run: flake8 src test + - name: Check formatting + run: black --check src test + - name: Run mypy run: mypy From d05f132ed9aae00607d87ca48ba4ba76dc56d1d7 Mon Sep 17 00:00:00 2001 From: Joltras <72395471+Joltras@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:15:18 +0000 Subject: [PATCH 6/6] chore(ci): point invalid pr message to dev branch --- .github/workflows/close_invalid_prs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/close_invalid_prs.yaml b/.github/workflows/close_invalid_prs.yaml index 9064b67..d9956f1 100644 --- a/.github/workflows/close_invalid_prs.yaml +++ b/.github/workflows/close_invalid_prs.yaml @@ -15,4 +15,4 @@ jobs: if: github.head_ref == 'master' with: comment: | - Hi there! :wave: This PR is targeting the `master` branch, which is not allowed. Please target the `develop` branch instead. Thanks! \ No newline at end of file + Hi there! :wave: This PR is targeting the `master` branch, which is not allowed. Please target the `dev` branch instead. Thanks! \ No newline at end of file