adding spells

This commit is contained in:
evilchili 2024-01-17 20:08:01 -08:00
parent 1c0bd7357d
commit f15b974a48
3 changed files with 3617 additions and 9 deletions

View File

@ -42,6 +42,16 @@ def wildmagic():
print(rt.as_table()) print(rt.as_table())
@app.command("spells")
def spells():
"""
Generate a random spell table.
"""
rt = RollTable([(Path(__file__).parent / 'sources' / 'spells.yaml').read_text()])
rt.set_headers('Level', 'Name', 'School', None, None, None, None, None)
print(rt.as_table())
@app.command("custom") @app.command("custom")
def custom( def custom(
sources: List[Path] = typer.Argument( sources: List[Path] = typer.Argument(

File diff suppressed because it is too large Load Diff

View File

@ -131,6 +131,16 @@ class RollTable:
table.add_row(*row) table.add_row(*row)
return table return table
def set_headers(self, *headers) -> None:
self._headers = list(headers)
# identify which columns to hide in the output by recording where a
# None header appears
self._header_excludes = []
for i in range(len(self._headers)):
if self.headers[i] is None:
self._header_excludes.append(i+1)
def _config(self): def _config(self):
""" """
Parse data sources, generate headers, and create the column filters Parse data sources, generate headers, and create the column filters
@ -147,16 +157,10 @@ class RollTable:
self._data.append(ds) self._data.append(ds)
# merge the headers # merge the headers
self._headers = [] headers = []
for ds in self._data: for ds in self._data:
self._headers += ds.headers headers += ds.headers
self.set_headers(*headers)
# identify which columns to hide in the output by recording where a
# None header appears
self._header_excludes = []
for i in range(len(self._headers)):
if self.headers[i] is None:
self._header_excludes.append(i)
def _column_filter(self, row): def _column_filter(self, row):
cols = [col or '' for (pos, col) in enumerate(row) if pos not in self._header_excludes] cols = [col or '' for (pos, col) in enumerate(row) if pos not in self._header_excludes]