Convert the keysym matching to match/case from if/elif

This commit is contained in:
Eryn Wells 2022-05-07 11:57:08 -07:00
parent 7b747fb4d3
commit 15e188b9f2

View file

@ -19,24 +19,24 @@ class EventHandler(tcod.event.EventDispatch[Action]):
action: Optional[Action] = None action: Optional[Action] = None
sym = event.sym sym = event.sym
match sym:
if sym == tcod.event.KeySym.b: case tcod.event.KeySym.b:
action = BumpAction(Direction.SouthWest) action = BumpAction(Direction.SouthWest)
elif sym == tcod.event.KeySym.h: case tcod.event.KeySym.h:
action = BumpAction(Direction.West) action = BumpAction(Direction.West)
elif sym == tcod.event.KeySym.j: case tcod.event.KeySym.j:
action = BumpAction(Direction.South) action = BumpAction(Direction.South)
elif sym == tcod.event.KeySym.k: case tcod.event.KeySym.k:
action = BumpAction(Direction.North) action = BumpAction(Direction.North)
elif sym == tcod.event.KeySym.l: case tcod.event.KeySym.l:
action = BumpAction(Direction.East) action = BumpAction(Direction.East)
elif sym == tcod.event.KeySym.n: case tcod.event.KeySym.n:
action = BumpAction(Direction.SouthEast) action = BumpAction(Direction.SouthEast)
elif sym == tcod.event.KeySym.u: case tcod.event.KeySym.u:
action = BumpAction(Direction.NorthEast) action = BumpAction(Direction.NorthEast)
elif sym == tcod.event.KeySym.y: case tcod.event.KeySym.y:
action = BumpAction(Direction.NorthWest) action = BumpAction(Direction.NorthWest)
elif sym == tcod.event.KeySym.SPACE: case tcod.event.KeySym.SPACE:
action = RegenerateRoomsAction() action = RegenerateRoomsAction()
return action return action