Changeset 699


Ignore:
Timestamp:
01/08/11 03:14:25 (9 years ago)
Author:
technomage
Message:

Patch by Technomage

  • Renamed the default_root_section and root_sections attributes of the Dialogue class to "default_greeting" and "greetings", respectively;
  • Renamed the RootDialogueSection? class to "DialogueGreeting?" for clarity;
  • Renamed the DEFAULT_ROOT_SECTION and ROOT_SECTIONS tags in the YAML dialogue files as "DEFAULT_GREETING" and "GREETINGS", respectively;
Location:
trunk/game
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/dialogue/bouncer.yaml

    r698 r699  
    1616NPC_NAME: Dig 
    1717AVATAR_PATH: gui/portraits/bouncer.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "What do you want?  Can't you see I'm drinking here?" 
  • trunk/game/dialogue/camilla.yaml

    r698 r699  
    1616NPC_NAME: Camilla Niitty 
    1717AVATAR_PATH: gui/portraits/camilla.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Oh, another vagabond.  What do you want?" 
  • trunk/game/dialogue/crazy_swede.yaml

    r698 r699  
    1616NPC_NAME: Skwisgaar the Crazy Swede 
    1717AVATAR_PATH: gui/portraits/crazy_swede.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Chop!  Chop!  Chopity Chop-chop?" 
  • trunk/game/dialogue/drunkard.yaml

    r698 r699  
    1616NPC_NAME: Bart The Drunkard 
    1717AVATAR_PATH: gui/portraits/drunkard.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Hey there, back up... no need to gang up on a poor guy!" 
  • trunk/game/dialogue/farm_boy1.yaml

    r698 r699  
    1616NPC_NAME: Sami 
    1717AVATAR_PATH: gui/portraits/farm_boy_temp.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Hi, I'm Sami.  How can I help you?" 
  • trunk/game/dialogue/farm_boy2.yaml

    r698 r699  
    1616NPC_NAME: Rasmus 
    1717AVATAR_PATH: gui/portraits/farm_boy_temp.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Hi, I'm Rasmus.  What can I do for you?" 
  • trunk/game/dialogue/farmer.yaml

    r698 r699  
    1616NPC_NAME: Farmer Manslow 
    1717AVATAR_PATH: gui/portraits/farmer.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Who the hell are you??" 
  • trunk/game/dialogue/fguard.yaml

    r698 r699  
    1616NPC_NAME: Janie 
    1717AVATAR_PATH: gui/portraits/fguard.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Halt, identify yourself!" 
  • trunk/game/dialogue/grifter1.yaml

    r698 r699  
    1616NPC_NAME: Cali 
    1717AVATAR_PATH: gui/portraits/grifter_temp.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Hi there stranger.  Buy a gal a drink?" 
  • trunk/game/dialogue/grifter2.yaml

    r698 r699  
    1616NPC_NAME: Kandi 
    1717AVATAR_PATH: gui/portraits/grifter_temp.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Hi there stranger.  Buy a gal a drink?" 
  • trunk/game/dialogue/innkeeper.yaml

    r698 r699  
    1616NPC_NAME: Jacob 
    1717AVATAR_PATH: gui/portraits/innkeeper.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Hi there, Stranger!  Welcome to Jacob's.  How can I help you?" 
  • trunk/game/dialogue/leader.yaml

    r698 r699  
    1616NPC_NAME: Kimmo Niitty 
    1717AVATAR_PATH: gui/portraits/leader.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "What do you want?" 
  • trunk/game/dialogue/ma.yaml

    r698 r699  
    1616NPC_NAME: Ma Niitty 
    1717AVATAR_PATH: gui/portraits/ma.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Why hello there... I don't recognize your face..." 
  • trunk/game/dialogue/mall_template.yaml

    r698 r699  
    1616NPC_NAME: Anyone 
    1717AVATAR_PATH: gui/portraits/npc.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Hello.  How can I help you?" 
  • trunk/game/dialogue/old_man.yaml

    r698 r699  
    1616NPC_NAME: Old Man 
    1717AVATAR_PATH: gui/portraits/crazy_swede.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialogue 
    2020    SAY: "The old man looks up at you from his chair with a dazed look upon\ 
     
    3030        GOTO: parting_shot 
    3131         
    32 START_SECTIONS: 
     32GREETINGS: 
    3333-   ID: found_ring 
    3434    SAY: "\"Lucy... Where is my Lucy?\"" 
  • trunk/game/dialogue/quartermaster.yaml

    r698 r699  
    1616NPC_NAME: Helja 
    1717AVATAR_PATH: gui/portraits/quartermaster.jpg 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Hello, there!  A new addition to the labor pool, I see." 
  • trunk/game/dialogue/quest_sample.yaml

    r698 r699  
    1616NPC_NAME: NPC 
    1717AVATAR_PATH: gui/portraits/npc.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Things are tough around here, let me tell you our problems" 
  • trunk/game/dialogue/sample.yaml

    r698 r699  
    1616NPC_NAME: Friendly NPC 
    1717AVATAR_PATH: gui/portraits/npc.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Things are tough around here, let me tell you our problems" 
  • trunk/game/dialogue/snowshoveler.yaml

    r698 r699  
    1616NPC_NAME: Matti 
    1717AVATAR_PATH: gui/portraits/snowshoveler.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: opening_dialog 
    2020    SAY: "Good to talk to someone, Matti could use a break" 
  • trunk/game/dialogue/synnove.yaml

    r698 r699  
    1616NPC_NAME: Synnove Niitty 
    1717AVATAR_PATH: gui/portraits/synnove.png 
    18 DEFAULT_ROOT_SECTION: 
     18DEFAULT_GREETING: 
    1919    ID: main_dialog 
    2020    SAY: "Hi there!  I don't recognize you.  Are you new here?" 
  • trunk/game/scripts/dialogue.py

    r698 r699  
    3030    data belonging to a particular NPC. 
    3131    """ 
    32     __slots__ = ['npc_name', 'avatar_path', 'default_root_section', 
    33                  'root_sections', 'sections'] 
     32    __slots__ = ['npc_name', 'avatar_path', 'default_greeting', 
     33                 'greetings', 'sections'] 
    3434     
    35     def __init__(self, npc_name, avatar_path, default_root_section, 
    36                  root_sections=None, sections=None): 
     35    def __init__(self, npc_name, avatar_path, default_greeting, greetings=None, 
     36                 sections=None): 
    3737        """ 
    3838        Initialize a new L{Dialogue} instance. 
     
    4343            NPC's avatar. 
    4444        @type avatar_path: basestring 
    45         @param default_root_section: section of dialogue that should be 
     45        @param default_greeting: section of dialogue that should be 
    4646            displayed when the dialogue is first initiated and no other start 
    4747            sections are available. 
    48         @type default_root_section: L{DialogueSection} 
    49         @param root_sections: sections of dialogue defining the conditions 
     48        @type default_greeting: L{DialogueSection} 
     49        @param greetings: sections of dialogue defining the conditions 
    5050            under which each should be displayed when the dialogue is first 
    5151            initiated. 
    52         @type root_section_references: list of  
    53             L{RootDialogueSections<RootDialogueSection>} 
     52        @type greetings: list of  
     53            L{RootDialogueSections<DialogueGreeting>} 
    5454        @param sections: sections of dialogue that make up this 
    5555            L{Dialogue} instance. 
     
    5858        self.npc_name = npc_name 
    5959        self.avatar_path = avatar_path 
    60         self.default_root_section = default_root_section 
    61         self.root_sections = root_sections 
     60        self.default_greeting = default_greeting 
     61        self.greetings = greetings 
    6262        self.sections = OrderedDict() 
    63         all_sections = sections + [default_root_section] + root_sections 
     63        all_sections = sections + [default_greeting] + greetings 
    6464        if (__debug__): 
    6565            section_ids = [section.id for section in all_sections] 
     
    125125 
    126126 
    127 class RootDialogueSection(DialogueSection): 
     127class DialogueGreeting(DialogueSection): 
    128128    """ 
    129129    Represents a root section of dialogue in a L{Dialogue} along with the 
     
    142142    def __init__(self, id_, condition, text, responses=None, actions=None): 
    143143        """ 
    144         Initialize a new L{RootDialogueSection} instance. 
     144        Initialize a new L{DialogueGreeting} instance. 
    145145         
    146146        @param id_: named used to uniquely identify the L{DialogueSection} 
  • trunk/game/scripts/dialogueparsers.py

    r698 r699  
    4545from scripts import COPYRIGHT_HEADER 
    4646from scripts.dialogue import (Dialogue, DialogueSection, DialogueResponse, 
    47     RootDialogueSection) 
     47    DialogueGreeting) 
    4848from scripts.dialogueactions import DialogueAction 
    4949 
     
    192192        dialogue_dict['NPC_NAME'] = dialogue.npc_name 
    193193        dialogue_dict['AVATAR_PATH'] = dialogue.avatar_path 
    194         dialogue_dict['DEFAULT_ROOT_SECTION'] = \ 
     194        dialogue_dict['DEFAULT_GREETING'] = \ 
    195195            self._representDialogueSection(dumper, 
    196                                            dialogue.default_root_section) 
     196                                           dialogue.default_greeting) 
    197197        # NOTE Technomage 2010-11-16: Dialogue stores its sections in an 
    198198        #     OrderedDict, so a round-trip load, dump, and load will preserve 
    199199        #     the order of DialogueSections. 
    200         if (len(dialogue.root_sections) > 0): 
    201             root_sections_list_node = dumper.represent_list([]) 
    202             root_sections_list = root_sections_list_node.value 
    203             for root_section in dialogue.root_sections: 
    204                 root_section_node = \ 
    205                     self._representRootDialogueSection(dumper, root_section) 
    206                 root_sections_list.append(root_section_node) 
    207             dialogue_dict['ROOT_SECTIONS'] = root_sections_list_node 
     200        if (len(dialogue.greetings) > 0): 
     201            greetings_list_node = dumper.represent_list([]) 
     202            greetings_list = greetings_list_node.value 
     203            for greeting in dialogue.greetings: 
     204                greeting_node = \ 
     205                    self._representRootDialogueSection(dumper, greeting) 
     206                greetings_list.append(greeting_node) 
     207            dialogue_dict['GREETINGS'] = greetings_list_node 
    208208        if (len(dialogue.setions) > 0): 
    209209            sections_list_node = dumper.represent_list([]) 
     
    226226        return dialogue_node 
    227227     
    228     def _representRootDialogueSection(self, dumper, root_section): 
    229         root_section_node = dumper.represent_dict({}) 
    230         root_section_dict = OrderedDict() 
    231         root_section_dict['ID'] = root_section.id 
    232         root_section_dict['CONDITION'] = dumper.represent_scalar( 
     228    def _representRootDialogueSection(self, dumper, greeting): 
     229        greeting_node = dumper.represent_dict({}) 
     230        greeting_dict = OrderedDict() 
     231        greeting_dict['ID'] = greeting.id 
     232        greeting_dict['CONDITION'] = dumper.represent_scalar( 
    233233            'tag:yaml.org,2002:str', 
    234             root_section.condition, 
     234            greeting.condition, 
    235235            style='"' 
    236236        ) 
    237         for key, value in root_section_dict.items(): 
     237        for key, value in greeting_dict.items(): 
    238238            if (isinstance(key, yaml.Node)): 
    239239                key_node = key 
     
    244244            else: 
    245245                value_node = dumper.represent_data(value) 
    246             root_section_node.value.append((key_node, value_node)) 
    247         return root_section_node 
     246            greeting_node.value.append((key_node, value_node)) 
     247        return greeting_node 
    248248     
    249249    def _representDialogueSection(self, dumper, dialogue_section): 
     
    346346        npc_name = None 
    347347        avatar_path = None 
    348         default_root_section = None 
    349         root_sections = [] 
     348        default_greeting = None 
     349        greetings = [] 
    350350        sections = [] 
    351351         
     
    357357                elif (key == u'AVATAR_PATH'): 
    358358                    avatar_path = loader.construct_object(value_node) 
    359                 elif (key == u'DEFAULT_ROOT_SECTION'): 
    360                     default_root_section = \ 
     359                elif (key == u'DEFAULT_GREETING'): 
     360                    default_greeting = \ 
    361361                        self._constructDialogueSection(loader, value_node) 
    362                 elif (key == u'ROOT_SECTIONS'): 
    363                     for root_section_node in value_node.value: 
    364                         root_section = self._constructRootDialogueSection( 
     362                elif (key == u'GREETINGS'): 
     363                    for greeting_node in value_node.value: 
     364                        greeting = self._constructRootDialogueSection( 
    365365                                loader, 
    366                                 root_section_node 
     366                                greeting_node 
    367367                        ) 
    368                         root_sections.append( 
    369                             root_section 
     368                        greetings.append( 
     369                            greeting 
    370370                        ) 
    371371                elif (key == u'SECTIONS'): 
     
    380380         
    381381        dialogue = Dialogue(npc_name=npc_name, avatar_path=avatar_path, 
    382                             default_root_section=default_root_section, 
    383                             root_sections=root_sections, 
     382                            default_greeting=default_greeting, 
     383                            greetings=greetings, 
    384384                            sections=sections) 
    385385        return dialogue 
    386386     
    387     def _constructRootDialogueSection(self, loader, root_section_node): 
     387    def _constructRootDialogueSection(self, loader, greeting_node): 
    388388        id = None 
    389389        text = None 
     
    391391        responses = [] 
    392392        actions = [] 
    393         root_section = None 
    394          
    395         try: 
    396             for key_node, value_node in root_section_node.value: 
     393        greeting = None 
     394         
     395        try: 
     396            for key_node, value_node in greeting_node.value: 
    397397                key = key_node.value 
    398398                if (key == u'ID'): 
     
    417417            raise DialogueFormatError(e) 
    418418        else: 
    419             root_section = DialogueSection(id=id, text=text, 
     419            greeting = DialogueSection(id=id, text=text, 
    420420                                           condition=condition, 
    421421                                           responses=responses, 
    422422                                           actions=actions) 
    423423         
    424         return root_section 
     424        return greeting 
    425425     
    426426    def _constructDialogueSection(self, loader, section_node): 
  • trunk/game/scripts/dialogueprocessor.py

    r698 r699  
    160160        dialogue = self.dialogue 
    161161        root_dialogue_section = None 
    162         for root_section in dialogue.root_sections: 
    163             if (eval(root_section.condition, self.game_state)): 
    164                 root_dialogue_section = root_section 
     162        for greeting in dialogue.greetings: 
     163            if (eval(greeting.condition, self.game_state)): 
     164                root_dialogue_section = greeting 
    165165        if (root_dialogue_section is None): 
    166             root_dialogue_section = dialogue.default_root_section 
     166            root_dialogue_section = dialogue.default_greeting 
    167167         
    168168        return root_dialogue_section 
  • trunk/game/tests/test_dialogueprocessor.py

    r698 r699  
    2828#    that it isn't a mistake to use them. 
    2929from scripts.dialogue import (Dialogue, DialogueSection, DialogueResponse, 
    30     RootDialogueSection) 
     30    DialogueGreeting) 
    3131 
    3232class MockDialogueAction(object): 
     
    6363            npc_name='Mr. NPC', 
    6464            avatar_path='/some/path', 
    65             default_root_section=DialogueSection( 
    66                 id_='root_section', 
     65            default_greeting=DialogueSection( 
     66                id_='greeting', 
    6767                text='This is the root dialogue section.', 
    6868                actions=[ 
     
    9393                ], 
    9494            ), 
    95             root_sections=[ 
    96                 RootDialogueSection( 
    97                     id_='alternative_root_section', 
     95            greetings=[ 
     96                DialogueGreeting( 
     97                    id_='alternative_greeting', 
    9898                    condition='use_alternative_root is True', 
    9999                    text='This is an alternate root section.', 
     
    135135         
    136136        # Default root dialogue section should have been pushed onto the stack. 
    137         root_dialogue_section = self.dialogue.default_root_section 
     137        root_dialogue_section = self.dialogue.default_greeting 
    138138        self.assertStateEqual(dialogue_processor, in_dialogue=True, 
    139139                              dialogue=self.dialogue, 
     
    176176        self.dialogue_processor.initiateDialogue() 
    177177        self.dialogue_action = \ 
    178             self.dialogue.default_root_section.actions[0] 
     178            self.dialogue.default_greeting.actions[0] 
    179179     
    180180    def testRunsDialogueActions(self): 
     
    218218        dialogue = self.dialogue 
    219219        root_dialogue_section = dialogue_processor.getRootDialogueSection() 
    220         expected_dialogue_section = dialogue.root_sections[0] 
     220        expected_dialogue_section = dialogue.greetings[0] 
    221221        self.assertEqual(root_dialogue_section, expected_dialogue_section) 
    222222 
     
    233233        """Test getCurrentDialogueSection returns section at top of stack""" 
    234234        dialogue_processor = self.dialogue_processor 
    235         expected_dialogue_section = self.dialogue.default_root_section 
     235        expected_dialogue_section = self.dialogue.default_greeting 
    236236        actual_dialogue_section = \ 
    237237            dialogue_processor.getCurrentDialogueSection() 
     
    309309        self.dialogue_processor = DialogueProcessor(self.dialogue, 
    310310                                                    self.game_state) 
    311         self.response = self.dialogue.default_root_section.responses[1] 
     311        self.response = self.dialogue.default_greeting.responses[1] 
    312312        self.ending_response = \ 
    313             self.dialogue.default_root_section.responses[3] 
     313            self.dialogue.default_greeting.responses[3] 
    314314     
    315315    def testRaisesExceptionWhenNotInitiated(self): 
     
    341341                      self.dialogue.sections.keys()) 
    342342        dialogue_processor.reply(self.response) 
    343         root_section = self.dialogue.default_root_section 
     343        greeting = self.dialogue.default_greeting 
    344344        next_section = self.dialogue.sections[self.response.next_section_id] 
    345345        self.assertStateEqual( 
     
    347347            in_dialogue=True, 
    348348            dialogue=self.dialogue, 
    349             dialogue_section_stack=[root_section, next_section], 
     349            dialogue_section_stack=[greeting, next_section], 
    350350        ) 
    351351     
Note: See TracChangeset for help on using the changeset viewer.