2024-01-17 21:15:39 -08:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import Any
|
|
|
|
|
2024-02-17 17:05:33 -08:00
|
|
|
from rolltable.types import RollTable
|
|
|
|
|
2024-01-17 21:15:39 -08:00
|
|
|
|
|
|
|
def from_sources(names: list[str] = []) -> list:
|
2024-02-17 17:05:33 -08:00
|
|
|
return RollTable([(Path(__file__).parent / "sources" / name).read_text() for name in names])
|
2024-01-17 21:15:39 -08:00
|
|
|
|
|
|
|
|
|
|
|
index = dict(
|
2024-02-17 17:05:33 -08:00
|
|
|
psychadelic_effects=from_sources(["psychadelic_effects.yaml"]),
|
|
|
|
trinkets=from_sources(["trinkets.yaml"]),
|
|
|
|
wild_magic=from_sources(["wild_magic.yaml"]),
|
|
|
|
spells=from_sources(["spells.yaml"]),
|
|
|
|
encounters=from_sources(["encounters.yaml"]),
|
2024-01-17 21:15:39 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def __getattr__(name: str) -> Any:
|
2024-01-17 22:37:53 -08:00
|
|
|
try:
|
|
|
|
return index[name]
|
|
|
|
except KeyError:
|
|
|
|
if name in globals():
|
|
|
|
return globals()[name]
|
|
|
|
raise AttributeError(f"No such attribute: {name}")
|