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
def readEmblemSlots(xmlCtx, section, subsectionName): """Reads section 'emblemSlots' to fetch sequence of emblem slots if they exist. :param xmlCtx: tuple(root ctx or None, path to section). :param section: instance of DataSection. :param subsectionName: string containing name of section to find slots configuration. :return: tuple containing EmblemSlot items. """ slots = [] for sname, subsection in _xml.getChildren(xmlCtx, section, subsectionName): if sname not in component_constants.ALLOWED_EMBLEM_SLOTS: _xml.raiseWrongXml(xmlCtx, 'emblemSlots/{}'.format(sname), 'expected {}'.format(_ALLOWED_EMBLEM_SLOTS)) ctx = (xmlCtx, 'emblemSlots/{}'.format(sname)) descr = shared_components.EmblemSlot( _xml.readVector3(ctx, subsection, 'rayStart'), _xml.readVector3(ctx, subsection, 'rayEnd'), _xml.readVector3(ctx, subsection, 'rayUp'), _xml.readPositiveFloat(ctx, subsection, 'size'), subsection.readBool('hideIfDamaged', False), _ALLOWED_EMBLEM_SLOTS[_ALLOWED_EMBLEM_SLOTS.index(sname)], subsection.readBool('isMirrored', False), subsection.readBool('isUVProportional', True), _xml.readIntOrNone(ctx, subsection, 'emblemId')) slots.append(descr) return tuple(slots)
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), hitTesterManager=_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))
def _readConfig(self, xmlCtx, section): self.delay = _xml.readPositiveFloat(xmlCtx, section, 'delay') self.modelName = _xml.readString(xmlCtx, section, 'modelName') if IS_CLIENT: self.soundEvent = _xml.readString(xmlCtx, section, 'wwsoundEvent') self.speed = _xml.readInt(xmlCtx, section, 'speed') self.heights = _xml.readTupleOfPositiveInts(xmlCtx, section, 'heights', 2) self.areaLength = _xml.readPositiveFloat(xmlCtx, section, 'areaLength') self.areaWidth = _xml.readPositiveFloat(xmlCtx, section, 'areaWidth') self.antepositions = _xml.readTupleOfFloats(xmlCtx, section, 'antepositions') self.lateropositions = _xml.readTupleOfFloats(xmlCtx, section, 'lateropositions') self.bombingMask = tuple((bool(v) for v in _xml.readTupleOfInts(xmlCtx, section, 'bombingMask'))) if not len(self.antepositions) == len(self.lateropositions) == len(self.bombingMask): _xml.raiseWrongSection(xmlCtx, 'bombers number mismatch') self.waveFraction = _xml.readPositiveFloat(xmlCtx, section, 'waveFraction') self.bombsNumber = _xml.readNonNegativeInt(xmlCtx, section, 'bombsNumber') self.shellCompactDescr = _xml.readInt(xmlCtx, section, 'shellCompactDescr') self.tracerKind = _xml.readInt(xmlCtx, section, 'tracerKind') self.piercingPower = _xml.readTupleOfPositiveInts(xmlCtx, section, 'piercingPower', 2) self.gravity = _xml.readPositiveFloat(xmlCtx, section, 'gravity') self.areaVisual = _xml.readStringOrNone(xmlCtx, section, 'areaVisual') self.areaColor = _xml.readIntOrNone(xmlCtx, section, 'areaColor') self.areaMarker = _xml.readStringOrNone(xmlCtx, section, 'areaMarker') self.reusable = _xml.readBool(xmlCtx, section, 'reusable') self.cooldownTime = _xml.readNonNegativeFloat(xmlCtx, section, 'cooldownTime') if self.reusable else 0.0 self.deployTime = _xml.readNonNegativeFloat(xmlCtx, section, 'deployTime')
def _readProjectionDecalSlot(ctx, subsection, slotType): descr = shared_components.ProjectionDecalSlotDescription( slotType=slotType, slotId=_xml.readInt(ctx, subsection, 'slotId'), position=_xml.readVector3OrNone(ctx, subsection, 'position'), rotation=_xml.readVector3OrNone(ctx, subsection, 'rotation'), scale=_xml.readVector3OrNone(ctx, subsection, 'scale'), scaleFactors=_xml.readVector3( ctx, subsection, 'scaleFactors', c11n_constants.DEFAULT_DECAL_SCALE_FACTORS), doubleSided=_xml.readBool(ctx, subsection, 'doubleSided', False), hiddenForUser=_xml.readBool(ctx, subsection, 'hiddenForUser', False), canBeMirroredVertically=_xml.readBool(ctx, subsection, 'verticalMirror', False), showOn=_xml.readIntOrNone(ctx, subsection, 'showOn'), tags=readOrderedTagsOrEmpty(ctx, subsection, _customizationSlotTagsValidator), clipAngle=_xml.readFloat(ctx, subsection, 'clipAngle', c11n_constants.DEFAULT_DECAL_CLIP_ANGLE), anchorShift=_xml.readFloat(ctx, subsection, 'anchorShift', c11n_constants.DEFAULT_DECAL_ANCHOR_SHIFT)) _verifySlotId(ctx, slotType, descr.slotId) _verifyMatchingSlotSettings(ctx, descr) if descr.showOn is not None: availableShowOnRegions = c11n_constants.ApplyArea.HULL | c11n_constants.ApplyArea.TURRET | c11n_constants.ApplyArea.GUN if descr.showOn | availableShowOnRegions != availableShowOnRegions: _xml.raiseWrongSection(ctx, 'showOn') if subsection.has_key('compatibleModels'): descr.compatibleModels = _xml.readTupleOfStrings( ctx, subsection, 'compatibleModels') if subsection.has_key('itemId'): descr.itemId = _xml.readInt(ctx, subsection, 'itemId') if subsection.has_key('options'): descr.options = _xml.readNonNegativeInt(ctx, subsection, 'options') return descr
def _readConfig(self, xmlCtx, section): self.delay = _xml.readPositiveFloat(xmlCtx, section, 'delay') self.modelName = _xml.readString(xmlCtx, section, 'modelName') self.soundEvent = _xml.readString(xmlCtx, section, 'soundEvent') self.speed = _xml.readInt(xmlCtx, section, 'speed') self.heights = _xml.readTupleOfPositiveInts(xmlCtx, section, 'heights', 2) self.areaLength = _xml.readPositiveFloat(xmlCtx, section, 'areaLength') self.areaWidth = _xml.readPositiveFloat(xmlCtx, section, 'areaWidth') self.antepositions = _xml.readTupleOfFloats(xmlCtx, section, 'antepositions') self.lateropositions = _xml.readTupleOfFloats(xmlCtx, section, 'lateropositions') self.bombingMask = tuple((bool(v) for v in _xml.readTupleOfInts(xmlCtx, section, 'bombingMask'))) if not len(self.antepositions) == len(self.lateropositions) == len(self.bombingMask): _xml.raiseWrongSection(xmlCtx, 'bombers number mismatch') self.waveFraction = _xml.readPositiveFloat(xmlCtx, section, 'waveFraction') self.bombsNumber = _xml.readNonNegativeInt(xmlCtx, section, 'bombsNumber') self.shellCompactDescr = _xml.readInt(xmlCtx, section, 'shellCompactDescr') self.tracerKind = _xml.readInt(xmlCtx, section, 'tracerKind') self.piercingPower = _xml.readTupleOfPositiveInts(xmlCtx, section, 'piercingPower', 2) self.gravity = _xml.readPositiveFloat(xmlCtx, section, 'gravity') self.areaVisual = _xml.readStringOrNone(xmlCtx, section, 'areaVisual') self.areaColor = _xml.readIntOrNone(xmlCtx, section, 'areaColor') self.areaMarker = _xml.readStringOrNone(xmlCtx, section, 'areaMarker') self.reusable = _xml.readBool(xmlCtx, section, 'reusable') self.cooldownTime = _xml.readNonNegativeFloat(xmlCtx, section, 'cooldownTime') if self.reusable else 0.0 self.deployTime = _xml.readNonNegativeFloat(xmlCtx, section, 'deployTime')
def _readClientOnlyFromXml(self, target, xmlCtx, section, cache=None): super(AttachmentXmlReader, self)._readClientOnlyFromXml(target, xmlCtx, section) target.modelName = ix.readStringOrNone(xmlCtx, section, 'modelName') target.sequenceId = ix.readIntOrNone(xmlCtx, section, 'sequenceId') target.attachmentLogic = ix.readStringOrNone(xmlCtx, section, 'attachmentLogic') target.initialVisibility = ix.readBool(xmlCtx, section, 'initialVisibility', True)
def _readEmblemSlot(ctx, subsection, slotType): descr = shared_components.EmblemSlot( _xml.readVector3(ctx, subsection, 'rayStart'), _xml.readVector3(ctx, subsection, 'rayEnd'), _xml.readVector3(ctx, subsection, 'rayUp'), _xml.readPositiveFloat(ctx, subsection, 'size'), subsection.readBool('hideIfDamaged', False), slotType, subsection.readBool('isMirrored', False), subsection.readBool('isUVProportional', True), _xml.readIntOrNone(ctx, subsection, 'emblemId')) return descr
def _readCustomizationSlot(ctx, subsection, slotType): descr = shared_components.CustomizationSlotDescription( slotType=slotType, anchorPosition=_xml.readVector3OrNone(ctx, subsection, 'anchorPosition'), anchorDirection=_xml.readVector3OrNone(ctx, subsection, 'anchorDirection'), applyTo=_xml.readIntOrNone(ctx, subsection, 'applyTo'), slotId=_xml.readInt(ctx, subsection, 'slotId')) if descr.applyTo is not None and descr.applyTo not in c11n_constants.ApplyArea.RANGE: _xml.raiseWrongSection(ctx, 'applyTo') return descr
def _readConfig(self, xmlCtx, section): self.delay = _xml.readPositiveFloat(xmlCtx, section, 'delay') self.duration = _xml.readPositiveFloat(xmlCtx, section, 'duration') self.shotsNumber = _xml.readNonNegativeInt(xmlCtx, section, 'shotsNumber') self.areaRadius = _xml.readPositiveFloat(xmlCtx, section, 'areaRadius') self.shellCompactDescr = _xml.readInt(xmlCtx, section, 'shellCompactDescr') self.piercingPower = _xml.readTupleOfPositiveInts(xmlCtx, section, 'piercingPower', 2) self.areaVisual = _xml.readStringOrNone(xmlCtx, section, 'areaVisual') self.areaColor = _xml.readIntOrNone(xmlCtx, section, 'areaColor') self.areaMarker = _xml.readStringOrNone(xmlCtx, section, 'areaMarker') self.areaLength = self.areaWidth = self.areaRadius * 2 self.reusable = _xml.readBool(xmlCtx, section, 'reusable') self.cooldownTime = _xml.readNonNegativeFloat(xmlCtx, section, 'cooldownTime') if self.reusable else 0.0 self.deployTime = _xml.readNonNegativeFloat(xmlCtx, section, 'deployTime')
def _readSlotsAnchor(ctx, subsection, slotType): applyTo = _xml.readIntOrNone(ctx, subsection, 'applyTo') if applyTo is not None: if applyTo not in c11n_constants.ApplyArea.RANGE: _xml.raiseWrongSection(ctx, 'applyTo') showOn = _xml.readIntOrNone(ctx, subsection, 'showOn') if showOn is not None: availableShowOnRegions = c11n_constants.ApplyArea.HULL | c11n_constants.ApplyArea.TURRET | c11n_constants.ApplyArea.GUN if showOn | availableShowOnRegions != availableShowOnRegions: _xml.raiseWrongSection(ctx, 'showOn') descr = shared_components.SlotsAnchor( type=slotType, anchorPosition=_xml.readVector3(ctx, subsection, 'anchorPosition'), anchorDirection=_xml.readVector3(ctx, subsection, 'anchorDirection'), applyTo=applyTo, slotId=_xml.readInt(ctx, subsection, 'slotId'), position=_xml.readVector3OrNone(ctx, subsection, 'position'), rotation=_xml.readVector3OrNone(ctx, subsection, 'rotation'), scale=_xml.readVector3OrNone(ctx, subsection, 'scale'), scaleFactors=_xml.readVector3OrNone(ctx, subsection, 'scaleFactors'), doubleSided=_xml.readBool(ctx, subsection, 'doubleSided', False), showOn=showOn) return descr
def _readEmblemSlot(ctx, subsection, slotType): descr = shared_components.EmblemSlot( _xml.readVector3(ctx, subsection, 'rayStart'), _xml.readVector3(ctx, subsection, 'rayEnd'), _xml.readVector3(ctx, subsection, 'rayUp'), _xml.readPositiveFloat(ctx, subsection, 'size'), subsection.readBool('hideIfDamaged', False), slotType, subsection.readBool('isMirrored', False), subsection.readBool('isUVProportional', True), _xml.readIntOrNone(ctx, subsection, 'emblemId'), _xml.readInt(ctx, subsection, 'slotId'), subsection.readBool('applyToFabric', True), _readCompatibleModels(subsection, ctx)) _verifySlotId(ctx, slotType, descr.slotId) return descr
def writeTrackBasicParams(trackBasicParams, section, cache): if trackBasicParams is None: return else: shared_writers.writeLodDist(trackBasicParams.lodDist, section, 'tracks/lodDist', cache) if len(trackBasicParams.trackPairs) == 1: pair = trackBasicParams.trackPairs[component_constants.MAIN_TRACK_PAIR_IDX] __writeTrackPairParams(pair, section['tracks']) else: for sname, subsection in _xml.getChildren(None, section, 'tracks'): if sname != 'trackPair': continue index = _xml.readIntOrNone(None, subsection, 'trackPairIdx') if index is None: continue __writeTrackPairParams(trackBasicParams.trackPairs[index], subsection) return
def _readProjectionDecalSlot(ctx, subsection, slotType): descr = shared_components.ProjectionDecalSlotDescription( slotType=slotType, slotId=_xml.readInt(ctx, subsection, 'slotId'), anchorPosition=_xml.readVector3OrNone(ctx, subsection, 'anchorPosition'), anchorDirection=_xml.readVector3OrNone(ctx, subsection, 'anchorDirection'), position=_xml.readVector3OrNone(ctx, subsection, 'position'), rotation=_xml.readVector3OrNone(ctx, subsection, 'rotation'), scale=_xml.readVector3OrNone(ctx, subsection, 'scale'), scaleFactors=_xml.readVector3( ctx, subsection, 'scaleFactors', c11n_constants.DEFAULT_DECAL_SCALE_FACTORS), doubleSided=_xml.readBool(ctx, subsection, 'doubleSided', False), canBeMirroredVertically=_xml.readBool(ctx, subsection, 'verticalMirror', False), showOn=_xml.readIntOrNone(ctx, subsection, 'showOn'), tags=readOrderedTagsOrEmpty(ctx, subsection, _customizationSlotTagsValidator), clipAngle=_xml.readFloat(ctx, subsection, 'clipAngle', c11n_constants.DEFAULT_DECAL_CLIP_ANGLE)) _verifySlotId(ctx, slotType, descr.slotId) if descr.showOn is not None: availableShowOnRegions = c11n_constants.ApplyArea.HULL | c11n_constants.ApplyArea.TURRET | c11n_constants.ApplyArea.GUN if descr.showOn | availableShowOnRegions != availableShowOnRegions: _xml.raiseWrongSection(ctx, 'showOn') if subsection.has_key('attachedPart'): attachedPartsData = _xml.readString(ctx, subsection, 'attachedPart') descr.attachedParts = defaultdict(set) for partData in attachedPartsData.split(): pType, pName = partData.split(':') if pType != 'hull': descr.attachedParts[pType].add(pName) if subsection.has_key('compatibleModels'): descr.compatibleModels = _xml.readTupleOfStrings( ctx, subsection, 'compatibleModels') if subsection.has_key('itemId'): descr.itemId = _xml.readInt(ctx, subsection, 'itemId') if subsection.has_key('options'): descr.options = _xml.readNonNegativeInt(ctx, subsection, 'options') return descr
def readEmblemSlots(xmlCtx, section, subsectionName): slots = [] for sname, subsection in _xml.getChildren(xmlCtx, section, subsectionName): if sname not in component_constants.ALLOWED_EMBLEM_SLOTS: _xml.raiseWrongXml(xmlCtx, 'emblemSlots/{}'.format(sname), 'expected {}'.format(_ALLOWED_EMBLEM_SLOTS)) ctx = (xmlCtx, 'emblemSlots/{}'.format(sname)) descr = shared_components.EmblemSlot( _xml.readVector3(ctx, subsection, 'rayStart'), _xml.readVector3(ctx, subsection, 'rayEnd'), _xml.readVector3(ctx, subsection, 'rayUp'), _xml.readPositiveFloat(ctx, subsection, 'size'), subsection.readBool('hideIfDamaged', False), _ALLOWED_EMBLEM_SLOTS[_ALLOWED_EMBLEM_SLOTS.index(sname)], subsection.readBool('isMirrored', False), subsection.readBool('isUVProportional', True), _xml.readIntOrNone(ctx, subsection, 'emblemId')) slots.append(descr) return tuple(slots)
def readLodSettings(xmlCtx, section, cache): return shared_components.LodSettings( maxLodDistance=readLodDist(xmlCtx, section, 'lodSettings/maxLodDistance', cache), maxPriority=_xml.readIntOrNone(xmlCtx, section, 'lodSettings/maxPriority'))
def readLodSettings(xmlCtx, section): return vehicle_config_types.LodSettings( readLodDist(xmlCtx, section, 'lodSettings/maxLodDistance'), _xml.readIntOrNone(xmlCtx, section, 'lodSettings/maxPriority'))