summaryrefslogtreecommitdiff
path: root/swiftstory
diff options
context:
space:
mode:
Diffstat (limited to 'swiftstory')
-rw-r--r--swiftstory/game_manager.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/swiftstory/game_manager.py b/swiftstory/game_manager.py
index e7b3305..7551ac4 100644
--- a/swiftstory/game_manager.py
+++ b/swiftstory/game_manager.py
@@ -1,3 +1,4 @@
+from dataclasses import dataclass
import logging
import os
from typing import Dict, List
@@ -7,26 +8,34 @@ from swiftstory.game import Game
from swiftstory.cards import Cards
-class GameManager:
- def __init__(self):
- self.langs: Dict[str, dict] = {}
+@dataclass
+class LangContainer:
+ """ Container for game ojects in a given language. """
+ black_cards: List[str]
+ white_cards: List[str]
+ games: Dict[str, Game]
+
- for filename in next(os.walk('usr/share/swiftstory/lang'))[1]:
- self.langs[filename] = {}
+class GameManager:
- for lang in self.langs:
- self.langs[lang]['black_cards'] = Cards.get_black_cards(lang)
- self.langs[lang]['white_cards'] = Cards.get_white_cards(lang)
+ def __init__(self) -> None:
+ self.lang_containers: Dict[str, LangContainer] = {}
- self.langs[lang]['games'] = {}
+ for language in next(os.walk('usr/share/swiftstory/lang'))[1]:
+ self.lang_containers[language] = LangContainer(
+ black_cards=Cards.get_black_cards(language),
+ white_cards=Cards.get_white_cards(language),
+ games={}
+ )
- def join_game(self, game_name, lang):
- if self.langs.get(lang) is None:
+ def join_game(self, game_name: str, lang: str) -> Game:
+ container = self.lang_containers.get(lang)
+ if container is None:
raise UnsupportedLanguage(lang)
- games = self.langs[lang]['games']
- black_cards = self.langs[lang]['black_cards']
- white_cards = self.langs[lang]['white_cards']
+ games = container.games
+ black_cards = container.black_cards
+ white_cards = container.white_cards
game = games.get(game_name)