diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2021-10-10 14:48:38 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2021-10-10 14:48:38 +0200 |
| commit | 163cafc1866b7e6aca821585ba131f0e5143f21f (patch) | |
| tree | f4f0cf69a15c01d8e5b93a1f7f513c8b8b042d80 /scripts/generate_map_img.py | |
| parent | 3a29bcfa511a884849815921ca27ce6babf20b85 (diff) | |
| download | muhqs-game-163cafc1866b7e6aca821585ba131f0e5143f21f.tar.gz muhqs-game-163cafc1866b7e6aca821585ba131f0e5143f21f.zip | |
[generate_map_img] fix pylint warnings and type hints
Diffstat (limited to 'scripts/generate_map_img.py')
| -rwxr-xr-x | scripts/generate_map_img.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/scripts/generate_map_img.py b/scripts/generate_map_img.py index f3b3671d..8dff559e 100755 --- a/scripts/generate_map_img.py +++ b/scripts/generate_map_img.py @@ -6,7 +6,7 @@ import os from typing import Sequence, Tuple import yaml -import cv2 +import cv2 # type: ignore import numpy MAP_ROOT = pathlib.Path(os.getcwd()) @@ -35,7 +35,9 @@ def is_connected_to(tiles: Tiles, return left, right, above, below -def count_connections(left:bool , right:bool, above:bool, below:bool) -> int: + +def count_connections(left: bool, right: bool, above: bool, + below: bool) -> int: return len([b for b in [left, right, above, below] if b is True]) @@ -162,7 +164,7 @@ def find_gate_tile(tiles: Sequence[Sequence[str]], x: int, y: int): def generate_img(map_path: pathlib.Path): """Generate a image from a map file""" - with open(map_path, 'r') as map_file: + with open(map_path, 'r', encoding="utf8") as map_file: map_definition = yaml.full_load(map_file) # remove the trailing new line @@ -210,6 +212,16 @@ def generate_img(map_path: pathlib.Path): cv2.imwrite(f'{map_path.stem}.png', map_img) +def main(map_input): + map_path = pathlib.Path(map_input) + map_files = [map_path] + if map_path.is_dir(): + map_files = map_path.glob('*.yml') + + for m in map_files: + generate_img(m) + + if __name__ == '__main__': parser = argparse.ArgumentParser( description='generate latex standalone cards') @@ -229,10 +241,4 @@ if __name__ == '__main__': if args.show_map: SHOW_MAP = True - map_path = pathlib.Path(args.map_input) - map_files = [map_path] - if map_path.is_dir(): - map_files = map_path.glob('*.yml') - - for m in map_files: - generate_img(m) + main(args.map_input) |
