diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-11-12 14:15:43 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2021-11-12 14:19:43 +0100 |
commit | 8f82ba5acd095b78fcec9d63f2977c04c778f02b (patch) | |
tree | 1d7c574a6c9f5e4217b62e51106c677186aee256 /cameltris/screens/pause.py | |
parent | 4df942db913383d2b2c829f8b89c306a1f75cd9d (diff) |
Update name of screen modules according to PEP8
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'cameltris/screens/pause.py')
-rw-r--r-- | cameltris/screens/pause.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/cameltris/screens/pause.py b/cameltris/screens/pause.py new file mode 100644 index 0000000..2ea7849 --- /dev/null +++ b/cameltris/screens/pause.py @@ -0,0 +1,39 @@ +import contextlib +import sys +from typing import Callable, NoReturn + +import pygame + +from .screen import Screen +from ..controller import Controller, KeyboardController, JoystickController, Input +from ..misc import UnPause + + +def handle_input_pressed(controller: Controller, event: pygame.event.Event): + if controller.get_input_down(event) == Input.PAUSE: + raise UnPause() + + +class Pause(Screen): + def __init__(self, screen: pygame.surface.Surface): + self.event_handler: dict[int, Callable[[pygame.event.Event], None]] = {} + + def exit(_) -> NoReturn: + sys.exit() + + self.event_handler[pygame.QUIT] = exit + self.event_handler[pygame.JOYBUTTONDOWN] = lambda evt: handle_input_pressed(JoystickController(evt.joy), evt) + self.event_handler[pygame.KEYDOWN] = lambda evt: handle_input_pressed(KeyboardController(pygame.key), evt) + + + def refresh(self) -> None: + pass + + def oneframe(self) -> None: + try: + for event in pygame.event.get(): + with contextlib.suppress(KeyError): + self.event_handler[event.type](event) + except UnPause: + pygame.event.clear() + raise |