Ignore:
Timestamp:
10/10/09 17:26:08 (10 years ago)
Author:
Kaydeth_parpg
Message:

Ticket #2: Patch by Kaydeth. Updated the classes in console.py through engine.py (went through files alphabetically) to correct some obvious discrepancies with our coding standard. comment[s:trac, t:2]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/console.py

    r295 r312  
    1717 
    1818class Console: 
    19     def __init__(self, appListener): 
     19    def __init__(self, app_listener): 
    2020        """  
    2121        Constructor 
     
    2323        @param appListener: ApplicationListener object providing a link with 
    2424        the engine, the world and the model""" 
     25        exit_help = "Terminate application" 
     26        grid_help = "Toggle grid display" 
     27        run_help = "Toggle player run/walk" 
     28        help_help = "Show this help string" 
     29        load_help = "load directory file" 
     30        python_help = "Run some python code" 
     31        quit_help = "Terminate application" 
     32        save_help = "save directory file" 
    2533 
    2634        self.commands = [ 
    27             {"cmd":"exit"  ,"callback":self.handleQuit  ,"help":"Terminate application "}, 
    28             {"cmd":"grid"  ,"callback":self.handleGrid  ,"help":"Toggle grid display   "}, 
    29             {"cmd":"run"   ,"callback":self.handleRun   ,"help":"Toggle player run/walk"}, 
    30             {"cmd":"help"  ,"callback":self.handleHelp  ,"help":"Show this help string "}, 
    31             {"cmd":"load"  ,"callback":self.handleLoad  ,"help":"load directory file   "}, 
    32             {"cmd":"python","callback":self.handlePython,"help":"Run some python code  "}, 
    33             {"cmd":"quit"  ,"callback":self.handleQuit  ,"help":"Terminate application "}, 
    34             {"cmd":"save"  ,"callback":self.handleSave  ,"help":"save directory file   "}, 
     35            {"cmd":"exit"  ,"callback":self.handleQuit  ,"help": exit_help}, 
     36            {"cmd":"grid"  ,"callback":self.handleGrid  ,"help": grid_help}, 
     37            {"cmd":"run"   ,"callback":self.handleRun   ,"help": run_help}, 
     38            {"cmd":"help"  ,"callback":self.handleHelp  ,"help": help_help}, 
     39            {"cmd":"load"  ,"callback":self.handleLoad  ,"help": load_help}, 
     40            {"cmd":"python","callback":self.handlePython,"help": python_help}, 
     41            {"cmd":"quit"  ,"callback":self.handleQuit  ,"help": quit_help}, 
     42            {"cmd":"save"  ,"callback":self.handleSave  ,"help": save_help}, 
    3543        ] 
    36         self.appListener=appListener 
     44        self.app_listener=app_listener 
    3745 
    3846    def handleQuit(self, command): 
     
    4351        @return: The resultstring""" 
    4452         
    45         self.appListener.quitGame() 
     53        self.app_listener.quitGame() 
    4654        return "Terminating ..." 
    4755 
     
    5361        @return: The resultstring""" 
    5462 
    55         self.appListener.world.activeMap.toggle_renderer('GridRenderer') 
     63        self.app_listener.world.activeMap.toggle_renderer('GridRenderer') 
    5664        return "Grid toggled" 
    5765 
     
    6371        @return: The response""" 
    6472         
    65         if self.appListener.model.pc_run==1: 
    66             self.appListener.model.pc_run=0 
     73        if self.app_listener.model.pc_run == 1: 
     74            self.app_listener.model.pc_run = 0 
    6775            return "PC is now walking" 
    6876        else: 
    69             self.appListener.model.pc_run=1 
     77            self.app_listener.model.pc_run = 1 
    7078            return "PC is now running" 
    7179             
     
    8088        res="" 
    8189        for cmd in self.commands: 
    82             res+= "%10s: %s\n" % (cmd["cmd"], cmd["help"]) 
     90            res += "%10s: %s\n" % (cmd["cmd"], cmd["help"]) 
    8391 
    8492        return res 
     
    9199        @return: The resultstring""" 
    92100 
    93         result=None 
     101        result = None 
    94102        python_regex = re.compile('^python') 
    95103        python_matches = python_regex.match(command.lower()) 
    96         if (python_matches != None): 
    97             end_python = command[python_matches.end()+1:] 
     104        if (python_matches is not None): 
     105            end_python = command[python_matches.end() + 1:] 
    98106            try: 
    99107                result = str(eval(end_python)) 
     
    110118        @return: The resultstring""" 
    111119 
    112         result=None 
     120        result = None 
    113121        load_regex = re.compile('^load') 
    114122        l_matches = load_regex.match(command.lower()) 
    115         if (l_matches != None): 
     123        if (l_matches is not None): 
    116124            end_load = l_matches.end() 
    117125            try: 
    118                 l_args = command.lower()[end_load+1:].strip() 
     126                l_args = command.lower()[end_load + 1:].strip() 
    119127                l_path, l_filename = l_args.split(' ') 
    120                 self.appListener.model.load(l_path, l_filename) 
     128                self.app_listener.model.load(l_path, l_filename) 
    121129                result = "Loaded file: " + l_path + l_filename 
    122130 
    123131            except Exception, l_error: 
    124                 self.appListener.engine.getGuiManager().getConsole().println('Error: ' + str(l_error)) 
     132                self.app_listener.engine.getGuiManager().getConsole().println('Error: ' + str(l_error)) 
    125133                result="Failed to load file" 
    126134 
     
    141149                s_args = command.lower()[end_save+1:].strip() 
    142150                s_path, s_filename = s_args.split(' ') 
    143                 self.appListener.model.save(s_path, s_filename) 
     151                self.app_listener.model.save(s_path, s_filename) 
    144152                result = "Saved to file: " + s_path + s_filename 
    145153 
    146154            except Exception, s_error: 
    147                 self.appListener.engine.getGuiManager().getConsole().println('Error: ' + str(s_error)) 
     155                self.app_listener.engine.getGuiManager().getConsole(). \ 
     156                    println('Error: ' + str(s_error)) 
    148157                result = "Failed to save file" 
    149158 
     
    164173                result=cmd["callback"](command) 
    165174 
    166         if result==None: 
     175        if result is None: 
    167176            result = "Invalid command, enter help for more information" 
    168177 
Note: See TracChangeset for help on using the changeset viewer.