def _getCommonChapterValues(self, bonuses, subSection, xmlCtx): chapterID = _xml.readString(xmlCtx, subSection, 'chapter-id') title = translation(_xml.readString(xmlCtx, subSection, 'title')) descSec = _xml.getSubsection(xmlCtx, subSection, 'description') defDesc = translation(descSec.asString) abDesc = translation(descSec.readString('after-battle', defDesc)) descriptions = (defDesc, abDesc) bonus = self._parseBonus(xmlCtx, subSection, bonuses) forcedLoading = subSection.readInt('forced-loading', -1) pathSec = _xml.getSubsection(xmlCtx, subSection, 'file-path') defFilePath = pathSec.asString afterBattleFilePath = pathSec.readString('after-battle', defFilePath) filePaths = (defFilePath, afterBattleFilePath) sharedScene = subSection.readString('shared-scene') predefinedVars = [] varsSection = subSection['vars'] or {} for name, varSection in varsSection.items(): if name == 'var-set': predefinedVars.append(sub_parsers.parseVarSet(xmlCtx, varSection, ())) else: _xml.raiseWrongXml(xmlCtx, name, 'Unknown tag') return (chapterID, title, descriptions, bonus, forcedLoading, filePaths, sharedScene, predefinedVars)
def _parseWindow(xmlCtx, section, flags): windowID = parseID(xmlCtx, section, 'Specify a window ID') windowType = _xml.readString(xmlCtx, section, 'type') bSec = _xml.getSubsection(xmlCtx, section, 'buttons') content = {'closeID': _xml.readString(xmlCtx, bSec, 'close')} parser = _WINDOW_SUB_PARERS.get(windowType) if parser is not None: window = parser(xmlCtx, section, flags, windowID, windowType, content) window.setActions(parseActions(xmlCtx, _xml.getSubsection(xmlCtx, section, 'actions'), flags)) else: window = None LOG_ERROR('Type of window is not supported: ', windowType) return window
def _readTeleportMarkerSection(xmlCtx, section, markerID, varRef): subSec = _xml.getSubsection(xmlCtx, section, 'world') worldData = { 'offset': _xml.readVector3(xmlCtx, subSec, 'offset'), 'yaw': _xml.readFloat(xmlCtx, subSec, 'yaw') } return chapter.AreaMarker(markerID, varRef, {}, {}, worldData, {})
def _readNationConfigSection(xmlCtx, section): config = {} firstNames = {} lastNames = {} icons = {} for kindName in component_constants.TANKMEN_GROUPS: groups = [] totalWeight = 0.0 for sname, subsection in _xml.getChildren(xmlCtx, section, kindName): ctx = (xmlCtx, kindName + '/' + sname) group = _readTankmenGroup(ctx, subsection, firstNames, lastNames, icons) totalWeight += group.weight groups.append(group) totalWeight = max(0.001, totalWeight) for group in groups: group.weight /= totalWeight config[kindName] = tuple(groups) ranks = _readRanks((xmlCtx, 'ranks'), _xml.getChildren(xmlCtx, section, 'ranks')) config['roleRanks'] = _readRoleRanks((xmlCtx, 'roleRanks'), _xml.getSubsection(xmlCtx, section, 'roleRanks'), ranks) if IS_CLIENT or IS_WEB: config['firstNames'] = firstNames config['lastNames'] = lastNames config['icons'] = icons config['ranks'] = ranks else: config['firstNames'] = frozenset(firstNames) config['lastNames'] = frozenset(lastNames) config['icons'] = frozenset(icons) return tankmen_components.NationConfig(xmlCtx[1], **config)
def _readHintSection(xmlCtx, section, flags): hintID = sub_parsers.parseID(xmlCtx, section, 'Specify a hint ID') if 'item-id' in section.keys(): itemID = sub_parsers.parseID(xmlCtx, section['item-id'], 'Specify a item ID') else: _xml.raiseWrongXml(xmlCtx, section.name, 'Specify a item ID') return tags = section.keys() text = translation(_xml.readString(xmlCtx, section, 'text')) if 'arrow' in tags: subSec = section['arrow'] direction = _xml.readString(xmlCtx, subSec, 'direction') if direction not in _AVAILABLE_DIRECTIONS: _xml.raiseWrongXml(xmlCtx, section, 'Arrow direction {} is invalid.'.format(direction)) arrow = _ArrowProps(direction, _xml.readBool(xmlCtx, subSec, 'loop')) else: arrow = None if 'padding' in tags: subSec = section['padding'] padding = _Padding(_xml.readFloat(xmlCtx, subSec, 'left'), _xml.readFloat(xmlCtx, subSec, 'top'), _xml.readFloat(xmlCtx, subSec, 'right'), _xml.readFloat(xmlCtx, subSec, 'bottom')) else: padding = None hint = chapter.ChainHint(hintID, itemID, text, section.readBool('has-box', True), arrow, padding) hint.setActions(sub_parsers.parseActions(xmlCtx, _xml.getSubsection(xmlCtx, section, 'actions'), flags)) return hint
def __readSharedMetrics(self, shared, xmlCtx, section): precessed = _xml.getChildren(xmlCtx, section, 'grids') for name, gridSection in precessed: gridName = gridSection.asString xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, gridName) gridCtx = (None, xPath) subSec = _xml.getSubsection(xmlCtx, gridSection, 'root') xmlCtx = (None, '{0:>s}/root'.format(xPath)) rootPos = {'start': _xml.readVector2(xmlCtx, subSec, 'start').tuple(), 'step': _xml.readInt(xmlCtx, subSec, 'step')} subSec = _xml.getSubsection(gridCtx, gridSection, 'vertical') xmlCtx = (None, '{0:>s}/vertical'.format(xPath)) vertical = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) subSec = _xml.getSubsection(gridCtx, gridSection, 'horizontal') xmlCtx = (None, '{0:>s}/horizontal'.format(xPath)) horizontal = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) shared['grids'][gridName] = {'root': rootPos, 'vertical': vertical, 'horizontal': horizontal} precessed = _xml.getChildren(xmlCtx, section, 'lines') lines = shared['lines'] for name, sub in precessed: xPath = '{0:>s}/{1:>s}'.format(TREE_SHARED_REL_FILE_PATH, name) xmlCtx = (None, xPath) pinsSec = _xml.getChildren(xmlCtx, sub, 'inPin') inPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'outPin') outPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'viaPin') viaPins = defaultdict(dict) for outPin, setSec in pinsSec: for inPin, pSec in setSec.items(): viaPins[outPin][inPin] = map(lambda section: section[1].asVector2.tuple(), pSec.items()) defSec = sub['default'] default = {} if defSec is not None: xmlCtx = (None, '{0:>s}/default'.format(xPath)) default = {'outPin': _xml.readString(xmlCtx, defSec, 'outPin'), 'inPin': _xml.readString(xmlCtx, defSec, 'inPin')} lines[name] = {'inPins': inPins, 'outPins': outPins, 'viaPins': viaPins, 'default': default} return
def __readSharedMetrics(self, shared, xmlCtx, section): precessed = _xml.getChildren(xmlCtx, section, 'grids') for name, gridSection in precessed: gridName = gridSection.asString xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, gridName) gridCtx = (None, xPath) subSec = _xml.getSubsection(xmlCtx, gridSection, 'root') xmlCtx = (None, '{0:>s}/root'.format(xPath)) rootPos = {'start': _xml.readVector2(xmlCtx, subSec, 'start').tuple(), 'step': _xml.readInt(xmlCtx, subSec, 'step')} subSec = _xml.getSubsection(gridCtx, gridSection, 'vertical') xmlCtx = (None, '{0:>s}/vertical'.format(xPath)) vertical = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) subSec = _xml.getSubsection(gridCtx, gridSection, 'horizontal') xmlCtx = (None, '{0:>s}/horizontal'.format(xPath)) horizontal = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) shared['grids'][gridName] = {'root': rootPos, 'vertical': vertical, 'horizontal': horizontal} precessed = _xml.getChildren(xmlCtx, section, 'lines') lines = shared['lines'] for name, sub in precessed: xPath = '{0:>s}/{1:>s}'.format(TREE_SHARED_REL_FILE_PATH, name) xmlCtx = (None, xPath) pinsSec = _xml.getChildren(xmlCtx, sub, 'inPin') inPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'outPin') outPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'viaPin') viaPins = defaultdict(dict) for outPin, setSec in pinsSec: for inPin, pSec in setSec.items(): viaPins[outPin][inPin] = [ section[1].asVector2.tuple() for section in pSec.items() ] defSec = sub['default'] default = {} if defSec is not None: xmlCtx = (None, '{0:>s}/default'.format(xPath)) default = {'outPin': _xml.readString(xmlCtx, defSec, 'outPin'), 'inPin': _xml.readString(xmlCtx, defSec, 'inPin')} lines[name] = {'inPins': inPins, 'outPins': outPins, 'viaPins': viaPins, 'default': default} return
def __parseChapterSummaries(self, xmlCtx, section, descriptor): for _, subSection in _xml.getChildren(xmlCtx, section, 'chapters'): chapterID = _xml.readString(xmlCtx, subSection, 'chapter-id') title = translation(_xml.readString(xmlCtx, subSection, 'title')) descSec = _xml.getSubsection(xmlCtx, subSection, 'description') defDesc = translation(descSec.asString) abDesc = translation(descSec.readString('after-battle', defDesc)) descriptions = (defDesc, abDesc) bonusSec = _xml.getSubsection(xmlCtx, subSection, 'bonus') bonus = Bonus(bonusSec.readInt('id', -1), bonusSec.readString('message'), sub_parsers._readBonusValues(bonusSec)) forcedLoading = subSection.readInt('forced-loading', -1) pathSec = _xml.getSubsection(xmlCtx, subSection, 'file-path') defFilePath = pathSec.asString afterBattleFilePath = pathSec.readString('after-battle', defFilePath) filePaths = (defFilePath, afterBattleFilePath) sharedScene = subSection.readString('shared-scene') descriptor.addChapter(Chapter(chapterID, title, descriptions, bonus, forcedLoading, filePaths, sharedScene))
def _readSkillBasics(xmlCtx, section, subsectionName): section = _xml.getSubsection(xmlCtx, section, subsectionName) xmlCtx = (xmlCtx, subsectionName) if IS_CLIENT or IS_WEB: skill = skills_components.BasicSkill(subsectionName, i18n=shared_components.I18nComponent(section.readString('userString'), section.readString('description')), icon=_xml.readNonEmptyString(xmlCtx, section, 'icon')) else: skill = skills_components.BasicSkill(subsectionName) return (skill, xmlCtx, section)
def _readModelMarkerSection(xmlCtx, section, name = 'model'): result = {} if name in section.keys(): subSec = _xml.getSubsection(xmlCtx, section, name) result = {'path': _xml.readString(xmlCtx, subSec, 'path'), 'action': _xml.readString(xmlCtx, subSec, 'action'), 'offset': _xml.readVector3(xmlCtx, subSec, 'offset')} return result
def __readControlsSounds(self, xmlCtx): """ Reading controls sounds data @param xmlCtx: [xml data section] xml context document """ controlsSection = _xml.getSubsection(xmlCtx, xmlCtx, self.CONTROLS) self.__default = doc_loaders.readDict(xmlCtx, controlsSection, self.CONTROLS_DEFAULT) controlsOverridesSection = _xml.getSubsection(xmlCtx, controlsSection, self.CONTROLS_OVERRIDES) for name in controlsOverridesSection.keys(): self.__overrides[name] = doc_loaders.readDict(xmlCtx, controlsOverridesSection, name) for schemaName, schemaSection in _xml.getChildren(xmlCtx, controlsSection, self.CONTROLS_SCHEMAS): self.__schemas[schemaName] = doc_loaders.readDict(xmlCtx, schemaSection, self.SCHEMA_SOUNDS) for groupName in _xml.getSubsection(xmlCtx, schemaSection, self.SCHEMA_GROUPS).asString.split(): if groupName in self.__groups: LOG_WARNING('Group has already been read. Will be overriden', groupName, schemaName) self.__groups[groupName] = schemaName
def _readBonusSection(xmlCtx, section, content): bonusSec = _xml.getSubsection(xmlCtx, section, 'bonus') content['bonusValue'] = translation( _xml.readString(xmlCtx, bonusSec, 'value')) content['bonusLabel'] = translation( _xml.readString(xmlCtx, bonusSec, 'label')) content['bonusImageUrl'] = _xml.readString(xmlCtx, bonusSec, 'background') return content
def _readWorldMarkerSection(xmlCtx, section): subSec = _xml.getSubsection(xmlCtx, section, 'world') return { 'shape': _xml.readString(xmlCtx, subSec, 'shape'), 'min-distance': _xml.readFloat(xmlCtx, subSec, 'min-distance'), 'max-distance': _xml.readFloat(xmlCtx, subSec, 'max-distance'), 'offset': _xml.readVector3(xmlCtx, subSec, 'offset') }
def readHintSection(xmlCtx, section, flags): sectionInfo = sub_parsers.parseHint(xmlCtx, section) hint = chapter.ChainHint(sectionInfo['hintID'], sectionInfo['itemID'], sectionInfo['text'], sectionInfo['hasBox'], sectionInfo['arrow'], sectionInfo['padding']) hint.setActions( sub_parsers.parseActions( xmlCtx, _xml.getSubsection(xmlCtx, section, 'actions'), flags)) return hint
def __readDefaultLine(self, shared, xmlCtx, section): defSec = _xml.getSubsection(xmlCtx, section, 'default-line') xPath = '{0:>s}/default-line'.format(TREE_SHARED_REL_FILE_PATH) xmlCtx = (None, xPath) name = _xml.readString(xmlCtx, defSec, 'line') outPin = _xml.readString(xmlCtx, defSec, 'outPin') inPin = _xml.readString(xmlCtx, defSec, 'inPin') self.__getLineInfo(xmlCtx, name, 0, outPin, inPin, shared['lines']) shared['default'] = {'line': name, 'inPin': inPin, 'outPin': outPin}
def _parseWindow(xmlCtx, section, flags): windowID = parseID(xmlCtx, section, 'Specify a window ID') windowType = _xml.readString(xmlCtx, section, 'type') content = {} bSec = _xml.getSubsection(xmlCtx, section, 'buttons') content['closeID'] = _xml.readString(xmlCtx, bSec, 'close') content['type'] = windowType content['windowID'] = windowID parser = _WINDOW_SUB_PARERS.get(windowType) if parser is not None: window = parser(xmlCtx, section, flags, windowID, windowType, content) window.setActions( parseActions(xmlCtx, _xml.getSubsection(xmlCtx, section, 'actions'), flags)) else: window = None LOG_ERROR('Type of window is not supported: ', windowType) return window
def _readSkillBasics(xmlCtx, section, subsectionName): section = _xml.getSubsection(xmlCtx, section, subsectionName) xmlCtx = (xmlCtx, subsectionName) res = {} if IS_CLIENT or IS_WEB: res['userString'] = i18n.makeString(section.readString('userString')) res['description'] = i18n.makeString(section.readString('description')) res['icon'] = _xml.readNonEmptyString(xmlCtx, section, 'icon') return (res, xmlCtx, section)
def _readSkillBasics(xmlCtx, section, subsectionName): section = _xml.getSubsection(xmlCtx, section, subsectionName) xmlCtx = (xmlCtx, subsectionName) res = {} if IS_CLIENT or IS_WEB: res["userString"] = i18n.makeString(section.readString("userString")) res["description"] = i18n.makeString(section.readString("description")) res["icon"] = _xml.readNonEmptyString(xmlCtx, section, "icon") return (res, xmlCtx, section)
def _readNationConfigSection(xmlCtx, section): res = {} firstNames = {} lastNames = {} icons = {} for kindName in ('normalGroups', 'premiumGroups'): groups = [] res[kindName] = groups totalWeight = 0.0 for sname, subsection in _xml.getChildren(xmlCtx, section, kindName): ctx = (xmlCtx, kindName + '/' + sname) group = { 'notInShop': subsection.readBool('notInShop', False), 'isFemales': 'female' == _xml.readNonEmptyString(ctx, subsection, 'sex'), 'firstNames': _readIDs((ctx, 'firstNames'), _xml.getChildren(ctx, subsection, 'firstNames'), firstNames, _parseName), 'lastNames': _readIDs((ctx, 'lastNames'), _xml.getChildren(ctx, subsection, 'lastNames'), lastNames, _parseName), 'icons': _readIDs((ctx, 'icons'), _xml.getChildren(ctx, subsection, 'icons'), icons, _parseIcon) } group['firstNamesList'] = list(group['firstNames']) group['lastNamesList'] = list(group['lastNames']) group['iconsList'] = list(group['icons']) weight = _xml.readNonNegativeFloat(ctx, subsection, 'weight') totalWeight += weight group['weight'] = weight groups.append(group) totalWeight = max(0.001, totalWeight) for group in groups: group['weight'] /= totalWeight ranks, rankIDsByNames = _readRanks( (xmlCtx, 'ranks'), _xml.getChildren(xmlCtx, section, 'ranks')) res['roleRanks'] = _readRoleRanks( (xmlCtx, 'roleRanks'), _xml.getSubsection(xmlCtx, section, 'roleRanks'), rankIDsByNames) if IS_CLIENT or IS_WEB: res['firstNames'] = firstNames res['lastNames'] = lastNames res['icons'] = icons res['ranks'] = ranks else: res['firstNames'] = frozenset(firstNames) res['lastNames'] = frozenset(lastNames) res['icons'] = frozenset(icons) return res
def _readInvokeGuiCmdSection(xmlCtx, section, _, conditions): commandID = parseID(xmlCtx, section, 'Specify a command ID') argOverrides = {} argsSection = _xml.getSubsection(xmlCtx, section, 'args', throwIfMissing=False) if argsSection is not None: for _, subSec in argsSection.items(): arg = resource_helper.readItem(xmlCtx, subSec, 'arg') argOverrides[arg.name] = arg.value return effects.InvokeGuiCommand(commandID, argOverrides, conditions=conditions)
def readQuestAwardWindowSection(xmlCtx, section, _, windowID, windowType, content): bSec = _xml.getSubsection(xmlCtx, section, 'buttons') content['nextID'] = _xml.readString(xmlCtx, bSec, 'next') content['closeID'] = _xml.readString(xmlCtx, bSec, 'close') content['description'] = translation(section.readString('description')) content['header'] = translation(section.readString('header')) content['bgImage'] = section.readString('image') varRef = None if 'var-ref' in section.keys(): varRef = _xml.readString(xmlCtx, section, 'var-ref') return chapter.PopUp(windowID, windowType, content, varRef, forcedQuery=True)
def _parseGlobalRuntimeEffects(self, xmlCtx, section, flags, chapter): subSec = _xml.getSubsection(xmlCtx, section, 'global-runtime-effects', False) if subSec is not None: priorities = (('pre-scene', False), ('post-scene', True)) for tagName, isPostScene in priorities: for _, effectSec in _xml.getChildren(xmlCtx, subSec, tagName, False): effect = sub_parsers._parseEffect(xmlCtx, effectSec, flags) if effect is not None: chapter.addGlobalEffect(effect, isPostScene) return
def _parseChapter(self, bonuses, descriptor, subSection, xmlCtx): sharedTriggers = subSection.readString('shared-triggers') sharedEntities = subSection.readString('shared-entities') sharedVars = subSection.readString('shared-vars') questConditions = readQuestConditions(subSection) image = subSection.readString('image') unlockChapter = subSection.readString('unlock-chapter') progressSec = _xml.getSubsection(xmlCtx, subSection, 'progress-condition') progressCondition = ProgressCondition(progressSec.readString('progressID'), sub_parsers.readValues(progressSec)) isHidden = subSection.readBool('isHidden') descriptor.addChapter(QuestChapter(questConditions, image, unlockChapter, progressCondition, sharedTriggers, sharedEntities, sharedVars, isHidden, *self._getCommonChapterValues(bonuses, subSection, xmlCtx)))
def initHitTesters(self, dataSection): if dataSection.has_key(self.CRASHED_MODEL_TAG): self.__hitTesters[ModelStatus.CRASHED] = self.__createHitTester( dataSection, self.CRASHED_MODEL_TAG) normalModelSection = dataSection if dataSection.has_key(self.NORMAL_MODEL_TAG): normalModelSection = _xml.getSubsection(None, dataSection, self.NORMAL_MODEL_TAG) modelHitTester = self.__createHitTester(normalModelSection) self.__hitTesters[ModelStatus.NORMAL] = modelHitTester return
def _readCheckpointSection(xmlCtx, section, flags): checkpointID = sub_parsers.parseID(xmlCtx, section, 'missing checkpoint ID') checkpointConditions = sub_parsers.readConditions( xmlCtx, _xml.getSubsection(xmlCtx, section, 'condition'), flags) checkpointEffects = [ effect for effect in ( sub_parsers._parseEffect(xmlCtx, effectSec, flags) for _, effectSec in _xml.getChildren(xmlCtx, section, 'effects')) if effect is not None ] return Checkpoint(checkpointID, checkpointConditions, checkpointEffects)
def _readFinalWindowSection(xmlCtx, section, _, windowID, windowType, content): bSec = _xml.getSubsection(xmlCtx, section, 'buttons') content['restartID'] = _xml.readString(xmlCtx, bSec, 'restart') content['showVideoID'] = _xml.readString(xmlCtx, bSec, 'show-video') content['imageUrl'] = section.readString('image') hintsSec = _xml.getSubsection(xmlCtx, section, 'battle-hints') hints = [] for typeName, hintSec in hintsSec.items(): if len(hintSec.keys()): data = {'type': typeName} for key, subSec in hintSec.items(): data[key] = translation(subSec.asString) hints.append(data) else: hints.append({'type': typeName, 'label': translation(hintSec.asString)}) content['battleHints'] = hints content['restartHint'] = translation(_xml.readString(xmlCtx, section, 'restart-hint')) return chapter.PopUp(windowID, windowType, content, _xml.readString(xmlCtx, section, 'var-ref'))
def _parseDialog(xmlCtx, section, flags): dialogID = parseID(xmlCtx, section, 'Specify a dialog ID') dialogType = _xml.readString(xmlCtx, section, 'type') bSec = _xml.getSubsection(xmlCtx, section, 'buttons') submitID = bSec.readString('submit', '') cancelID = bSec.readString('cancel', '') customID = bSec.readString('custom', '') content = {'type': dialogType, 'dialogID': dialogID, 'submitID': submitID, 'cancelID': cancelID, 'customID': customID, 'title': translation(_xml.readStringOrNone(xmlCtx, section, 'title') or ''), 'message': translation(_xml.readStringOrNone(xmlCtx, section, 'text') or ''), 'imageUrl': _xml.readStringOrNone(xmlCtx, section, 'image') or ''} parser = _DIALOG_SUB_PARERS.get(dialogType) if parser is not None: dialog = parser(xmlCtx, section, flags, dialogID, dialogType, content) else: dialog = tutorial_chapter.PopUp(dialogID, dialogType, content) dialog.setActions(parseActions(xmlCtx, _xml.getSubsection(xmlCtx, section, 'actions'), flags)) return dialog
def _readSequenceItem(ctx, sec, fields): messageContent = {'data': {}} if fields: subSec = _xml.getSubsection(ctx, sec, 'data') for field in fields: _fillValue(messageContent['data'], ctx, subSec, field, _xml.readStringOrNone, default='') return messageContent
def _parseDialog(xmlCtx, section, flags): dialogID = parseID(xmlCtx, section, 'Specify a dialog ID') dialogType = _xml.readString(xmlCtx, section, 'type') bSec = _xml.getSubsection(xmlCtx, section, 'buttons') submitID = bSec.readString('submit', '') cancelID = bSec.readString('cancel', '') if not len(submitID) and not len(cancelID): _xml.raiseWrongXml(xmlCtx, '', 'Tag submit or cancel must be specified.') content = {'type': dialogType, 'dialogID': dialogID, 'submitID': submitID, 'cancelID': cancelID, 'title': translation(_xml.readString(xmlCtx, section, 'title')), 'message': translation(_xml.readString(xmlCtx, section, 'text')), 'imageUrl': section.readString('image')} parser = _DIALOG_SUB_PARERS.get(dialogType) if parser is not None: dialog = parser(xmlCtx, section, flags, dialogID, dialogType, content) else: dialog = chapter.PopUp(dialogID, dialogType, content) dialog.setActions(parseActions(xmlCtx, _xml.getSubsection(xmlCtx, section, 'actions'), flags)) return dialog
def __readControlsSounds(self, xmlCtx): controlsSection = _xml.getSubsection(xmlCtx, xmlCtx, self.CONTROLS) self.__default = doc_loaders.readDict(xmlCtx, controlsSection, self.CONTROLS_DEFAULT) controlsOverridesSection = _xml.getSubsection(xmlCtx, controlsSection, self.CONTROLS_OVERRIDES) for name in controlsOverridesSection.keys(): self.__overrides[name] = doc_loaders.readDict( xmlCtx, controlsOverridesSection, name) for schemaName, schemaSection in _xml.getChildren( xmlCtx, controlsSection, self.CONTROLS_SCHEMAS): self.__schemas[schemaName] = doc_loaders.readDict( xmlCtx, schemaSection, self.SCHEMA_SOUNDS) for groupName in _xml.getSubsection( xmlCtx, schemaSection, self.SCHEMA_GROUPS).asString.split(): if groupName in self.__groups: LOG_WARNING( 'Group has already been read. Will be overriden', groupName, schemaName) self.__groups[groupName] = schemaName
def _readSkinItem(pricesCache, cache, xmlCtx, section, storage): skinID = _xml.readInt(xmlCtx, section, 'id', 1) if skinID in storage: _xml.raiseWrongXml(xmlCtx, 'id', "duplicate id '%s'" % skinID) priceGroup = section.readString('priceGroup') tags = _readGroupTags((xmlCtx, 'tags'), section, 'tags') firstNameID = _xml.readStringOrEmpty(xmlCtx, section, 'firstName') lastNameID = _xml.readNonEmptyString(xmlCtx, section, 'lastName') description = _xml.readNonEmptyString(xmlCtx, section, 'description') iconID = _xml.readNonEmptyString(xmlCtx, section, 'icon') rarity = _xml.readInt(xmlCtx, section, 'rarity', 1) maxCount = _xml.readInt(xmlCtx, section, 'maxCount') soundSetID = section.readString('soundSet', crew_skins_constants.NO_CREW_SKIN_SOUND_SET) historical = _xml.readBool(xmlCtx, section, 'historical', False) realmsStr = section.readString('realms', '') realms = realmsStr.split() unexpectedRealms = set(realms) - REGIONAL_REALMS if unexpectedRealms: _xml.raiseWrongXml(xmlCtx, 'realms', "unknown realms '%s'" % unexpectedRealms) crewSkinItem = cc.CrewSkin(skinID, priceGroup, firstNameID, lastNameID, iconID, description, rarity, maxCount, tags, historical, soundSetID, realms) if section.has_key('filters'): filterSection = _xml.getSubsection(xmlCtx, section, 'filters') if filterSection.has_key('role'): roleName = filterSection.readString('role') if roleName not in skills_constants.ROLES: _xml.raiseWrongXml(xmlCtx, 'role', "unknown tankmanRole '%s'" % roleName) crewSkinItem.roleID = roleName if roleName else None if filterSection.has_key('nation'): nation = filterSection.readString('nation', '') if nation and nation not in nations.NAMES: _xml.raiseWrongXml(xmlCtx, 'nation', "unknown nation '%s'" % nation) crewSkinItem.nation = nation if nation else None if filterSection.has_key('sex'): sex = filterSection.readString('sex', '') if sex not in crew_skins_constants.TANKMAN_SEX.AVAILABLE: _xml.raiseWrongXml(xmlCtx, 'sex', "unknown tankman sex '%s'" % sex) crewSkinItem.sex = sex storage[skinID] = crewSkinItem groupsDict = cache.priceGroups itemToGroup = cache.itemToPriceGroup if crewSkinItem.priceGroup: if crewSkinItem.priceGroup not in cache.priceGroupNames: _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'unknown price group %s for item %s' % (crewSkinItem.priceGroup, crewSkinItem.id)) priceGroupId = cache.priceGroupNames[crewSkinItem.priceGroup] crewSkinItem.priceGroupTags = groupsDict[priceGroupId].tags itemToGroup[crewSkinItem.compactDescr] = groupsDict[priceGroupId].compactDescr itemNotInShop = section.readBool('notInShop', False) _copyPriceForItem(pricesCache, groupsDict[priceGroupId].compactDescr, crewSkinItem.compactDescr, itemNotInShop) else: _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'no price for item %s' % crewSkinItem.id) return
def _readMessageDialogSequenceItem(xmlCtx, section): messageContent = {} nations = _xml.getChildren(xmlCtx, section, 'nations', False) if nations: nationsDataDict = messageContent['nations_data'] = {} for _, subSec in nations: nationID, data = _readMessageDialogData(xmlCtx, subSec, True) nationsDataDict[nationID] = data else: subSec = _xml.getSubsection(xmlCtx, section, 'data') _, messageContent['data'] = _readMessageDialogData( xmlCtx, subSec, False) return messageContent
def _readQueueDialogSection(xmlCtx, section, _, dialogID, dialogType, content): content['avgTimeTextFormat'] = translation(_xml.readString(xmlCtx, section, 'avg-time-text')) subSec = _xml.getSubsection(xmlCtx, section, 'player-time-text') content['playerTimeTextStart'] = translation(_xml.readString(xmlCtx, subSec, 'start')) content['playerTimeTextEnd'] = translation(_xml.readString(xmlCtx, subSec, 'end')) pointcuts = [] for _, subSec in _xml.getChildren(xmlCtx, section, 'time-pointcuts'): value = subSec.asFloat if value > 0: pointcuts.append(subSec.asInt) if len(pointcuts) < 2: _xml.raiseWrongSection(xmlCtx, 'time-pointcuts: should be the minimum and maximum value') content['timePointcuts'] = sorted(pointcuts) return chapter.PopUp(dialogID, dialogType, content, _xml.readString(xmlCtx, section, 'var-ref'))
def _readGuiItemPropertiesEffectSection(xmlCtx, section, _, conditions, fixedProp=None): itemID = parseID(xmlCtx, section, 'Specify a item ID') props = {} if fixedProp is None: for _, subSec in _xml.getChildren(xmlCtx, section, 'properties'): propType, propSec = subSec.items()[0] props[subSec.asString] = readVarValue(propType, propSec) else: propName, propType = fixedProp if propType is not None: props[propName] = readVarValue(propType, _xml.getSubsection(xmlCtx, section, 'val')) else: props[propName] = None return effects.SetGuiItemProperties(itemID, props, conditions=conditions)
def _readRanks(xmlCtx, subsections): ranks = [] rankIDsByNames = {} for sname, subsection in subsections: if rankIDsByNames.has_key(sname): _xml.raiseWrong(xmlCtx, sname, 'is not unique') ctx = (xmlCtx, sname) rankIDsByNames[sname] = len(ranks) if not (IS_CLIENT or IS_WEB): ranks.append(None) else: ranks.append({'userString': i18n.makeString(_xml.readNonEmptyString(ctx, subsection, 'userString')), 'icon': _parseIcon((ctx, 'icon'), _xml.getSubsection(ctx, subsection, 'icon'))}) return (ranks, rankIDsByNames)
def _readCustomizationSlotIdRanges(): filePath = _CUSTOMIZATION_CONSTANTS_PATH section = ResMgr.openSection(filePath) if section is None: _xml.raiseWrongXml(None, filePath, 'can not open or read') xmlCtx = (None, filePath) slots = _xml.getSubsection(xmlCtx, section, 'slot_id_ranges') for partName, part in _xml.getChildren(xmlCtx, section, 'slot_id_ranges'): partIds = __customizationSlotIdRanges[partName] for itemName, item in _xml.getChildren(xmlCtx, slots, partName): range_min = _xml.readInt(xmlCtx, item, 'range_min') range_max = _xml.readInt(xmlCtx, item, 'range_max') partIds[itemName] = (range_min, range_max) return
def _readNationConfigSection(xmlCtx, section): res = {} firstNames = {} lastNames = {} icons = {} for kindName in ("normalGroups", "premiumGroups"): groups = [] res[kindName] = groups totalWeight = 0.0 for sname, subsection in _xml.getChildren(xmlCtx, section, kindName): ctx = (xmlCtx, kindName + "/" + sname) group = { "notInShop": subsection.readBool("notInShop", False), "isFemales": "female" == _xml.readNonEmptyString(ctx, subsection, "sex"), "firstNames": _readIDs( (ctx, "firstNames"), _xml.getChildren(ctx, subsection, "firstNames"), firstNames, _parseName ), "lastNames": _readIDs( (ctx, "lastNames"), _xml.getChildren(ctx, subsection, "lastNames"), lastNames, _parseName ), "icons": _readIDs((ctx, "icons"), _xml.getChildren(ctx, subsection, "icons"), icons, _parseIcon), } group["firstNamesList"] = list(group["firstNames"]) group["lastNamesList"] = list(group["lastNames"]) group["iconsList"] = list(group["icons"]) weight = _xml.readNonNegativeFloat(ctx, subsection, "weight") totalWeight += weight group["weight"] = weight groups.append(group) totalWeight = max(0.001, totalWeight) for group in groups: group["weight"] /= totalWeight ranks, rankIDsByNames = _readRanks((xmlCtx, "ranks"), _xml.getChildren(xmlCtx, section, "ranks")) res["roleRanks"] = _readRoleRanks( (xmlCtx, "roleRanks"), _xml.getSubsection(xmlCtx, section, "roleRanks"), rankIDsByNames ) if IS_CLIENT or IS_WEB: res["firstNames"] = firstNames res["lastNames"] = lastNames res["icons"] = icons res["ranks"] = ranks else: res["firstNames"] = frozenset(firstNames) res["lastNames"] = frozenset(lastNames) res["icons"] = frozenset(icons) return res
def _readRanks(xmlCtx, subsections): ranks = tankmen_components.RanksSet() for sname, subsection in subsections: if ranks.getRankByName(sname) is not None: _xml.raiseWrongXml(xmlCtx, sname, 'is not unique') sname = intern(sname) ctx = (xmlCtx, sname) if IS_CLIENT or IS_WEB: i18n = shared_components.I18nString(_xml.readNonEmptyString(ctx, subsection, 'userString')) icon = _parseIcon((ctx, 'icon'), _xml.getSubsection(ctx, subsection, 'icon')) rank = tankmen_components.Rank(sname, i18n=i18n, icon=icon) else: rank = tankmen_components.Rank(sname) ranks.add(rank) return ranks
def _readSkillsConfig(xmlPath): xmlCtx = (None, xmlPath) section = ResMgr.openSection(xmlPath) if section is None: _xml.raiseWrongXml(None, xmlPath, 'can not open or read') res = {} for skillName in ROLES: res[skillName] = _readRole(xmlCtx, section, 'roles/' + skillName) section = _xml.getSubsection(xmlCtx, section, 'skills') xmlCtx = (xmlCtx, 'skills') for skillName in ACTIVE_SKILLS: res[skillName] = _g_skillConfigReaders[skillName](xmlCtx, section, skillName) section = None ResMgr.purge(xmlPath, True) return res
def _readDynamicGuiItemSection(xmlCtx, section, itemFlags, itemID, props, conditions): item = chapter.DynamicGuiItemRef(itemID, props, conditions=conditions) if 'find-criteria' in section.keys(): subSec = _xml.getSubsection(xmlCtx, section, 'find-criteria') parentID = _xml.readString(xmlCtx, subSec, 'parent-ref') varPath = _xml.readString(xmlCtx, subSec, 'var-path') varRef = _xml.readString(xmlCtx, subSec, 'var-ref') item.setFindCriteria([parentID, varPath, varRef]) for _, effectSec in _xml.getChildren(xmlCtx, section, 'not-on-scene-effects'): effect = _parseEffect(xmlCtx, effectSec, itemFlags) if effect is not None: item.addNotOnSceneEffect(effect) for _, effectSec in _xml.getChildren(xmlCtx, section, 'on-scene-effects'): effect = _parseEffect(xmlCtx, effectSec, itemFlags) if effect is not None: item.addOnSceneEffect(effect) return item
def _readItemTypes(): xmlPath = ITEM_DEFS_PATH + 'item_types.xml' section = ResMgr.openSection(xmlPath) if section is None: _xml.raiseWrongXml(None, xmlPath, 'can not open or read') xmlCtx = (None, xmlPath) res = {} for index, name in enumerate(ITEM_TYPE_NAMES): if name == 'reserved': continue itemSection = _xml.getSubsection(xmlCtx, section, name) ctx = (xmlCtx, name) tagNames = [] tags = {} if itemSection.has_key('tags'): for tagSection in itemSection['tags'].values(): tagName = intern(tagSection.name) if tags.has_key(tagName): _xml.raiseWrongXml(xmlCtx, 'tags' + tagName, 'tag name is not unique') tagDescr = {'name': tagName, 'index': len(tagNames)} if IS_CLIENT: tagDescr['userString'] = i18n.makeString(tagSection.readString('userString')) tagDescr['description'] = i18n.makeString(tagSection.readString('description')) tags[tagName] = tagDescr tagNames.append(tagName) descr = {'index': index, 'tags': tags, 'tagNames': tuple(tagNames)} if IS_CLIENT: descr['userString'] = i18n.makeString(itemSection.readString('userString')) descr['description'] = i18n.makeString(itemSection.readString('description')) res[name] = descr section = None itemSection = None tagSection = None ResMgr.purge(xmlPath, True) return res
def _readNationConfigSection(xmlCtx, section): res = {} firstNames = {} lastNames = {} icons = {} for kindName in ('normalGroups', 'premiumGroups'): groups = [] res[kindName] = groups totalWeight = 0.0 for sname, subsection in _xml.getChildren(xmlCtx, section, kindName): ctx = (xmlCtx, kindName + '/' + sname) group = {'notInShop': subsection.readBool('notInShop', False), 'isFemales': 'female' == _xml.readNonEmptyString(ctx, subsection, 'sex'), 'firstNames': _readIDs((ctx, 'firstNames'), _xml.getChildren(ctx, subsection, 'firstNames'), firstNames, _parseName), 'lastNames': _readIDs((ctx, 'lastNames'), _xml.getChildren(ctx, subsection, 'lastNames'), lastNames, _parseName), 'icons': _readIDs((ctx, 'icons'), _xml.getChildren(ctx, subsection, 'icons'), icons, _parseIcon)} group['firstNamesList'] = list(group['firstNames']) group['lastNamesList'] = list(group['lastNames']) group['iconsList'] = list(group['icons']) weight = _xml.readNonNegativeFloat(ctx, subsection, 'weight') totalWeight += weight group['weight'] = weight groups.append(group) totalWeight = max(0.001, totalWeight) for group in groups: group['weight'] /= totalWeight ranks, rankIDsByNames = _readRanks((xmlCtx, 'ranks'), _xml.getChildren(xmlCtx, section, 'ranks')) res['roleRanks'] = _readRoleRanks((xmlCtx, 'roleRanks'), _xml.getSubsection(xmlCtx, section, 'roleRanks'), rankIDsByNames) if IS_CLIENT or IS_WEB: res['firstNames'] = firstNames res['lastNames'] = lastNames res['icons'] = icons res['ranks'] = ranks else: res['firstNames'] = frozenset(firstNames) res['lastNames'] = frozenset(lastNames) res['icons'] = frozenset(icons) return res
def _readItemTypes(): xmlPath = ITEM_DEFS_PATH + "item_types.xml" section = ResMgr.openSection(xmlPath) if section is None: _xml.raiseWrongXml(None, xmlPath, "can not open or read") xmlCtx = (None, xmlPath) res = {} for index, name in enumerate(ITEM_TYPE_NAMES): if name.startswith("_"): continue itemSection = _xml.getSubsection(xmlCtx, section, name) ctx = (xmlCtx, name) tagNames = [] tags = {} if itemSection.has_key("tags"): for tagSection in itemSection["tags"].values(): tagName = intern(tagSection.name) if tags.has_key(tagName): _xml.raiseWrongXml(xmlCtx, "tags" + tagName, "tag name is not unique") tagDescr = {"name": tagName, "index": len(tagNames)} if IS_CLIENT: tagDescr["userString"] = i18n.makeString(tagSection.readString("userString")) tagDescr["description"] = i18n.makeString(tagSection.readString("description")) tags[tagName] = tagDescr tagNames.append(tagName) descr = {"index": index, "tags": tags, "tagNames": tuple(tagNames)} if IS_CLIENT: descr["userString"] = i18n.makeString(itemSection.readString("userString")) descr["description"] = i18n.makeString(itemSection.readString("description")) res[name] = descr section = None itemSection = None tagSection = None ResMgr.purge(xmlPath, True) return res
def __readNation(self, shared, nation, clearCache = False): xmlPath = NATION_TREE_REL_FILE_PATH % nation if clearCache: ResMgr.purge(xmlPath) section = ResMgr.openSection(xmlPath) if section is None: LOG_ERROR('can not open or read nation tree: ', nation, xmlPath) return {} else: xmlCtx = (None, xmlPath) settingsName = _xml.readString(xmlCtx, section, 'settings') if settingsName not in shared['settings']: LOG_ERROR('not found settings (<settings> tag): ', settingsName, xmlPath) return {} precessed = _xml.getSubsection(xmlCtx, section, 'grid') gridName = precessed.asString if gridName not in shared['grids']: LOG_ERROR('not found grid (<grid> tag): ', gridName, xmlPath) return {} xPath = '{0:>s}/grid'.format(xmlPath) xmlCtx = (None, xPath) grid = shared['grids'][gridName] settings = shared['settings'][settingsName] rows = _xml.readInt(xmlCtx, precessed, 'rows') columns = _xml.readInt(xmlCtx, precessed, 'columns') self.__displaySettings[nations.INDICES[nation]] = settings nationIndex = self.__availableNations.index(nation) hasRoot = settings['hasRoot'] if hasRoot: coords = self.__makeGridCoordsWithRoot(grid, nationIndex, rows, columns) else: coords = self.__makeGridCoordsWoRoot(grid, rows, columns) getIDsByName = vehicles.g_list.getIDsByName makeIntCDByID = vehicles.makeIntCompactDescrByID getVehicle = vehicles.g_cache.vehicle precessed = _xml.getChildren(xmlCtx, section, 'nodes') displayInfo = {} for name, nodeSection in precessed: xPath = '{0:>s}/nodes/{1:>s}'.format(xmlPath, name) xmlCtx = (None, xPath) uName = '{0:>s}:{1:>s}'.format(nation, name) try: nationID, vTypeID = getIDsByName(uName) except Exception: raise _ConfigError(xmlCtx, 'Unknown vehicle type name {0:>s}'.format(uName)) nodeCD = makeIntCDByID(_VEHICLE_TYPE_NAME, nationID, vTypeID) vType = getVehicle(nationID, vTypeID) nextLevel = filter(lambda data: getTypeOfCompactDescr(data[1][1]) == _VEHICLE, enumerate(vType.unlocksDescrs)) for unlockDescr in vType.unlocksDescrs: self.__unlockPrices[unlockDescr[1]][vType.compactDescr] = unlockDescr[0] for idx, data in nextLevel: xpCost = data[0] nextCD = data[1] required = data[2:] self.__nextLevels[nodeCD][nextCD] = (idx, xpCost, set(required)) self.__topLevels[nextCD].add(nodeCD) for itemCD in required: self.__topItems[itemCD].add(nodeCD) row = _xml.readInt(xmlCtx, nodeSection, 'row') column = _xml.readInt(xmlCtx, nodeSection, 'column') if hasRoot and row > 1 and column is 1: raise _ConfigError(xmlCtx, 'In first column must be one node - root node, {0:>s} '.format(uName)) elif row > rows or column > columns: raise _ConfigError(xmlCtx, 'Invalid row or column index: {0:>s}, {1:d}, {2:d}'.format(uName, row, column)) lines = self.__readNodeLines(nodeCD, nation, xmlCtx, nodeSection, shared) displayInfo[nodeCD] = {'row': row, 'column': column, 'position': coords[column - 1][row - 1], 'lines': lines} return displayInfo
def _readWorldMarkerSection(xmlCtx, section): subSec = _xml.getSubsection(xmlCtx, section, 'world') return {'shape': _xml.readString(xmlCtx, subSec, 'shape'), 'min-distance': _xml.readFloat(xmlCtx, subSec, 'min-distance'), 'max-distance': _xml.readFloat(xmlCtx, subSec, 'max-distance'), 'offset': _xml.readVector3(xmlCtx, subSec, 'offset')}
def _readAreaMarkerSection(xmlCtx, section, markerID, varRef): subSec = _xml.getSubsection(xmlCtx, section, 'minimap') minimapData = {'entry-name': _xml.readString(xmlCtx, subSec, 'entry-name'), 'entry-type': _xml.readString(xmlCtx, subSec, 'entry-type')} return chapter.AreaMarker(markerID, varRef, _readModelMarkerSection(xmlCtx, section), _readModelMarkerSection(xmlCtx, section, name='ground'), _readWorldMarkerSection(xmlCtx, section), minimapData, createInd=section.readBool('create-indicator', True))
def _readTeleportMarkerSection(xmlCtx, section, markerID, varRef): subSec = _xml.getSubsection(xmlCtx, section, 'world') worldData = {'offset': _xml.readVector3(xmlCtx, subSec, 'offset'), 'yaw': _xml.readFloat(xmlCtx, subSec, 'yaw')} return chapter.AreaMarker(markerID, varRef, {}, {}, worldData, {})
def __readShared(self, clearCache = False): if clearCache: ResMgr.purge(TREE_SHARED_REL_FILE_PATH) shared = {'settings': {}, 'grids': {}, 'default': {}, 'lines': {}} section = ResMgr.openSection(TREE_SHARED_REL_FILE_PATH) if section is None: _xml.raiseWrongXml(None, TREE_SHARED_REL_FILE_PATH, 'can not open or read') xmlCtx = (None, TREE_SHARED_REL_FILE_PATH) precessed = _xml.getChildren(xmlCtx, section, 'settings-set') for name, settingsSec in precessed: settingsName = settingsSec.asString xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, settingsName) xmlCtx = (None, xPath) settings = {} for _, settingSec in settingsSec.items(): name = _xml.readString(xmlCtx, settingSec, 'name') if name not in DISPLAY_SETTINGS: LOG_ERROR('Setting is invalid', name) continue reader = DISPLAY_SETTINGS[name] value = getattr(_xml, reader)(xmlCtx, settingSec, 'value') settings[name] = value for name in DISPLAY_SETTINGS.iterkeys(): if name not in settings: raise _ConfigError(xmlCtx, 'Setting not found') shared['settings'][settingsName] = settings precessed = _xml.getChildren(xmlCtx, section, 'grids') for name, gridSection in precessed: gridName = gridSection.asString xPath = '{0:>s}/{1:>s}/{2:>s}'.format(TREE_SHARED_REL_FILE_PATH, name, gridName) gridCtx = (None, xPath) subSec = _xml.getSubsection(xmlCtx, gridSection, 'root') xmlCtx = (None, '{0:>s}/root'.format(xPath)) rootPos = {'start': _xml.readVector2(xmlCtx, subSec, 'start').tuple(), 'step': _xml.readInt(xmlCtx, subSec, 'step')} subSec = _xml.getSubsection(gridCtx, gridSection, 'vertical') xmlCtx = (None, '{0:>s}/vertical'.format(xPath)) vertical = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) subSec = _xml.getSubsection(gridCtx, gridSection, 'horizontal') xmlCtx = (None, '{0:>s}/horizontal'.format(xPath)) horizontal = (_xml.readInt(xmlCtx, subSec, 'start'), _xml.readInt(xmlCtx, subSec, 'step')) shared['grids'][gridName] = {'root': rootPos, 'vertical': vertical, 'horizontal': horizontal} if self.__availableNations is None: self.__availableNations = self.__readAvailableNations((None, TREE_SHARED_REL_FILE_PATH), section) precessed = _xml.getChildren(xmlCtx, section, 'lines') lines = shared['lines'] for name, sub in precessed: xPath = '{0:>s}/{1:>s}'.format(TREE_SHARED_REL_FILE_PATH, name) xmlCtx = (None, xPath) pinsSec = _xml.getChildren(xmlCtx, sub, 'inPin') inPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'outPin') outPins = dict(((pName, pSec.asVector2.tuple()) for pName, pSec in pinsSec)) pinsSec = _xml.getChildren(xmlCtx, sub, 'viaPin') viaPins = defaultdict(_makeDict) for outPin, setSec in pinsSec: for inPin, pSec in setSec.items(): viaPins[outPin][inPin] = map(lambda section: section[1].asVector2.tuple(), pSec.items()) defSec = sub['default'] default = {} if defSec is not None: xmlCtx = (None, '{0:>s}/default'.format(xPath)) default = {'outPin': _xml.readString(xmlCtx, defSec, 'outPin'), 'inPin': _xml.readString(xmlCtx, defSec, 'inPin')} lines[name] = {'inPins': inPins, 'outPins': outPins, 'viaPins': viaPins, 'default': default} defSec = _xml.getSubsection(xmlCtx, section, 'default-line') xPath = '{0:>s}/default-line'.format(TREE_SHARED_REL_FILE_PATH) xmlCtx = (None, xPath) name = _xml.readString(xmlCtx, defSec, 'line') outPin = _xml.readString(xmlCtx, defSec, 'outPin') inPin = _xml.readString(xmlCtx, defSec, 'inPin') self.__getLineInfo(xmlCtx, name, 0, outPin, inPin, lines) shared['default'] = {'line': name, 'inPin': inPin, 'outPin': outPin} return shared
def readHintSection(xmlCtx, section, flags): sectionInfo = sub_parsers.parseHint(xmlCtx, section) hint = chapter.ChainHint(sectionInfo['hintID'], sectionInfo['itemID'], sectionInfo['text'], sectionInfo['hasBox'], sectionInfo['arrow'], sectionInfo['padding']) hint.setActions(sub_parsers.parseActions(xmlCtx, _xml.getSubsection(xmlCtx, section, 'actions'), flags)) return hint
def _readBonusSection(xmlCtx, section, content): bonusSec = _xml.getSubsection(xmlCtx, section, 'bonus') content['bonusValue'] = translation(_xml.readString(xmlCtx, bonusSec, 'value')) content['bonusLabel'] = translation(_xml.readString(xmlCtx, bonusSec, 'label')) content['bonusImageUrl'] = _xml.readString(xmlCtx, bonusSec, 'background') return content