Skip to content

app

TowerApp

Bases: App

A TUI that manages a tumbling tower mechanic via die rolls.

action_roll_tower

action_roll_tower() -> None

Roll the tower and send the results to the child widgets as needed.

Source code in src/wretched_tower/app.py
def action_roll_tower(self) -> None:
    """Roll the tower and send the results to the child widgets as needed."""
    try:
        self.tower.roll_tower()
        dice_left = self.tower.get_dice_left()
        tower_status_widget = self.query_one(TowerStatus)
        tower_status_widget.peril_level = self.tower.get_peril_level()
        self.query_one(DiceCounter).update(get_dice_display(dice_left))
        self.query_one(PerilMeter).update(
            get_peril_meter_display_from_peril_level(
                tower_status_widget.peril_level
            )
        )
        last_result = self.tower.roll_distributions[-1]
        tower_status_widget.query_one(DataTable).add_row(
            last_result.dice_rolled,
            last_result.dice_results[1],
            last_result.dice_results[2],
            last_result.dice_results[3],
            last_result.dice_results[4],
            last_result.dice_results[5],
            last_result.dice_results[6],
        )
        if dice_left == 0:
            self.notify("[b][red]You Have Died[/red][/b]")
    except EmptyTowerError:
        self.notify("You are already dead.", severity="error")

action_toggle_dark

action_toggle_dark() -> None

Toggles between dark and light mode.

Source code in src/wretched_tower/app.py
def action_toggle_dark(self) -> None:
    """Toggles between dark and light mode."""
    self.theme = (  # type: ignore
        "textual-dark" if self.theme == "textual-light" else "textual-light"
    )

compose

compose() -> ComposeResult

Create child widgets

Source code in src/wretched_tower/app.py
def compose(self) -> ComposeResult:
    """Create child widgets"""
    yield Header()
    yield TowerStatus(tower=self.tower, id="status")
    yield Footer()

TowerStatus

TowerStatus(tower: Tower, *args: Any, **kwargs: Any)

Bases: Widget

A widget that displays the current status of the tower.

Source code in src/wretched_tower/app.py
def __init__(self, tower: Tower, *args: Any, **kwargs: Any) -> None:  # noqa: ARG002
    super().__init__()
    self.peril_level = tower.get_peril_level()
    self.tower_color = get_tower_color_from_peril_level(self.peril_level)