Ignore:
Timestamp:
11/17/10 21:44:05 (9 years ago)
Author:
technomage
Message:

Ticket #269: Patch by Technomage.

  • Working prototype of the redesigned DialogueEngine? for the upcoming Techdemo2 release; major redesign of the existing DialogueEngine? and YAML dialogue file syntax.
  • Moved the redesigned DialogueEngine? class to the more descriptive dialogueengine.py module; the DialogueEngine? is now a singleton object and provides all functionality through class methods and attributes, and thus should not be instantiated
  • Abstracted the data structures used to store dialogue data away from the YAML data structures; the relevant classes are stored in the dialogue.py module
  • Abstracted the dialogue commands/actions from the DialogueEngine? code to make modifications and maintenance of dialogue logic easier; the relevant classes are stored in the dialogueactions.py module
  • The PyYAML loader has been replaced with a more robust YamlDialogueParser? class (see the dialogueparsers.py module) that interfaces with the new dialogue data structure classes and supports the new YAML dialogue file syntax; an OldYamlDialogueParser? class is provided to support reading the old Techdemo1 syntax
  • Removed the existing dialogue validator; runtime dialogue validation is not yet implemented
  • Added the convert_dialogue script, which converts dialogue files in the old Techdemo1 format to the new format; all existing dialogue files have been converted to work with the new parser
  • Added two support modules for the new classes and script: ordereddict.py, which provides a Python 2.7-like OrderedDict? class for Python versions 2.4-2.6; optionparser.py, which is a simplified command-line option parser for writing scripts as an alternative to argparse and optparse
  • Updated the dialogue_demo.py script to work with the new DialogueEngine?
  • fixes[s:trac, t:269]
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        44.settings 
        55Thumbs.db 
         6 
         7.externalToolBuilders 
         8 
         9.cproject 
  • trunk/game/scripts/gamemodel.py

    r667 r668  
    1919import sys 
    2020import os.path 
     21import logging 
    2122from copy import deepcopy 
    2223 
     
    3132from common.utils import parseBool 
    3233from inventory import Inventory 
     34from scripts.dialogueparser import YamlDialogueParser, DialogueFormatError 
    3335 
    3436try: 
     
    732734        """Searches the dialogue directory for dialogues """ 
    733735        files = locateFiles("*.yaml", self.dialogues_directory) 
    734         for dialogue_file in files: 
    735             dialogue_file = os.path.relpath(dialogue_file).replace("\\", "/") 
    736             dialogues = yaml.load_all(file(dialogue_file, "r")) 
    737             for dialogue in dialogues: 
    738                 self.dialogues[dialogue["NPC"]] = dialogue 
     736        dialogue_parser = YamlDialogueParser() 
     737        for dialogue_filepath in files: 
     738            dialogue_filepath = os.path.relpath(dialogue_filepath) \ 
     739                                .replace("\\", "/") 
     740            # Note Technomage 2010-11-13: the new DialogueEngine uses its own 
     741            #     parser now, YamlDialogueParser. 
     742#            dialogues = yaml.load_all(file(dialogue_file, "r")) 
     743            with file(dialogue_filepath, 'r') as dialogue_file: 
     744                try: 
     745                    dialogue = dialogue_parser.load(dialogue_file) 
     746                except DialogueFormatError as error: 
     747                    logging.error('unable to load dialogue file {0}: {1}' 
     748                                  .format(dialogue_filepath, error)) 
     749                else: 
     750                    self.dialogues[dialogue.npc_name] = dialogue 
     751            # Note Technomage 2010-11-13: the below code is used to load 
     752            #     multiple dialogues from a single file. Is this functionality 
     753            #     used/necessary? 
     754#            for dialogue in dialogues: 
     755#                self.dialogues[dialogue["NPC"]] = dialogue 
Note: See TracChangeset for help on using the changeset viewer.