changeset 427:e89a1afe4e84

Make Position simplifiable. Override unsimplify for animals to update their image after recreating.
author Simon Cross <hodgestar@gmail.com>
date Sat, 21 Nov 2009 16:17:48 +0000
parents d34be925b9fc
children a356e57529ea
files gamelib/animal.py gamelib/misc.py
diffstat 2 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animal.py	Sat Nov 21 15:58:54 2009 +0000
+++ b/gamelib/animal.py	Sat Nov 21 16:17:48 2009 +0000
@@ -54,6 +54,13 @@
         return cls((0, 0))
     make = classmethod(make)
 
+    def unsimplify(cls, value):
+        """Override default Simplifiable unsimplification."""
+        obj = super(Animal, cls).unsimplify(value)
+        obj.redraw()
+        return obj
+    unsimplify = classmethod(unsimplify)
+
     def loop(self, tv, _sprite):
         ppos = tv.tile_to_view(self.pos.to_tile_tuple())
         self.rect.x = ppos[0]
--- a/gamelib/misc.py	Sat Nov 21 15:58:54 2009 +0000
+++ b/gamelib/misc.py	Sat Nov 21 16:17:48 2009 +0000
@@ -5,9 +5,13 @@
 from pygame.locals import KEYDOWN, K_ESCAPE
 from pgu import gui
 
-class Position(object):
+import serializer
+
+class Position(serializer.Simplifiable):
     """2D position / vector"""
 
+    SIMPLIFY = ['x', 'y', 'z']
+
     def __init__(self, x, y, z=0):
         self.x = x
         self.y = y