Coverage for client/parts/lobby.py : 100%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2from __future__ import annotations
4# -- stdlib --
5from typing import List, TYPE_CHECKING
6import logging
8# -- third party --
9# -- own --
10from utils.events import EventHub
11import wire
13# -- typing --
14if TYPE_CHECKING:
15 from client.core import Core # noqa: F401
18# -- code --
19log = logging.getLogger('client.parts.Lobby')
20STOP = EventHub.STOP_PROPAGATION
23class Lobby(object):
24 def __init__(self, core: Core):
25 self.core = core
26 self.games: List[wire.model.Game] = []
27 self.users: List[wire.model.User] = []
29 core.events.server_dropped += self._server_dropped
31 D = core.events.server_command
32 D[wire.CurrentGames] += self._current_games
33 D[wire.CurrentUsers] += self._current_users
35 # ----- Reactions -----
36 def _current_games(self, ev: wire.msg.CurrentGames) -> wire.msg.CurrentGames:
37 self.games = ev.games
38 core = self.core
39 core.events.lobby_updated.emit((self.users, self.games))
40 return ev
42 def _current_users(self, ev: wire.msg.CurrentUsers) -> wire.msg.CurrentUsers:
43 self.users = ev.users
44 core = self.core
45 core.events.lobby_updated.emit((self.users, self.games))
46 return ev
48 def _server_dropped(self, v: bool) -> bool:
49 self.users = []
50 self.games = []
51 return v