projects
/
python-bulletml.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Mention BulletYAML support. (Fixes issue #6)
[python-bulletml.git]
/
bulletml
/
parser.py
diff --git
a/bulletml/parser.py
b/bulletml/parser.py
index
51e15ad
..
9b2fbf8
100644
(file)
--- a/
bulletml/parser.py
+++ b/
bulletml/parser.py
@@
-394,7
+394,7
@@
class BulletDef(object):
elif tag == "actionRef":
actions.append(ActionRef.FromXML(doc, subelem))
dfn = cls(actions, direction, speed)
elif tag == "actionRef":
actions.append(ActionRef.FromXML(doc, subelem))
dfn = cls(actions, direction, speed)
- doc.bullets[element.get("label")] = dfn
+ doc.
_
bullets[element.get("label")] = dfn
return dfn
def __call__(self, params, rank):
return dfn
def __call__(self, params, rank):
@@
-478,7
+478,7
@@
class ActionDef(object):
else:
actions.append(ctr.FromXML(doc, subelem))
dfn = cls(actions)
else:
actions.append(ctr.FromXML(doc, subelem))
dfn = cls(actions)
- doc.actions[element.get("label")] = dfn
+ doc.
_
actions[element.get("label")] = dfn
return dfn
def __call__(self, params, rank):
return dfn
def __call__(self, params, rank):
@@
-584,7
+584,7
@@
class FireDef(object):
try:
params = self.bullet.params
except AttributeError:
try:
params = self.bullet.params
except AttributeError:
- state
= dict(bullet=self.bullet
)
+ state
.append(('bullet', self.bullet)
)
else:
if params.params:
state.append(('bullet', self.bullet))
else:
if params.params:
state.append(('bullet', self.bullet))
@@
-621,7
+621,7
@@
class FireDef(object):
except UnboundLocalError as exc:
raise ParseError(str(exc))
else:
except UnboundLocalError as exc:
raise ParseError(str(exc))
else:
- doc.fires[element.get("label")] = fire
+ doc.
_
fires[element.get("label")] = fire
return fire
def __call__(self, params, rank):
return fire
def __call__(self, params, rank):
@@
-674,8
+674,8
@@
class FireRef(object):
class BulletML(object):
"""BulletML document.
class BulletML(object):
"""BulletML document.
- A BulletML document is a collection of
bullets, actions, and
-
firings, as well as a
base game type.
+ A BulletML document is a collection of
top-level actions and the
+ base game type.
You can add tags to the BulletML.CONSTRUCTORS dictionary to extend
its parsing. It maps tag names to classes with a FromXML
You can add tags to the BulletML.CONSTRUCTORS dictionary to extend
its parsing. It maps tag names to classes with a FromXML
@@
-690,11
+690,9
@@
class BulletML(object):
fire=FireDef,
)
fire=FireDef,
)
- def __init__(self, type="none",
bullets=None, fires=None,
actions=None):
+ def __init__(self, type="none", actions=None):
self.type = type
self.type = type
- self.bullets = {} if bullets is None else bullets
- self.actions = {} if actions is None else actions
- self.fires = {} if fires is None else fires
+ self.actions = [] if actions is None else actions
def __getstate__(self):
return [('type', self.type), ('actions', self.actions)]
def __getstate__(self):
return [('type', self.type), ('actions', self.actions)]
@@
-714,6
+712,9
@@
class BulletML(object):
self = cls(type=root.get("type", "none"))
self = cls(type=root.get("type", "none"))
+ self._bullets = {}
+ self._actions = {}
+ self._fires = {}
self._bullet_refs = []
self._action_refs = []
self._fire_refs = []
self._bullet_refs = []
self._action_refs = []
self._fire_refs = []
@@
-725,22
+726,24
@@
class BulletML(object):
try:
for ref in self._bullet_refs:
try:
for ref in self._bullet_refs:
- ref.bullet = self.bullets[ref.bullet]
+ ref.bullet = self.
_
bullets[ref.bullet]
for ref in self._fire_refs:
for ref in self._fire_refs:
- ref.fire = self.fires[ref.fire]
+ ref.fire = self.
_
fires[ref.fire]
for ref in self._action_refs:
for ref in self._action_refs:
- ref.action = self.actions[ref.action]
+ ref.action = self.
_
actions[ref.action]
except KeyError as exc:
raise ParseError("unknown reference %s" % exc)
except KeyError as exc:
raise ParseError("unknown reference %s" % exc)
+ self.actions = [act for name, act in self._actions.items()
+ if name and name.startswith("top")]
+
del(self._bullet_refs)
del(self._action_refs)
del(self._fire_refs)
del(self._bullet_refs)
del(self._action_refs)
del(self._fire_refs)
-
- self.bullets.pop(None, None)
- self.actions.pop(None, None)
- self.fires.pop(None, None)
-
+ del(self._bullets)
+ del(self._actions)
+ del(self._fires)
+
return self
@classmethod
return self
@classmethod
@@
-776,16
+779,9
@@
class BulletML(object):
else:
raise ParseError("unknown initial character %r" % start)
else:
raise ParseError("unknown initial character %r" % start)
- @property
- def top(self):
- """Get a list of all top-level actions."""
- return [dfn for name, dfn in self.actions.items()
- if name and name.startswith("top")]
-
def __repr__(self):
def __repr__(self):
- return "%s(type=%r, bullets=%r, actions=%r, fires=%r)" % (
- type(self).__name__, self.type, self.bullets, self.actions,
- self.fires)
+ return "%s(type=%r, actions=%r)" % (
+ type(self).__name__, self.type, self.actions)
ActionDef.CONSTRUCTORS = dict(
repeat=Repeat,
ActionDef.CONSTRUCTORS = dict(
repeat=Repeat,