mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-28 22:33:59 -06:00
25 lines
672 B
Python
25 lines
672 B
Python
import pickle
|
|
import typing as T
|
|
from pathlib import Path
|
|
|
|
from pqcli.mechanic import Player
|
|
|
|
|
|
class Roster:
|
|
def __init__(self, path: Path, players: T.List[Player]) -> None:
|
|
self.path = path
|
|
self.players = players
|
|
|
|
@staticmethod
|
|
def load(path: T.Union[str, Path]) -> "Roster":
|
|
real_path = Path(path)
|
|
if real_path.exists():
|
|
return Roster(
|
|
real_path, players=pickle.loads(real_path.read_bytes())
|
|
)
|
|
return Roster(real_path, players=[])
|
|
|
|
def save(self) -> None:
|
|
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
self.path.write_bytes(pickle.dumps(self.players))
|