changeset 488:d8087848722d engine_refactor

Factor Thing interactive stuff out into a mixing. (Items to follow.)
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 29 Aug 2010 13:15:14 +0200
parents efb34a6cd2a1
children 463a8d60c73e
files gamelib/state.py
diffstat 1 files changed, 25 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/state.py	Sun Aug 29 13:07:49 2010 +0200
+++ b/gamelib/state.py	Sun Aug 29 13:15:14 2010 +0200
@@ -374,7 +374,31 @@
         return self._background.get_size()
 
 
-class Thing(StatefulGizmo):
+class InteractiveMixin(object):
+    def is_interactive(self):
+        return True
+
+    def interact(self, item):
+        if not self.is_interactive():
+            return
+        if item is None:
+            return self.interact_without()
+        else:
+            handler = getattr(self, 'interact_with_' + item.tool_name, None)
+            if handler is not None:
+                return handler(item)
+            else:
+                return self.interact_default(item)
+
+    def interact_without(self):
+        return self.interact_default(None)
+
+    def interact_default(self, item=None):
+        return None
+
+
+
+class Thing(StatefulGizmo, InteractiveMixin):
     """Base class for things in a scene that you can interact with."""
 
     # name of thing
@@ -448,9 +472,6 @@
     def get_description(self):
         return None
 
-    def is_interactive(self):
-        return True
-
     def enter(self, item):
         """Called when the cursor enters the Thing."""
         pass
@@ -459,27 +480,9 @@
         """Called when the cursr leaves the Thing."""
         pass
 
-    def interact(self, item):
-        if not self.is_interactive():
-            return
-        if item is None:
-            return self.interact_without()
-        else:
-            handler = getattr(self, 'interact_with_' + item.tool_name, None)
-            if handler is not None:
-                return handler(item)
-            else:
-                return self.interact_default(item)
-
     def animate(self):
         return self.current_interact.animate()
 
-    def interact_without(self):
-        return self.interact_default(None)
-
-    def interact_default(self, item):
-        return None
-
     def draw(self, surface):
         old_rect = self.current_interact.rect
         if old_rect: