diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-09-04 16:11:05 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-09-04 18:10:36 +0200 |
| commit | eb98e84558f1211eb28f7839fc178d9974187e37 (patch) | |
| tree | ac6259a5261295d1512f063b5bde6485b7c87bfd /scripts | |
| parent | 07758e639074a89b580f67cc807543a209672898 (diff) | |
| download | muhqs-game-eb98e84558f1211eb28f7839fc178d9974187e37.tar.gz muhqs-game-eb98e84558f1211eb28f7839fc178d9974187e37.zip | |
improve python scripts and pipenv environment
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/.pylint.rc | 6 | ||||
| -rwxr-xr-x | scripts/generate_boss_html.py | 7 | ||||
| -rwxr-xr-x | scripts/generate_card.py | 2 | ||||
| -rwxr-xr-x | scripts/generate_deck.py | 1 | ||||
| -rwxr-xr-x | scripts/generate_map_img.py | 62 |
5 files changed, 55 insertions, 23 deletions
diff --git a/scripts/.pylint.rc b/scripts/.pylint.rc index 4211e3be..7fc60c95 100644 --- a/scripts/.pylint.rc +++ b/scripts/.pylint.rc @@ -457,9 +457,9 @@ timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests. [MISCELLANEOUS] # List of note tags to take in consideration, separated by a comma. -notes=FIXME, - XXX, - TODO +notes=FIXME + #XXX, + #TODO # Regular expression of note tags to take in consideration. notes-rgx= diff --git a/scripts/generate_boss_html.py b/scripts/generate_boss_html.py index 12eadea3..f21c10e4 100755 --- a/scripts/generate_boss_html.py +++ b/scripts/generate_boss_html.py @@ -264,7 +264,8 @@ def gen_startdeck_ul(map_def: dict, lang: str) -> str: hlink = generate_card_hover_links.gen_hoverable_link( c, - lambda _: c, + # The closed-over c is immediately used in each loop iteration. + lambda _: c, # pylint: disable=W0640 gen_link_target, '../latex-build/', lang, @@ -284,8 +285,8 @@ def main(): help='the name of the boss', choices=['kraken', 'tyrant']) parser.add_argument('data', help='directory containing the card data') - parser.add_argument('maps', help='directoey containing the map data') - parser.add_argument('rules', help='directoey containing the rules') + parser.add_argument('maps', help='directory containing the map data') + parser.add_argument('rules', help='directory containing the rules') args = parser.parse_args() diff --git a/scripts/generate_card.py b/scripts/generate_card.py index c80271e3..d00dcb2c 100755 --- a/scripts/generate_card.py +++ b/scripts/generate_card.py @@ -152,7 +152,7 @@ def generate_markdown(card: MutableMapping, language='en', indentation=3): def gen_png_link_text(_): return 'png' - def gen_png_link_target(c, l): + def gen_png_link_target(_c, _l): return f'{built_card_path}.png' png_hover_link = generate_card_hover_links.gen_hoverable_link( diff --git a/scripts/generate_deck.py b/scripts/generate_deck.py index 8ccd12d0..75095e58 100755 --- a/scripts/generate_deck.py +++ b/scripts/generate_deck.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +"""Format a deck list as TeX or Markdown enumeration""" import argparse from pathlib import Path from data import name2set diff --git a/scripts/generate_map_img.py b/scripts/generate_map_img.py index 39c41a45..6923e2e5 100755 --- a/scripts/generate_map_img.py +++ b/scripts/generate_map_img.py @@ -6,7 +6,8 @@ import os from typing import Sequence, Tuple import yaml -import cv2 # type: ignore +import cv2 +import cv2.typing import numpy MAP_ROOT = pathlib.Path(os.getcwd()) @@ -49,7 +50,7 @@ def is_connected_to(tiles: Tiles, x: int, y: int, kind=None) -> Tuple[bool, bool, bool, bool]: - """Return a Quadruple of bools if the naeighbours of (x,y) are one of kind""" + """Return a Quadruple of bools if the neighbors of (x,y) are one of kind""" row = tiles[y] left = x > 0 and is_kind(row[x - 1], kind) right = x < len(row) - 1 and is_kind(row[x + 1], kind) @@ -65,7 +66,8 @@ def count_connections(left: bool, right: bool, above: bool, return len([b for b in [left, right, above, below] if b is True]) -def find_street_tile(tiles: Tiles, x: int, y: int): +def find_street_tile(tiles: Tiles, x: int, y: int) -> cv2.typing.MatLike: + """Return the appropriate street tile image""" # find street continuations left, right, above, below = is_connected_to(tiles, x, y, kind='street') @@ -87,12 +89,14 @@ def find_street_tile(tiles: Tiles, x: int, y: int): elif connections == 1 or (connections == 2 and ((left and right) or (above and below))): tile_img = cv2.imread(str(get_tile_path('street'))) + assert tile_img is not None if above or below: tile_img = numpy.rot90(tile_img) # elbow elif connections == 2: # normal orientation above and right tile_img = cv2.imread(str(get_tile_path('street_2'))) + assert tile_img is not None if right and below: tile_img = numpy.rot90(tile_img, 3) elif left and below: @@ -102,6 +106,7 @@ def find_street_tile(tiles: Tiles, x: int, y: int): elif connections == 3: # normal orientation left above right tile_img = cv2.imread(str(get_tile_path('street_3'))) + assert tile_img is not None if above and right and below: tile_img = numpy.rot90(tile_img, 3) elif left and below and right: @@ -111,10 +116,13 @@ def find_street_tile(tiles: Tiles, x: int, y: int): elif connections == 4: tile_img = cv2.imread(str(get_tile_path('street_4'))) + assert tile_img is not None return tile_img -def find_wall_tile(tiles: Sequence[Sequence[str]], x: int, y: int): +def find_wall_tile(tiles: Sequence[Sequence[str]], x: int, + y: int) -> cv2.typing.MatLike: + """Return the appropriate wall tile image""" # find fortification continuations left, right, above, below = is_connected_to(tiles, x, @@ -150,17 +158,21 @@ def find_wall_tile(tiles: Sequence[Sequence[str]], x: int, y: int): else: tile_img = cv2.imread(str(get_tile_path('wall_elbow_down'))) + assert tile_img is not None if left: tile_img = cv2.flip(tile_img, 1) - elif connections == 3 or connections == 4: + elif connections in (3, 4): # We don't have wall tiles for those structures yet use default vertical wall tile_img = cv2.imread(str(get_tile_path('wall'))) + assert tile_img is not None return tile_img -def find_gate_tile(tiles: Sequence[Sequence[str]], x: int, y: int): +def find_gate_tile(tiles: Sequence[Sequence[str]], x: int, + y: int) -> cv2.typing.MatLike: + """Return the appropriate gate tile image""" # find relevant structure tiles left, right, above, below = is_connected_to(tiles, x, @@ -170,19 +182,30 @@ def find_gate_tile(tiles: Sequence[Sequence[str]], x: int, y: int): connections = count_connections(left, right, above, below) if connections == 0: - return cv2.imread(str(get_tile_path('gate'))) + tile_img = cv2.imread(str(get_tile_path('gate'))) + + # Prefer double connected gates over single connected ones. + # Prefer horizontal gates over vertical ones. + elif left and right: + tile_img = cv2.imread(str(get_tile_path('gate_lr'))) + + elif above and below: + tile_img = cv2.imread(str(get_tile_path('gate_ud'))) # straight gates are the only special gates we have - if above or below: - return cv2.imread(str(get_tile_path('gate_ud'))) + elif left or right: + tile_img = cv2.imread(str(get_tile_path('gate_lr'))) - if left or right: - return cv2.imread(str(get_tile_path('gate_lr'))) + elif above or below: + tile_img = cv2.imread(str(get_tile_path('gate_ud'))) - return cv2.imread(str(get_tile_path('gate'))) + assert tile_img is not None + return tile_img -def find_tower_tile(tiles: Sequence[Sequence[str]], x: int, y: int): +def find_tower_tile(tiles: Sequence[Sequence[str]], x: int, + y: int) -> cv2.typing.MatLike: + """Return the appropriate tower tile image""" # find wall continuations left, right, above, below = is_connected_to(tiles, x, @@ -193,7 +216,9 @@ def find_tower_tile(tiles: Sequence[Sequence[str]], x: int, y: int): # This tower is not connected to a relevant structure if connections == 0: - return cv2.imread(str(get_tile_path('tower'))) + img = cv2.imread(str(get_tile_path('tower'))) + assert img is not None + return img # generate connection selector selector = '' @@ -216,7 +241,10 @@ def find_tower_tile(tiles: Sequence[Sequence[str]], x: int, y: int): tile_name = 'tower' if selector: tile_name = f'{tile_name}_{selector}' - return cv2.imread(str(get_tile_path(tile_name))) + + img = cv2.imread(str(get_tile_path(tile_name))) + assert img is not None + return img TILE_SELECTORS = { @@ -259,7 +287,9 @@ def generate_img(map_path: pathlib.Path): if tile in TILE_SELECTORS: tile_img = TILE_SELECTORS[tile](tiles, x, y) else: - tile_img = cv2.imread(str(get_tile_path(tile))) + img = cv2.imread(str(get_tile_path(tile))) + assert img is not None + tile_img = img tile_imgs.append(tile_img) |
