from GameEvent import *
from pygame.locals import *
from Movement import *


class KeyMapping:

    keyEventTypeMapping = {
        'w': GameEvent.MOVE_UP,
        's': GameEvent.MOVE_DOWN,
        'a': GameEvent.MOVE_LEFT,
        'd': GameEvent.MOVE_RIGHT,
    }

    @staticmethod
    def setMovement(mov):
        KeyMapping.movement = mov

    @staticmethod
    def handleInputEvent(event):
        if event.type == KEYDOWN:
            KeyMapping._keydownEvent(event)
        elif event.type == KEYUP:
            KeyMapping._keyupEvent(event)
        elif event.type == MOUSEBUTTONDOWN:
            KeyMapping._mousedownEvent(event)
        elif event.type == MOUSEBUTTONUP:
            KeyMapping._mouseupEvent(event)
        elif event.type == MOUSEMOTION:
            KeyMapping._mousemotionEvent(event)

    @staticmethod
    def _keydownEvent(event):
        if event.unicode in KeyMapping.keyEventTypeMapping:
            move = KeyMapping.keyEventTypeMapping[event.unicode]
            if move == GameEvent.MOVE_UP:
                KeyMapping.movement.addVelocity(Movement.UP)
            elif move == GameEvent.MOVE_DOWN:
                KeyMapping.movement.addVelocity(Movement.DOWN)
            elif move == GameEvent.MOVE_LEFT:
                KeyMapping.movement.addVelocity(Movement.LEFT)
            elif move == GameEvent.MOVE_RIGHT:
                KeyMapping.movement.addVelocity(Movement.RIGHT)

    @staticmethod
    def _keyupEvent(event):
        pass

    @staticmethod
    def _mousedownEvent(event):
        pass

    @staticmethod
    def _mouseupEvent(event):
        pass

    @staticmethod
    def _mousemotionEvent(event):
        pass
@@ -129,11 +129,11 @@
     
-'w'
+K_w
 : Ga
@@ -161,11 +161,11 @@
     
-'s'
+K_s
 : Ga
@@ -195,11 +195,11 @@
     
-'a'
+K_a
 : Ga
@@ -229,11 +229,11 @@
     
-'d'
+K_d
 : Ga
@@ -873,23 +873,19 @@
 f event.
-unicode
+key
  in KeyM
@@ -972,15 +972,11 @@
 ent.
-unicode
+key
 %5D%0A  
@@ -1452,36 +1452,572 @@
 event):%0A        
-pass
+if event.key in KeyMapping.keyEventTypeMapping:%0A            move = KeyMapping.keyEventTypeMapping%5Bevent.key%5D%0A            if move == GameEvent.MOVE_UP:%0A                KeyMapping.movement.subVelocity(Movement.UP)%0A            elif move == GameEvent.MOVE_DOWN:%0A                KeyMapping.movement.subVelocity(Movement.DOWN)%0A            elif move == GameEvent.MOVE_LEFT:%0A                KeyMapping.movement.subVelocity(Movement.LEFT)%0A            elif move == GameEvent.MOVE_RIGHT:%0A                KeyMapping.movement.subVelocity(Movement.RIGHT)
 %0A%0A    @staticmet

Implement functionality for keyup events handling for the use in common WASD movement.