Simplify CLI

This commit is contained in:
evilchili 2025-08-11 17:30:02 -07:00
parent 60528926ee
commit abd1aa28c4
7 changed files with 21 additions and 59 deletions

View File

@ -1,19 +0,0 @@
....
.__.
....
.
..... .....
.,,,........
.,_,. .....
.,,,. .....
..... ..... ...
. ...
.............
. . ...
. .....
_ .___.
.___.
.___.
.....

View File

@ -1,10 +0,0 @@
,,,,,,,,
m,__,,,_,
m____,,,,
m.__,,,,,
mm...,,,,
m,___.,,,,
m,,,,,,,

View File

@ -1,5 +0,0 @@
,,,,,,,
,,___,,
,,___,,
,,___,,
,,,,,,,

View File

@ -1,10 +0,0 @@
,,,,TTTTT
,,,.....TTT
,,,.....TTTTT
,,.......TTT
,,........TT
MM._________..M
MM.________..MM
MM._____o_____..M
M__o___________.M

View File

@ -1,7 +0,0 @@
,,,,,,,,,,,,,,
,,,........,,,
,,,.______.,,,
,,,._o____.,,,
,,,.______.,,,
,,,........,,,
,,,,,,,,,,,,,,

View File

@ -13,8 +13,8 @@
....v. ....v.
.^......... .^.........
........... ...,,,,,...
........... ...,___,...
........... ...,,,,,...
........... 5 ........... 5

View File

@ -2,6 +2,7 @@ import logging
import os import os
import sys import sys
from pathlib import Path from pathlib import Path
from typing import Union
import typer import typer
from rich.console import Console from rich.console import Console
@ -13,13 +14,13 @@ from tilemapper import tileset as _tileset
app = typer.Typer() app = typer.Typer()
app_state = {} app_state = {}
INSTALL_DIR = Path(__file__).parent.parent
@app.callback(invoke_without_command=True) @app.callback(invoke_without_command=True)
def main( def main(
ctx: typer.Context, ctx: typer.Context,
config_dir: Path = typer.Option( config_dir: Path = typer.Option(default=INSTALL_DIR / "tilesets", help="The path containing tile sets to load."),
default=Path(__file__).parent.parent / "tilesets", help="The path containing tile sets to load."
),
verbose: bool = typer.Option(default=False, help="If True, increase verbosity of status messages."), verbose: bool = typer.Option(default=False, help="If True, increase verbosity of status messages."),
): ):
app_state["tileset_manager"] = _tileset.TileSetManager(config_dir) app_state["tileset_manager"] = _tileset.TileSetManager(config_dir)
@ -31,6 +32,8 @@ def main(
level=logging.DEBUG if debug else logging.INFO, level=logging.DEBUG if debug else logging.INFO,
handlers=[RichHandler(rich_tracebacks=True, tracebacks_suppress=[typer])], handlers=[RichHandler(rich_tracebacks=True, tracebacks_suppress=[typer])],
) )
if ctx.invoked_subcommand is None:
render_map()
@app.command() @app.command()
@ -44,7 +47,9 @@ def list():
@app.command() @app.command()
def render( def render(
source: Path = typer.Argument(help="The battle map text file to load."), source: Path = typer.Option(
help="The battle map text file to load.", default=INSTALL_DIR / "examples" / "five_room_dungeon.txt"
),
outfile: Path = typer.Option(help="The file to create. If not specified, print to STDOUT", default=None), outfile: Path = typer.Option(help="The file to create. If not specified, print to STDOUT", default=None),
tileset: str = typer.Option( tileset: str = typer.Option(
help="The name of the tile set to use (run mapper list to see what's available).", default="colorized" help="The name of the tile set to use (run mapper list to see what's available).", default="colorized"
@ -54,6 +59,14 @@ def render(
Create a rendered battle map using a tile set. Will generate a PNG file if the tile set supports it, Create a rendered battle map using a tile set. Will generate a PNG file if the tile set supports it,
otherwise text output. otherwise text output.
""" """
render_map(source, outfile, tileset)
def render_map(
source: Path = INSTALL_DIR / "examples" / "five_room_dungeon.txt",
outfile: Union[Path, None] = None,
tileset: str = 'colorized'
):
manager = app_state["tileset_manager"] manager = app_state["tileset_manager"]
if tileset not in manager.available: if tileset not in manager.available:
raise RuntimeError(f"Could not locate the tile set {tileset} in {manager.config_dir}.") raise RuntimeError(f"Could not locate the tile set {tileset} in {manager.config_dir}.")