Ignore:
Timestamp:
12/10/10 19:11:29 (9 years ago)
Author:
technomage
Message:

Patch by Technomage

  • Refactored the DialogueEngine? singleton into the DialogueProcessor? instance factory, eliminating some of the problems the singleton pattern caused with encapsulation and unit testing.
  • Renamed the dialogueengine.py module to dialogueprocessor.py for clarity.
  • Added type-checking code to the instance variables defined by the DialogueProcessor? and Dialogue classes using assert statements that are removed when the optimization '-O' flag is passed to the Python interpreter.
  • Moved the 'main' logic in dialogue_demo.py script into a 'main' method to avoid cluttering the module namespace with runtime variables.
  • Fixed a few code documentation issues pointed out by aspidites.
Location:
trunk/game
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/game

    • Property svn:ignore
      •  

        old new  
        55settings-old.xml 
        66settings.xml 
         7config.py 
  • trunk/game/scripts/gui/dialoguegui.py

    r680 r684  
    2121from fife.extensions.pychan import widgets 
    2222 
    23 from scripts.dialogueengine import DialogueEngine 
     23from scripts.dialogueprocessor import DialogueProcessor 
    2424 
    25 def setup_logging(): 
     25def setupLogging(): 
    2626    """Set various logging parameters for this module.""" 
    2727    module_logger = logging.getLogger('dialoguegui') 
    2828    if (__debug__): 
    2929        module_logger.setLevel(logging.DEBUG) 
    30 setup_logging() 
     30setupLogging() 
    3131 
    3232class DialogueGUI(object): 
     
    6060        game_state = {'npc': self.npc, 'pc': self.player_character, 
    6161                      'quest': self.quest_engine} 
    62         DialogueEngine.initiateDialogue(self.npc.dialogue, game_state) 
    63         self.continueDialogue() 
     62        try: 
     63            self.dialogue_processor = DialogueProcessor(self.npc.dialogue, 
     64                                                        game_state) 
     65            self.dialogue_processor.initiateDialogue() 
     66        except (TypeError) as error: 
     67            self._logger.error(str(error)) 
     68        else: 
     69            self.continueDialogue() 
    6470     
    6571    def setDialogueText(self, text): 
     
    7682        """Display the dialogue text and responses for the current 
    7783           L{DialogueSection}.""" 
    78         dialogue_text = DialogueEngine.getCurrentDialogueSection().text 
     84        dialogue_processor = self.dialogue_processor 
     85        dialogue_text = dialogue_processor.getCurrentDialogueSection().text 
    7986        self.setDialogueText(dialogue_text) 
    80         self.responses = DialogueEngine.continueDialogue() 
     87        self.responses = dialogue_processor.continueDialogue() 
    8188        self.setResponses(self.responses) 
    8289     
     
    93100        response_n = int(args[0].name.replace('response', '')) 
    94101        response = self.responses[response_n] 
    95         DialogueEngine.reply(response) 
    96         if (not DialogueEngine.in_dialogue): 
     102        dialogue_processor = self.dialogue_processor 
     103        dialogue_processor.reply(response) 
     104        if (not dialogue_processor.in_dialogue): 
    97105            self.handleEnd() 
    98106        else: 
     
    134142           respective on-click callbacks. 
    135143           @param responses: list of L{DialogueResponses} from the 
    136                L{DialogueEngine} 
     144               L{DialogueProcessor} 
    137145           @type responses: list of L{DialogueResponses}""" 
    138146        choices_list = self.dialogue_gui.findChild(name='choices_list') 
Note: See TracChangeset for help on using the changeset viewer.