コード例 #1
0
def readLevelRewards(xmlPath):
    cache = {}
    with openSection(xmlPath) as section:
        if section is None:
            raise NYSoftException("Can't open '%s'" % xmlPath)
        for levelSec in section.values():
            cfg = _readLevelRewardSection(levelSec)
            rewardID = cfg['id']
            if rewardID in cache:
                raise NYSoftException("Repeated boxID '%s'" % rewardID)
            cache[rewardID] = LevelDescriptor(cfg)

    return cache
コード例 #2
0
def buildVariadicDiscountsCache(xmlPath):
    section = ResMgr.openSection(xmlPath)
    if section is None:
        raise NYSoftException("Can't open '%s'" % xmlPath)
    cache = {}
    for vdSec in section.values():
        cfg = _readVariadicDiscount(vdSec)
        vdID = cfg['id']
        if vdID in cache:
            raise NYSoftException("Repeated variadic discount ID '%s'" % vdID)
        cache[vdID] = VariadicDiscountDescriptor(cfg['id'],
                                                 cfg['firstGoodieId'],
                                                 cfg['lastGoodieId'],
                                                 cfg['level'])

    return cache
コード例 #3
0
def _buildToyGroups(toysDescrs):
    groups = {}
    for toy in toysDescrs:
        groupID = getToyGroupID(toyDescr=toy)
        groups.setdefault(groupID, [])
        groups[groupID].append(toy.id)

    if any((len(gv) < 1 for gk, gv in groups.iteritems())):
        raise NYSoftException('Inconsistent toys description. Degenerate group size < 1')
    currYearMaxToyRank = YEARS_INFO.currYearMaxToyRank()
    toysInfos = [(currYearMaxToyRank, CONSTS.ToySettings.NEW, CONSTS.TOY_USUAL_TYPES), (MAX_MEGA_TOY_RANK, CONSTS.ToySettings.MEGA, CONSTS.MEGA_TOY_TYPES)]
    expectedGroupsCount = _calculateExpectedCount(toysInfos)
    if len(groups) == expectedGroupsCount:
        return groups
    missingToys = _findMissingToys(toysInfos, groups)
    raise NYSoftException('Inconsistent toys description. Missing toys (groups len={}, expectedGroupsLen={} toyRank={}): {} of {}'.format(len(groups), expectedGroupsCount, currYearMaxToyRank, len(missingToys), missingToys))
コード例 #4
0
def readSlots(xmlPath):
    cache = None
    with openSection(xmlPath) as section:
        if section is None:
            raise NYSoftException("Can't open '%s'" % xmlPath)
        subsections = section['slots'].values()
        numSlots = len(subsections)
        cache = [None] * numSlots
        for slotSec in subsections:
            cfg = _readSlotSection(slotSec)
            slotID = cfg['id']
            if not 0 <= slotID < numSlots:
                raise NYSoftException('Wrong slotID {}, {}'.format(
                    slotID, numSlots))
            if cache[slotID] is not None:
                raise NYSoftException("Repeated slotID '%d'" % slotID)
            cache[slotID] = SlotDescriptor(cfg)

    return cache
コード例 #5
0
def readCollectionRewards(xmlPath):
    cache = {}
    with openSection(xmlPath) as section:
        if section is None:
            raise NYSoftException("Can't open '%s'" % xmlPath)
        for reward in section.values():
            rewardID = reward.readString('id')
            collName = reward.readString('collection')
            if rewardID in cache:
                raise NYSoftException("Repeated boxID '%s'" % rewardID)
            prefix = rewardID[:4]
            year = prefix[2:4]
            collectionStrID = YEARS_INFO.getCollectionSettingID(
                collName, prefix)
            cache[rewardID] = collectionStrID
            cache[collectionStrID] = rewardID
            cache[collName + year] = rewardID

    return cache
コード例 #6
0
def readToysTransformations(xmlPath):
    cache = {}
    with openSection(xmlPath) as section:
        if section is None:
            raise NYSoftException("Can't open '%s" % xmlPath)
        for subSection in section.values():
            modelName, nodes = _readToyTransformationsSection(subSection)
            cache[modelName] = nodes

    return cache
コード例 #7
0
def _readToy(section, collectionName=None):
    cfg = {intern('collection'): collectionName} if collectionName else {}
    toyData = {
        intern(name):
        (section.readInt(name) if name in ('id', 'rank') else intern(
            section.readString(name)))
        for name, subsection in section.items()
    }
    if collectionName and collectionName != 'defaultToys':
        if not MIN_TOY_RANK <= toyData[
                'rank'] <= YEARS_INFO.getMaxToyRankByYear(collectionName):
            raise NYSoftException(
                'Invalid toy rank, toy collection:{}, toy id: {}'.format(
                    collectionName, toyData['id']))
        if toyData['setting'] not in YEARS_INFO.getCollectionTypesByYear(
                collectionName):
            raise NYSoftException(
                'Invalid setting, toy collection:{}, toy id: {}'.format(
                    collectionName, toyData['id']))
    cfg.update(toyData)
    return cfg
コード例 #8
0
def _readSlotSection(section):
    cfg = {'id': section.readInt('id')}
    cfg['type'] = slotType = section.readString('type')
    if slotType not in TOY_TYPES:
        raise NYSoftException("Wrong slot type '%s'" % slotType)
    if IS_CLIENT:
        cfg['object'] = section.readString('object')
        cfg['nodes'] = section.readString('nodes')
        cfg['direction'] = section.readString('direction')
        cfg['selectable'] = section.readBool('selectable')
        cfg['defaultToy'] = section.readInt('defaultToy', -1)
        cfg['hoverEffect'] = section.readString('hoverEffect')
    return cfg
コード例 #9
0
def _readLevelRewardSection(section):
    cfg = {'id': section.readString('id')}
    cfg['level'] = level = section.readInt('level')
    if not MIN_ATMOSPHERE_LVL <= level <= MAX_ATMOSPHERE_LVL:
        raise NYSoftException("Wrong reward level '%d'" % level)
    return cfg