mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-28 22:33:59 -06:00
roster: extract to a separate module
This commit is contained in:
+3
-8
@@ -1,25 +1,20 @@
|
|||||||
import pickle
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import xdg
|
import xdg
|
||||||
|
|
||||||
from pqcli.mechanic import Roster
|
from pqcli.roster import Roster
|
||||||
from pqcli.ui import Ui
|
from pqcli.ui import Ui
|
||||||
|
|
||||||
SAVE_PATH = Path(xdg.XDG_CONFIG_HOME) / "pqcli" / "save.dat"
|
SAVE_PATH = Path(xdg.XDG_CONFIG_HOME) / "pqcli" / "save.dat"
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
if SAVE_PATH.exists():
|
roster = Roster.load(SAVE_PATH)
|
||||||
roster = pickle.loads(SAVE_PATH.read_bytes())
|
|
||||||
else:
|
|
||||||
roster = Roster()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Ui(roster).run()
|
Ui(roster).run()
|
||||||
finally:
|
finally:
|
||||||
SAVE_PATH.parent.mkdir(parents=True, exist_ok=True)
|
roster.save(SAVE_PATH)
|
||||||
SAVE_PATH.write_bytes(pickle.dumps(roster))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -757,14 +757,6 @@ def monster_task(
|
|||||||
return KillTask(f"Executing {result}", duration, monster=monster)
|
return KillTask(f"Executing {result}", duration, monster=monster)
|
||||||
|
|
||||||
|
|
||||||
class Roster:
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self.players: T.List[Player] = []
|
|
||||||
|
|
||||||
def add_player(self, player: Player) -> None:
|
|
||||||
self.players.append(player)
|
|
||||||
|
|
||||||
|
|
||||||
class StatsBuilder:
|
class StatsBuilder:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.history: T.List[Stats] = []
|
self.history: T.List[Stats] = []
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import pickle
|
||||||
|
import typing as T
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from pqcli.mechanic import Player
|
||||||
|
|
||||||
|
|
||||||
|
class Roster:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.players: T.List[Player] = []
|
||||||
|
|
||||||
|
def add_player(self, player: Player) -> None:
|
||||||
|
self.players.append(player)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def load(path: Path) -> "Roster":
|
||||||
|
if path.exists():
|
||||||
|
return pickle.loads(path.read_bytes())
|
||||||
|
return Roster()
|
||||||
|
|
||||||
|
def save(self, path: Path) -> None:
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path.write_bytes(pickle.dumps(self))
|
||||||
@@ -2,7 +2,7 @@ import typing as T
|
|||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
from pqcli.mechanic import Roster
|
from pqcli.roster import Roster
|
||||||
from pqcli.ui.exit_view import ExitView
|
from pqcli.ui.exit_view import ExitView
|
||||||
from pqcli.ui.new_game_view import NewGameView
|
from pqcli.ui.new_game_view import NewGameView
|
||||||
from pqcli.ui.roster_view import RosterView
|
from pqcli.ui.roster_view import RosterView
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import typing as T
|
|||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
from pqcli.mechanic import Roster
|
from pqcli.roster import Roster
|
||||||
from pqcli.ui.button import MenuButton
|
from pqcli.ui.button import MenuButton
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user