Initial user events for Naja.
authorSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 15:06:23 +0000 (17:06 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 15:06:23 +0000 (17:06 +0200)
naja/events.py [new file with mode: 0644]

diff --git a/naja/events.py b/naja/events.py
new file mode 100644 (file)
index 0000000..b2cdee1
--- /dev/null
@@ -0,0 +1,28 @@
+"""
+Custom Pygame events.
+"""
+
+import pygame.event as pge
+
+
+class NajaEvent(pge.Event):
+
+    TYPE = "UNKNOWN"
+
+    @classmethod
+    def post(cls, **attributes):
+        event = pge.Event(pge.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
+
+
+class SceneChangeEvent(NajaEvent):
+    TYPE = "SCENE_CHANGE"
+
+    @classmethod
+    def post(cls, scene):
+        super(SceneChangeEvent, cls).post(scene=scene)