示例#1
0
def _parseChapterInfoCondition(xmlCtx, section, _):
    conditionID = sub_parsers._parseID(xmlCtx, section,
                                       'Specify a charter info ID')
    return chapter.HasIDConditions(
        sub_parsers._parseID(xmlCtx, section,
                             'Specify a charter info condition ID'),
        sub_parsers._readConditions(xmlCtx, section, []))
示例#2
0
def _readProgressSection(xmlCtx, section, _):
    progressID = sub_parsers._parseID(xmlCtx, section, 'Specify a progress ID')
    conditions = []
    for _, subSec in _xml.getChildren(xmlCtx, section, 'steps'):
        condID = sub_parsers._parseID(xmlCtx, subSec, 'Specify a condition ID')
        conditions.append(chapter.HasIDConditions(sub_parsers._parseID(xmlCtx, subSec, 'Specify a condition ID'), sub_parsers._readConditions(xmlCtx, subSec, [])))

    return chapter.ChapterProgress(progressID, conditions)
示例#3
0
def _readProgressSection(xmlCtx, section, _):
    progressID = sub_parsers._parseID(xmlCtx, section, 'Specify a progress ID')
    conditions = []
    for _, subSec in _xml.getChildren(xmlCtx, section, 'steps'):
        condID = sub_parsers._parseID(xmlCtx, subSec, 'Specify a condition ID')
        conditions.append(
            chapter.HasIDConditions(
                sub_parsers._parseID(xmlCtx, subSec, 'Specify a condition ID'),
                sub_parsers._readConditions(xmlCtx, subSec, [])))

    return chapter.ChapterProgress(progressID, conditions)
示例#4
0
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)
示例#5
0
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 chapter.HasTargetEffect(flagID,
                                   chapter.Effect.EXIT_QUEUE,
                                   conditions=conditions)
示例#6
0
 def __readGuiItemsSection(self, xmlCtx, section):
     self.__guiItems.clear()
     for _, subSection in _xml.getChildren(xmlCtx, section, 'gui-items'):
         itemID = sub_parsers._parseID(xmlCtx, subSection,
                                       'Specify a GUI item ID')
         path = _xml.readString(xmlCtx, subSection, 'path')
         self.__guiItems[itemID] = {'path': path, 'locked': True}
示例#7
0
def _readSetFilterSection(xmlCtx, section, _, conditions):
    filterID = sub_parsers._parseID(xmlCtx, section, 'Specify a filter ID')
    value = []
    for name, subSec in _xml.getChildren(xmlCtx, section, 'value'):
        value.append(sub_parsers._readVarValue(name, subSec))

    return chapter.SetFilter(filterID, tuple(value), conditions=conditions)
示例#8
0
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)
示例#9
0
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)
示例#10
0
def _readSetFilterSection(xmlCtx, section, _, conditions):
    filterID = sub_parsers._parseID(xmlCtx, section, 'Specify a filter ID')
    value = []
    for name, subSec in _xml.getChildren(xmlCtx, section, 'value'):
        value.append(sub_parsers._readVarValue(name, subSec))

    return chapter.SetFilter(filterID, tuple(value), conditions=conditions)
示例#11
0
 def __readGuiItemsSection(self, xmlCtx, section):
     self.__guiItems.clear()
     for _, subSection in _xml.getChildren(xmlCtx, section, 'gui-items'):
         itemID = sub_parsers._parseID(xmlCtx, subSection, 'Specify a GUI item ID')
         path = _xml.readString(xmlCtx, subSection, 'path')
         self.__guiItems[itemID] = {'path': path,
          'locked': True}
示例#12
0
    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
示例#13
0
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)
示例#14
0
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)
示例#15
0
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'))
示例#16
0
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
示例#17
0
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
示例#18
0
def _readHintSection(xmlCtx, section, _):
    hintID = sub_parsers._parseID(xmlCtx, section, 'Specify a hint ID')
    text = translation(_xml.readString(xmlCtx, section, 'text'))
    image = None
    if 'image' in section.keys():
        image = _xml.readString(xmlCtx, section, 'image')
    speakID = None
    if 'speak' in section.keys():
        speakID = _xml.readString(xmlCtx, section, 'speak')
    return chapter.SimpleHint(hintID, text, image=image, speakID=speakID)
示例#19
0
def _readHintSection(xmlCtx, section, _):
    hintID = sub_parsers._parseID(xmlCtx, section, 'Specify a hint ID')
    text = translation(_xml.readString(xmlCtx, section, 'text'))
    image = None
    if 'image' in section.keys():
        image = _xml.readString(xmlCtx, section, 'image')
    speakID = None
    if 'speak' in section.keys():
        speakID = _xml.readString(xmlCtx, section, 'speak')
    return chapter.SimpleHint(hintID, text, image=image, speakID=speakID)
示例#20
0
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
示例#21
0
    def __readCommandsSection(self, xmlCtx, section):
        self.__commands.clear()
        for _, subSection in _xml.getChildren(xmlCtx, section, 'gui-commands'):
            commandID = sub_parsers._parseID(xmlCtx, subSection, 'Specify a command ID')
            cmdType = _xml.readString(xmlCtx, subSection, 'type')
            command = _xml.readString(xmlCtx, subSection, 'name')
            argsSec = _xml.getChildren(xmlCtx, subSection, 'args')
            args = []
            for name, argSec in argsSec:
                args.append(sub_parsers._readVarValue(name, argSec))

            self.__commands[commandID] = CommandData(cmdType, command, args)
示例#22
0
def _parseHint(xmlCtx, section, _):
    hintID = sub_parsers._parseID(xmlCtx, section, 'Specify a hint ID')
    targetID = _xml.readString(xmlCtx, section, 'gui-item-ref')
    containerID = section.readString('container-ref')
    if not len(containerID):
        containerID = None
    text = translation(_xml.readString(xmlCtx, section, 'text'))
    inPin = _xml.readString(xmlCtx, section, 'inPin')
    outPin = _xml.readString(xmlCtx, section, 'outPin')
    line = _xml.readString(xmlCtx, section, 'line')
    position = section.readVector2('position')
    topmostLevel = section.readBool('topmost-level', True)
    return chapter.ItemHint(hintID, targetID, containerID, position, text, inPin, outPin, line, topmostLevel)
示例#23
0
    def __readCommandsSection(self, xmlCtx, section):
        self.__commands.clear()
        for _, subSection in _xml.getChildren(xmlCtx, section, 'gui-commands'):
            commandID = sub_parsers._parseID(xmlCtx, subSection,
                                             'Specify a command ID')
            cmdType = _xml.readString(xmlCtx, subSection, 'type')
            command = _xml.readString(xmlCtx, subSection, 'name')
            argsSec = _xml.getChildren(xmlCtx, subSection, 'args')
            args = []
            for name, argSec in argsSec:
                args.append(sub_parsers._readVarValue(name, argSec))

            self.__commands[commandID] = CommandData(cmdType, command, args)
示例#24
0
 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))
示例#25
0
def _parseHint(xmlCtx, section, _):
    hintID = sub_parsers._parseID(xmlCtx, section, 'Specify a hint ID')
    targetID = _xml.readString(xmlCtx, section, 'gui-item-ref')
    containerID = section.readString('container-ref')
    if not len(containerID):
        containerID = None
    text = translation(_xml.readString(xmlCtx, section, 'text'))
    inPin = _xml.readString(xmlCtx, section, 'inPin')
    outPin = _xml.readString(xmlCtx, section, 'outPin')
    line = _xml.readString(xmlCtx, section, 'line')
    position = section.readVector2('position')
    topmostLevel = section.readBool('topmost-level', True)
    return chapter.ItemHint(hintID, targetID, containerID, position, text,
                            inPin, outPin, line, topmostLevel)
示例#26
0
def _readShowMarkerSection(xmlCtx, section, _, conditions):
    markerID = sub_parsers._parseID(xmlCtx, section, 'Specify a marker ID')
    return chapter.HasTargetEffect(markerID, chapter.Effect.SHOW_MARKER, conditions=conditions)
示例#27
0
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)
示例#28
0
def _readShowGreetingSection(xmlCtx, section, _, conditions):
    greetingID = sub_parsers._parseID(xmlCtx, section, 'Specify a greeting ID')
    return chapter.HasTargetEffect(greetingID, chapter.Effect.SHOW_GREETING, conditions=conditions)
示例#29
0
def _readTeleportSection(xmlCtx, section, _, conditions):
    pointID = sub_parsers._parseID(xmlCtx, section, 'Specify a point ID')
    return chapter.HasTargetEffect(pointID, chapter.Effect.TELEPORT, conditions=conditions)
示例#30
0
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'))
示例#31
0
def _readNextTaskSection(xmlCtx, section, _, conditions):
    taskID = sub_parsers._parseID(xmlCtx, section, 'Specify a next task ID')
    return chapter.HasTargetEffect(taskID,
                                   chapter.Effect.NEXT_TASK,
                                   conditions=conditions)
示例#32
0
def _readShowMarkerSection(xmlCtx, section, _, conditions):
    markerID = sub_parsers._parseID(xmlCtx, section, 'Specify a marker ID')
    return chapter.HasTargetEffect(markerID,
                                   chapter.Effect.SHOW_MARKER,
                                   conditions=conditions)
示例#33
0
def _readNextTaskSection(xmlCtx, section, _, conditions):
    taskID = sub_parsers._parseID(xmlCtx, section, 'Specify a next task ID')
    return chapter.HasTargetEffect(taskID, chapter.Effect.NEXT_TASK, conditions=conditions)
示例#34
0
def _parseChapterInfoCondition(xmlCtx, section, _):
    conditionID = sub_parsers._parseID(xmlCtx, section, 'Specify a charter info ID')
    return chapter.HasIDConditions(sub_parsers._parseID(xmlCtx, section, 'Specify a charter info condition ID'), sub_parsers._readConditions(xmlCtx, section, []))
示例#35
0
def _readCloseHintSection(xmlCtx, section, _, conditions):
    hintID = sub_parsers._parseID(xmlCtx, section, 'Specify a hint ID')
    return chapter.HasTargetEffect(hintID, chapter.Effect.CLOSE_HINT, conditions=conditions)
示例#36
0
def _readTeleportSection(xmlCtx, section, _, conditions):
    pointID = sub_parsers._parseID(xmlCtx, section, 'Specify a point ID')
    return chapter.HasTargetEffect(pointID,
                                   chapter.Effect.TELEPORT,
                                   conditions=conditions)
示例#37
0
def _readShowGreetingSection(xmlCtx, section, _, conditions):
    greetingID = sub_parsers._parseID(xmlCtx, section, 'Specify a greeting ID')
    return chapter.HasTargetEffect(greetingID,
                                   chapter.Effect.SHOW_GREETING,
                                   conditions=conditions)
示例#38
0
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 chapter.HasTargetEffect(flagID, chapter.Effect.EXIT_QUEUE, conditions=conditions)
示例#39
0
def _readCloseHintSection(xmlCtx, section, _, conditions):
    hintID = sub_parsers._parseID(xmlCtx, section, 'Specify a hint ID')
    return chapter.HasTargetEffect(hintID,
                                   chapter.Effect.CLOSE_HINT,
                                   conditions=conditions)