def _readProgressSection(xmlCtx, section, _): progressID = sub_parsers.parseID(xmlCtx, section, 'Specify a progress ID') conditions = [] for _, subSec in _xml.getChildren(xmlCtx, section, 'steps'): conditions.append(chapter.HasIDConditions(sub_parsers.parseID(xmlCtx, subSec, 'Specify a condition ID'), sub_parsers.readConditions(xmlCtx, subSec, []))) return chapter.ChapterProgress(progressID, conditions)
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 _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 _readChapterTaskSection(xmlCtx, section, _): taskID = sub_parsers.parseID(xmlCtx, section, 'Specify a task ID') text = translation(_xml.readString(xmlCtx, section, 'text')) flagID = None if 'flag' in section.keys(): flagID = _xml.readString(xmlCtx, section, 'flag') return chapter.ChapterTask(taskID, text, flagID=flagID)
def _parseScenes(self, xmlCtx, section, chapter, flags, itemFlags, afterBattle, initial): for _, sceneSec in _xml.getChildren(xmlCtx, section, 'scenes'): sceneID = sub_parsers.parseID(xmlCtx, sceneSec, 'Specify a unique name for the scene') scene = Scene(entityID=sceneID) self._parseScene(xmlCtx, sceneSec, scene, flags, itemFlags, afterBattle=afterBattle) self._parseSharedScene(chapter, scene, flags, itemFlags) chapter.addScene(scene)
def _readDispatcherTriggerSection(xmlCtx, section, _, triggerID): triggerIDs = set() for _, subSec in _xml.getChildren(xmlCtx, section, 'includes'): triggerIDs.add( sub_parsers.parseID(xmlCtx, subSec, 'Specify a trigger ID')) return triggers.TriggersDispatcher(triggerID, triggerIDs)
def _readExitQueueEffectSection(xmlCtx, section, flags, conditions): flagID = sub_parsers.parseID(xmlCtx, section, 'Specify a flag ID') if flagID not in flags: flags.append(flagID) return effects.HasTargetEffect(flagID, _EFFECT_TYPE.EXIT_QUEUE, conditions=conditions)
def _readInternalBrowserSection(xmlCtx, section, flags, conditions): flagID = sub_parsers.parseID(xmlCtx, section, 'Specify a flag ID') if flagID not in flags: flags.append(flagID) return effects.HasTargetEffect(flagID, _EFFECT_TYPE.OPEN_INTERNAL_BROWSER, conditions=conditions)
def _readEnterModeEffectSection(xmlCtx, section, flags, conditions): flagID = sub_parsers.parseID(xmlCtx, section, 'Specify a flag ID') if flagID not in flags: flags.append(flagID) return effects.HasTargetEffect(flagID, _EFFECT_TYPE.ENTER_MODE, conditions=conditions)
def _readGreetingSection(xmlCtx, section, _): greetingID = sub_parsers.parseID(xmlCtx, section, 'Specify a greeting ID') title = translation(_xml.readString(xmlCtx, section, 'title')) text = translation(_xml.readString(xmlCtx, section, 'text')) speakID = None if 'speak' in section.keys(): speakID = _xml.readString(xmlCtx, section, 'speak') return chapter.Greeting(greetingID, title, text, speakID=speakID)
def _readGreetingSection(xmlCtx, section, _): greetingID = sub_parsers.parseID(xmlCtx, section, 'Specify a greeting ID') title = translation(_xml.readString(xmlCtx, section, 'title')) text = translation(_xml.readString(xmlCtx, section, 'text')) speakID = None if 'wwspeak' in section.keys(): speakID = _xml.readString(xmlCtx, section, 'wwspeak') return chapter.Greeting(greetingID, title, text, speakID=speakID)
def _readExitSection(xmlCtx, section, _): exitID = sub_parsers.parseID(xmlCtx, section, 'Specify a exit ID') return chapter.Exit(exitID, nextChapter=_xml.readString(xmlCtx, section, 'chapter-id'), nextDelay=_xml.readFloat(xmlCtx, section, 'next-delay'), finishDelay=section.readFloat('finish-delay'), isSpeakOver=section.readBool('is-speak-over'))
def _readImageSection(xmlCtx, section, _): imageID = sub_parsers.parseID(xmlCtx, section, 'Specify a image ID') imageType = _xml.readString(xmlCtx, section, 'type') image = None if imageType in _IMAGE_TYPES: parser = _IMAGE_TYPES[imageType] image = parser(xmlCtx, section, imageID) else: LOG_ERROR('Image is not supported:', imageType) return image
def _readMarkerSection(xmlCtx, section, _): markerID = sub_parsers.parseID(xmlCtx, section, 'Specify a marker ID') type = _xml.readString(xmlCtx, section, 'type') marker = None if type in _MARKER_TYPES: parser = _MARKER_TYPES[type] marker = parser(xmlCtx, section, markerID, _xml.readString(xmlCtx, section, 'var-ref')) else: LOG_ERROR('Marker is not supported:', type) return marker
def _parseVars(self, xmlCtx, section, flags, chapter): gVarIDs = [] for name, subSec in _xml.getChildren(xmlCtx, section, 'vars'): if name == 'var-set': chapter.addVarSet(sub_parsers.parseVarSet(xmlCtx, subSec, flags)) if name == 'var-set-ref': gVarIDs.append(sub_parsers.parseID(xmlCtx, subSec, 'Specify a var ID')) _xml.raiseWrongXml(xmlCtx, name, 'Unknown tag') if gVarIDs: GlobalRefParser().parse(chapter, varIDs=gVarIDs, flags=flags)
def parse(self): section = ResMgr.openSection(BONUSES_REFS_FILE_PATH) if section is None: _xml.raiseWrongXml(None, BONUSES_REFS_FILE_PATH, 'can not open or read') xmlCtx = (None, BONUSES_REFS_FILE_PATH) result = {} for _, subSec in _xml.getChildren(xmlCtx, section, 'bonuses'): bonusID = sub_parsers.parseID(xmlCtx, subSec, 'Specify a bonus ID') result[bonusID] = Bonus(subSec.readInt('id', -1), subSec.readString('message'), sub_parsers.readValues(subSec)) return result
def _readRequestExclusiveHintEffectSection(xmlCtx, section, _, conditions): componentID = sub_parsers.parseID(xmlCtx, section, 'missing hint target component ID') soundID = _xml.readStringOrNone(xmlCtx, section, 'sound') if soundID is None: soundID = 'bc_new_ui_element_button' if conditions is None: conditions = Conditions() conditions.insert(0, ComponentOnSceneCondition(componentID)) return bc_effects.RequestExclusiveHintEffect(componentID, soundID, conditions=conditions)
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 _parseBonus(self, xmlCtx, section, bonuses): tags = section.keys() if 'bonus' in tags: subSection = section['bonus'] return sub_parsers.parseBonus(xmlCtx, subSection) if 'bonus-ref' in tags: bonusID = sub_parsers.parseID(xmlCtx, section['bonus-ref'], 'Specify a bonus ID') if bonusID in bonuses: return bonuses[bonusID] _xml.raiseWrongXml(xmlCtx, section.name, 'Bonus reference {0} is not found'.format(bonusID)) else: _xml.raiseWrongXml(xmlCtx, section.name, 'Bonuses is not found')
def parse(self): section = ResMgr.openSection(BONUSES_REFS_FILE_PATH) if section is None: _xml.raiseWrongXml(None, BONUSES_REFS_FILE_PATH, 'can not open or read') xmlCtx = (None, BONUSES_REFS_FILE_PATH) result = {} for _, subSec in _xml.getChildren(xmlCtx, section, 'bonuses'): bonusID = sub_parsers.parseID(xmlCtx, subSec, 'Specify a bonus ID') bonus = sub_parsers.parseBonus(xmlCtx, subSec) result[bonusID] = bonus return result
def _parseVars(self, xmlCtx, section, flags, chapter): gVarIDs = [] for name, subSec in _xml.getChildren(xmlCtx, section, 'vars'): if name == 'var-set': chapter.addVarSet(sub_parsers.parseVarSet(xmlCtx, subSec, flags)) elif name == 'var-set-ref': gVarIDs.append(sub_parsers.parseID(xmlCtx, subSec, 'Specify a var ID')) else: _xml.raiseWrongXml(xmlCtx, name, 'Unknown tag') if gVarIDs: GlobalRefParser().parse(chapter, varIDs=gVarIDs, flags=flags)
def _parseBonus(self, xmlCtx, section, bonuses): tags = section.keys() if 'bonus' in tags: subSection = section['bonus'] return Bonus(subSection.readInt('id', -1), subSection.readString('message'), sub_parsers.readValues(subSection)) if 'bonus-ref' in tags: bonusID = sub_parsers.parseID(xmlCtx, section['bonus-ref'], 'Specify a bonus ID') if bonusID in bonuses: return bonuses[bonusID] _xml.raiseWrongXml(xmlCtx, section.name, 'Bonus reference {0} is not found'.format(bonusID)) else: _xml.raiseWrongXml(xmlCtx, section.name, 'Bonuses is not found')
def _readHintSection(xmlCtx, section, _): hintID = sub_parsers.parseID(xmlCtx, section, 'Specify a hint ID') text = translation(_xml.readString(xmlCtx, section, 'text')) if 'image' in section.keys(): image = chapter.SimpleImagePath(None, _xml.readString(xmlCtx, section, 'image')) elif 'image-ref' in section.keys(): image = _xml.readString(xmlCtx, section, 'image-ref') else: image = chapter.SimpleImagePath() speakID = None if 'speak' in section.keys(): speakID = _xml.readString(xmlCtx, section, 'speak') return chapter.SimpleHint(hintID, text, image, speakID=speakID)
def _readHintSection(xmlCtx, section, _): hintID = sub_parsers.parseID(xmlCtx, section, 'Specify a hint ID') text = translation(_xml.readString(xmlCtx, section, 'text')) if 'image' in section.keys(): image = chapter.SimpleImagePath(None, _xml.readString(xmlCtx, section, 'image')) elif 'image-ref' in section.keys(): image = _xml.readString(xmlCtx, section, 'image-ref') else: image = chapter.SimpleImagePath() speakID = None if 'wwspeak' in section.keys(): speakID = _xml.readString(xmlCtx, section, 'wwspeak') return chapter.SimpleHint(hintID, text, image, speakID=speakID)
def _readLinearCheckpointControllerTriggerSection(xmlCtx, section, _, triggerID): checkpointsSequence = [ sub_parsers.parseID(xmlCtx, subSec, 'missing checkpoint ID in sequence') for _, subSec in _xml.getChildren(xmlCtx, section, 'sequence') ] return sub_parsers.readValidateVarTriggerSection( xmlCtx, section, triggerID, bc_triggers.LinearCheckpointControllerTrigger, checkpointsSequence=checkpointsSequence)
def readTutorialSettingSection(xmlCtx, section, flags): settingID = sub_parsers.parseID(xmlCtx, section, 'Specify a setting ID') settingName = None if 'setting-name' in section.keys(): settingName = _xml.readString(xmlCtx, section, 'setting-name') else: _xml.raiseWrongXml(xmlCtx, section.name, 'Specify a setting name') settingValue = None if 'setting-value' in section.keys(): settingValue = _xml.readBool(xmlCtx, section, 'setting-value') else: _xml.raiseWrongXml(xmlCtx, section.name, 'Specify a setting value') return chapter.TutorialSetting(settingID, settingName, settingValue)
def parse(self, chapter, varIDs = None, flags = None): if varIDs is None: varIDs = [] if flags is None: flags = [] section = ResMgr.openSection(GLOBAL_REFS_FILE_PATH) if section is None: _xml.raiseWrongXml(None, GLOBAL_REFS_FILE_PATH, 'can not open or read') xmlCtx = (None, GLOBAL_REFS_FILE_PATH) if len(varIDs): for _, subSec in _xml.getChildren(xmlCtx, section, 'vars'): varID = sub_parsers.parseID(xmlCtx, subSec, 'Specify a var ID') if varID in varIDs: chapter.addVarSet(sub_parsers.parseVarSet(xmlCtx, subSec, flags))
def parse(self, chapter, varIDs=None, flags=None): if varIDs is None: varIDs = [] if flags is None: flags = [] section = ResMgr.openSection(GLOBAL_REFS_FILE_PATH) if section is None: _xml.raiseWrongXml(None, GLOBAL_REFS_FILE_PATH, 'can not open or read') xmlCtx = (None, GLOBAL_REFS_FILE_PATH) if len(varIDs): for _, subSec in _xml.getChildren(xmlCtx, section, 'vars'): varID = sub_parsers.parseID(xmlCtx, subSec, 'Specify a var ID') if varID in varIDs: chapter.addVarSet( sub_parsers.parseVarSet(xmlCtx, subSec, flags))
def readLoadViewDataSection(xmlCtx, section, flags): settingID = sub_parsers.parseID(xmlCtx, section, 'Specify a setting ID') alias = None if 'alias' in section.keys(): alias = _xml.readString(xmlCtx, section, 'alias') else: _xml.raiseWrongXml(xmlCtx, section.name, 'Specify a setting name') scope = EVENT_BUS_SCOPE.DEFAULT if 'scope' in section.keys(): scope = _xml.readInt(xmlCtx, section, 'scope') else: _xml.raiseWrongXml(xmlCtx, section.name, 'Specify a setting value') ctx = None if 'context' in section.keys(): ctx = readVarValue('asDict', section['context']) return chapter.LoadViewData(settingID, alias, scope, ctx)
def _parseBonus(self, xmlCtx, section, bonuses): tags = section.keys() if 'bonus' in tags: subSection = section['bonus'] return Bonus(subSection.readInt('id', -1), subSection.readString('message'), sub_parsers.readValues(subSection)) if 'bonus-ref' in tags: bonusID = sub_parsers.parseID(xmlCtx, section['bonus-ref'], 'Specify a bonus ID') if bonusID in bonuses: return bonuses[bonusID] _xml.raiseWrongXml( xmlCtx, section.name, 'Bonus reference {0} is not found'.format(bonusID)) else: _xml.raiseWrongXml(xmlCtx, section.name, 'Bonuses is not found')
def readSaveTutorialSettingSection(xmlCtx, section, _, conditions): settingID = sub_parsers.parseID(xmlCtx, section, 'Specify a setting ID') return effects.HasTargetEffect(settingID, _EFFECT_TYPE.SAVE_TUTORIAL_SETTING, conditions=conditions)
def _readCheckpointReachedCondition(xmlCtx, section, state): checkpointID = sub_parsers.parseID(xmlCtx, section, 'missing checkpoint ID in condition') return bc_conditions.CheckpointReachedCondition(checkpointID, state=state)
def _readRemoveMarkerSection(xmlCtx, section, _, conditions): markerID = sub_parsers.parseID(xmlCtx, section, 'Specify a marker ID') return effects.HasTargetEffect(markerID, _EFFECT_TYPE.REMOVE_MARKER, conditions=conditions)
def _readShowGreetingSection(xmlCtx, section, _, conditions): greetingID = sub_parsers.parseID(xmlCtx, section, 'Specify a greeting ID') return effects.HasTargetEffect(greetingID, _EFFECT_TYPE.SHOW_GREETING, conditions=conditions)
def _readTeleportSection(xmlCtx, section, _, conditions): pointID = sub_parsers.parseID(xmlCtx, section, 'Specify a point ID') return effects.HasTargetEffect(pointID, _EFFECT_TYPE.TELEPORT, conditions=conditions)
def _readSetBootcampNationEffectSection(xmlCtx, section, _, conditions): varID = sub_parsers.parseID(xmlCtx, section, 'missing selected nation variable ID') return effects.HasTargetEffect(varID, _EFFECT_TYPE.SAVE_ACCOUNT_SETTING, conditions=conditions)
def _reaLoadViewSection(xmlCtx, section, _, conditions): viewID = parseID(xmlCtx, section, 'Specify a view ID') return effects.HasTargetEffect(viewID, effects.EFFECT_TYPE.LOAD_VIEW, conditions=conditions)
def _readNextTaskSection(xmlCtx, section, _, conditions): taskID = sub_parsers.parseID(xmlCtx, section, 'Specify a next task ID') return effects.HasTargetEffect(taskID, _EFFECT_TYPE.NEXT_TASK, conditions=conditions)
def readSaveAccountSettingSection(xmlCtx, section, _, conditions): settingID = sub_parsers.parseID(xmlCtx, section, 'Specify a setting ID') return effects.HasTargetEffect(settingID, _EFFECT_TYPE.SAVE_ACCOUNT_SETTING, conditions=conditions)
def _readDispatcherTriggerSection(xmlCtx, section, _, triggerID): triggerIDs = set() for _, subSec in _xml.getChildren(xmlCtx, section, 'includes'): triggerIDs.add(sub_parsers.parseID(xmlCtx, subSec, 'Specify a trigger ID')) return triggers.TriggersDispatcher(triggerID, triggerIDs)