def _getDefaultMapSettings(): edgeFogSettings = ResMgr.DataSection() edgeFogSettings.createSectionFromString( '\n <Fog>\n <version>\t1.000000\t</version>\n <innerBB>\t-0.000000 -0.000000 0.000000 200.000000\t</innerBB>\n <outerBB>\t-200.000000 -200.000000 200.000000 400.000000\t</outerBB>\n <deferred>\n <heightFog>\ttrue\t</heightFog>\n <nearLow>\t0.000000\t</nearLow>\n <farLow>\t100.000000\t</farLow>\n <nearHigh>\t10.000000\t</nearHigh>\n <farHigh>\t100.000000\t</farHigh>\n <altitudeLow>\t-6.000000\t</altitudeLow>\n <altitudeMid>\t10.000000\t</altitudeMid>\n <altitudeHigh>\t100.000000\t</altitudeHigh>\n <skyAltitudeLow>\t-10.000000\t</skyAltitudeLow>\n <skyAltitudeMid>\t10.000000\t</skyAltitudeMid>\n <skyAltitudeHigh>\t1500.000000\t</skyAltitudeHigh>\n <exponent>\t0.650000\t</exponent>\n <sunAngle>\t35.000000\t</sunAngle>\n <sunExponent>\t0.500000\t</sunExponent>\n <colorLow>\t0.991500 1.000000 0.490000 0.400000\t</colorLow>\n <colorHigh>\t0.991501 1.000000 0.490000 0.300000\t</colorHigh>\n <colorSunLow>\t0.991500 1.000000 0.490000 0.500000\t</colorSunLow>\n <colorSunHigh>\t0.991500 1.000000 0.490000 0.450000\t</colorSunHigh>\n <useEdgeFog>\ttrue\t</useEdgeFog>\n </deferred>\n <forward>\n <heightFog>\ttrue\t</heightFog>\n <nearLow>\t0.000000\t</nearLow>\n <farLow>\t100.000000\t</farLow>\n <nearHigh>\t10.000000\t</nearHigh>\n <farHigh>\t100.000000\t</farHigh>\n <altitudeLow>\t-18.000000\t</altitudeLow>\n <altitudeMid>\t9.000000\t</altitudeMid>\n <altitudeHigh>\t200.000000\t</altitudeHigh>\n <skyAltitudeLow>\t0.000000\t</skyAltitudeLow>\n <skyAltitudeMid>\t10.000000\t</skyAltitudeMid>\n <skyAltitudeHigh>\t1300.000000\t</skyAltitudeHigh>\n <colorLow>\t0.684355 0.694268 0.552637 0.000000\t</colorLow>\n <colorHigh>\t0.684363 0.694268 0.552761 0.000000\t</colorHigh>\n <useEdgeFog>\ttrue\t</useEdgeFog>\n </forward>\n <enable>\ttrue\t</enable>\n </Fog>\n ' ) shimmerSettings = ResMgr.DataSection() shimmerSettings.createSectionFromString( '\n <shimmerSettings>\n <windDir> 0.500 1.000 0.5 5.0 </windDir>\n <waveSpeed> 0.000 0.010 2.0 1.0 </waveSpeed>\n <spreadFreq> 0.005 0.005 6.0 6.0 </spreadFreq>\n <displacement> system/maps/post_processing/distortion_3D.dds </displacement>\n </shimmerSettings>\n ' ) return GasAttackMapSettings( cloudModel='particles/mesh_particles/funnel_death/gas_ring.model', cloudClimbTime=5, cloudStartHeight=0, cloudEndHeight=150, cameraProximityDist=30, windSpeed=Math.Vector2(50, 50), windGustiness=50, mapActivities=(), vehicleGAEffect=_getVehicleEffectsSettings(), cameraGAEffect=_getCameraEffectsSettings(), centerFogSettings=edgeFogSettings, edgeFogSettings=edgeFogSettings, edgeToCenterFogSettings=edgeFogSettings, shimmerSettings=shimmerSettings, edgeToCenterAngle=0.392699082, edgeToCenterAngleDelta=0.261799388, edgeToCenterDistance=400.0, centerSunIntensityDef=1.0, centerSunIntensityFwd=1.0, edgeSunIntensityDef=0.0, edgeSunIntensityFwd=0.0, soundSettings=_getSoundSettings())
def writeCustomizationSlots(slots, section, subsectionName): section.deleteSection(subsectionName) if not slots: return else: sectionItems = section.items() precedingSectionIndex = getPrecedingSectionIndex(sectionItems, 'customization') if precedingSectionIndex is not None: newSection = ResMgr.DataSection().createSection(subsectionName) baseSection = section if isinstance(section, CombinedDataSection): baseSection = section.getPrioritySection() subsection = baseSection.insertSection(newSection, sectionItems[precedingSectionIndex][1]) else: subsection = section.createSection(subsectionName) slots.sort(key=lambda x: x.slotId) for slot in slots: slotDS = subsection.createSection('slot') slotDS.write('slotType', slot.type) slotDS.write('slotId', slot.slotId) if slot.type in ALLOWED_PROJECTION_DECALS_ANCHORS: writeProjectionSlots(slotDS, slot) if slot.type in ALLOWED_SLOTS_ANCHORS: writeAnchorSlots(slotDS, slot) if slot.type in ALLOWED_EMBLEM_SLOTS: writeEmblemSlots(slotDS, slot) if slot.type in component_constants.ALLOWED_MISC_SLOTS: writeMiscSlots(slotDS, slot) LOG_ERROR('unexpected slot type: {}'.format(slot.type)) return
def openSection(cls, xmlPath, mergeFiles): extensions = g_extensionsManager.activeExtensions if not IS_EDITOR else g_extensionsManager.extensions xmlPaths = [ ext.path + xmlPath for ext in extensions if rmgr.isFile(ext.path + xmlPath) ] if not xmlPaths: return rmgr.openSection(xmlPath) genString = cls._openTag('{} {}'.format(_ROOT_TAG, _XML_NAMESPACE)) if mergeFiles: genString += cls._openTag(_MERGE_TAG) if rmgr.isFile(xmlPath): xmlPaths = [xmlPath] + xmlPaths if not (IS_CLIENT or IS_EDITOR): xmlPaths = [(getRealmFilePath(xmlPath) if rmgr.isFile( getRealmFilePath(xmlPath)) else xmlPath) for xmlPath in xmlPaths] for path in xmlPaths: if mergeFiles: genString += cls._openTag(_CONTENT_TAG) genString += cls._attributeTag(_INCLUDE_TAG, 'href', path) if mergeFiles: genString += cls._closeTag(_CONTENT_TAG) if mergeFiles: genString += cls._closeTag(_MERGE_TAG) genString += cls._closeTag(_ROOT_TAG) section = rmgr.DataSection() section.createSectionFromString(genString) if section.child(0).name == 'root': section = section.child(0) return section
def writeSplineDesc(splineDesc, section, cache): if splineDesc is None: return else: 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 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) if section.has_key('splineDesc'): section.deleteSection('splineDesc') prioritySection = section.getPrioritySection() sectionItems = prioritySection.items() precedingSectionIndex = shared_writers.getPrecedingSectionIndex(sectionItems, 'physicalTracks') newSplineDescSection = None if precedingSectionIndex is not None: newSection = ResMgr.DataSection().createSection('splineDesc') newSplineDescSection = prioritySection.insertSection(newSection, sectionItems[precedingSectionIndex][1]) else: newSplineDescSection = section.createSection('splineDesc') newTrackPairsSection = True if len(splineDesc.trackPairs) == 1: newTrackPairsSection = False for trackPair in splineDesc.trackPairs.values(): pairSection = newSplineDescSection.createSection('trackPair') if newTrackPairsSection else newSplineDescSection writeTrackPairParams(trackPair, pairSection) writeModelSets(trackPair, pairSection) shared_writers.writeLodDist(splineDesc.lodDist, newSplineDescSection, 'lodDist', cache) return
def __init__(self, propertyType, values, expectedValues): self.propertyType, self.values, self.expectedValues = propertyType, values, expectedValues xmlValues = '\n'.join( (self.ELEMENT_TEMPLATE.format(elementName=propertyType.sectionName, value=v) for v in self.values)) self.xmlText = self.XML_TEMPLATE.format(elements=xmlValues) self.dataSection = ResMgr.DataSection('root', ElementTree.XML(self.xmlText), '')
def eqDataSection(eqName): global _dataSection if not _dataSection: if constants.IS_CELLAPP or constants.IS_CLIENT: xmlPath = constants.ITEM_DEFS_PATH else: xmlPath = '../../../res/wot/scripts/item_defs/' xmlPath += 'vehicles/common/equipments.xml' _dataSection = ResMgr.openSection(xmlPath) ds = ResMgr.DataSection(eqName) ds.copy(_dataSection[eqName]) return ds
def _CSISResponseParser(out, requestedIDs): result = _createDefaultCSISResponse(requestedIDs) root = ResMgr.DataSection().createSectionFromString(out) itemsSec = None if root is not None: itemsSec = root['items'] if itemsSec is not None: for _, subSec in itemsSec.items(): rType = subSec.readString('type') name = subSec.readInt('name') if rType == 'periphery' and name: result[name] = subSec.readInt('availability', HOST_AVAILABILITY.UNKNOWN) return result
def _CSISResponseParser(out): result = {} root = ResMgr.DataSection().createSectionFromString(out) itemsSec = None if root is not None: itemsSec = root['items'] if itemsSec is not None: for _, subSec in itemsSec.items(): type = subSec.readString('type') name = subSec.readInt('name') if type == 'periphery' and name: result[name] = subSec.readInt('availability', HOST_AVAILABILITY.NOT_AVAILABLE) return result
def __createCrew(self, crewXml, vCompDescr): crew = {} if not crewXml: return crew else: crewStr = '<root>{}</root>'.format(crewXml.encode('ascii')) crewSection = ResMgr.DataSection().createSectionFromString(crewStr) if crewSection is not None: crew['tankmen'] = [] _, nationId, vehTypeId = vehicles.parseIntCompactDescr( vCompDescr) for tankmanSection in crewSection.values(): tmanDict = {} tmanId = tankmanSection.readString('name') if not tmanId: continue tData = None tIdx = None for idx, tMan in tankmen.getNationConfig( nationId).premiumGroups.iteritems(): if tMan.name == tmanId: tData = tMan tIdx = idx break if tData is None: continue tmanDict['isPremium'] = True tmanDict['gId'] = tIdx tmanDict['nationID'] = nationId tmanDict['firstNameID'] = first(tData.firstNames) tmanDict['lastNameID'] = first(tData.lastNames) tmanDict['iconID'] = first(tData.icons) tmanDict['vehicleTypeID'] = vehTypeId tmanDict['role'] = tankmanSection.readString('role') for param in ('roleLevel', 'freeXP'): tmanDict[param] = tankmanSection.readInt(param) for param in ('skills', 'freeSkills'): paramAsStr = tankmanSection.readString(param) tmanDict[param] = paramAsStr.split( ' ') if paramAsStr else [] crew['tankmen'].append(tmanDict) return crew
def __allMedalsTextLoadedCallback(achievementId, data, onTextLoadedCallback): description = {} achievementIdStr = str(achievementId) if data is not None: try: dataSection = ResMgr.DataSection() dataSection.createSectionFromString(data) achievementsSection = dataSection['root/medals'] for item in achievementsSection.values(): if item.readString('id') == achievementIdStr: description = __getAchievementDescription(item) break except: LOG_CURRENT_EXCEPTION() description = {} onTextLoadedCallback(achievementId, description)
def __prepareData(self, entryData): description = entryData.get('description') if description is not None: try: section = ResMgr.DataSection() section.createSectionFromString(encodeUtf8(description)) _, section = findFirst(lambda (name, _): name == 'div', section.items()) description, _ = unicode_from_utf8(section.asString) if len(description) > self.DESCRIPTION_MAX_LENGTH: description = description[:self.DESCRIPTION_CUT_LENGTH] + self.DESCRIPTION_TAIL except Exception: LOG_ERROR('Invalid RSS entry description', entryData, description) LOG_CURRENT_EXCEPTION() return return {'id': entryData.get('id', str(uuid.uuid4())), 'link': entryData.get('link'), 'description': encodeUtf8(description)}
class ChunkItemFunctor: def __init__( self, tool, oi ): # set up the tool we are part of self.mouseLocator = Locator.ChunkItemLocator( Locator.TerrainToolLocator() ) self.mouseRevealer = self.mouseLocator.revealer self.selection = WorldEditor.ChunkItemGroup() self.mouseView = View.ChunkItemBounds( self.mouseRevealer, 0xff0000ff ) self.selView = View.ChunkItemBounds( self.selection, 0xff00ff00 ) tool.locator = self.mouseLocator tool.addView( self.mouseView ) tool.addView( self.selView ) # store a reference to the object info class self.objInfo = oi # key event entry point def onKeyEvent( self, (isDown, key, modifiers), tool ): handled = 0 if isDown: if key == KEY_LEFTMOUSE: self.onLeftMouse() handled = 1 elif key == KEY_INSERT: bp = self.objInfo.getBrowsePath() if len(bp)>6 and bp[-6:] == ".model": d = ResMgr.DataSection( "model" ) d.writeString( "resource", bp ) # WorldEditor.createChunkItem( d, self.mouseLocator.subLocator ) elif key == KEY_DELETE: if self.selection.size: WorldEditor.deleteChunkItem( self.selection ) self.selection.rem( self.selection ) return handled
def fromString(xml): section = ResMgr.DataSection().createSectionFromString(xml) if not section: raise ParseError('Can not read notification') return _parse(section)
def _getVehicleEffectsSettings(): effectsSettins = ResMgr.DataSection() effectsSettins.createSectionFromString('\n <vehicleGAEffect>\n <stages>\n <fire>\t1.0\t</fire>\n <noEmission> 4.0 </noEmission>\n </stages>\n <effects>\n <pixie>\n <startKey>\tfire </startKey>\n <file>\tparticles/Tank/destruction/fire_storm_destruction.xml </file>\n </pixie>\n <stopEmission>\n <startKey> noEmission </startKey>\n </stopEmission>\n </effects>\n </vehicleGAEffect>\n ')
def readFromString(self, xml, curTime): section = ResMgr.DataSection('root').createSectionFromString(xml) return {} if not section.has_key('quests') else self.__readXML( section['quests'], curTime)
def _getSoundSettings(): soundSettings = ResMgr.DataSection() soundSettings.createSectionFromString('\n <soundSettings>\n <wwalarm>fallout_gaz_alarm</wwalarm>\n <gascloud_close> sauron_burn_close </gascloud_close>\n <gascloud_far> sauron_burn_far </gascloud_far>\n <gascloud_inside> sauron_inside_burn </gascloud_inside>\n </soundSettings>\n ') return soundSettings
def readCurrentSettings(self, quiet=True): configPath = self.configPath + 'configs/' if not os.path.exists(configPath): LOG_ERROR('config folder not found: ' + configPath) os.makedirs(configPath) effectsXmlPath = _VEHICLE_TYPE_XML_PATH + 'common/gun_effects.xml' effectsXml = ResMgr.openSection(effectsXmlPath) for confPath in glob.iglob(configPath + '*.json'): confName = os.path.basename(confPath).split('.')[0] try: confdict = loadJson(self.ID, confName, {}, os.path.dirname(confPath) + '/') except StandardError: print self.ID + ': config', os.path.basename( confPath), 'is invalid.' traceback.print_exc() continue self.confList.add(confName) for itemType, itemsDict in confdict.iteritems(): if itemType not in self.data: if not quiet: print self.ID + ': invalid item type in', confName + ':', itemType continue itemsData = self.data[itemType] if itemType in ('engines', 'guns'): for nationName, nationData in itemsDict.iteritems(): if nationName.split(':')[0] not in nations.NAMES: print self.ID + ': unknown nation in', itemType, 'in', confName + ':', nationName continue for itemName in nationData: itemsData.setdefault(nationName, {}).setdefault( itemName, {}).update(nationData[itemName]) if itemType in ('gun_reload_effects', 'shot_effects', 'sound_notifications'): for itemName in itemsDict: itemsData.setdefault(itemName, {}).update(itemsDict[itemName]) if itemType == 'gun_effects': for itemName, itemData in itemsDict.iteritems(): if 'origin' not in itemData: print self.ID + ':', confName + ':', itemName, 'has no origin' continue origin = itemData['origin'] if origin not in effectsXml.keys(): print self.ID + ':', confName + ':', itemName, 'has unknown origin:', origin continue itemName = intern(itemName) for key in itemData.keys(): if key not in ('origin', 'timeline', 'effects'): print self.ID + ':', confName + ': incorrect key', key, 'in', itemName, 'ignored' itemData.pop(key, None) if 'effects' in itemData: for key in itemData['effects'].keys(): if key != 'shotSound': print self.ID + ':', confName + ': only shotSound effects are supported,', key, 'ignored' itemData['effects'].pop(key) itemsData.setdefault(itemName, {}).update(itemData) print self.ID + ': loaded configs:', ', '.join( x + '.json' for x in sorted(self.confList)) for sname, effData in self.data['gun_effects'].iteritems(): if sname not in g_cache._gunEffects: g_cache._gunEffects[sname] = readEffectsTimeLine( ((None, effectsXmlPath), effData['origin']), effectsXml[effData['origin']]) effectDesc = g_cache._gunEffects[sname] if 'timeline' in effData: for keyPointName, timePoint in effData['timeline'].iteritems(): for keyPoint in effectDesc.keyPoints: if keyPoint.name == keyPointName: effectDesc.keyPoints.remove(keyPoint) effectDesc.keyPoints.append( keyPoint._replace(time=float(timePoint))) break else: effectDesc.keyPoints.append( KeyPoint(keyPointName, timePoint)) effectDesc.keyPoints.sort(key=lambda i: i.time) if 'effects' in effData and 'shotSound' in effData['effects']: data = effData['effects']['shotSound'] for effect in effectDesc.effectsList._EffectsList__effectDescList: if effect.TYPE == '_ShotSoundEffectDesc': effect._soundName = tuple( (tuple(data[key]) if key in data else effectDesc._soundName[idx]) for idx, key in enumerate(('wwsoundPC', 'wwsoundNPC'))) for sname, effData in self.data['gun_reload_effects'].iteritems(): if effData['type'] not in reloadTypes: print self.ID + ': wrong reload effect type:', effData[ 'type'], 'available:', sorted(reloadTypes.keys()) continue reloadType = reloadTypes[effData['type']] orig, desc, sect = g_cache._gunReloadEffects.get( sname, None), None, ResMgr.DataSection() if not isinstance(orig, reloadType): # None is not an instance too if orig is not None: print self.ID + ': changing type of reload effect %s. Might cause problems!' % sname orig, desc = None, reloadType(sect) for slot in reloadType.__slots__: slotName = mismatchSlots.get(slot, slot) if slotName in effData: value = effData[slotName] else: value = getattr(orig or desc, slot) if slot in modifiers: value = modifiers[slot](value) sect.writeString(slotName, str(value)) new_desc = reloadType(sect) if orig is None: g_cache._gunReloadEffects[sname] = new_desc else: # set new attributes to existing descriptors, otherwise they don't update [ setattr(orig, slot, getattr(new_desc, slot)) for slot in reloadType.__slots__ ] for item_type, items_storage in (('engines', g_cache._Cache__engines), ('guns', g_cache._Cache__guns)): for nationID, nation_items in enumerate(items_storage): nationData = self.data[item_type].get(nations.NAMES[nationID]) if not nationData: continue for item in nation_items.itervalues(): itemData = nationData.get(item.name) if not itemData: continue if item_type == 'engines': s = item.sounds.getEvents() item.sounds = SoundConfig( '', itemData.get('wwsoundPC', s[0]), itemData.get('wwsoundNPC', s[1])) elif item_type == 'guns': if 'effects' in itemData: item.effects = g_cache._gunEffects.get( itemData['effects'], item.effects) if 'reloadEffect' in itemData: item.reloadEffect = g_cache._gunReloadEffects.get( itemData['reloadEffect'], item.reloadEffect) for sname, index in g_cache.shotEffectsIndexes.iteritems(): effData = self.data['shot_effects'].get(sname) if effData is None: continue res = g_cache.shotEffects[index] for effType in (x for x in ('projectile', ) if x in effData): typeData = effData[effType] for effectDesc in res[effType][2]._EffectsList__effectDescList: if isinstance(effectDesc, _TracerSoundEffectDesc): effectDesc._soundName = tuple( (typeData.get(key, effectDesc._soundName[idx]), ) for idx, key in enumerate(('wwsoundPC', 'wwsoundNPC'))) for effType in (x for x in ( tuple(x + 'Hit' for x in EFFECT_MATERIALS) + ('armorBasicRicochet', 'armorRicochet', 'armorResisted', 'armorHit', 'armorCriticalHit')) if x in effData): typeData = effData[effType] for effectDesc in res[ effType].effectsList._EffectsList__effectDescList: if isinstance(effectDesc, _SoundEffectDesc): effectDesc._impactNames = ImpactNames( *(typeData.get( key, getattr(effectDesc._impactNames, key)) for key in ('impactNPC_PC', 'impactPC_NPC', 'impactNPC_NPC', 'impactFNPC_PC'))) for vehicleType in g_cache._Cache__vehicles.itervalues(): self.inject_vehicleType(vehicleType)
def _getCameraEffectsSettings(): effectsSettings = ResMgr.DataSection() effectsSettings.createSectionFromString('\n <cameraGAEffect>\n <stages>\n <fire>\t1.0\t</fire>\n <noEmission> 4.0 </noEmission>\n </stages>\n <effects>\n <pixie>\n <startKey>\tfire </startKey>\n <file>\tparticles/Environment/weather/fire_storm.xml </file>\n </pixie>\n <stopEmission>\n <startKey> noEmission </startKey>\n </stopEmission>\n </effects>\n </cameraGAEffect>\n ')
def __init__(self, propertyType, value, expectedValue): self.propertyType, self.value, self.expectedValue = propertyType, value, expectedValue xmlText = self.XML_TEMPLATE.format(value=value) self.dataSection = ResMgr.DataSection('root', ElementTree.XML(xmlText), '')