BulletML: FromDocument for parity with FromElement.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 17 Mar 2010 09:13:21 +0000 (02:13 -0700)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 17 Mar 2010 09:13:21 +0000 (02:13 -0700)
bulletml-parse [deleted file]
bulletml-runner
bulletml/impl.py
bulletml/parser.py

diff --git a/bulletml-parse b/bulletml-parse
deleted file mode 100755 (executable)
index 6f36ccc..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-from bulletml import BulletML
-
-for filename in sys.argv[1:]:
-    print BulletML(open(filename, "rU"))
index 21ba80e0f5da332f6b2e7b2c4bcc3eff89e7a6a0..de0fa5a30f37cea8ab95f6884186f04265a35d1d 100755 (executable)
@@ -23,9 +23,10 @@ def main(argv):
 
     while True:
         filename = argv[file_idx % len(argv)]
-        doc = bulletml.BulletML(open(filename, "rU"))
-        source = bulletml.Bullet.FromDoc(
-            doc, x=150, y=150, target=target, rank=0.5)
+        doc = bulletml.BulletML.FromDocument(open(filename, "rU"))
+        actions = [act([], 0.5) for act in doc.top]
+        source = bulletml.Bullet(
+            x=150, y=150, target=target, actions=actions, rank=0.5)
                                          
         active = set([source])
         source.vanished = True
@@ -58,8 +59,10 @@ def main(argv):
                     elif event.key == pygame.K_RETURN:
                         newfile = True
                     elif event.key == pygame.K_s:
-                        source = bulletml.Bullet.FromDoc(
-                            doc, x=150, y=150, target=target, rank=0.5)
+                        actions = [act([], 0.5) for act in doc.top]
+                        source = bulletml.Bullet(
+                            x=150, y=150, target=target,
+                            actions=actions, rank=0.5)
                         source.vanished = True
                         active.add(source)
             target.x, target.y = pygame.mouse.get_pos()
index fcb3aab34ea99da4e76f2c6fdee77b1fd7ded9ce..98b0ef75547a6e55baea75526c30e801cec47be4 100644 (file)
@@ -308,10 +308,3 @@ class Bullet(object):
         self.y += self.my - math.cos(self.direction) * self.speed
 
         return created
-
-    @classmethod
-    def FromDoc(cls, doc, params=(), x=0, y=0, speed=0, direction=0,
-                target=None, rank=0.5):
-        """Construct a bullet from top-level actions in a document."""
-        actions = [act(params, rank) for act in doc.top]
-        return cls(x, y, direction, speed, target, actions, rank=rank)
index b39437ac8dd951d3c20def3b6523c2b68f12f1ed..edb9d29e4c544bae3506e1681cbe25141a78c1db 100644 (file)
@@ -443,22 +443,25 @@ class BulletML(object):
         fire=FireDef,
         )
 
-    def __init__(self, source):
+    def __init__(self, type="none", bullets={}, fires={}, actions={}):
+        self.type = type
         self.bullets = {}
         self.actions = {}
         self.fires = {}
 
-        self._bullet_refs = []
-        self._action_refs = []
-        self._fire_refs = []
-
+    @classmethod
+    def FromDocument(cls, source):
         if isinstance(source, (str, unicode)):
             source = StringIO(source)
 
         tree = ElementTree()
         root = tree.parse(source)
 
-        self.type = root.get("type", "none")
+        self = cls(type=root.get("type", "none"))
+
+        self._bullet_refs = []
+        self._action_refs = []
+        self._fire_refs = []
 
         for element in root.getchildren():
             tag = realtag(element)
@@ -483,6 +486,8 @@ class BulletML(object):
         self.actions.pop(None, None)
         self.fires.pop(None, None)
 
+        return self
+
     @property
     def top(self):
         """Get a list of all top-level actions."""