Make chess puzzle level (Kasparov to F3) winnable.
[naja.git] / naja / events.py
index b2cdee1e5a748e614c604af3b5913ff167db1874..dbf7a03711fa1a4dd87a9ef15544332e4eddb948 100644 (file)
@@ -3,26 +3,54 @@ Custom Pygame events.
 """
 
 import pygame.event as pge
+import pygame.locals as pgl
 
 
-class NajaEvent(pge.Event):
+def finish_event(handled=True, skip_invalidate=False):
+    if not skip_invalidate:
+        InvalidateTheWorld.post()
+    return handled
 
+
+class NajaEvent(object):
     TYPE = "UNKNOWN"
 
     @classmethod
     def post(cls, **attributes):
-        event = pge.Event(pge.USEREVENT, naja_event_type=cls.TYPE,
+        event = pge.Event(pgl.USEREVENT, naja_event_type=cls.TYPE,
                           **attributes)
         pge.post(event)
 
     @classmethod
     def matches(cls, ev):
-        return ev.type == pge.USEREVENT and ev.naja_event_type == cls.TYPE
+        return ev.type == pgl.USEREVENT and ev.naja_event_type == cls.TYPE
 
 
 class SceneChangeEvent(NajaEvent):
     TYPE = "SCENE_CHANGE"
 
     @classmethod
-    def post(cls, scene):
-        super(SceneChangeEvent, cls).post(scene=scene)
+    def post(cls, scene_cls):
+        super(SceneChangeEvent, cls).post(scene_cls=scene_cls)
+
+
+class QuitGameEvent(NajaEvent):
+    TYPE = "QUIT_GAME"
+
+
+class InvalidateTheWorld(NajaEvent):
+    # This is used to signal to all the widgets that the world has changed
+    # and cached state may need to be recreated
+    TYPE = "INVALIDATE"
+
+
+class SelectEvent(NajaEvent):
+    TYPE = "SELECT"
+
+
+class LoadGameEvent(NajaEvent):
+    TYPE = "LOAD_GAME"
+
+    @classmethod
+    def post(cls, state):
+        super(LoadGameEvent, cls).post(state=state)