2022-04-30 21:59:01 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
|
|
|
|
import tcod
|
2022-05-07 11:16:17 -07:00
|
|
|
from .actions import Action, ExitAction, RegenerateRoomsAction, BumpAction
|
2022-05-03 18:21:24 -07:00
|
|
|
from .geometry import Direction
|
2022-04-30 21:59:01 -07:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
class EventHandler(tcod.event.EventDispatch[Action]):
|
|
|
|
def ev_quit(self, event: tcod.event.Quit) -> Optional[Action]:
|
|
|
|
return ExitAction()
|
|
|
|
|
|
|
|
def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
|
|
|
|
action: Optional[Action] = None
|
|
|
|
|
|
|
|
sym = event.sym
|
|
|
|
|
2022-05-04 09:25:35 -07:00
|
|
|
if sym == tcod.event.KeySym.b:
|
2022-05-07 11:16:17 -07:00
|
|
|
action = BumpAction(Direction.SouthWest)
|
2022-05-04 09:25:35 -07:00
|
|
|
elif sym == tcod.event.KeySym.h:
|
2022-05-07 11:16:17 -07:00
|
|
|
action = BumpAction(Direction.West)
|
2022-04-30 21:59:01 -07:00
|
|
|
elif sym == tcod.event.KeySym.j:
|
2022-05-07 11:16:17 -07:00
|
|
|
action = BumpAction(Direction.South)
|
2022-04-30 21:59:01 -07:00
|
|
|
elif sym == tcod.event.KeySym.k:
|
2022-05-07 11:16:17 -07:00
|
|
|
action = BumpAction(Direction.North)
|
2022-04-30 21:59:01 -07:00
|
|
|
elif sym == tcod.event.KeySym.l:
|
2022-05-07 11:16:17 -07:00
|
|
|
action = BumpAction(Direction.East)
|
2022-05-04 09:25:35 -07:00
|
|
|
elif sym == tcod.event.KeySym.n:
|
2022-05-07 11:16:17 -07:00
|
|
|
action = BumpAction(Direction.SouthEast)
|
2022-05-04 09:25:35 -07:00
|
|
|
elif sym == tcod.event.KeySym.u:
|
2022-05-07 11:16:17 -07:00
|
|
|
action = BumpAction(Direction.NorthEast)
|
2022-05-04 09:25:35 -07:00
|
|
|
elif sym == tcod.event.KeySym.y:
|
2022-05-07 11:16:17 -07:00
|
|
|
action = BumpAction(Direction.NorthWest)
|
2022-04-30 21:59:01 -07:00
|
|
|
elif sym == tcod.event.KeySym.SPACE:
|
|
|
|
action = RegenerateRoomsAction()
|
|
|
|
|
|
|
|
return action
|