-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf30283
commit 44c7ad3
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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.K_UP: | ||
action = MovementAction(dx=0, dy=-1) | ||
elif key == tcod.event.K_DOWN: | ||
action = MovementAction(dx=0, dy=1) | ||
elif key == tcod.event.K_LEFT: | ||
action = MovementAction(dx=-1, dy=0) | ||
elif key == tcod.event.K_RIGHT: | ||
action = MovementAction(dx=1, dy=0) | ||
|
||
elif key == tcod.event.K_ESCAPE: | ||
action = EscapeAction() | ||
|
||
# No valid key was pressed | ||
return action |