# Coverage for client/parts/lobby.py : 100%

## 30 statements 30 run 0 missing 2 excluded 0 partial

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 -*-

2 from __future__ import annotations

3

4# -- stdlib --

5 from typing import List, TYPE_CHECKING

6 import logging

7

8# -- third party --

9# -- own --

10 from utils.events import EventHub

11 import wire

12

13# -- typing --

14 if TYPE_CHECKING:

15 from client.core import Core # noqa: F401

16

17

18# -- code --

19 log = logging.getLogger('client.parts.Lobby')

20 STOP = EventHub.STOP_PROPAGATION

21

22

23 class 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] = []

28

29 core.events.server_dropped += self._server_dropped

30

31 D = core.events.server_command

32 D[wire.CurrentGames] += self._current_games

33 D[wire.CurrentUsers] += self._current_users

34

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

41

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

47

48 def _server_dropped(self, v: bool) -> bool:

49 self.users = []

50 self.games = []

51 return v