Hide keyboard shortcuts

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 

3 

4# -- stdlib -- 

5from typing import Any, List, TYPE_CHECKING 

6import logging 

7 

8# -- third party -- 

9# -- own -- 

10from game.base import EventHandler 

11from server.base import Game 

12 

13 

14# -- typing -- 

15if TYPE_CHECKING: 

16 from server.core import Core # noqa: F401 

17 

18# -- code -- 

19log = logging.getLogger('server.parts.hooks') 

20 

21 

22class ServerEventHooks(EventHandler): 

23 def __init__(self) -> None: 

24 self.hooks: List[EventHandler] = [ 

25 ] 

26 

27 def handle(self, evt_type: str, arg: Any) -> Any: 

28 for h in self.hooks: 28 ↛ 29line 28 didn't jump to line 29, because the loop on line 28 never started

29 arg = h.handle(evt_type, arg) 

30 

31 return arg 

32 

33 

34class Hooks(object): 

35 def __init__(self, core: Core): 

36 self.core = core 

37 core.events.game_started += self.handle_game_started 

38 

39 def __repr__(self) -> str: 

40 return self.__class__.__name__ 

41 

42 def handle_game_started(self, g: Game) -> Game: 

43 g.event_observer = ServerEventHooks() 

44 return g