Highlight tiles that are legal moves.
[naja.git] / naja / events.py
1 """
2 Custom Pygame events.
3 """
4
5 import pygame.event as pge
6 import pygame.locals as pgl
7
8
9 def finish_event(handled=True, skip_invalidate=False):
10     if not skip_invalidate:
11         InvalidateTheWorld.post()
12     return handled
13
14
15 class NajaEvent(object):
16     TYPE = "UNKNOWN"
17
18     @classmethod
19     def post(cls, **attributes):
20         event = pge.Event(pgl.USEREVENT, naja_event_type=cls.TYPE,
21                           **attributes)
22         pge.post(event)
23
24     @classmethod
25     def matches(cls, ev):
26         return ev.type == pgl.USEREVENT and ev.naja_event_type == cls.TYPE
27
28
29 class SceneChangeEvent(NajaEvent):
30     TYPE = "SCENE_CHANGE"
31
32     @classmethod
33     def post(cls, scene_cls):
34         super(SceneChangeEvent, cls).post(scene_cls=scene_cls)
35
36
37 class QuitGameEvent(NajaEvent):
38     TYPE = "QUIT_GAME"
39
40
41 class InvalidateTheWorld(NajaEvent):
42     # This is used to signal to all the widgets that the world has changed
43     # and cached state may need to be recreated
44     TYPE = "INVALIDATE"
45
46
47 class SelectEvent(NajaEvent):
48     TYPE = "SELECT"