-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_handlers.py
29 lines (21 loc) · 901 Bytes
/
input_handlers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from typing import Optional
import tcod.event
from actions import Action, EscapeAction, MovementAction
class EventHandler(tcod.event.EventDispatch[Action]):
def ev_quit(self, event: tcod.event.Quit) -> Optional[Action]:
raise SystemExit()
def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
action: Optional[Action] = None
key = event.sym
if key == tcod.event.KeySym.UP:
action = MovementAction(dx=0, dy=-1)
elif key == tcod.event.KeySym.DOWN:
action = MovementAction(dx=0, dy=1)
elif key == tcod.event.KeySym.LEFT:
action = MovementAction(dx=-1, dy=0)
elif key == tcod.event.KeySym.RIGHT:
action = MovementAction(dx=1, dy=0)
elif key == tcod.event.KeySym.ESCAPE:
action = EscapeAction()
# No valid key pressed
return action