2023-12-23 15:36:42 -08:00
|
|
|
from rolltable.types import RollTable
|
2022-07-30 14:20:26 -07:00
|
|
|
import typer
|
2023-04-12 10:37:31 -07:00
|
|
|
from enum import Enum
|
2022-07-30 14:20:26 -07:00
|
|
|
from rich import print
|
2022-07-31 15:03:19 -07:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import List
|
2022-07-30 14:20:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
|
2023-04-12 10:37:31 -07:00
|
|
|
class OUTPUT_FORMATS(Enum):
|
|
|
|
text = 'text'
|
|
|
|
yaml = 'yaml'
|
|
|
|
markdown = 'markdown'
|
|
|
|
|
|
|
|
|
2024-01-16 22:05:06 -08:00
|
|
|
@app.command("psychadelic-effects")
|
|
|
|
def psycheffects():
|
|
|
|
"""
|
|
|
|
Generate a roll table of psychadelic effects.
|
|
|
|
"""
|
|
|
|
rt = RollTable([(Path(__file__).parent / 'sources' / 'psychadelic_effects.yaml').read_text()])
|
|
|
|
print(rt.as_table())
|
|
|
|
|
|
|
|
|
|
|
|
@app.command("trinkets")
|
|
|
|
def trinkets():
|
|
|
|
"""
|
|
|
|
Generate a roll table of random junk.
|
|
|
|
"""
|
|
|
|
rt = RollTable([(Path(__file__).parent / 'sources' / 'trinkets.yaml').read_text()])
|
|
|
|
print(rt.as_table())
|
|
|
|
|
|
|
|
|
|
|
|
@app.command("wild-magic")
|
|
|
|
def wildmagic():
|
|
|
|
"""
|
|
|
|
Generate a wild magic surge table.
|
|
|
|
"""
|
|
|
|
rt = RollTable([(Path(__file__).parent / 'sources' / 'wild_magic.yaml').read_text()])
|
|
|
|
print(rt.as_table())
|
|
|
|
|
|
|
|
|
|
|
|
@app.command("custom")
|
|
|
|
def custom(
|
2022-07-31 15:03:19 -07:00
|
|
|
sources: List[Path] = typer.Argument(
|
2022-07-30 14:20:26 -07:00
|
|
|
...,
|
2022-07-31 15:03:19 -07:00
|
|
|
help="Path to one or more yaml-formatted source file."),
|
2022-07-30 14:20:26 -07:00
|
|
|
frequency: str = typer.Option(
|
|
|
|
'default',
|
|
|
|
help='use the specified frequency from the source file'),
|
|
|
|
die: int = typer.Option(
|
|
|
|
20,
|
|
|
|
help='The size of the die for which to create a table'),
|
2023-04-12 10:37:31 -07:00
|
|
|
hide_rolls: bool = typer.Option(
|
|
|
|
False,
|
|
|
|
help='If True, do not show the Roll column.',
|
|
|
|
),
|
2022-07-31 15:03:19 -07:00
|
|
|
collapsed: bool = typer.Option(
|
2022-07-30 14:20:26 -07:00
|
|
|
True,
|
2022-08-06 17:33:54 -07:00
|
|
|
help='If True, collapse multiple die values with the same option.'),
|
2023-04-12 10:37:31 -07:00
|
|
|
width: int = typer.Option(
|
|
|
|
120,
|
|
|
|
help='Width of the table.'),
|
|
|
|
output: OUTPUT_FORMATS = typer.Option(
|
|
|
|
'text',
|
|
|
|
help='The output format to use.',
|
|
|
|
)
|
2022-07-30 14:20:26 -07:00
|
|
|
):
|
|
|
|
"""
|
2024-01-16 22:05:06 -08:00
|
|
|
Create roll tables from custom sources.
|
2022-07-30 14:20:26 -07:00
|
|
|
"""
|
2022-07-31 15:03:19 -07:00
|
|
|
|
2023-12-23 15:36:42 -08:00
|
|
|
rt = RollTable([Path(s).read_text() for s in sources], frequency=frequency, die=die, hide_rolls=hide_rolls)
|
2022-07-31 15:03:19 -07:00
|
|
|
|
2023-04-12 10:37:31 -07:00
|
|
|
if output == OUTPUT_FORMATS.yaml:
|
2022-08-06 21:19:59 -07:00
|
|
|
print(rt.as_yaml())
|
2023-04-12 10:37:31 -07:00
|
|
|
elif output == OUTPUT_FORMATS.markdown:
|
2024-01-06 12:21:30 -08:00
|
|
|
print(rt.as_markdown())
|
2023-04-12 10:37:31 -07:00
|
|
|
else:
|
2024-01-06 12:21:30 -08:00
|
|
|
print(rt.as_table(width=width, expanded=not collapsed))
|
2022-07-30 14:20:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app()
|