|
1 | 1 | """ |
2 | 2 | This module contains utility functions for the floor generator. |
3 | 3 | """ |
| 4 | +import os |
4 | 5 | import random |
5 | 6 | import math |
6 | 7 | from typing import Tuple |
7 | 8 |
|
8 | 9 | import utils.globals as my_globals |
9 | 10 | from utils.direction import Direction |
| 11 | +from utils.room_type import RoomType |
| 12 | +from PIL import Image, ImageTk |
| 13 | + |
| 14 | + |
| 15 | +def get_picture_for_room_type(room_type: RoomType) -> ImageTk: |
| 16 | + """ |
| 17 | + Gets the picture for the given room type. |
| 18 | + @param room_type: room type to get the picture for |
| 19 | + @return: picture for the given room type |
| 20 | + """ |
| 21 | + # Get the directory of the current file |
| 22 | + current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 23 | + # Go up two levels to the project root directory |
| 24 | + project_root = os.path.dirname(os.path.dirname(current_dir)) |
| 25 | + # Define the relative path to the image file |
| 26 | + image_file = f"{room_type.name.lower()}.png" |
| 27 | + # Join the project root directory with the relative path to get the absolute path |
| 28 | + image_path = os.path.join(project_root, "resources", "room_icons", image_file) |
| 29 | + try: |
| 30 | + return ImageTk.PhotoImage( |
| 31 | + Image.open( |
| 32 | + image_path |
| 33 | + ).resize((32, 32)) |
| 34 | + ) |
| 35 | + except FileNotFoundError: |
| 36 | + return None |
10 | 37 |
|
11 | 38 |
|
12 | 39 | def calculate_room_amount(stage_id: int): |
@@ -36,7 +63,7 @@ def rgb2hex(r, g, b): |
36 | 63 |
|
37 | 64 |
|
38 | 65 | def add_direction_to_coordinates( |
39 | | - direction: Direction, coordinates: Tuple[int, int] |
| 66 | + direction: Direction, coordinates: Tuple[int, int] |
40 | 67 | ) -> Tuple[int, int]: |
41 | 68 | """ |
42 | 69 | Calculates the room according to the given room and direction |
@@ -81,5 +108,5 @@ def calculate_distance(cord1, cord2) -> int: |
81 | 108 | Calculates the distance between two points. |
82 | 109 | """ |
83 | 110 | return (cord1[0] - cord2[0]) * (cord1[0] - cord2[0]) + (cord1[1] - cord2[1]) * ( |
84 | | - cord1[1] - cord2[1] |
| 111 | + cord1[1] - cord2[1] |
85 | 112 | ) |
0 commit comments