Construct Actions before passing to Bullet.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 22 Apr 2010 05:26:33 +0000 (22:26 -0700)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 22 Apr 2010 05:26:33 +0000 (22:26 -0700)
bulletml/impl.py
bulletml/parser.py

index dad5601..836fb41 100644 (file)
@@ -153,8 +153,7 @@ class Bullet(object):
     """
 
     def __init__(self, x=0, y=0, direction=0, speed=0, target=None,
     """
 
     def __init__(self, x=0, y=0, direction=0, speed=0, target=None,
-                 actions=(), rank=0.5, tags=(), appearance=None,
-                 Action=Action):
+                 actions=(), rank=0.5, tags=(), appearance=None):
         self.x = self.px = x
         self.y = self.py = y
         self.mx = 0
         self.x = self.px = x
         self.y = self.py = y
         self.mx = 0
@@ -166,17 +165,18 @@ class Bullet(object):
         self.rank = rank
         self.tags = set(tags)
         self.appearance = appearance
         self.rank = rank
         self.tags = set(tags)
         self.appearance = appearance
-        # New bullets reset the parent hierarchy.
-        self.actions = [Action(None, action, params, rank)
-                         for action, params in actions]
+        self.actions = list(actions)
 
     @classmethod
     def FromDocument(cls, doc, x=0, y=0, direction=0, speed=0, target=None,
                      params=(), rank=0.5, Action=Action):
         """Construct a new Bullet from a loaded BulletML document."""
 
     @classmethod
     def FromDocument(cls, doc, x=0, y=0, direction=0, speed=0, target=None,
                      params=(), rank=0.5, Action=Action):
         """Construct a new Bullet from a loaded BulletML document."""
-        actions = [a(params, rank) for a in doc.actions]
+        actions = [action(params, rank) for action in doc.actions]
+        # New bullets reset the parent hierarchy.
+        actions = [Action(None, action, params, rank)
+                   for action, params in actions]
         return cls(x=x, y=y, direction=direction, speed=speed,
         return cls(x=x, y=y, direction=direction, speed=speed,
-                   target=target, actions=actions, rank=rank, Action=Action)
+                   target=target, actions=actions, rank=rank)
 
     def __repr__(self):
         return ("%s(%r, %r, accel=%r, direction=%r, speed=%r, "
 
     def __repr__(self):
         return ("%s(%r, %r, accel=%r, direction=%r, speed=%r, "
index aee4f90..8bc23c0 100644 (file)
@@ -861,10 +861,13 @@ class FireDef(object):
 
         if appearance is None:
             appearance = owner.appearance
 
         if appearance is None:
             appearance = owner.appearance
+        Action = action.__class__
+        actions = [Action(None, action, params, rank)
+                   for action, params in actions]
         bullet = owner.__class__(
             x=x, y=y, direction=direction, speed=speed,
             target=owner.target, actions=actions, rank=rank,
         bullet = owner.__class__(
             x=x, y=y, direction=direction, speed=speed,
             target=owner.target, actions=actions, rank=rank,
-            appearance=appearance, tags=tags, Action=action.__class__)
+            appearance=appearance, tags=tags)
         created.append(bullet)
 
     def __repr__(self):
         created.append(bullet)
 
     def __repr__(self):