mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui: save every 60 seconds
This commit is contained in:
@@ -100,7 +100,7 @@ class Ui:
|
||||
|
||||
def switch_to_game_view(self, player_idx: int) -> None:
|
||||
player = self.roster.players[player_idx]
|
||||
self.loop.widget = GameView(self.loop, player, self.args)
|
||||
self.loop.widget = GameView(self.loop, self.roster, player, self.args)
|
||||
self._connect("cancel", self.switch_to_roster_view)
|
||||
|
||||
def switch_to_delete_player_view(self, player_idx: int) -> None:
|
||||
|
||||
+12
-1
@@ -14,6 +14,7 @@ from pqcli.mechanic import (
|
||||
Simulation,
|
||||
Spell,
|
||||
)
|
||||
from pqcli.roster import Roster
|
||||
from pqcli.ui.custom_line_box import CustomLineBox
|
||||
from pqcli.ui.custom_list_box import CustomListBox
|
||||
from pqcli.ui.custom_progress_bar import CustomProgressBar
|
||||
@@ -359,9 +360,14 @@ class GameView(urwid.Pile):
|
||||
signals = ["cancel"]
|
||||
|
||||
def __init__(
|
||||
self, loop: urwid.MainLoop, player: Player, args: argparse.Namespace
|
||||
self,
|
||||
loop: urwid.MainLoop,
|
||||
roster: Roster,
|
||||
player: Player,
|
||||
args: argparse.Namespace,
|
||||
) -> None:
|
||||
self.loop = loop
|
||||
self.roster = roster
|
||||
self.player = player
|
||||
self.args = args
|
||||
self.simulation = Simulation(player)
|
||||
@@ -413,6 +419,7 @@ class GameView(urwid.Pile):
|
||||
)
|
||||
|
||||
self.tick()
|
||||
self.save()
|
||||
|
||||
def cancel(self) -> None:
|
||||
self._emit("cancel")
|
||||
@@ -424,6 +431,10 @@ class GameView(urwid.Pile):
|
||||
self.loop.set_alarm_in(0.1, lambda _loop, _user_data: self.tick())
|
||||
self.last_tick = datetime.datetime.now()
|
||||
|
||||
def save(self) -> None:
|
||||
self.roster.save()
|
||||
self.loop.set_alarm_in(60.0, lambda _loop, _user_data: self.save())
|
||||
|
||||
def unhandled_input(self, key: str) -> bool:
|
||||
if key == "esc":
|
||||
self.cancel()
|
||||
|
||||
Reference in New Issue
Block a user