return cls([NumberDef(subelem.text) for subelem in element
if realtag(subelem) == "param"])
+ def __getstate__(self):
+ if self.params:
+ return dict(params=[param.expr for param in self.params])
+ else:
+ return {}
+
+ def __setstate__(self, state):
+ self.__init__(NumberDef(param) for param in state.get("params", []))
+
def __call__(self, params, rank):
return [param(params, rank) for param in self.params]
self.type = type
self.value = value
+ def __getstate__(self):
+ return dict(type=self.type, value=self.value.expr)
+
+ def __setstate__(self, state):
+ self.__init__(state["type"], NumberDef(state["value"]))
+
@classmethod
def FromElement(cls, doc, element, default="absolute"):
"""Construct using an ElementTree-style element."""
self.term = term
self.direction = direction
+ def __getstate__(self):
+ return dict(frames=self.term.expr,
+ type=self.direction.type,
+ value=self.direction.value.expr)
+
+ def __setstate__(self, state):
+ self.__init__(INumberDef(state["frames"]),
+ Direction(state["type"], NumberDef(state["value"])))
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
self.type = type
self.value = value
+ def __getstate__(self):
+ return dict(type=self.type, value=self.value.expr)
+
+ def __setstate__(self, state):
+ self.__init__(state["type"], NumberDef(state["value"]))
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
self.term = term
self.speed = speed
+ def __getstate__(self):
+ return dict(frames=self.term.expr,
+ type=self.speed.type,
+ value=self.speed.value.expr)
+
+ def __setstate__(self, state):
+ self.__init__(INumberDef(state["frames"]),
+ Speed(state["type"], NumberDef(state["value"])))
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
def __init__(self, frames):
self.frames = frames
+ def __getstate__(self):
+ return dict(frames=self.frames.expr)
+
+ def __setstate__(self, state):
+ self.__init__(INumberDef(state["frames"]))
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
def __init__(self, tag):
self.tag = tag
+ def __getstate__(self):
+ return dict(tag=self.tag)
+
+ def __setstate__(self, state):
+ self.__init__(state["tag"])
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
def __init__(self, tag):
self.tag = tag
+
+ def __getstate__(self):
+ return dict(tag=self.tag)
+
+ def __setstate__(self, state):
+ self.__init__(state["tag"])
@classmethod
def FromElement(cls, doc, element):
def __init__(self, times, action):
self.times = times
self.action = action
+
+ def __getstate__(self):
+ return dict(times=self.times.expr, action=self.action)
+
+ def __setstate__(self, state):
+ self.__init__(INumberDef(state["times"]), state["action"])
@classmethod
def FromElement(cls, doc, element):
self.horizontal = horizontal
self.vertical = vertical
+ def __getstate__(self):
+ state = dict(frames=self.term.expr)
+ if self.horizontal:
+ state["horizontal"] = self.horizontal
+ if self.vertical:
+ state["vertical"] = self.vertical
+ return state
+
+ def __setstate__(self, state):
+ self.__init__(INumberDef(state["term"]), state.get("horizontal"),
+ state.get("vertical"))
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
self.speed = speed
self.actions = list(actions)
+ def __getstate__(self):
+ state = dict()
+ if self.direction:
+ state["direction"] = self.direction
+ if self.speed:
+ state["speed"] = self.speed
+ if self.actions:
+ state["actions"] = self.actions
+ return state
+
+ def __setstate__(self, state):
+ self.__init__(**state)
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
def __init__(self, bullet, params=None):
self.bullet = bullet
- self.params = params or ParamList()
+ self.params = ParamList() if params is None else params
+
+ def __getstate__(self):
+ state = dict(bullet=self.bullet)
+ if self.params.params:
+ state["params"] = self.params.__getstate__()
+ return state
+
+ def __setstate__(self, state):
+ bullet = state["bullet"]
+ params = [NumberDef(param) for param in state.get("params", [])]
+ self.__init__(bullet, params)
@classmethod
def FromElement(cls, doc, element):
def __init__(self, actions):
self.actions = list(actions)
+ def __getstate__(self):
+ return dict(actions=self.actions)
+
+ def __setstate__(self, state):
+ self.__init__(state)
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
self.action = action
self.params = params or ParamList()
+ def __getstate__(self):
+ state = dict(action=self.action)
+ if self.params.params:
+ state["params"] = self.params.__getstate__()
+ return state
+
+ def __setstate__(self, state):
+ action = state["action"]
+ params = [NumberDef(param) for param in state.get("params", [])]
+ self.__init__(action, params)
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
self.x = x
self.y = y
+ def __getstate__(self):
+ state = dict(type=self.type)
+ if self.x:
+ state["x"] = self.x.expr
+ if self.y:
+ state["y"] = self.y.expr
+ return state
+
+ def __setstate__(self, state):
+ self.__init__(state["type"], state.get("x"), state.get("y"))
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
self.speed = speed
self.offset = offset
+ def __getstate__(self):
+ try:
+ params = self.bullet.params
+ except AttributeError:
+ state = dict(bullet=self.bullet)
+ else:
+ if params.params:
+ state = dict(bullet=self.bullet)
+ else:
+ state = dict(bullet=self.bullet.bullet)
+ if self.direction:
+ state["direction"] = self.direction
+ if self.speed:
+ state["speed"] = self.speed
+ if self.offset:
+ state["offset"] = self.offset
+ return state
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
self.fire = fire
self.params = params or ParamList()
+ def __getstate__(self):
+ state = dict(fire=self.fire)
+ if self.params.params:
+ state["params"] = self.params.__getstate__()
+ return state
+
+ def __setstate__(self, state):
+ fire = state["fire"]
+ params = [NumberDef(param) for param in state.get("params", [])]
+ self.__init__(fire, params)
+
@classmethod
def FromElement(cls, doc, element):
"""Construct using an ElementTree-style element."""
self.actions = {} if actions is None else actions
self.fires = {} if fires is None else fires
+ def __getstate__(self):
+ return dict(type=self.type, actions=self.actions)
+
+ def __setstate__(self, state):
+ self.__init__(state["type"], state.get("actions"))
+
@classmethod
def FromDocument(cls, source):
"""Return a BulletML instance based on a string or file-like."""