def __init__(self, xmlCtx, section, itemTypeName):
     self.__installed = set()
     self.__active = set()
     for subsection in section.values():
         if subsection.name == 'installed':
             self.__installed.update(_readTags((xmlCtx, subsection.name), subsection, '', itemTypeName))
         if subsection.name == 'active':
             self.__active.update(_readTags((xmlCtx, subsection.name), subsection, '', itemTypeName))
         _xml.raiseWrongXml(xmlCtx, subsection.name, 'should be <installed> or <active>')
 def __readItemFilterNodeFromXml(itemType, xmlCtx, section):
     fn = cc.ItemsFilter.FilterNode()
     if section.has_key('id'):
         fn.ids = ix.readTupleOfPositiveInts(xmlCtx, section, 'id')
     if section.has_key('itemGroupName'):
         fn.itemGroupNames = ix.readTupleOfStrings(xmlCtx,
                                                   section,
                                                   'itemGroupName',
                                                   separator=';')
     if section.has_key('tags'):
         fn.tags = iv._readTags(xmlCtx, section, 'tags',
                                'customizationItem')
     if section.has_key('type'):
         if itemType is not CustomizationType.DECAL:
             ix.raiseWrongXml(xmlCtx, 'type',
                              'type can be used only with decals')
         types = set(
             (getattr(DecalType, typeName)
              for typeName in ix.readTupleOfStrings(xmlCtx, section, 'type')
              ))
         if not types.issubset(DecalType.ALL):
             ix.raiseWrongXml(xmlCtx, 'type', 'unsupported type is used')
         fn.types = types
     if section.has_key('historical'):
         fn.historical = section.readBool('historical', None)
     return fn
예제 #3
0
 def _readFromXml(self, target, xmlCtx, section, cache=None):
     if section.has_key('id'):
         target.id = ix.readInt(xmlCtx, section, 'id', 1)
     if section.has_key('tags'):
         target.tags = iv._readTags(xmlCtx, section, 'tags',
                                    'customizationItem')
         if target.itemType == CustomizationType.PROJECTION_DECAL:
             formTags = [
                 tag for tag in target.tags
                 if tag in ProjectionDecalFormTags.ALL
             ]
             if len(formTags) > 1:
                 ix.raiseWrongXml(
                     xmlCtx, 'tags',
                     'wrong formfactor for prjection decal ID%i' %
                     target.id)
     if section.has_key('vehicleFilter'):
         target.filter = self.readVehicleFilterFromXml(
             (xmlCtx, 'vehicleFilter'), section['vehicleFilter'])
     target.season = readFlagEnum(xmlCtx, section, 'season', SeasonType,
                                  target.season)
     target.customizationDisplayType = section.readInt(
         'historical', target.customizationDisplayType)
     if section.has_key('priceGroup'):
         target.priceGroup = section.readString('priceGroup')
     if section.has_key('requiredToken'):
         target.requiredToken = section.readString('requiredToken')
     if section.has_key('maxNumber'):
         target.maxNumber = ix.readPositiveInt(xmlCtx, section, 'maxNumber')
         if target.maxNumber <= 0:
             ix.raiseWrongXml(xmlCtx, 'maxNumber',
                              'should not be less then 1')
     if IS_CLIENT or IS_EDITOR or IS_WEB:
         self._readClientOnlyFromXml(target, xmlCtx, section, cache)
 def _readComponentFilterInfo(ctx, section, itemTypeName):
     minLevel = section.readInt('minLevel', MIN_VEHICLE_LEVEL)
     if not MIN_VEHICLE_LEVEL <= minLevel <= MAX_VEHICLE_LEVEL:
         _xml.raiseWrongSection(ctx, 'minLevel')
     maxLevel = section.readInt('maxLevel', MAX_VEHICLE_LEVEL)
     if not MIN_VEHICLE_LEVEL <= maxLevel <= MAX_VEHICLE_LEVEL:
         _xml.raiseWrongSection(ctx, 'maxLevel')
     tags = set()
     if section.has_key('tags'):
         tags = _readTags(ctx, section, 'tags', itemTypeName)
     return (minLevel, maxLevel, tags)
예제 #5
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
예제 #6
0
 def _readFromXml(self, target, xmlCtx, section):
     if section.has_key('id'):
         target.id = ix.readInt(xmlCtx, section, 'id', 1)
     if section.has_key('tags'):
         target.tags = iv._readTags(xmlCtx, section, 'tags',
                                    'customizationItem')
     if section.has_key('vehicleFilter'):
         target.filter = self.readVehicleFilterFromXml(
             (xmlCtx, 'vehicleFilter'), section['vehicleFilter'])
     target.season = readEnum(xmlCtx, section, 'season', SeasonType,
                              target.season)
     target.historical = section.readBool('historical', target.historical)
     if section.has_key('priceGroup'):
         target.priceGroup = section.readString('priceGroup')
     if section.has_key('requiredToken'):
         target.requiredToken = section.readString('requiredToken')
     if IS_CLIENT or IS_WEB:
         self._readClientOnlyFromXml(target, xmlCtx, section)
예제 #7
0
    def __readFilterNodeFromXml(xmlCtx, section):
        fn = cc.VehicleFilter.FilterNode()
        strNations = ix.readStringOrNone(xmlCtx, section, 'nations')
        if strNations:
            r = []
            for nation in strNations.split():
                nationId = nations.INDICES.get(nation)
                if nationId is None:
                    ix.raiseWrongXml(xmlCtx, 'nations',
                                     "unknown nation '%s'" % nation)
                r.append(nationId)

            fn.nations = r
        if section.has_key('levels'):
            fn.levels = ix.readTupleOfPositiveInts(xmlCtx, section, 'levels')
        if section.has_key('vehicles'):
            fn.vehicles = iv._readNationVehiclesByNames(
                xmlCtx, section, 'vehicles', None)
        if section.has_key('tags'):
            fn.tags = iv._readTags(xmlCtx, section, 'tags', 'vehicle')
        return fn