Coverage for server/parts/hooks.py : 91%
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 Any, List, TYPE_CHECKING
6import logging
8# -- third party --
9# -- own --
10from game.base import EventHandler
11from server.base import Game
14# -- typing --
15if TYPE_CHECKING:
16 from server.core import Core # noqa: F401
18# -- code --
19log = logging.getLogger('server.parts.hooks')
22class ServerEventHooks(EventHandler):
23 def __init__(self) -> None:
24 self.hooks: List[EventHandler] = [
25 ]
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)
31 return arg
34class Hooks(object):
35 def __init__(self, core: Core):
36 self.core = core
37 core.events.game_started += self.handle_game_started
39 def __repr__(self) -> str:
40 return self.__class__.__name__
42 def handle_game_started(self, g: Game) -> Game:
43 g.event_observer = ServerEventHooks()
44 return g