+++ /dev/null
-#!/usr/bin/env python
-
-import sys
-
-from bulletml import BulletML
-
-for filename in sys.argv[1:]:
- print BulletML(open(filename, "rU"))
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
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()
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)
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)
self.actions.pop(None, None)
self.fires.pop(None, None)
+ return self
+
@property
def top(self):
"""Get a list of all top-level actions."""