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