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, afterBattle = False, initial = False): filePath = chapter.getFilePath(afterBattle=afterBattle) section = ResMgr.openSection(filePath) if section is None: _xml.raiseWrongXml(None, filePath, 'can not open or read') xmlCtx = (None, filePath) chapter.clear() flags = [] itemFlags = [] if 'initial-scene' in section.keys(): chapter.setInitialSceneID(_xml.readString(xmlCtx, section, 'initial-scene')) if 'default-scene' in section.keys(): chapter.setDefaultSceneID(_xml.readString(xmlCtx, section, 'default-scene')) for name, subSec in _xml.getChildren(xmlCtx, section, 'has-id'): entity = sub_parsers._parseEntity(xmlCtx, name, subSec, flags) if entity is not None: chapter.addHasIDEntity(entity) for _, subSec in _xml.getChildren(xmlCtx, section, 'triggers'): trigger = sub_parsers._parseTrigger(xmlCtx, subSec, flags, chapter) if trigger is not None: chapter.addTrigger(trigger) 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 len(gVarIDs): GlobalRefParser().parse(chapter, varIDs=gVarIDs, flags=flags) 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) chapter.addScene(scene) if initial: scene = chapter.getInitialScene() self.__parseSharedScene(chapter, scene, flags, itemFlags) flags = filter(lambda flag: flag not in itemFlags, flags) chapter.setFlags(flags) chapter.setValid(True) return chapter