aboutsummaryrefslogtreecommitdiff
path: root/scripts/generate_map_img.py
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2021-03-27 11:34:28 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2021-03-27 11:35:41 +0100
commit795939a2cf91100b05a81cd597fdb1d47ff76270 (patch)
treeb9fe071342b95da9405e1ad5ab9d252983ab903c /scripts/generate_map_img.py
parent18a43ec42d0fc83a49c27ab36886567152eb7fcc (diff)
downloadmuhqs-game-795939a2cf91100b05a81cd597fdb1d47ff76270.tar.gz
muhqs-game-795939a2cf91100b05a81cd597fdb1d47ff76270.zip
add script Makefile, python tooling and run yapf in generate_map_img.py
Diffstat (limited to 'scripts/generate_map_img.py')
-rwxr-xr-xscripts/generate_map_img.py29
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()