diff options
Diffstat (limited to 'scripts/generate_map_img.py')
| -rwxr-xr-x | scripts/generate_map_img.py | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/scripts/generate_map_img.py b/scripts/generate_map_img.py index 84a72abb..ee30cd90 100755 --- a/scripts/generate_map_img.py +++ b/scripts/generate_map_img.py @@ -11,10 +11,12 @@ MAP_ROOT = pathlib.Path(os.getcwd()) TILES_DIR = MAP_ROOT / '../assets/tiles' SHOW_MAP = False + def get_tile_path(tile: str) -> pathlib.Path: """Return the corresponding image file name for a tile""" return TILES_DIR / f'{tile.lower().replace(" ", "_")}.png' + def generate_img(map_path: pathlib.Path): """Generate a image from a map file""" with open(map_path, 'r') as map_file: @@ -46,14 +48,17 @@ def generate_img(map_path: pathlib.Path): # find the right street and rotation if tile == 'street': # check continuations - left = j > 1 and row[j-1] == 'street' - right = j < len(row) - 1 and row[j+1] == 'street' - above = i > 1 and tiles[i-1][j] == 'street' - below = i < len(tiles) - 1 and tiles[i+1][j] == 'street' + left = j > 1 and row[j - 1] == 'street' + right = j < len(row) - 1 and row[j + 1] == 'street' + above = i > 1 and tiles[i - 1][j] == 'street' + below = i < len(tiles) - 1 and tiles[i + 1][j] == 'street' - connections = len([b for b in [left, right, above, below] if b == True]) + connections = len( + [b for b in [left, right, above, below] if b == True]) # straight lines - if connections == 1 or (connections == 2 and ((left and right) or (above and below))): + if connections == 1 or (connections == 2 and + ((left and right) or + (above and below))): tile_img = cv2.imread(str(get_tile_path('street'))) if above or below: tile_img = numpy.rot90(tile_img) @@ -92,13 +97,18 @@ def generate_img(map_path: pathlib.Path): cv2.waitKey(0) cv2.imwrite(f'{map_path.stem}.png', map_img) + def main(): """Generate map images from map files""" - parser = argparse.ArgumentParser(description='generate latex standalone cards') - parser.add_argument('map_input', help='map file or directory containing map files') + parser = argparse.ArgumentParser( + description='generate latex standalone cards') + parser.add_argument('map_input', + help='map file or directory containing map files') parser.add_argument('--map-root', help='path to the map root directory') - parser.add_argument('--show-map', help='show the generated map', action='store_true') + parser.add_argument('--show-map', + help='show the generated map', + action='store_true') args = parser.parse_args() @@ -120,5 +130,6 @@ def main(): for m in map_files: generate_img(m) + if __name__ == '__main__': main() |
