Exemple #1
0
def readWeaponsFromXML(filename):
    tree = ElementTree.parse(filename)
    xArsenal= tree.getroot()
    # First we read all weapon-patterns
    patterns = {}
    for xPattern in none2Empty(xArsenal.findall("Muster")):
        pattern = readWeaponFromXMLTag(xPattern, patterns)
        patterns[pattern.name] = pattern
    # Now we read all actual weapons
    weapons = {}
    for xWeapon in none2Empty(xArsenal.findall("Waffe")):
        weapon = readWeaponFromXMLTag(xWeapon, patterns)
        weapons[weapon.name] = weapon
    return weapons
Exemple #2
0
def readManeuversFromXML(filename):
    tree = ElementTree.parse(filename)
    xManeuvers= tree.getroot()
    # first we read all maneuver-patterns
    patterns = {}
    for xPattern in none2Empty(xManeuvers.findall("Muster")):
        pattern = readManeuverFromXMLTag(xPattern, patterns)
        patterns[pattern.name] = pattern
        # Now we read all actual maneuvers
    maneuvers = {}
    for xManeuver in none2Empty(xManeuvers.findall("Manoever")):
        maneuver = readManeuverFromXMLTag(xManeuver, patterns)
        maneuvers[maneuver.name] = maneuver
    return maneuvers
Exemple #3
0
def readVantagesFromFile(filename):
    vantages = {}
    parser = ElementTree.XMLParser(encoding="utf-8")
    tree = ElementTree.parse(filename, parser)
    xVantages = tree.getroot()
    xAdvantages = none2Empty(xVantages.findall("Vorteil"))
    xDisadvantages = none2Empty(xVantages.findall("Nachteil"))
    for xVantage in xAdvantages + xDisadvantages:
        vantageName = xVantage.get("id")
        vantageCost = xVantage.get("kosten", 0)
        if vantageName is not None:
            vantage = Vantage(vantageName, int(vantageCost))
            for attMod in none2Empty(xVantage.findall("Attributsmod")) :
                vantage.mods[attMod.get("attr")] = int(attMod.get("mod", 0))
            vantages[vantageName] = vantage
    return vantages
Exemple #4
0
def readRaceFromXMLFile(filename):
    tree = ElementTree.parse(filename)
    xRace = tree.getroot()
    raceName = xRace.find("Name").text
    race = Race(raceName)
    # Read Attribute Modifiers

    for attMod in none2Empty(xRace.find("Attribute")):
        assert attMod.tag == "Attributsmod"
        attributeName = attMod.get("attribut")
        attributeMod = int(attMod.get("mod"))
        race.attributeMods[attributeName] = attributeMod
    # Read Advantages and Disadvantages
    for vantage in none2Empty(xRace.find("Teile")):
        assert vantage.tag in ["Vorteil", "Nachteil"]
        race.vantages.append(unicode(vantage.get("id")))
    return race
Exemple #5
0
def readCharacterFromXML(filename):
    tree = ElementTree.parse(filename)
    xChar = tree.getroot()
    # Name
    char = Character(xChar.find("Name").text)
    # Race
    raceName = xChar.find("Rasse").text
    char.setRace(Race.getRaceByName(raceName))
    # Attributes
    for att in xChar.find("Attribute"):
        char.attributes[rules.Attributes.mapping[att.tag]] = int(att.get("value"))
    # Vantages
    for v in none2Empty(xChar.find("Teile")):
        vantageName = v.get("id")
        if vantageName in rules.vantages:
            char.addVantage(rules.vantages[vantageName])
        else:
            import warnings

            warnings.warn("Unknown Vantage '%s'" % vantageName)
    # Feats
    for f in none2Empty(xChar.find("Sonderfertigkeiten")):
        featName = f.get("id")
        if featName in rules.feats:
            char.addFeat(rules.feats[featName])
        else:
            import warnings

            warnings.warn("Unknown Feat '%s' in char %s" % (featName, char.name))
    # Skills
    recursiveSkillAdd(char.skills, xChar.find("Fertigkeiten"))
    # Maneuvers
    for xManeuver in none2Empty(xChar.find("ManöverListe")):
        maneuverName = xManeuver.get("id")
        if maneuverName in rules.maneuvers:
            maneuver = rules.maneuvers[maneuverName].copy()
            maneuver.level = int(xManeuver.get("stufe"))
            char.maneuvers.append(maneuver)
        else:
            import warnings

            warnings.warn("Unknown Maneuver %s in Char %s" % (maneuverName, char.name))
    return char
Exemple #6
0
def recursiveSkillAdd(root, xRoot):
    for xSkill in none2Empty(xRoot.findall("Fertigkeit")):
        skillName = xSkill.get("id")
        skillValue = xSkill.get("value", 0)
        if skillName is None:
            import warnings
            warnings.warn("Skill without id" + xSkill)
            continue
        skill = Skill(skillName, skillValue)
        root.add(skill)
        recursiveSkillAdd(root[skillName], xSkill)
Exemple #7
0
def readFeatsFromFile(filename):
    feats = {}
    parser = ElementTree.XMLParser(encoding="utf-8")
    tree = ElementTree.parse(filename, parser)
    xFeats = tree.getroot()
    for xVantage in none2Empty(xFeats.findall("Sonderfertigkeit")):
        featName = xVantage.get("id")
        featCost = xVantage.get("kosten", "0")
        if featName is not None:
            feat = Feat(featName, int(featCost))
            feats[featName] = feat
    return feats
Exemple #8
0
def readManeuversFromXElement(xManeuvers):
    maneuvers = {}
    for xManeuver in none2Empty(xManeuvers.findall("Manoever")) :
        # get name action points and base difficulty
        maneuverName = xManeuver.get("id")
        AP = xManeuver.get("AP")
        baseDiff = xManeuver.get("GS")
        maneuver = Maneuver(maneuverName, actionPoints=AP, baseDifficulty=baseDiff)
        # get Pool
        xPool = xManeuver.find("Pool")
        if xPool is not None :
            maneuver.pool = xPool.text
        # get impetus
        xImpetus = xManeuver.find("Wucht")
        if xImpetus is not None :
            maneuver.impetus = xImpetus.text
        # todo get options
        maneuvers[maneuverName] = maneuver
    return maneuvers