Exemple #1
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)
Exemple #2
0
def writeFontType(writer, cache, folder, itemName):

    def parseSourceSection(fontFilesPathes, fontItems, changedRefs):
        fontRefs = {}
        fontsSections = {}
        for fontFile in fontFilesPathes:
            refSection = ResMgr.openSection(fontFile)
            if refSection is None:
                _xml.raiseWrongXml(None, refSection, "can't find datasection")
            fontRefs[fontFile] = refSection
            for name, isection in refSection.items():
                if isection.has_key('id'):
                    id = isection['id'].asInt
                    if id in fontsSections.keys():
                        raise SoftException('Some font items have the same id {}.'.format(id))
                    if id in fontItems.keys():
                        fontsSections[id] = isection
                    else:
                        refSection.deleteSection(isection)
                        changedRefs.add(refSection)

            return (fontRefs, fontsSections)

        return

    sourceFiles = cache.editorData.sourceFiles[CUSTOMIZATION_ITEMS_NAME_TO_TYPE[itemName]]
    if len(sourceFiles) == 0:
        return
    else:
        if sourceFiles is None:
            raise SoftException('Item {} has no sourceXml, data format has changed?'.format(itemName + str(id)))
        items = cache.fonts
        changedRefs = set()
        refSections, fontsSections = parseSourceSection(sourceFiles, items, changedRefs)
        for id, item in items.items():
            sourceFile = item.editorData.sourceXml
            if sourceFile not in refSections.keys():
                raise SoftException("writeFontType: Couldn't find file {} ".format(sourceFile))
            sourceRef = refSections[sourceFile]
            if id not in fontsSections.keys():
                fontsSections[id] = sourceRef.createSection(itemName)
                _xml.rewriteInt(fontsSections[id], 'id', id)
            isection = fontsSections[id]
            changed = writer.write(item, isection)
            if changed:
                changedRefs.add(sourceRef)

        for refsection in changedRefs:
            refsection.save()

        return
Exemple #3
0
 def writeOneSectionParams(item, sect):
     segment2ModelLeft = item.segment2ModelLeft()
     segment2ModelRight = item.segment2ModelRight()
     _xml.rewriteString(sect, 'segmentModelLeft', item.segmentModelLeft())
     _xml.rewriteString(sect, 'segmentModelRight', item.segmentModelRight())
     if segment2ModelLeft is not None:
         _xml.rewriteString(sect, 'segment2ModelLeft', segment2ModelLeft)
     if segment2ModelRight is not None:
         _xml.rewriteString(sect, 'segment2ModelRight', segment2ModelRight)
     _xml.rewriteString(sect, 'left', item.leftDesc[0][0])
     _xml.rewriteString(sect, 'right', item.rightDesc[0][0])
     _xml.rewriteFloat(sect, 'segmentLength', item.editorData.leftDesc[0][2])
     _xml.rewriteFloat(sect, 'segmentOffset', item.editorData.leftDesc[0][3])
     if item.editorData.leftDesc[0][4] != 0.0:
         _xml.rewriteFloat(sect, 'segment2Offset', item.editorData.leftDesc[0][4])
     shared_writers.writeLodDist(item.lodDist, sect, 'lodDist', cache)
     _xml.rewriteInt(sect, 'atlas/UTiles', item.atlasUTiles)
     _xml.rewriteInt(sect, 'atlas/VTiles', item.atlasVTiles)
     return
Exemple #4
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)
Exemple #5
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
Exemple #6
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,))
Exemple #7
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
Exemple #8
0
 def writeTrackPairParams(item, section):
     segment2ModelLeft = item.segment2ModelLeft()
     segment2ModelRight = item.segment2ModelRight()
     _xml.rewriteInt(section, 'trackPairIdx', item.trackPairIdx, 0)
     _xml.rewriteString(section, 'segmentModelLeft', item.segmentModelLeft())
     _xml.rewriteString(section, 'segmentModelRight', item.segmentModelRight())
     if segment2ModelLeft is not None:
         _xml.rewriteString(section, 'segment2ModelLeft', segment2ModelLeft)
     if segment2ModelRight is not None:
         _xml.rewriteString(section, 'segment2ModelRight', segment2ModelRight)
     _xml.rewriteString(section, 'left', item.leftDesc)
     _xml.rewriteString(section, 'right', item.rightDesc)
     _xml.rewriteFloat(section, 'segmentLength', item.segmentLength)
     _xml.rewriteFloat(section, 'segmentOffset', item.segmentOffset)
     if item.segment2Offset != 0.0:
         _xml.rewriteFloat(section, 'segment2Offset', item.segment2Offset)
     _xml.rewriteInt(section, 'atlas/UTiles', item.atlasUTiles)
     _xml.rewriteInt(section, 'atlas/VTiles', item.atlasVTiles)
     return