Ejemplo n.º 1
0
def writeHullAimingSound(hullAimingSound, section, cache):
    if hullAimingSound is None:
        return _xml.deleteAndCleanup(section, 'hullAiming/audio')
    else:
        changed = False
        audioKey = 'hullAiming/audio/'
        changed |= shared_writers.writeLodDist(hullAimingSound.lodDist,
                                               section, audioKey + 'lodDist',
                                               cache)
        changed |= _xml.rewriteFloat(
            section, audioKey + 'angleLimitValue',
            math.degrees(hullAimingSound.angleLimitValue))
        soundsKey = audioKey + 'sounds/'
        soundsDS = _xml.ListRewriter(section, soundsKey + '*')
        for sound in hullAimingSound.sounds:
            soundDS = soundsDS.next(
                preferredPredicate=lambda ds, snd=sound: ds.name == snd.state,
                path=soundsKey + sound.state)
            changed |= _xml.rewriteString(soundDS,
                                          'underLimitSounds/wwsoundPC',
                                          sound.underLimitSounds.PC)
            changed |= _xml.rewriteString(soundDS,
                                          'underLimitSounds/wwsoundNPC',
                                          sound.underLimitSounds.NPC)
            changed |= _xml.rewriteString(soundDS, 'overLimitSounds/wwsoundPC',
                                          sound.overLimitSounds.PC)
            changed |= _xml.rewriteString(soundDS,
                                          'overLimitSounds/wwsoundNPC',
                                          sound.overLimitSounds.NPC)

        changed |= soundsDS.flush()
        return changed
Ejemplo n.º 2
0
def writeWheelsAndGroups(wheelsConfig, section):
    wheelId = 0
    groupId = 0
    defSyncAngle = section.readFloat('wheels/leadingWheelSyncAngle', 60)
    for sname, subsection in _xml.getChildren(None, section, 'wheels'):
        if sname == 'group':
            group = wheelsConfig.groups[groupId]
            _xml.rewriteString(subsection, 'template', group.template)
            _xml.rewriteInt(subsection, 'count', group.count, 1)
            _xml.rewriteInt(subsection, 'startIndex', group.startIndex, 0)
            _xml.rewriteFloat(subsection, 'radius', group.radius)
            groupId += 1
        if sname == 'wheel':
            from items.vehicles import _writeHitTester, _writeArmor
            index = _xml.readIntOrNone(None, subsection, 'index')
            if index is not None:
                wheelId = index
            wheel = wheelsConfig.wheels[wheelId]
            radiusKey = 'radius' if subsection.has_key('radius') else 'geometry/radius'
            _xml.rewriteInt(subsection, 'index', wheelId, createNew=False)
            _xml.rewriteFloat(subsection, radiusKey, wheel.radius)
            _xml.rewriteString(subsection, 'name', wheel.nodeName)
            _xml.rewriteBool(subsection, 'isLeading', wheel.isLeading)
            _xml.rewriteFloat(subsection, 'syncAngle', wheel.leadingSyncAngle, defSyncAngle)
            _xml.rewriteVector3(subsection, 'wheelPos', wheel.position, Vector3(0, 0, 0))
            _writeHitTester(wheel.hitTester, None, subsection, 'hitTester')
            _writeArmor(wheel.materials, None, subsection, 'armor', optional=True, index=wheelId)
            wheelId += 1

    return
Ejemplo n.º 3
0
 def writeGroundNode(curGroup, curSection):
     _xml.rewriteString(curSection, 'template', curGroup.nodesTemplate)
     _xml.rewriteInt(curSection, 'startIndex', curGroup.startIndex)
     _xml.rewriteInt(curSection, 'count', curGroup.nodesCount)
     _xml.rewriteBool(curSection, 'isLeft', curGroup.isLeft)
     _xml.rewriteFloat(curSection, 'minOffset', curGroup.minOffset)
     _xml.rewriteFloat(curSection, 'maxOffset', curGroup.maxOffset)
Ejemplo n.º 4
0
def writeSwingingSettings(item, section):

    def paramsToString(floatTuple):
        return ' '.join([ '{:.2f}'.format(x) for x in floatTuple ])

    _xml.rewriteFloat(section, 'sensitivityToImpulse', item.sensitivityToImpulse)
    _xml.rewriteString(section, 'pitchParams', paramsToString(item.pitchParams))
    _xml.rewriteString(section, 'rollParams', paramsToString(item.rollParams))
Ejemplo n.º 5
0
def writeTrackBasicParams(trackBasicParams, section, cache):
    if trackBasicParams is None:
        return
    else:
        shared_writers.writeLodDist(trackBasicParams.lodDist, section, 'tracks/lodDist', cache)
        _xml.rewriteString(section, 'tracks/leftMaterial', trackBasicParams.leftMaterial)
        _xml.rewriteString(section, 'tracks/rightMaterial', trackBasicParams.rightMaterial)
        _xml.rewriteFloat(section, 'tracks/textureScale', trackBasicParams.textureScale)
        return
Ejemplo n.º 6
0
def writeTraces(traces, section, cache):
    shared_writers.writeLodDist(traces.lodDist, section, 'traces/lodDist',
                                cache)
    _xml.rewriteString(section, 'traces/bufferPrefs', traces.bufferPrefs)
    _xml.rewriteString(section, 'traces/textureSet', traces.textureSet)
    _xml.rewriteVector2(section, 'traces/size', traces.size)
    _xml.rewriteBool(section,
                     'traces/activePostmortem',
                     traces.activePostmortem,
                     defaultValue=False)
Ejemplo n.º 7
0
def writeRecoilEffect(item, section, cache):
    if item.effectName != 'none':
        _xml.rewriteString(section, 'recoilEffect', item.effectName)
        section.deleteSection('backoffTime')
        section.deleteSection('returnTime')
    else:
        _xml.rewriteFloat(section, 'backoffTime', item.backoffTime)
        _xml.rewriteFloat(section, 'returnTime', item.returnTime)
        section.deleteSection('recoilEffect')
    _xml.rewriteFloat(section, 'amplitude', item.amplitude)
    shared_writers.writeLodDist(item.lodDist, section, 'lodDist', cache)
Ejemplo n.º 8
0
def __writeDebris(tracksDebris, section):
    if tracksDebris is None:
        return
    else:
        for sname, subsection in section.items():
            if sname != 'trackDebris':
                continue
            isLeft = _xml.readBool(None, subsection, 'isLeft', True)
            tracksDebrisParams = tracksDebris.left if isLeft else tracksDebris.right
            if tracksDebrisParams is not None:
                _xml.rewriteString(subsection, 'destructionEffect', tracksDebrisParams.destructionEffect)
                physicalParams = tracksDebrisParams.physicalParams
                if physicalParams is not None and physicalParams.hingeJointStiffness is not None:
                    _xml.rewriteFloat(subsection, 'physicalParams/hingeJointStiffness', physicalParams.hingeJointStiffness)

        return
Ejemplo n.º 9
0
    def __write3dProgression(self, progression, isection):
        sectionName = 'styleProgressions'
        if progression is None or len(progression) == 0:
            if isection.has_key(sectionName):
                isection.deleteSection(sectionName)
                return True
            return False
        else:
            changed = False
            stagesCount = len(progression)
            if stagesCount == 0:
                if isection.has_key(sectionName):
                    isection.deleteSection(sectionName)
                    changed |= True
            else:
                progression3dSection = isection[sectionName]
                if progression3dSection is None:
                    progression3dSection = isection.createSection(sectionName)
                    changed |= True
                if stagesCount != len(progression3dSection):
                    changed |= resizeSection(progression3dSection, stagesCount, lambda id: 'stage')
                stageIndex = 0
                for stageName, progressionValue in progression.iteritems():
                    stageSection = progression3dSection.child(stageIndex)
                    if 'materials' in progressionValue.keys():
                        materialsList = progressionValue['materials']
                        materialsStr = ' '.join(materialsList)
                        changed |= _xml.rewriteString(stageSection, 'materials', materialsStr)
                    if 'additionalOutfit' in progressionValue.keys():
                        outfit = progressionValue['additionalOutfit']
                        changed |= self.__writeOutfits(outfit, stageSection)
                    stageIndex += 1

            return changed
Ejemplo n.º 10
0
def rewritePalettes(section, item):
    if not _needWrite(item, 'palettes'):
        return section.deleteSection('palettes')
    changed = False
    palettes = item.palettes
    if not palettes or len(palettes) == 0:
        return section.deleteSection('palettes')
    palettesSection = findOrCreate(section, 'palettes')
    changed |= resizeSection(palettesSection, len(palettes), lambda id: 'palette')
    for index, palette in enumerate(palettes):

        def sectName(id):
            return 'c' + str(id)

        paletteSection = palettesSection.child(index)
        changed |= resizeSection(paletteSection, len(palette), sectName)
        for i, iPalette in enumerate(palette):
            r = iPalette & 255
            g = iPalette >> 8 & 255
            b = iPalette >> 16 & 255
            a = iPalette >> 24 & 255
            colorStr = ' '.join([str(r),
             str(g),
             str(b),
             str(a)])
            changed |= _xml.rewriteString(paletteSection, sectName(i), colorStr)

    return changed
Ejemplo n.º 11
0
    def __writeAlternateItems(self, alterItems, isection):
        changed = False
        if len(alterItems) == 0:
            if isection.has_key('alternateItems'):
                isection.deleteSection('alternateItems')
                changed |= True
        else:
            alternateItemsSection = isection['alternateItems']
            if alternateItemsSection is None:
                alternateItemsSection = isection.createSection('alternateItems')
                changed |= True
            childCount = len(alternateItemsSection)
            childIndex = childCount - 1
            currentItemsNames = ' '.join(natsorted(map(lambda item: ALTERNATE_TO_NAME[item], alterItems.keys())))
            while childIndex >= 0:
                childSection = alternateItemsSection.child(childIndex)
                sectionName = childSection.name
                if sectionName not in currentItemsNames:
                    alternateItemsSection.deleteSection(sectionName)
                    changed |= True
                childIndex -= 1

        for itemType, itemValues in alterItems.iteritems():
            alternateItemSectionName = ALTERNATE_TO_NAME[itemType]
            oSection = alternateItemsSection[alternateItemSectionName]
            if oSection is None:
                oSection = alternateItemsSection.createSection(alternateItemSectionName)
                changed |= True
            itemsValue = ' '.join(map(str, sorted(itemValues)))
            changed |= _xml.rewriteString(oSection, 'id', itemsValue)

        return changed
Ejemplo n.º 12
0
 def write(self, item, section):
     changed = super(DecalXmlWriter, self).write(item, section)
     changed |= rewriteBool(section, 'mirror', item, 'canBeMirrored')
     if _needWrite(item, 'type'):
         changed |= _xml.rewriteString(section, 'type', encodeEnum(DecalType, item.type))
     else:
         changed |= section.deleteSection('type')
     return changed
Ejemplo n.º 13
0
 def __writeOutfit(self, oSections, season, outfit):
     changed = False
     seasonName = encodeEnum(SeasonType, season)
     oSection = oSections.next(
         lambda s: s.readString('season').lower() == seasonName)
     changed |= _xml.rewriteString(oSection, 'season', seasonName)
     changed |= self.__outfitSerializer.encode(oSection, outfit)
     return changed
Ejemplo n.º 14
0
 def writeModelSets(item, section):
     if len(item.segmentModelSets) < 2:
         return
     modelSetsSection = section.createSection('modelSets')
     for modelSetName, modelSet in item.segmentModelSets.iteritems():
         if modelSetName == 'default':
             continue
         currentModelSetSection = modelSetsSection.createSection(modelSetName)
         _xml.rewriteString(currentModelSetSection, 'segmentModelLeft', modelSet.editorLeft)
         _xml.rewriteString(currentModelSetSection, 'segmentModelRight', modelSet.editorRight)
         _xml.rewriteString(currentModelSetSection, 'segment2ModelLeft', modelSet.editorSecondLeft)
         _xml.rewriteString(currentModelSetSection, 'segment2ModelRight', modelSet.editorSecondRight)
Ejemplo n.º 15
0
def rewriteCamouflageGlossMetallicSettings(section, camouflageItem):
    changed = False
    if camouflageItem.editorData.glossMetallicSettingsType == 0:
        changed |= section.deleteSection('glossMetallicMap')
        changed |= _xml.rewriteVector4(section, 'gloss', camouflageItem.glossMetallicSettings['gloss'])
        changed |= _xml.rewriteVector4(section, 'metallic', camouflageItem.glossMetallicSettings['metallic'])
    elif camouflageItem.editorData.glossMetallicSettingsType == 1:
        changed |= section.deleteSection('gloss')
        changed |= section.deleteSection('metallic')
        changed |= _xml.rewriteString(section, 'glossMetallicMap', camouflageItem.glossMetallicSettings['glossMetallicMap'])
    return changed
Ejemplo n.º 16
0
    def __encodeEnum(self, section, key, value, enum, flags):
        if flags & FieldFlags.SAVE_AS_STRING:
            items = []
            degree = 1
            while value > 0:
                value = value >> 1
                if value % 2 == 1:
                    items.append(encodeEnum(enum, 1 << degree))
                degree += 1

            return _xml.rewriteString(section, key, ' '.join(items).upper())
        return _xml.rewriteInt(section, key, value)
Ejemplo n.º 17
0
def writeModelsSets(item, section):
    if item is None:
        return
    else:
        setsSection = section['sets'] if section.has_key('sets') else None
        if setsSection is not None:
            for setName in setsSection.keys():
                if setName not in item.keys():
                    setsSection.deleteSection(setName)

        if len(item) > 1:
            if not section.has_key('sets'):
                setsSection = section.createSection('sets')
            else:
                setsSection = section['sets']
        for key in item:
            if key == 'default':
                setSection = section
            elif setsSection.has_key(key):
                setSection = setsSection[key]
            else:
                setSection = setsSection.createSection(key)
            if item[key] is not None:
                _xml.rewriteString(setSection, 'undamaged', item[key].undamaged)
                _xml.rewriteString(setSection, 'destroyed', item[key].destroyed)
                _xml.rewriteString(setSection, 'exploded', item[key].exploded)

        return
Ejemplo n.º 18
0
 def __encodeValue(self, section, key, value, fieldType):
     if fieldType.type == FieldTypes.VARINT:
         return _xml.rewriteInt(section, key, value)
     if fieldType.type == FieldTypes.FLOAT:
         return _xml.rewriteFloat(section, key, value)
     if fieldType.type == FieldTypes.APPLY_AREA_ENUM:
         if fieldType.flags & FieldFlags.SAVE_AS_STRING:
             return _xml.rewriteString(section, key, encodeFlagEnum(ApplyArea, value).upper())
         return _xml.rewriteInt(section, key, value)
     if fieldType.type == FieldTypes.TAGS:
         return _xml.rewriteString(section, key, ' '.join(value))
     if fieldType.type == FieldTypes.STRING:
         return _xml.rewriteString(section, key, value)
     if fieldType.type == FieldTypes.OPTIONS_ENUM:
         return _xml.rewriteInt(section, key, value)
     if fieldType.type & FieldTypes.TYPED_ARRAY:
         ft = fieldType._asdict()
         ft['type'] ^= FieldTypes.TYPED_ARRAY
         return self.__encodeArray(section, key, value, FieldType(**ft))
     if fieldType.type >= FieldTypes.CUSTOM_TYPE_OFFSET:
         return self.__encodeCustomType(section, key, value)
     raise SerializationException('Unsupported field type %d' % (fieldType.type,))
Ejemplo n.º 19
0
 def saveFilterValue(subFilterSection, valueSectionName, listOfValues,
                     convertor):
     if len(listOfValues) == 0:
         if subFilterSection.has_key(valueSectionName):
             subFilterSection.deleteSection(valueSectionName)
             return True
     else:
         strValue = convertor.convertToString(listOfValues)
         if strValue is None:
             return False
         return _xml.rewriteString(subFilterSection, valueSectionName,
                                   strValue)
     return False
Ejemplo n.º 20
0
def writeGroup(itemWriter, group, groupSection, itemName):
    prototype = group.itemPrototype
    changed = itemWriter.write(prototype, groupSection)
    changed |= _xml.rewriteString(groupSection, 'name', group.name, defaultValue='')
    listRewriter = _xml.ListRewriter(groupSection, itemName)
    for itemRef in group.editorData.itemRefs:
        item = itemRef()
        if item.id == EMPTY_ITEM_ID:
            continue
        itemSection = listRewriter.next(lambda s, i=item: s['id'].asInt == i.id)
        changed |= itemWriter.write(item, itemSection)

    changed |= listRewriter.flush()
    return changed
Ejemplo n.º 21
0
def rewriteTags(gsection, isection, tags):
    section = selectSection(gsection, isection, 'tags')
    rewrite = len(tags) > 0
    if section.has_key('tags'):
        if not rewrite:
            section.deleteSection('tags')
            return True
        oldTags = iv._readTags(None, section, 'tags', 'customizationItem')
        rewrite = oldTags != tags
    if rewrite:
        tagsStr = ' '.join(tags)
        return _xml.rewriteString(section, 'tags', tagsStr)
    else:
        return False
Ejemplo n.º 22
0
 def writeTrackNode(curNode, curSection):
     _xml.rewriteBool(curSection, 'isLeft', curNode.isLeft)
     _xml.rewriteString(curSection, 'name', curNode.name)
     _xml.rewriteFloat(curSection, 'forwardElastK', curNode.forwardElasticityCoeff, defForwardElastK)
     _xml.rewriteFloat(curSection, 'backwardElastK', curNode.backwardElasticityCoeff, defBackwardElastK)
     _xml.rewriteFloat(curSection, 'offset', curNode.initialOffset, defOffset)
     if curNode.leftNodeName:
         _xml.rewriteString(curSection, 'leftSibling', curNode.leftNodeName)
     if curNode.rightNodeName:
         _xml.rewriteString(curSection, 'rightSibling', curNode.rightNodeName)
def writeModelsSets(item, section):
    if item is None:
        return
    else:
        defaultModelPaths = item['default']
        if defaultModelPaths is None:
            return
        _xml.rewriteString(section, 'undamaged', defaultModelPaths.undamaged)
        _xml.rewriteString(section, 'destroyed', defaultModelPaths.destroyed)
        _xml.rewriteString(section, 'exploded', defaultModelPaths.exploded)
        return
Ejemplo n.º 24
0
def writeWWTripleSoundConfig(soundConfig, section):
    _xml.rewriteString(section,
                       'wwsound',
                       soundConfig.wwsound,
                       defaultValue='')
    _xml.rewriteString(section,
                       'wwsoundPC',
                       soundConfig.wwsoundPC,
                       defaultValue='')
    _xml.rewriteString(section,
                       'wwsoundNPC',
                       soundConfig.wwsoundNPC,
                       defaultValue='')
Ejemplo n.º 25
0
    def __writeOutfit(self, oSections, season, outfit):
        changed = False
        seasonName = encodeEnum(SeasonType, season)
        oSection = oSections.next(lambda s: s.readString('season').lower() == seasonName)
        changed |= _xml.rewriteString(oSection, 'season', seasonName)
        for projectionDecal in outfit.projection_decals:
            if projectionDecal.editorData.decalType == ProjectionDecalType.POSITION:
                projectionDecal.tags = None
                projectionDecal.scaleFactorId = None
                projectionDecal.options = None
            projectionDecal.position = None
            projectionDecal.rotation = None
            projectionDecal.scale = None
            projectionDecal.doubleSided = None
            projectionDecal.hiddenForUser = None
            projectionDecal.showOn = None

        changed |= self.__outfitSerializer.encode(oSection, outfit)
        return changed
Ejemplo n.º 26
0
 def saveFilterValue(subFilterSection, valueSectionName, valueHolder, atrributeListName, convertor):
     listOfValues = getattr(valueHolder, atrributeListName)
     if listOfValues is None:
         return False
     else:
         needWrite = True
         if isinstance(listOfValues, bool):
             needWrite = listOfValues
         elif len(listOfValues) == 0:
             needWrite = False
         if needWrite is False:
             if subFilterSection.has_key(valueSectionName):
                 subFilterSection.deleteSection(valueSectionName)
                 return True
         else:
             strValue = convertor.convertToString(listOfValues)
             if strValue is None:
                 return False
             return _xml.rewriteString(subFilterSection, valueSectionName, strValue)
         return False
Ejemplo n.º 27
0
def rewriteCamouflageTilingSettings(section, camouflageItem):
    if not _needWrite(camouflageItem, 'tilingSettings') or camouflageItem.tilingSettings is None:
        return section.deleteSection('tilingSettings')
    else:
        changed = False
        tilingSettings = camouflageItem.tilingSettings
        tilingType = tilingSettings[0]
        if section.has_key('tilingSettings'):
            tilingSettingsSection = section['tilingSettings']
        elif tilingType != CamouflageTilingType.LEGACY:
            tilingSettingsSection = section.createSection('tilingSettings')
        else:
            return changed
        tilingTypeStr = encodeEnum(CamouflageTilingType, tilingType)
        changed |= _xml.rewriteString(tilingSettingsSection, 'type', tilingTypeStr, 'legacy')
        if tilingSettings[1] is not None:
            factor = Math.Vector2(tilingSettings[1][0], tilingSettings[1][1])
            changed |= _xml.rewriteVector2(tilingSettingsSection, 'factor', factor)
        if tilingSettings[2] is not None:
            offset = Math.Vector2(tilingSettings[2][0], tilingSettings[2][1])
            changed |= _xml.rewriteVector2(tilingSettingsSection, 'offset', offset)
        return changed
Ejemplo n.º 28
0
 def write(self, item, section):
     changed = False
     changed |= rewriteInt(section, 'id', item, 'id')
     changed |= rewriteInt(section, 'historical', item, 'customizationDisplayType')
     changed |= rewriteString(section, 'priceGroup', item, 'priceGroup', '')
     changed |= rewriteString(section, 'requiredToken', item, 'requiredToken', '')
     changed |= rewriteString(section, 'texture', item, 'texture', '')
     changed |= rewriteInt(section, 'maxNumber', item, 'maxNumber', 0)
     changed |= rewriteTags(section, item)
     if _needWrite(item, 'season'):
         enumValue = encodeEnum(SeasonType, item.season)
         if enumValue is None:
             enumValue = encodeFlagEnum(SeasonType, item.season)
         changed |= _xml.rewriteString(section, 'season', enumValue, 'undefined')
     else:
         section.deleteSection('season')
     changed |= rewriteString(section, 'userString', item, 'i18n.userKey', '')
     changed |= rewriteString(section, 'description', item, 'i18n.descriptionKey', '')
     if not _needWrite(item, 'filter'):
         changed |= section.deleteSection('filter')
     else:
         changed |= saveItemFilter(item.filter, section, 'vehicleFilter', VEHICLE_FILTER_VALUE_DESCRIPTION)
     return changed
Ejemplo n.º 29
0
    def __writeDependencies(self, dependencies, isection):
        changed = False
        collection = dependencies
        camouflagesCount = len(collection)
        if camouflagesCount == 0:
            if isection.has_key('dependencies'):
                isection.deleteSection('dependencies')
                changed |= True
        else:
            dependenciesSection = findOrCreate(isection, 'dependencies')
            changed |= resizeSection(dependenciesSection, camouflagesCount, lambda id: 'camouflage')
            sectionIndex = 0
            for camoId, items in collection.iteritems():
                camoSection = dependenciesSection.child(sectionIndex)
                changed |= _xml.rewriteInt(camoSection, 'id', camoId)
                for childKey, idsList in items.iteritems():
                    childName = '{}'.format(lower(CustomizationTypeNames[childKey]))
                    idsStr = ' '.join(map(str, idsList))
                    changed |= _xml.rewriteString(camoSection, childName, idsStr)

                sectionIndex += 1

        return changed
Ejemplo n.º 30
0
def writeFontAlphabet(item):
    xmlPath = item.editorData.alphabet
    if xmlPath is None or len(xmlPath) == 0:
        return
    else:
        section = ResMgr.openSection(xmlPath)
        if section is None:
            return
        changed = False
        if len(section.items()) != len(item.editorData.alphabetList):
            changed |= resizeSection(section, len(item.editorData.alphabetList), lambda id: 'glyph')
        itemIndex = 0
        for name, isection in section.items():
            glyphItem = item.editorData.alphabetList[itemIndex]
            changed |= _xml.rewriteString(isection, 'name', glyphItem.name)
            vBegin = Math.Vector2(glyphItem.position[0], glyphItem.position[1])
            changed |= _xml.rewriteVector2(isection, 'begin', vBegin)
            vEnd = Math.Vector2(glyphItem.position[2], glyphItem.position[3])
            changed |= _xml.rewriteVector2(isection, 'end', vEnd)
            itemIndex += 1

        if changed:
            section.save()
        return