示例#1
0
def readSplineConfig(xmlCtx, section, cache):
    """Reads levered suspension section.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param section: instance of DataSection.
    :param cache: instance of vehicles.Cache.
    :return: instance of SplineConfig or None.
    """
    if section['splineDesc'] is None:
        return
    else:
        return chassis_components.SplineConfig(
            segmentModelLeft=_xml.readNonEmptyString(
                xmlCtx, section, 'splineDesc/segmentModelLeft'),
            segmentModelRight=_xml.readNonEmptyString(
                xmlCtx, section, 'splineDesc/segmentModelRight'),
            segmentLength=_xml.readFloat(xmlCtx, section,
                                         'splineDesc/segmentLength'),
            leftDesc=_xml.readStringOrNone(xmlCtx, section, 'splineDesc/left'),
            rightDesc=_xml.readStringOrNone(xmlCtx, section,
                                            'splineDesc/right'),
            lodDist=shared_readers.readLodDist(xmlCtx, section,
                                               'splineDesc/lodDist', cache),
            segmentOffset=section.readFloat('splineDesc/segmentOffset', 0),
            segment2ModelLeft=_xml.readStringOrNone(
                xmlCtx, section, 'splineDesc/segment2ModelLeft'),
            segment2ModelRight=_xml.readStringOrNone(
                xmlCtx, section, 'splineDesc/segment2ModelRight'),
            segment2Offset=section.readFloat('splineDesc/segment2Offset', 0),
            atlasUTiles=section.readInt('splineDesc/atlas/UTiles', 1),
            atlasVTiles=section.readInt('splineDesc/atlas/VTiles', 1))
示例#2
0
def readGroundNodesAndGroups(xmlCtx, section):
    if section['groundNodes'] is None:
        return (component_constants.EMPTY_TUPLE,
                component_constants.EMPTY_TUPLE)
    else:
        groundGroups = []
        groundNodes = []
        for sname, subsection in _xml.getChildren(xmlCtx, section,
                                                  'groundNodes'):
            if sname == 'group':
                ctx = (xmlCtx, 'groundNodes/group')
                group = chassis_components.GroundNodeGroup(
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'),
                    template=intern(
                        _xml.readNonEmptyString(ctx, subsection, 'template')),
                    count=_xml.readInt(ctx, subsection, 'count', 1),
                    startIndex=subsection.readInt('startIndex', 0))
                groundGroups.append(group)
            if sname == 'node':
                ctx = (xmlCtx, 'groundNodes/node')
                groundNode = chassis_components.GroundNode(
                    name=intern(
                        _xml.readNonEmptyString(ctx, subsection, 'name')),
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'))
                groundNodes.append(groundNode)

        return (tuple(groundGroups), tuple(groundNodes))
示例#3
0
def readWheelsAndGroups(xmlCtx, section):
    wheelGroups = []
    wheels = []
    defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60)
    for sname, subsection in _xml.getChildren(xmlCtx, section, 'wheels'):
        if sname == 'group':
            ctx = (xmlCtx, 'wheels/group')
            group = chassis_components.WheelGroup(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                template=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'template')),
                count=_xml.readInt(ctx, subsection, 'count', 1),
                startIndex=subsection.readInt('startIndex', 0),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'))
            wheelGroups.append(group)
        if sname == 'wheel':
            ctx = (xmlCtx, 'wheels/wheel')
            w = chassis_components.Wheel(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'),
                nodeName=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'name')),
                isLeading=subsection.readBool('isLeading', False),
                leadingSyncAngle=subsection.readFloat('syncAngle',
                                                      defSyncAngle))
            wheels.append(w)

    return (tuple(wheelGroups), tuple(wheels))
示例#4
0
def readWheelsAndGroups(xmlCtx, section):
    """Reads sections 'wheels/group' and 'wheels/wheel' for each chassis.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param section: instance of DataSection.
    :return: tuple(sequence of groups, sequence of wheels).
    """
    wheelGroups = []
    wheels = []
    defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60)
    for sname, subsection in _xml.getChildren(xmlCtx, section, 'wheels'):
        if sname == 'group':
            ctx = (xmlCtx, 'wheels/group')
            group = chassis_components.WheelGroup(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                template=_xml.readNonEmptyString(ctx, subsection, 'template'),
                count=_xml.readInt(ctx, subsection, 'count', 1),
                startIndex=subsection.readInt('startIndex', 0),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'))
            wheelGroups.append(group)
        elif sname == 'wheel':
            ctx = (xmlCtx, 'wheels/wheel')
            w = chassis_components.Wheel(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'),
                nodeName=_xml.readNonEmptyString(ctx, subsection, 'name'),
                isLeading=subsection.readBool('isLeading', False),
                leadingSyncAngle=subsection.readFloat('syncAngle',
                                                      defSyncAngle))
            wheels.append(w)

    return (tuple(wheelGroups), tuple(wheels))
示例#5
0
def readLeveredSuspension(xmlCtx, section, cache):
    leveredSection = section['leveredSuspension']
    if leveredSection is None:
        return
    else:
        levers = []
        for sname, subsection in _xml.getChildren(xmlCtx, section,
                                                  'leveredSuspension'):
            if sname != 'lever':
                continue
            ctx = (xmlCtx, 'leveredSuspension/lever')
            limits = _xml.readVector2(ctx, subsection, 'limits')
            lever = chassis_components.SuspensionLever(
                startNodeName=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'startNode')),
                jointNodeName=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'jointNode')),
                trackNodeName=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'trackNode')),
                minAngle=math.radians(limits.x),
                maxAngle=math.radians(limits.y))
            levers.append(lever)

        ctx = (xmlCtx, 'leveredSuspension')
        leveredSuspensionConfig = chassis_components.LeveredSuspensionConfig(
            levers=levers,
            interpolationSpeedMul=_xml.readFloat(ctx, leveredSection,
                                                 'interpolationSpeedMul',
                                                 10.0),
            lodSettings=shared_readers.readLodSettings(ctx, leveredSection,
                                                       cache))
        return leveredSuspensionConfig
def _readBookItem(pricesCache, cache, xmlCtx, section, storage):
    bookID = _xml.readInt(xmlCtx, section, 'id', 1)
    priceGroup = section.readString('priceGroup')
    tags = _readGroupTags((xmlCtx, 'tags'), section, 'tags')
    nameID = _xml.readStringOrEmpty(xmlCtx, section, 'name')
    descriptionID = _xml.readStringOrEmpty(xmlCtx, section, 'description')
    iconID = _xml.readNonEmptyString(xmlCtx, section, 'icon')
    type = _xml.readNonEmptyString(xmlCtx, section, 'type')
    if type not in crew_books_constants.CREW_BOOK_RARITY.ALL_TYPES:
        _xml.raiseWrongXml(xmlCtx, 'type', "unknown crew book rarity type '%s'" % type)
    crewBookItem = cb.CrewBook(bookID, priceGroup, nameID, descriptionID, iconID, type, tags)
    if section.has_key('filters'):
        filterSection = _xml.getSubsection(xmlCtx, section, 'filters')
        if filterSection.has_key('nation'):
            nation = filterSection.readString('nation', '')
            if nation and nation not in nations.NAMES:
                _xml.raiseWrongXml(xmlCtx, 'nation', "unknown nation '%s'" % nation)
            crewBookItem.nation = nation if nation else None
    if not crewBookItem.nation and type not in crew_books_constants.CREW_BOOK_RARITY.NO_NATION_TYPES:
        _xml.raiseWrongXml(xmlCtx, 'nation', "crew book with rarity type '%s' should have nation" % type)
    storage[bookID] = crewBookItem
    groupsDict = cache.priceGroups
    itemToGroup = cache.itemToPriceGroup
    if crewBookItem.priceGroup:
        if crewBookItem.priceGroup not in cache.priceGroupNames:
            _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'unknown price group %s for item %s' % (crewBookItem.priceGroup, crewBookItem.id))
        priceGroupId = cache.priceGroupNames[crewBookItem.priceGroup]
        crewBookItem.priceGroupTags = groupsDict[priceGroupId].tags
        itemToGroup[crewBookItem.compactDescr] = groupsDict[priceGroupId].compactDescr
        itemNotInShop = section.readBool('notInShop', False)
        _copyPriceForItem(pricesCache, groupsDict[priceGroupId].compactDescr, crewBookItem.compactDescr, itemNotInShop)
    else:
        _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'no price for item %s' % crewBookItem.id)
    return
示例#7
0
def readGroundNodesAndGroups(xmlCtx, section):
    """Reads section 'groundNodes' for each chassis if it has.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param section: instance of DataSection.
    :return: tuple(sequence of groups, sequence of nodes).
    """
    if section['groundNodes'] is None:
        return (component_constants.EMPTY_TUPLE,
                component_constants.EMPTY_TUPLE)
    else:
        groundGroups = []
        groundNodes = []
        for sname, subsection in _xml.getChildren(xmlCtx, section,
                                                  'groundNodes'):
            if sname == 'group':
                ctx = (xmlCtx, 'groundNodes/group')
                group = chassis_components.GroundNodeGroup(
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'),
                    template=_xml.readNonEmptyString(ctx, subsection,
                                                     'template'),
                    count=_xml.readInt(ctx, subsection, 'count', 1),
                    startIndex=subsection.readInt('startIndex', 0))
                groundGroups.append(group)
            elif sname == 'node':
                ctx = (xmlCtx, 'groundNodes/node')
                groundNode = chassis_components.GroundNode(
                    name=_xml.readNonEmptyString(ctx, subsection, 'name'),
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'))
                groundNodes.append(groundNode)

        return (tuple(groundGroups), tuple(groundNodes))
def readWheelsAndGroups(xmlCtx, section):
    wheelGroups = []
    wheels = []
    wheelId = 0
    defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60)
    for sname, subsection in _xml.getChildren(xmlCtx, section, 'wheels'):
        if sname == 'group':
            ctx = (xmlCtx, 'wheels/group')
            group = chassis_components.WheelGroup(
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                template=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'template')),
                count=_xml.readInt(ctx, subsection, 'count', 1),
                startIndex=subsection.readInt('startIndex', 0),
                radius=_xml.readPositiveFloat(ctx, subsection, 'radius'))
            wheelGroups.append(group)
        if sname == 'wheel':
            from items.vehicles import _readHitTester, _readArmor
            ctx = (xmlCtx, 'wheels/wheel[{}]'.format(wheelId))
            radiusKey = 'radius' if subsection.has_key(
                'radius') else 'geometry/radius'
            index = _xml.readIntOrNone(ctx, subsection, 'index')
            actualIndex = wheelId if index is None else index
            w = chassis_components.Wheel(
                index=index,
                isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                radius=_xml.readPositiveFloat(ctx, subsection, radiusKey),
                nodeName=intern(
                    _xml.readNonEmptyString(ctx, subsection, 'name')),
                isLeading=subsection.readBool('isLeading', False),
                leadingSyncAngle=subsection.readFloat('syncAngle',
                                                      defSyncAngle),
                hitTester=_readHitTester(ctx,
                                         subsection,
                                         'hitTester',
                                         optional=True),
                materials=_readArmor(ctx,
                                     subsection,
                                     'armor',
                                     optional=True,
                                     index=actualIndex),
                position=subsection.readVector3('wheelPos', (0, 0, 0)))
            if IS_EDITOR:
                w.editorData.defSyncAngle = defSyncAngle
            wheels.append(w)
            wheelId += 1

    wheelIndices = [wheel.index for wheel in wheels]
    if sorted(wheelIndices) == range(len(wheels)):
        sortedWheels = [None] * len(wheels)
        for wheel in wheels:
            sortedWheels[wheel.index] = wheel

        wheels = sortedWheels
    elif wheelIndices == [None] * len(wheels):
        pass
    else:
        LOG_ERROR('Invalid wheel index detected', xmlCtx, wheels)
    return (tuple(wheelGroups), tuple(wheels))
示例#9
0
def readTrackMaterials(xmlCtx, section, cache):
    return chassis_components.TrackMaterials(
        lodDist=shared_readers.readLodDist(xmlCtx, section, 'tracks/lodDist',
                                           cache),
        leftMaterial=intern(
            _xml.readNonEmptyString(xmlCtx, section, 'tracks/leftMaterial')),
        rightMaterial=intern(
            _xml.readNonEmptyString(xmlCtx, section, 'tracks/rightMaterial')),
        textureScale=_xml.readFloat(xmlCtx, section, 'tracks/textureScale'))
 def __readAnnouncements(self, xmlCtx, root):
     for name, section in _xml.getChildren(xmlCtx, root, 'announcements'):
         if name in self.__announcements:
             _xml.raiseWrongXml(xmlCtx, 'announcements', 'Announcement vehicles {0:>s} is already added'.format(name))
         tags = _xml.readNonEmptyString(xmlCtx, section, 'tags')
         if tags:
             tags = frozenset(tags.split(' '))
         else:
             tags = frozenset()
         self.__announcements[name] = _AnnouncementInfo(_xml.readNonEmptyString(xmlCtx, section, 'user-string'), _xml.readNonEmptyString(xmlCtx, section, 'tooltip'), tags, _xml.readInt(xmlCtx, section, 'level'), _xml.readNonEmptyString(xmlCtx, section, 'icon'), _xml.readBool(xmlCtx, section, 'is-elite'))
示例#11
0
def readTraces(xmlCtx, section, centerOffset, cache):
    return chassis_components.Traces(
        lodDist=shared_readers.readLodDist(xmlCtx, section, 'traces/lodDist',
                                           cache),
        bufferPrefs=intern(
            _xml.readNonEmptyString(xmlCtx, section, 'traces/bufferPrefs')),
        textureSet=intern(
            _xml.readNonEmptyString(xmlCtx, section, 'traces/textureSet')),
        centerOffset=centerOffset,
        size=_xml.readPositiveVector2(xmlCtx, section, 'traces/size'))
def _readPerkItem(xmlCtx, section, storage):
    perkID = _xml.readInt(xmlCtx, section, 'id', 1)
    name = _xml.readStringOrEmpty(xmlCtx, section, 'name')
    description = _xml.readNonEmptyString(xmlCtx, section, 'description')
    icon = _xml.readNonEmptyString(xmlCtx, section, 'icon')
    branchID = _xml.readInt(xmlCtx, section, 'branchID', 0)
    ultimative = section.readBool('ultimative', False)
    maxCount = _xml.readInt(xmlCtx, section, 'maxCount', 1)
    situational = _xml.readBool(xmlCtx, section, 'situational', False)
    perkItem = Perk(perkID, name, description, icon, branchID, ultimative, maxCount, situational)
    storage[perkID] = perkItem
def readTrackBasicParams(xmlCtx, section, cache):
    tracksSection = section['tracks']
    return None if tracksSection is None else chassis_components.TrackBasicParams(
        lodDist=shared_readers.readLodDist(xmlCtx, section, 'tracks/lodDist',
                                           cache),
        leftMaterial=intern(
            _xml.readNonEmptyString(xmlCtx, section, 'tracks/leftMaterial')),
        rightMaterial=intern(
            _xml.readNonEmptyString(xmlCtx, section, 'tracks/rightMaterial')),
        textureScale=_xml.readFloat(xmlCtx, section, 'tracks/textureScale'),
        pairsCount=section.readInt('tracks/pairsCount', 1))
示例#14
0
 def __init__(self, dataSection, exhaustEffectsDescriptors, xmlCtx):
     self.nodes = _xml.readNonEmptyString(xmlCtx, dataSection, 'exhaust/nodes').split()
     defaultPixieName = _xml.readNonEmptyString(xmlCtx, dataSection, 'exhaust/pixie')
     dieselPixieName = defaultPixieName
     gasolinePixieName = defaultPixieName
     exhaustTagsSection = dataSection['exhaust/tags']
     if exhaustTagsSection is not None:
         dieselPixieName = exhaustTagsSection.readString('diesel', dieselPixieName)
         gasolinePixieName = exhaustTagsSection.readString('gasoline', gasolinePixieName)
     tmpDefault = exhaustEffectsDescriptors['default']
     self.diesel = exhaustEffectsDescriptors.get(dieselPixieName, tmpDefault)
     self.gasoline = exhaustEffectsDescriptors.get(gasolinePixieName, tmpDefault)
示例#15
0
 def __init__(self, dataSection, exhaustEffectsDescriptors, xmlCtx):
     self.nodes = _xml.readNonEmptyString(xmlCtx, dataSection, "exhaust/nodes").split()
     defaultPixieName = _xml.readNonEmptyString(xmlCtx, dataSection, "exhaust/pixie")
     dieselPixieName = defaultPixieName
     gasolinePixieName = defaultPixieName
     exhaustTagsSection = dataSection["exhaust/tags"]
     if exhaustTagsSection is not None:
         dieselPixieName = exhaustTagsSection.readString("diesel", dieselPixieName)
         gasolinePixieName = exhaustTagsSection.readString("gasoline", gasolinePixieName)
     tmpDefault = exhaustEffectsDescriptors["default"]
     self.diesel = exhaustEffectsDescriptors.get(dieselPixieName, tmpDefault)
     self.gasoline = exhaustEffectsDescriptors.get(gasolinePixieName, tmpDefault)
示例#16
0
 def __init__(self, dataSection, exhaustEffectsDescriptors, xmlCtx):
     self.nodes = _xml.readNonEmptyString(xmlCtx, dataSection, 'exhaust/nodes').split()
     defaultPixieName = _xml.readNonEmptyString(xmlCtx, dataSection, 'exhaust/pixie')
     dieselPixieName = defaultPixieName
     gasolinePixieName = defaultPixieName
     exhaustTagsSection = dataSection['exhaust/tags']
     if exhaustTagsSection is not None:
         dieselPixieName = exhaustTagsSection.readString('diesel', dieselPixieName)
         gasolinePixieName = exhaustTagsSection.readString('gasoline', gasolinePixieName)
     tmpDefault = exhaustEffectsDescriptors['default']
     self.diesel = exhaustEffectsDescriptors.get(dieselPixieName, tmpDefault)
     self.gasoline = exhaustEffectsDescriptors.get(gasolinePixieName, tmpDefault)
示例#17
0
def readModelsSets(xmlCtx, section, subsectionName):
    undamaged = _xml.readNonEmptyString(xmlCtx, section, subsectionName + '/undamaged')
    destroyed = _xml.readNonEmptyString(xmlCtx, section, subsectionName + '/destroyed')
    exploded = _xml.readNonEmptyString(xmlCtx, section, subsectionName + '/exploded')
    modelsSets = {'default': shared_components.ModelStatesPaths(undamaged, destroyed, exploded)}
    subsection = section[subsectionName]
    if subsection:
        setSection = subsection['sets'] or {}
        for k, v in setSection.items():
            modelsSets[k] = shared_components.ModelStatesPaths(_xml.readStringOrNone(xmlCtx, v, 'undamaged') or undamaged, _xml.readStringOrNone(xmlCtx, v, 'destroyed') or destroyed, _xml.readStringOrNone(xmlCtx, v, 'exploded') or exploded)

    return modelsSets
def readGroundNodesAndGroups(xmlCtx, section, cache):
    if section['groundNodes'] is None:
        return (component_constants.EMPTY_TUPLE,
                component_constants.EMPTY_TUPLE, False, None)
    else:
        groundGroups = []
        groundNodes = []
        for sname, subsection in _xml.getChildren(xmlCtx, section,
                                                  'groundNodes'):
            if sname == 'group':
                ctx = (xmlCtx, 'groundNodes/group')
                group = chassis_components.GroundNodeGroup(
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'),
                    nodesTemplate=intern(
                        _xml.readNonEmptyString(ctx, subsection, 'template')),
                    affectedWheelsTemplate=_xml.readStringOrNone(
                        ctx, subsection, 'affectedWheelsTemplate'),
                    nodesCount=_xml.readInt(ctx, subsection, 'count', 1),
                    startIndex=subsection.readInt('startIndex', 0),
                    collisionSamplesCount=subsection.readInt(
                        'collisionSamplesCount', 1),
                    hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode',
                                              False))
                groundGroups.append(group)
            if sname == 'node':
                ctx = (xmlCtx, 'groundNodes/node')
                groundNode = chassis_components.GroundNode(
                    nodeName=intern(
                        _xml.readNonEmptyString(ctx, subsection, 'name')),
                    affectedWheelName=_xml.readStringOrEmpty(
                        ctx, subsection, 'affectedWheelName'),
                    isLeft=_xml.readBool(ctx, subsection, 'isLeft'),
                    minOffset=_xml.readFloat(ctx, subsection, 'minOffset'),
                    maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'),
                    collisionSamplesCount=_xml.readInt(
                        ctx, subsection, 'collisionSamplesCount', 1),
                    hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode',
                                              False))
                groundNodes.append(groundNode)

        activePostmortem = _xml.readBool(xmlCtx, section,
                                         'groundNodes/activePostmortem', False)
        lodSettingsSection = section['groundNodes/lodSettings']
        if lodSettingsSection is not None:
            lodSettings = shared_readers.readLodSettings(
                xmlCtx, section['groundNodes'], cache)
        else:
            lodSettings = None
        return (tuple(groundGroups), tuple(groundNodes), activePostmortem,
                lodSettings)
示例#19
0
def _readSkinItem(pricesCache, cache, xmlCtx, section, storage):
    skinID = _xml.readInt(xmlCtx, section, 'id', 1)
    if skinID in storage:
        _xml.raiseWrongXml(xmlCtx, 'id', "duplicate id '%s'" % skinID)
    priceGroup = section.readString('priceGroup')
    tags = _readGroupTags((xmlCtx, 'tags'), section, 'tags')
    firstNameID = _xml.readStringOrEmpty(xmlCtx, section, 'firstName')
    lastNameID = _xml.readNonEmptyString(xmlCtx, section, 'lastName')
    description = _xml.readNonEmptyString(xmlCtx, section, 'description')
    iconID = _xml.readNonEmptyString(xmlCtx, section, 'icon')
    rarity = _xml.readInt(xmlCtx, section, 'rarity', 1)
    maxCount = _xml.readInt(xmlCtx, section, 'maxCount')
    soundSetID = section.readString('soundSet', crew_skins_constants.NO_CREW_SKIN_SOUND_SET)
    historical = _xml.readBool(xmlCtx, section, 'historical', False)
    realmsStr = section.readString('realms', '')
    realms = realmsStr.split()
    unexpectedRealms = set(realms) - REGIONAL_REALMS
    if unexpectedRealms:
        _xml.raiseWrongXml(xmlCtx, 'realms', "unknown realms '%s'" % unexpectedRealms)
    crewSkinItem = cc.CrewSkin(skinID, priceGroup, firstNameID, lastNameID, iconID, description, rarity, maxCount, tags, historical, soundSetID, realms)
    if section.has_key('filters'):
        filterSection = _xml.getSubsection(xmlCtx, section, 'filters')
        if filterSection.has_key('role'):
            roleName = filterSection.readString('role')
            if roleName not in skills_constants.ROLES:
                _xml.raiseWrongXml(xmlCtx, 'role', "unknown tankmanRole '%s'" % roleName)
            crewSkinItem.roleID = roleName if roleName else None
        if filterSection.has_key('nation'):
            nation = filterSection.readString('nation', '')
            if nation and nation not in nations.NAMES:
                _xml.raiseWrongXml(xmlCtx, 'nation', "unknown nation '%s'" % nation)
            crewSkinItem.nation = nation if nation else None
        if filterSection.has_key('sex'):
            sex = filterSection.readString('sex', '')
            if sex not in crew_skins_constants.TANKMAN_SEX.AVAILABLE:
                _xml.raiseWrongXml(xmlCtx, 'sex', "unknown tankman sex '%s'" % sex)
            crewSkinItem.sex = sex
    storage[skinID] = crewSkinItem
    groupsDict = cache.priceGroups
    itemToGroup = cache.itemToPriceGroup
    if crewSkinItem.priceGroup:
        if crewSkinItem.priceGroup not in cache.priceGroupNames:
            _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'unknown price group %s for item %s' % (crewSkinItem.priceGroup, crewSkinItem.id))
        priceGroupId = cache.priceGroupNames[crewSkinItem.priceGroup]
        crewSkinItem.priceGroupTags = groupsDict[priceGroupId].tags
        itemToGroup[crewSkinItem.compactDescr] = groupsDict[priceGroupId].compactDescr
        itemNotInShop = section.readBool('notInShop', False)
        _copyPriceForItem(pricesCache, groupsDict[priceGroupId].compactDescr, crewSkinItem.compactDescr, itemNotInShop)
    else:
        _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'no price for item %s' % crewSkinItem.id)
    return
示例#20
0
def readModels(xmlCtx, section, subsectionName):
    """Reads section with name 'subsectionName' to fetch paths of models
        for each hull, chassis, turret and gun.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param section: instance of DataSection.
    :param subsectionName: string containing name of desired section.
    :return: instance of ModelStatesPaths.
    """
    return shared_components.ModelStatesPaths(
        _xml.readNonEmptyString(xmlCtx, section,
                                subsectionName + '/undamaged'),
        _xml.readNonEmptyString(xmlCtx, section,
                                subsectionName + '/destroyed'),
        _xml.readNonEmptyString(xmlCtx, section, subsectionName + '/exploded'))
示例#21
0
def readTrackMaterials(xmlCtx, section, cache):
    """Reads section 'tracks' for each chassis to fetch configuration of materials.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param section: instance of DataSection.
    :param cache: instance of vehicles.Cache.
    :return: instance of TrackMaterials.
    """
    return chassis_components.TrackMaterials(
        lodDist=shared_readers.readLodDist(xmlCtx, section, 'tracks/lodDist',
                                           cache),
        leftMaterial=_xml.readNonEmptyString(xmlCtx, section,
                                             'tracks/leftMaterial'),
        rightMaterial=_xml.readNonEmptyString(xmlCtx, section,
                                              'tracks/rightMaterial'),
        textureScale=_xml.readFloat(xmlCtx, section, 'tracks/textureScale'))
def readTrackNodes(xmlCtx, section):
    if section['trackNodes'] is None:
        return component_constants.EMPTY_TUPLE
    else:
        defElasticity = _xml.readFloat(xmlCtx, section, 'trackNodes/elasticity', 1500.0)
        defDamping = _xml.readFloat(xmlCtx, section, 'trackNodes/damping', 1.0)
        defForwardElastK = _xml.readFloat(xmlCtx, section, 'trackNodes/forwardElastK', 1.0)
        defBackwardElastK = _xml.readFloat(xmlCtx, section, 'trackNodes/backwardElastK', 1.0)
        defOffset = _xml.readFloat(xmlCtx, section, 'trackNodes/offset', 0.0)
        trackNodes = []
        xmlCtx = (xmlCtx, 'trackNodes')
        for sname, subsection in _xml.getChildren(xmlCtx, section, 'trackNodes'):
            if sname == 'node':
                ctx = (xmlCtx, 'trackNodes/node')
                name = _xml.readStringOrNone(ctx, subsection, 'leftSibling')
                if name is not None:
                    leftNodeName = intern(name)
                else:
                    leftNodeName = None
                name = _xml.readStringOrNone(ctx, subsection, 'rightSibling')
                if name is not None:
                    rightNodeName = intern(name)
                else:
                    rightNodeName = None
                trackNode = chassis_components.TrackNode(name=intern(_xml.readNonEmptyString(ctx, subsection, 'name')), isLeft=_xml.readBool(ctx, subsection, 'isLeft'), initialOffset=_xml.readFloat(ctx, subsection, 'offset', defOffset), leftNodeName=leftNodeName, rightNodeName=rightNodeName, damping=_xml.readFloat(ctx, subsection, 'damping', defDamping), elasticity=_xml.readFloat(ctx, subsection, 'elasticity', defElasticity), forwardElasticityCoeff=_xml.readFloat(ctx, subsection, 'forwardElastK', defForwardElastK), backwardElasticityCoeff=_xml.readFloat(ctx, subsection, 'backwardElastK', defBackwardElastK))
                trackNodes.append(trackNode)

        return tuple(trackNodes)
示例#23
0
def _readTankmenGroup(xmlCtx, subsection, firstNames, lastNames, icons):
    """Reads section containing data of tankmen group and stores it to NationGroup.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param subsection: instance of DataSection.
    :param firstNames: dict(ID of first name: string or None)
    :param lastNames: dict(ID of last name: string or None)
    :param icons: dict(ID of icon: string or None)
    :return: instance of NationGroup.
    """
    if IS_CLIENT or IS_WEB:
        parseName = _parseName
        parseIcon = _parseIcon
    else:
        parseName = parseIcon = None
    return tankmen_components.NationGroup(
        subsection.asString,
        'female' == _xml.readNonEmptyString(xmlCtx, subsection, 'sex'),
        subsection.readBool('notInShop', False),
        _readIDs((xmlCtx, 'firstNames'),
                 _xml.getChildren(xmlCtx, subsection, 'firstNames'),
                 firstNames, parseName),
        _readIDs((xmlCtx, 'lastNames'),
                 _xml.getChildren(xmlCtx, subsection, 'lastNames'), lastNames,
                 parseName),
        _readIDs((xmlCtx, 'icons'),
                 _xml.getChildren(xmlCtx, subsection, 'icons'), icons,
                 parseIcon),
        _xml.readNonNegativeFloat(xmlCtx, subsection, 'weight'),
        _readGroupTags((xmlCtx, 'tags'), subsection, 'tags'),
        _readGroupRoles((xmlCtx, 'roles'), subsection, 'roles'))
示例#24
0
def readLodDist(xmlCtx, section, subsectionName, cache):
    name = _xml.readNonEmptyString(xmlCtx, section, subsectionName)
    dist = cache.commonConfig['lodLevels'].get(name)
    if dist is None:
        _xml.raiseWrongXml(xmlCtx, subsectionName,
                           "unknown lod level '%s'" % name)
    return dist
 def __init__(self, dataSection, xmlCtx, customDescriptors, name):
     super(ExhaustEffectDescriptor, self).__init__()
     self.__descriptors = customDescriptors
     self.nodes = [
         intern(node) for node in _xml.readNonEmptyString(
             xmlCtx, dataSection, name).split()
     ]
示例#26
0
def __readProgressLevel(xmlCtx, section):
    level = {}
    for sectionName, subSections in section.items():
        if sectionName == 'price':
            level.update({
                'price': ix.readPrice(xmlCtx, section, 'price'),
                'notInShop': section.readBool('notInShop', False)
            })
        if sectionName == 'condition':
            conditions = level.setdefault('conditions', list())
            condition = {}
            for subSection in subSections.values():
                sectionName = subSection.name
                if sectionName == 'description':
                    condition.update({
                        'description':
                        ix.readNonEmptyString(xmlCtx, subSection, '')
                    })
                condition.update(
                    __readCondition((xmlCtx, subSection.name), subSection,
                                    [sectionName]))

            if not condition:
                ix.raiseWrongXml(xmlCtx, 'progression',
                                 "Customization don't have conditions")
            conditions.append(condition)

    return level
def _readTankmenGroup(xmlCtx, subsection, firstNames, lastNames, icons):
    if IS_CLIENT or IS_WEB:
        parseName = _parseName
        parseIcon = _parseIcon
    else:
        parseName = parseIcon = None
    return tankmen_components.NationGroup(subsection.asString, 'female' == _xml.readNonEmptyString(xmlCtx, subsection, 'sex'), subsection.readBool('notInShop', False), _readIDs((xmlCtx, 'firstNames'), _xml.getChildren(xmlCtx, subsection, 'firstNames'), firstNames, parseName), _readIDs((xmlCtx, 'lastNames'), _xml.getChildren(xmlCtx, subsection, 'lastNames'), lastNames, parseName), _readIDs((xmlCtx, 'icons'), _xml.getChildren(xmlCtx, subsection, 'icons'), icons, parseIcon), _xml.readNonNegativeFloat(xmlCtx, subsection, 'weight'), _readGroupTags((xmlCtx, 'tags'), subsection, 'tags'), _readGroupRoles((xmlCtx, 'roles'), subsection, 'roles'))
def readHullAimingSound(xmlCtx, section, cache):
    if section['hullAiming'] is None:
        return
    else:
        try:
            lodDist = shared_readers.readLodDist(xmlCtx, section,
                                                 'hullAiming/audio/lodDist',
                                                 cache)
            angleLimit = math.radians(
                _xml.readFloat(xmlCtx, section,
                               'hullAiming/audio/angleLimitValue',
                               component_constants.ZERO_FLOAT))
            sounds = []
            for actionName, actionSection in _xml.getChildren(
                    xmlCtx, section, 'hullAiming/audio/sounds'):
                ctx = (xmlCtx, 'hullAiming/audio/sounds')
                underLimitSouns = sound_components.SoundPair(
                    PC=intern(
                        _xml.readNonEmptyString(ctx, actionSection,
                                                'underLimitSounds/wwsoundPC')),
                    NPC=intern(
                        _xml.readNonEmptyString(
                            ctx, actionSection,
                            'underLimitSounds/wwsoundNPC')))
                overLimitSounds = sound_components.SoundPair(
                    PC=intern(
                        _xml.readNonEmptyString(ctx, actionSection,
                                                'overLimitSounds/wwsoundPC')),
                    NPC=intern(
                        _xml.readNonEmptyString(ctx, actionSection,
                                                'overLimitSounds/wwsoundNPC')))
                sound = sound_components.StatedSounds(
                    state=actionName,
                    underLimitSounds=underLimitSouns,
                    overLimitSounds=overLimitSounds)
                sounds.append(sound)

            hullAimingSound = sound_components.HullAimingSound(
                lodDist=lodDist,
                angleLimitValue=_xml.cachedFloat(angleLimit),
                sounds=sounds)
            return hullAimingSound
        except:
            LOG_DEBUG('Incorrect hullAiming/audio section')
            return

        return
示例#29
0
def readTraces(xmlCtx, section, centerOffset, cache):
    """Reads section 'traces' for each chassis.
    :param xmlCtx: tuple(root ctx or None, path to section).
    :param section: instance of DataSection.
    :param centerOffset: float containing offset by x coordinate.
    :param cache: instance of vehicles.Cache.
    :return: instance of Traces.
    """
    return chassis_components.Traces(
        lodDist=shared_readers.readLodDist(xmlCtx, section, 'traces/lodDist',
                                           cache),
        bufferPrefs=_xml.readNonEmptyString(xmlCtx, section,
                                            'traces/bufferPrefs'),
        textureSet=_xml.readNonEmptyString(xmlCtx, section,
                                           'traces/textureSet'),
        centerOffset=centerOffset,
        size=_xml.readPositiveVector2(xmlCtx, section, 'traces/size'))
示例#30
0
 def getDescriptor(dataSection, customDescriptors, xmlCtx, name):
     effectName = _xml.readNonEmptyString(xmlCtx, dataSection, name)
     effectDesc = None
     if effectName is not None:
         effectDesc = customDescriptors.get(effectName, None)
     if effectDesc is None:
         effectDesc = customDescriptors.get('default', None)
     return effectDesc
示例#31
0
 def getDescriptor(dataSection, customDescriptors, xmlCtx, name):
     effectName = _xml.readNonEmptyString(xmlCtx, dataSection, name)
     effectDesc = None
     if effectName is not None:
         effectDesc = customDescriptors.get(effectName, None)
     if effectDesc is None:
         effectDesc = customDescriptors.get('default', None)
     return effectDesc
示例#32
0
def _readRoleRanks(xmlCtx, section, rankIDsByNames):
    res = {}
    for roleName in ROLES:
        rankIDs = []
        res[roleName] = rankIDs
        for rankName in _xml.readNonEmptyString(xmlCtx, section, roleName).split():
            rankIDs.append(rankIDsByNames[rankName])

    return res
示例#33
0
def _readSkillBasics(xmlCtx, section, subsectionName):
    section = _xml.getSubsection(xmlCtx, section, subsectionName)
    xmlCtx = (xmlCtx, subsectionName)
    res = {}
    if IS_CLIENT or IS_WEB:
        res['userString'] = i18n.makeString(section.readString('userString'))
        res['description'] = i18n.makeString(section.readString('description'))
        res['icon'] = _xml.readNonEmptyString(xmlCtx, section, 'icon')
    return (res, xmlCtx, section)
示例#34
0
def _readSkillBasics(xmlCtx, section, subsectionName):
    section = _xml.getSubsection(xmlCtx, section, subsectionName)
    xmlCtx = (xmlCtx, subsectionName)
    res = {}
    if IS_CLIENT or IS_WEB:
        res["userString"] = i18n.makeString(section.readString("userString"))
        res["description"] = i18n.makeString(section.readString("description"))
        res["icon"] = _xml.readNonEmptyString(xmlCtx, section, "icon")
    return (res, xmlCtx, section)
示例#35
0
def _readSkillBasics(xmlCtx, section, subsectionName):
    section = _xml.getSubsection(xmlCtx, section, subsectionName)
    xmlCtx = (xmlCtx, subsectionName)
    res = {}
    if IS_CLIENT or IS_WEB:
        res['userString'] = i18n.makeString(section.readString('userString'))
        res['description'] = i18n.makeString(section.readString('description'))
        res['icon'] = _xml.readNonEmptyString(xmlCtx, section, 'icon')
    return (res, xmlCtx, section)
示例#36
0
def _readRoleRanks(xmlCtx, section, rankIDsByNames):
    res = {}
    for roleName in ROLES:
        rankIDs = []
        res[roleName] = rankIDs
        for rankName in _xml.readNonEmptyString(xmlCtx, section, roleName).split():
            rankIDs.append(rankIDsByNames[rankName])

    return res
示例#37
0
def _readRanks(xmlCtx, subsections):
    ranks = []
    rankIDsByNames = {}
    for sname, subsection in subsections:
        if rankIDsByNames.has_key(sname):
            _xml.raiseWrong(xmlCtx, sname, 'is not unique')
        ctx = (xmlCtx, sname)
        rankIDsByNames[sname] = len(ranks)
        if not (IS_CLIENT or IS_WEB):
            ranks.append(None)
        else:
            ranks.append({'userString': i18n.makeString(_xml.readNonEmptyString(ctx, subsection, 'userString')),
             'icon': _parseIcon((ctx, 'icon'), _xml.getSubsection(ctx, subsection, 'icon'))})

    return (ranks, rankIDsByNames)
示例#38
0
def _readNationConfigSection(xmlCtx, section):
    res = {}
    firstNames = {}
    lastNames = {}
    icons = {}
    for kindName in ("normalGroups", "premiumGroups"):
        groups = []
        res[kindName] = groups
        totalWeight = 0.0
        for sname, subsection in _xml.getChildren(xmlCtx, section, kindName):
            ctx = (xmlCtx, kindName + "/" + sname)
            group = {
                "notInShop": subsection.readBool("notInShop", False),
                "isFemales": "female" == _xml.readNonEmptyString(ctx, subsection, "sex"),
                "firstNames": _readIDs(
                    (ctx, "firstNames"), _xml.getChildren(ctx, subsection, "firstNames"), firstNames, _parseName
                ),
                "lastNames": _readIDs(
                    (ctx, "lastNames"), _xml.getChildren(ctx, subsection, "lastNames"), lastNames, _parseName
                ),
                "icons": _readIDs((ctx, "icons"), _xml.getChildren(ctx, subsection, "icons"), icons, _parseIcon),
            }
            group["firstNamesList"] = list(group["firstNames"])
            group["lastNamesList"] = list(group["lastNames"])
            group["iconsList"] = list(group["icons"])
            weight = _xml.readNonNegativeFloat(ctx, subsection, "weight")
            totalWeight += weight
            group["weight"] = weight
            groups.append(group)

        totalWeight = max(0.001, totalWeight)
        for group in groups:
            group["weight"] /= totalWeight

    ranks, rankIDsByNames = _readRanks((xmlCtx, "ranks"), _xml.getChildren(xmlCtx, section, "ranks"))
    res["roleRanks"] = _readRoleRanks(
        (xmlCtx, "roleRanks"), _xml.getSubsection(xmlCtx, section, "roleRanks"), rankIDsByNames
    )
    if IS_CLIENT or IS_WEB:
        res["firstNames"] = firstNames
        res["lastNames"] = lastNames
        res["icons"] = icons
        res["ranks"] = ranks
    else:
        res["firstNames"] = frozenset(firstNames)
        res["lastNames"] = frozenset(lastNames)
        res["icons"] = frozenset(icons)
    return res
示例#39
0
def _readNationConfigSection(xmlCtx, section):
    res = {}
    firstNames = {}
    lastNames = {}
    icons = {}
    for kindName in ('normalGroups', 'premiumGroups'):
        groups = []
        res[kindName] = groups
        totalWeight = 0.0
        for sname, subsection in _xml.getChildren(xmlCtx, section, kindName):
            ctx = (xmlCtx, kindName + '/' + sname)
            group = {'notInShop': subsection.readBool('notInShop', False),
             'isFemales': 'female' == _xml.readNonEmptyString(ctx, subsection, 'sex'),
             'firstNames': _readIDs((ctx, 'firstNames'), _xml.getChildren(ctx, subsection, 'firstNames'), firstNames, _parseName),
             'lastNames': _readIDs((ctx, 'lastNames'), _xml.getChildren(ctx, subsection, 'lastNames'), lastNames, _parseName),
             'icons': _readIDs((ctx, 'icons'), _xml.getChildren(ctx, subsection, 'icons'), icons, _parseIcon)}
            group['firstNamesList'] = list(group['firstNames'])
            group['lastNamesList'] = list(group['lastNames'])
            group['iconsList'] = list(group['icons'])
            weight = _xml.readNonNegativeFloat(ctx, subsection, 'weight')
            totalWeight += weight
            group['weight'] = weight
            groups.append(group)

        totalWeight = max(0.001, totalWeight)
        for group in groups:
            group['weight'] /= totalWeight

    ranks, rankIDsByNames = _readRanks((xmlCtx, 'ranks'), _xml.getChildren(xmlCtx, section, 'ranks'))
    res['roleRanks'] = _readRoleRanks((xmlCtx, 'roleRanks'), _xml.getSubsection(xmlCtx, section, 'roleRanks'), rankIDsByNames)
    if IS_CLIENT or IS_WEB:
        res['firstNames'] = firstNames
        res['lastNames'] = lastNames
        res['icons'] = icons
        res['ranks'] = ranks
    else:
        res['firstNames'] = frozenset(firstNames)
        res['lastNames'] = frozenset(lastNames)
        res['icons'] = frozenset(icons)
    return res
示例#40
0
 def __init__(self, dataSection, xmlCtx, customDescriptor, name):
     super(ExhaustEffectDescriptor, self).__init__()
     self._selectorDesc = customDescriptor
     self.nodes = _xml.readNonEmptyString(xmlCtx, dataSection, name).split()
示例#41
0
 def _readConfig(self, xmlCtx, section):
     self.__value = _xml.readFloat(xmlCtx, section, 'value')
     self.__attr = _xml.readNonEmptyString(xmlCtx, section, 'attribute').split('/', 1)
示例#42
0
 def _readConfig(self, xmlCtx, section):
     self.__factor = _xml.readPositiveFloat(xmlCtx, section, 'factor')
     self.__attr = _xml.readNonEmptyString(xmlCtx, section, 'attribute').split('/', 1)
示例#43
0
 def _parseIcon(xmlCtx, section):
     return _xml.readNonEmptyString(xmlCtx, section, '')
示例#44
0
 def _parseName(xmlCtx, section):
     return i18n.makeString(_xml.readNonEmptyString(xmlCtx, section, ''))