2022-01-02 15:23:25 +00:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
import tcod.event
|
|
|
|
|
2022-01-02 17:19:43 +00:00
|
|
|
from actions import Action, EscapeAction, BumpAction
|
2022-01-02 15:23:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
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.K_UP:
|
2022-01-02 17:19:43 +00:00
|
|
|
action = BumpAction(dx=0, dy=-1)
|
2022-01-02 15:23:25 +00:00
|
|
|
elif key == tcod.event.K_DOWN:
|
2022-01-02 17:19:43 +00:00
|
|
|
action = BumpAction(dx=0, dy=1)
|
2022-01-02 15:23:25 +00:00
|
|
|
elif key == tcod.event.K_LEFT:
|
2022-01-02 17:19:43 +00:00
|
|
|
action = BumpAction(dx=-1, dy=0)
|
2022-01-02 15:23:25 +00:00
|
|
|
elif key == tcod.event.K_RIGHT:
|
2022-01-02 17:19:43 +00:00
|
|
|
action = BumpAction(dx=1, dy=0)
|
2022-01-02 15:23:25 +00:00
|
|
|
|
|
|
|
elif key == tcod.event.K_ESCAPE:
|
|
|
|
action = EscapeAction()
|
|
|
|
|
|
|
|
return action
|