Beispiel #1
0
def _readItems(cache, itemCls, xmlCtx, section, itemSectionName, storage):
    """Read items and corresponding item groups from xml.
    
    :param itemCls: Target item class
    :param xmlCtx: Tuple with xml context used by ResMgr
    :param section: Section pointing to xml element with item group collection
    :param itemSectionName: tag of item element
    :param storage: dict to store loaded values
    :return: dictionary {id, item} of loaded items
    """
    reader = __xmlReaders[itemCls]
    groupsDict = cache.priceGroups
    itemToGroup = cache.itemToPriceGroup
    for i, (gname, gsection) in enumerate(section.items()):
        if gname != 'itemGroup' and 'xmlns:' not in gname:
            ix.raiseWrongSection(xmlCtx, gname)
        if gname != 'itemGroup':
            continue
        group = cc.ItemGroup(itemCls)
        gCtx = (xmlCtx, 'itemGroup {0}'.format(i))
        itemPrototype = itemCls()
        reader._readFromXml(itemPrototype, gCtx, gsection)
        group.itemPrototype = itemPrototype
        j = 0
        for iname, isection in gsection.items():
            if iname != itemSectionName:
                continue
            iCtx = (gCtx, '{0} {1}'.format(iname, j))
            j += 1
            item = itemCls(group)
            reader._readFromXml(item, iCtx, isection)
            if item.compactDescr in itemToGroup:
                ix.raiseWrongXml(
                    iCtx, 'id', 'duplicate item. id: %s found in group %s' %
                    (item.id, itemToGroup[item.compactDescr]))
            storage[item.id] = item
            if isection.has_key('price'):
                iv._readPriceForItem(iCtx, isection, item.compactDescr)
            elif item.priceGroup:
                if item.priceGroup not in cache.priceGroupNames:
                    ix.raiseWrongXml(
                        iCtx, 'priceGroup',
                        'unknown price group %s for item %s' %
                        (item.priceGroup, item.id))
                priceGroupId = cache.priceGroupNames[item.priceGroup]
                item.priceGroupTags = groupsDict[priceGroupId].tags
                itemToGroup[
                    item.compactDescr] = groupsDict[priceGroupId].compactDescr
                itemNotInShop = isection.readBool('notInShop', False)
                iv._copyPriceForItem(groupsDict[priceGroupId].compactDescr,
                                     item.compactDescr, itemNotInShop)
            else:
                ix.raiseWrongXml(iCtx, 'priceGroup',
                                 'no price for item %s' % item.id)
Beispiel #2
0
def _readItems(groupName, cache, itemCls, xmlCtx, section, storage):
    reader = LegacyCamouflageReader(
    ) if itemCls == cc.CamouflageItem else PaintXmlReader()
    groupsDict = cache.priceGroups
    itemToGroup = cache.itemToPriceGroup
    group = cc.ItemGroup(itemCls)
    itemPrototype = itemCls()
    itemPrototype.season = SeasonType.ALL
    itemPrototype.priceGroup = 'custom'
    itemPrototype.historical = False
    itemPrototype.i18n = shared_components.I18nExposedComponent(groupName, '')
    group.itemPrototype = itemPrototype
    j = 0
    if section.has_key('camouflages'):
        section = section['camouflages']
    for i_name, i_section in section.items():
        iCtx = (xmlCtx, '{0} {1}'.format(i_name, j))
        j += 1
        item = itemCls(group)
        reader._readFromXml(item, iCtx, i_section)
        if itemCls == cc.CamouflageItem:
            item.invisibilityFactor = 0
            item.i18n = shared_components.I18nExposedComponent(i_name, '')
        item.id = max(20000, *storage) + 1
        if item.compactDescr in itemToGroup:
            ix.raiseWrongXml(
                iCtx, 'id', 'duplicate item. id: %s found in group %s' %
                (item.id, itemToGroup[item.compactDescr]))
        storage[item.id] = item
        if item.priceGroup:
            if item.priceGroup not in cache.priceGroupNames:
                ix.raiseWrongXml(
                    iCtx, 'priceGroup', 'unknown price group %s for item %s' %
                    (item.priceGroup, item.id))
            priceGroupId = cache.priceGroupNames[item.priceGroup]
            item.priceGroupTags = groupsDict[priceGroupId].tags
            itemToGroup[
                item.compactDescr] = groupsDict[priceGroupId].compactDescr
            itemNotInShop = i_section.readBool('notInShop', True)
            iv._copyPriceForItem(groupsDict[priceGroupId].compactDescr,
                                 item.compactDescr, itemNotInShop)
        else:
            ix.raiseWrongXml(iCtx, 'priceGroup',
                             'no price for item %s' % item.id)
def _readItems(cache, itemCls, xmlCtx, section, itemSectionName, storage):
    reader = __xmlReaders[itemCls]
    groupsDict = cache.priceGroups
    itemToGroup = cache.itemToPriceGroup
    for i, (gname, gsection) in enumerate(section.items()):
        if gname != 'itemGroup' and 'xmlns:' not in gname:
            ix.raiseWrongSection(xmlCtx, gname)
        if gname != 'itemGroup':
            continue
        group = cc.ItemGroup(itemCls)
        gCtx = (xmlCtx, 'itemGroup {0}'.format(i))
        itemPrototype = itemCls()
        reader._readFromXml(itemPrototype, gCtx, gsection)
        group.itemPrototype = itemPrototype
        j = 0
        for iname, isection in gsection.items():
            if iname != itemSectionName:
                continue
            iCtx = (gCtx, '{0} {1}'.format(iname, j))
            j += 1
            item = itemCls(group)
            reader._readFromXml(item, iCtx, isection)
            if item.compactDescr in itemToGroup:
                ix.raiseWrongXml(
                    iCtx, 'id', 'duplicate item. id: %s found in group %s' %
                    (item.id, itemToGroup[item.compactDescr]))
            storage[item.id] = item
            if isection.has_key('price'):
                iv._readPriceForItem(iCtx, isection, item.compactDescr)
            if item.priceGroup:
                if item.priceGroup not in cache.priceGroupNames:
                    ix.raiseWrongXml(
                        iCtx, 'priceGroup',
                        'unknown price group %s for item %s' %
                        (item.priceGroup, item.id))
                priceGroupId = cache.priceGroupNames[item.priceGroup]
                item.priceGroupTags = groupsDict[priceGroupId].tags
                itemToGroup[
                    item.compactDescr] = groupsDict[priceGroupId].compactDescr
                itemNotInShop = isection.readBool('notInShop', False)
                iv._copyPriceForItem(groupsDict[priceGroupId].compactDescr,
                                     item.compactDescr, itemNotInShop)
            ix.raiseWrongXml(iCtx, 'priceGroup',
                             'no price for item %s' % item.id)
def _readItems(cache, itemCls, xmlCtx, section, itemSectionName, storage,
               progression):
    reader = __xmlReaders[itemCls]
    groupsDict = cache.priceGroups
    itemToGroup = cache.itemToPriceGroup
    for i, (gname, gsection) in enumerate(section.items()):
        if gname != 'itemGroup' and 'xmlns:' not in gname:
            ix.raiseWrongSection(xmlCtx, gname)
        if gname != 'itemGroup':
            continue
        group = cc.ItemGroup(itemCls)
        gCtx = (xmlCtx, 'itemGroup {0}'.format(i))
        itemPrototype = itemCls()
        sharedProps = set()
        with storeChangedProperties(itemPrototype, sharedProps):
            reader._readFromXml(itemPrototype, gCtx, gsection, cache)
        group.itemPrototype = itemPrototype
        groupItems = []
        if gsection.has_key('name'):
            group.name = gsection.readString('name')
        j = 0
        for iname, isection in gsection.items():
            if iname != itemSectionName:
                continue
            iCtx = (gCtx, '{0} {1}'.format(iname, j))
            j += 1
            item = itemCls(group)
            overrideProps = set()
            with storeChangedProperties(item, overrideProps):
                reader._readFromXml(item, iCtx, isection, cache)
            if IS_EDITOR:
                item.editorData.sharedPropertiesInfo = EditorSharedPropertiesInfo(
                )
                item.editorData.sharedPropertiesInfo.markAsOverride(
                    *overrideProps)
            groupItems.append(item)
            if item.compactDescr in itemToGroup:
                ix.raiseWrongXml(
                    iCtx, 'id', 'duplicate item. id: %s found in group %s' %
                    (item.id, itemToGroup[item.compactDescr]))
            storage[item.id] = item
            item.progression = progression.get(item.id, None)
            if item.progression is not None:
                cache.customizationWithProgression[item.compactDescr] = item
            if isection.has_key('price'):
                iv._readPriceForItem(iCtx, isection, item.compactDescr)
            if item.priceGroup:
                if item.priceGroup not in cache.priceGroupNames:
                    ix.raiseWrongXml(
                        iCtx, 'priceGroup',
                        'unknown price group %s for item %s' %
                        (item.priceGroup, item.id))
                priceGroupId = cache.priceGroupNames[item.priceGroup]
                item.priceGroupTags = groupsDict[priceGroupId].tags
                itemToGroup[
                    item.compactDescr] = groupsDict[priceGroupId].compactDescr
                itemNotInShop = isection.readBool('notInShop', False)
                iv._copyPriceForItem(groupsDict[priceGroupId].compactDescr,
                                     item.compactDescr, itemNotInShop)
            ix.raiseWrongXml(iCtx, 'priceGroup',
                             'no price for item %s' % item.id)

        if IS_EDITOR:
            if len(groupItems) > 1 and len(sharedProps) > 0:
                for item in groupItems:
                    for p in sharedProps:
                        if not item.editorData.sharedPropertiesInfo.isOverriden(
                                p):
                            item.editorData.sharedPropertiesInfo.markAsShared(
                                p)

    _addEmptyItem(itemCls, storage)
    return
Beispiel #5
0
def _readItems(cache, itemCls, xmlCtx, section, itemSectionName, storage,
               progression):
    reader = __xmlReaders[itemCls]
    priceGroupsDict = cache.priceGroups
    itemToPriceGroup = cache.itemToPriceGroup
    if IS_EDITOR:
        itemType = CUSTOMIZATION_CLASSES[itemCls]
        cache.editorData.groups[itemType] = []
        sourceFiles = set()
    for i, (gname, gsection) in enumerate(section.items()):
        if gname != 'itemGroup' and 'xmlns:' not in gname:
            ix.raiseWrongSection(xmlCtx, gname)
        if gname != 'itemGroup':
            continue
        group = cc.ItemGroup(itemCls)
        gCtx = (xmlCtx, 'itemGroup {0}'.format(i))
        itemPrototype = itemCls()
        sharedProps = set()
        with storeChangedProperties(itemPrototype, sharedProps):
            reader._readFromXml(itemPrototype, gCtx, gsection, cache)
        group.itemPrototype = itemPrototype
        groupItems = []
        if gsection.has_key('name'):
            group.name = gsection.readString('name')
        j = 0
        for iname, isection in gsection.items():
            if iname != itemSectionName:
                continue
            iCtx = (gCtx, '{0} {1}'.format(iname, j))
            j += 1
            item = itemCls(group)
            overrideProps = set()
            with storeChangedProperties(item, overrideProps):
                reader._readFromXml(item, iCtx, isection, cache)
            if IS_EDITOR:
                item.editorData.sharedPropertiesInfo.markAsOverride(
                    *overrideProps)
            groupItems.append(item)
            if item.compactDescr in itemToPriceGroup:
                ix.raiseWrongXml(
                    iCtx, 'id', 'duplicate item. id: %s found in group %s' %
                    (item.id, itemToPriceGroup[item.compactDescr]))
            storage[item.id] = item
            item.progression = progression.get(item.id, None)
            if item.progression is not None:
                cache.customizationWithProgression[item.compactDescr] = item
                iv._readPriceForProgressionLvl(item.compactDescr,
                                               item.progression.levels)
                for arenaTypeID, items in cache.itemGroupByProgressionBonusType.iteritems(
                ):
                    if arenaTypeID in item.progression.bonusTypes:
                        items.append(item)

            if isection.has_key('price'):
                iv._readPriceForItem(iCtx, isection, item.compactDescr)
            if item.priceGroup:
                if item.priceGroup not in cache.priceGroupNames:
                    ix.raiseWrongXml(
                        iCtx, 'priceGroup',
                        'unknown price group %s for item %s' %
                        (item.priceGroup, item.id))
                priceGroupId = cache.priceGroupNames[item.priceGroup]
                item.priceGroupTags = priceGroupsDict[priceGroupId].tags
                itemToPriceGroup[item.compactDescr] = priceGroupsDict[
                    priceGroupId].compactDescr
                itemNotInShop = isection.readBool('notInShop', False)
                iv._copyPriceForItem(
                    priceGroupsDict[priceGroupId].compactDescr,
                    item.compactDescr, itemNotInShop)
            ix.raiseWrongXml(iCtx, 'priceGroup',
                             'no price for item %s' % item.id)

        if IS_EDITOR:
            refs = gsection.references
            if len(refs) == 1:
                group.editorData.sourceXml = refs[0]
                sourceFiles.add(refs[0])
            itemPrototype.edIsPrototype = True
            group.editorData.itemRefs = [
                UnintrusiveWeakRef(item) for item in groupItems
            ]
            cache.editorData.groups[itemType].append(group)

    if IS_EDITOR:
        cache.editorData.sourceFiles[itemType] = list(sourceFiles)
    _addEmptyItem(itemCls, storage, itemSectionName)
    return