Esempio n. 1
0
    def getDialogues(self):
        """Searches the dialogue directory for dialogues """
        files = locateFiles("*.yaml", self.dialogue_directory)
        dialogue_parser = YamlDialogueParser()
        for dialogue_filepath in files:
            # Note Technomage 2010-11-13: the new DialogueEngine uses its own
            #     parser now, YamlDialogueParser.
#            dialogues = yaml.load_all(file(dialogue_file, "r"))
            dialogue_file = vfs.VFS.open(dialogue_filepath)
            try:
                dialogue = dialogue_parser.load(dialogue_file)
            except DialogueFormatError as error:
                logging.error('unable to load dialogue file {0}: {1}'
                              .format(dialogue_filepath, error))
            else:
                self.dialogues[dialogue.npc_name] = dialogue
Esempio n. 2
0
def convert_dialogue_file(filepath, backup):
    logging.info("processing {0}...".format(filepath))
    dummy, extension = os.path.splitext(filepath)
    if not extension == ".yaml":
        logging.info("    skipping {0}: not a yaml file".format(filepath))
        return 1
    with file(filepath, "r") as dialogue_file:
        old_parser = OldYamlDialogueParser()
        new_parser = YamlDialogueParser()
        try:
            dialogue = old_parser.load(dialogue_file)
        except DialogueFormatError as error:
            logging.info("    unable to convert {0}: unrecognized dialogue format".format(filepath))
            return 1
    if backup:
        backup_file(filepath)
    logging.info("    backed up {0} as {0}.backup".format(filepath))
    with file(filepath, "w") as dialogue_file:
        new_parser.dump(dialogue, dialogue_file)
    logging.info("    successfully converted {0}!".format(filepath))
Esempio n. 3
0
def main():
    parser = OptionParser(description='Script for testing dialogue files')
    parser.add_option('-s', '--settings', nargs=2,
                      dest='paths', default=['.'],
                      help='One or more paths to load settings from')
    parser.add_option('-f', '--logfile',
                        help='Name of log file to save to')
    parser.add_option('-l', '--loglevel', default='critical',
                    help='desired output level for log file')
    
    opts, args = parser.parse_args()

    settings = Settings(*opts.paths)

    levels = {'debug': logging.DEBUG,
              'info': logging.INFO,
              'warning': logging.WARNING,
              'error': logging.ERROR,
              'critical': logging.CRITICAL}

    #TODO: setup formating
    logging.basicConfig(filename=opts.logfile, level=levels[opts.loglevel])
    logger = logging.getLogger('dialogue_demo')

    try:
        dialogue_file_path = args[0]
    except IndexError:
        logger.info('No dialogue file provided, generating a list..')
        dialogue_file_path = selectDialogueFile(settings)

    game_state = {
        'quest': QuestEngine('quests'),
        'pc': MockPlayerCharacter(),
        'box': MockBox(),
        'beer': MockBeer()
    }
    dialogue_parser = YamlDialogueParser()
    with file(dialogue_file_path, 'r') as dialogue_file:
        dialogue = dialogue_parser.load(dialogue_file)
    processDialogue(dialogue, game_state)