# HG changeset patch # User Jeremy Thurgood # Date 1283080514 -7200 # Node ID d8087848722da9e48f9e8f1bbbb42799bd102166 # Parent efb34a6cd2a1aac6f4418d74ac1a1b6889d23928 Factor Thing interactive stuff out into a mixing. (Items to follow.) diff -r efb34a6cd2a1 -r d8087848722d gamelib/state.py --- 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: