def test_ManaExpressions(self): s0 = MgManaSymbol(cvalue=1) s1 = MgManaSymbol(colorv=MgManaSymbol.ManaType.Red) s2 = MgManaSymbol(colorv=MgManaSymbol.ManaType.Green) s3 = MgManaSymbol(colorv=MgManaSymbol.ManaType.White) mexpr = MgManaExpression(s0,s1,s2,s3) self.assertTrue(mexpr.isTraversable()) self.assertEqual(len(mexpr.getTraversalSuccessors()),4) self.assertTrue(mexpr.isChild(s0)) self.assertEqual(s0.getParent(),mexpr) self.assertEqual(mexpr.unparseToString(),"{1}{R}{G}{W}")
class MgCard(core.MgNode): """This node represents a Magic card. When a card is parsed, one of these objects is produced. It contains features for interacting with all aspects of a Magic card. From the rules... The parts of a card are name, mana cost, illustration, color indicator, type line, expansion symbol, text box, power and toughness, loyalty, hand modifier, life modifier, illustration credit, legal text, and collector number. Some cards may have more than one of any or all of these parts. """ def __init__(self, **kwargs): """kwargs: A keyword argument dictionary, because there are so many damn fields in this card, most of which are optional.""" if "name" in kwargs: self._name = kwargs["name"] if self._name is not None: self._name.setParent(self) else: self._name = MgName() self._name.setParent(self) if "manaCost" in kwargs: self._manaCost = kwargs["manaCost"] if self._manaCost is not None: self._manaCost.setParent(self) else: self._manaCost = MgManaExpression() self._manaCost.setParent(self) if "colorIndicator" in kwargs: self._colorIndicator = kwargs["colorIndicator"] if self._colorIndicator is not None: self._colorIndicator.setParent(self) else: self._colorIndicator = None if "typeLine" in kwargs: self._typeLine = kwargs["typeLine"] if self._typeLine is not None: self._typeLine.setParent(self) else: self._typeLine = MgTypeLine() if "loyalty" in kwargs: self._loyalty = kwargs["loyalty"] if self._loyalty is not None: self._loyalty.setParent(self) else: self._loyalty = None #TODO: The expansion symbol is going into some kind of 'card details' data structure, #along with info like artist name. if "expansionSymbol" in kwargs: self._expansionSymbol = kwargs["expansionSymbol"] else: self._expansionSymbol = None if "textBox" in kwargs: self._textBox = kwargs["textBox"] if self._textBox is not None: self._textBox.setParent(self) else: self._textBox = MgTextBox() self._textBox.setParent(self) if "powerToughness" in kwargs: self._powerToughness = kwargs["powerToughness"] if self._powerToughness is not None: self._powerToughness.setParent(self) else: self._powerToughness = None if "handModifier" in kwargs: self._handModifier = kwargs["handModifier"] if self._handModifier is not None: self._handModifier.setParent(self) else: self._handModifier = None if "lifeModifier" in kwargs: self._lifeModifier = kwargs["lifeModifier"] if self._lifeModifier is not None: self._lifeModifier.setParent(self) else: self._lifeModifier = None if "flavor" in kwargs: self._flavor = kwargs["flavor"] if self._flavor is not None: self._flavor.setParent(self) else: self._flavor = None def getName(self): return self._name def hasName(self): return self._name is not None def setName(self, name): self._name = name self._name.setParent(self) def getManaCost(self): return self._manaCost def hasManaCost(self): return self._manaCost is not None def setManaCost(self, manaCost): self._manaCost = manaCost self._manaCost.setParent(self) def getColorIndicator(self): return self._colorIndicator def hasColorIndicator(self): return self._colorIndicator is not None def setColorIndicator(self, colorIndicator): self._colorIndicator = colorIndicator def getTypeLine(self): return self._typeLine def hasTypeLine(self): return self._typeLine is not None def setTypeLine(self): return self._typeLine self._typeline.setParent(self) def getLoyalty(self): return self._loyalty def hasLoyalty(self): return self._loyalty is not None def setLoyalty(self, loyalty): self._loyalty = loyalty self._loyalty.setParent(self) def getExpansionSymbol(self): return self._expansionSymbol def hasExpansionSymbol(self): return self._expansionSymbol is not None def setExpansionSymbol(self, expansionSymbol): self._expansionSymbol = expansionSymbol def getTextBox(self): return self._textBox def hasTextBox(self): return self._textBox is not None def setTextBox(self, textBox): self._textBox = textBox self._textBox.setParent(self) def getPowerToughness(self): return self._powerToughness def hasPowerToughness(self): return self._powerToughness is not None def setPowerToughness(self, powerToughness): self._powerToughness = powerToughness self._powerToughness.setParent(self) def getHandModifier(self): """Note: This only matters for Vanguard cards.""" return self._handModifier def hasHandModifier(self): """Note: This only matters for Vanguard cards.""" return self._handModifier is not None def setHandModifier(self, handModifier): """Note: This only matters for Vanguard cards.""" self._handModifier = handModifier self._handModifier.setParent(self) def getLifeModifier(self): """Note: This only matters for Vanguard cards.""" return self._lifeModifier def hasLifeModifier(self): """Note: This only matters for Vanguard cards.""" return self._lifeModifier is not None def setLifeModifier(self, lifeModifier): """Note: This only matters for Vanguard cards.""" self._lifeModifier = lifeModifier self._lifeModifier.setParent(self) def getFlavor(self): return self._flavor def hasFlavor(self): return self._flavor is not None def setFlavor(self, flavor): self._flavor = flavor self._flavor.setParent(self) def isChild(self, child): return child in { self._name, self._manaCost, self._colorIndicator, self._typeLine, self._loyalty, self._expansionSymbol, self._textBox, self._powerToughness, self._handModifier, self._lifeModifier } def getTraversalSuccessors(self): return [ ts for ts in { self._name, self._manaCost, self._colorIndicator, self. _typeLine, self._loyalty, self._expansionSymbol, self._textBox, self._powerToughness, self._handModifier, self._lifeModifier } if ts is not None and ts.isTraversable() ] def unparseToString(self): output = "" if self._name is not None: output += "{0}".format(self._name.unparseToString()) if self._manaCost is not None: output += " {0}\n".format(self._manaCost.unparseToString()) else: output += "\n" if self._colorIndicator is not None: output += "Color Indicator: {0}\n".format(self._colorIndicator) if self._typeLine is not None: output += "{0}".format(self._typeLine.unparseToString()) if self._expansionSymbol is not None: output += " {0}\n".format(self._typeline.unparseToString()) else: output += "\n" if self._textBox is not None: output += "{0}\n".format(self._textBox.unparseToString()) if self._loyalty is not None: output += "{0}\n".format(self._loyalty.unparseToString()) if self._powerToughness is not None: output += "{0}\n".format(self._powerToughness.unparseToString()) if self._handModifier is not None: output += "{0}\n".format(self._lifeModifier.unparseToString()) if self._lifeModifier is not None: output += "{0}\n".format(self._lifeModifier.unparseToString()) return output