Esempio n. 1
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))
Esempio n. 2
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))
Esempio n. 3
0
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)
Esempio n. 4
0
def apply(vDesc, modelDesc, modelsSet):
    for key in chassis_params:
        obj = copy.deepcopy(modelDesc['chassis'][key])
        if key == 'traces':
            obj['size'] = tuple(obj['size'])
            obj = cc.Traces(**obj)
        elif key == 'tracks':
            obj = cc.TrackBasicParams(**obj)
        elif key == 'wheels':
            obj = cc.WheelsConfig(groups=tuple(cc.WheelGroup(**d) for d in obj['groups']),
                                  wheels=tuple(cc.Wheel(**d) for d in obj['wheels']))
        elif key == 'groundNodes':
            obj = NodesAndGroups(nodes=tuple(cc.GroundNode(**d) for d in obj['nodes']),
                                 groups=tuple(cc.GroundNodeGroup(**d) for d in obj['groups']),
                                 activePostmortem=obj['activePostmortem'], lodSettings=obj['lodSettings'])
        elif key == 'trackNodes':
            obj = NodesAndGroups(nodes=tuple(cc.TrackNode(**d) for d in obj['nodes']), groups=(),
                                 activePostmortem=obj['activePostmortem'], lodSettings=obj['lodSettings'])
        elif key == 'splineDesc':
            obj = cc.SplineConfig(({modelsSet: cc.SplineSegmentModelSet(**obj['segmentModelSets'])} or None),
                                  **{k: v for k, v in obj.items() if k != 'segmentModelSets'})
        elif key == 'trackSplineParams':
            obj = cc.TrackSplineParams(**obj)
        elif key == 'leveredSuspension':
            if obj is not None:
                obj = cc.LeveredSuspensionConfig(([cc.SuspensionLever(**d) for d in obj['levers']] or None),
                                                 **{k: v for k, v in obj.items() if k != 'levers'})
        setattr(vDesc.chassis, key, obj)
    vDesc.chassis.chassisLodDistance = modelDesc['chassis']['chassisLodDistance']
    vDesc.chassis.physicalTracks = {}
    if modelDesc['chassis']['AODecals']:
        AODecalsOffset = vDesc.chassis.hullPosition - Math.Vector3(*modelDesc['chassis']['hullPosition'])
        vDesc.chassis.AODecals = copy.deepcopy(modelDesc['chassis']['AODecals'])
        vDesc.chassis.AODecals[0].setElement(3, 1, AODecalsOffset.y)
    exclMask = modelDesc['common']['camouflage']['exclusionMask']
    vDesc.type.camouflage = Camouflage(
        modelDesc['common']['camouflage']['tiling'] if exclMask else vDesc.type.camouflage.tiling, exclMask, None, None)
    for partName in TankPartNames.ALL:
        part = getattr(vDesc, partName)
        models = part.modelsSets[modelsSet]
        part.modelsSets[modelsSet] = ModelStatesPaths(modelDesc[partName]['undamaged'], models.destroyed, models.exploded)
        part.models = part.modelsSets['default']
        part.emblemSlots = tuple(modelDesc[partName]['emblemSlots'])
        if partName == 'chassis':
            continue
        camoData = modelDesc[partName]['camouflage']
        exclMask = camoData['exclusionMask']
        if exclMask:
            part.camouflage = Camouflage(camoData['tiling'], exclMask, None, None)
    vDesc.gun.drivenJoints = modelDesc['gun']['drivenJoints']
    exhaust = modelDesc['hull']['exhaust']
    for effectDesc in vDesc.hull.customEffects:
        if exhaust['nodes']:
            effectDesc.nodes[:] = exhaust['nodes']
        effectDesc._selectorDesc = g_cache._customEffects['exhaust'].get(exhaust['pixie'], effectDesc._selectorDesc)
    nationID = vDesc.type.id[0]
    for partName, cacheName, cacheIDs in (
            ('chassis', 'chassis', 'chassisIDs'), ('engine', 'engines', 'engineIDs'), ('gun', 'guns', 'gunIDs')):
        soundID = modelDesc[partName].get('soundID')
        if soundID:
            part = getattr(vDesc, partName)
            pickFrom = getattr(g_cache, cacheName)(nationID).get(getattr(g_cache, cacheIDs)(nationID).get(soundID))
            if pickFrom is not None:
                if partName != 'gun':
                    part.sounds = pickFrom.sounds
                else:
                    part.effects = pickFrom.effects
                    part.reloadEffect = pickFrom.reloadEffect