diff options
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) |
