Changeset 281


Ignore:
Timestamp:
09/11/09 12:31:14 (10 years ago)
Author:
Kaydeth_parpg
Message:

Ticket: #94: Patch by amo-ej1. "grid" console command added to display a grid overlay on the map. Console command logic moved to it's own class (console.py). Also unit tests added for console class. fixes[s:trac, t:94]

Location:
trunk/game
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/run.py

    r254 r281  
    2727from scripts import world 
    2828from scripts import engine 
     29from scripts import console 
    2930from scripts.engine import Engine 
    3031from scripts.common import eventlistenerbase 
     
    5960        self.quit = False 
    6061        self.aboutWindow = None 
     62        self.console=console.Console(self) 
    6163 
    6264    def quitGame(self): 
     
    6769    def onConsoleCommand(self, command): 
    6870        """ 
    69         Called on every console comand 
     71        Called on every console comand, delegates calls  to the a console 
     72        object, implementing the callbacks 
    7073        @type command: string 
    7174        @param command: the command to run 
    7275        @return: result 
    7376        """ 
    74         result = None 
    7577 
    76         if (command.lower() in ('quit', 'exit')): 
    77             self.quitGame() 
    78  
    79         load_regex = re.compile('^load') 
    80         l_matches = load_regex.match(command.lower()) 
    81         if (l_matches != None): 
    82             end_load = l_matches.end() 
    83             try: 
    84                 l_args = command.lower()[end_load+1:].strip() 
    85                 l_path, l_filename = l_args.split(' ') 
    86                 self.model.load(l_path, l_filename) 
    87                 result = "Loaded file: " + l_path + l_filename 
    88  
    89             except Exception, l_error: 
    90                 self.engine.getGuiManager().getConsole().println('Error: ' + str(l_error)) 
    91  
    92         save_regex = re.compile('^save') 
    93         s_matches = save_regex.match(command.lower()) 
    94         if (s_matches != None): 
    95             end_save = s_matches.end() 
    96             try: 
    97                 s_args = command.lower()[end_save+1:].strip() 
    98                 s_path, s_filename = s_args.split(' ') 
    99                 self.model.save(s_path, s_filename) 
    100                 result = "Saved to file: " + s_path + s_filename 
    101  
    102             except Exception, s_error: 
    103                 self.engine.getGuiManager().getConsole().println('Error: ' + str(s_error)) 
    104                     
    105         else: 
    106             try: 
    107                 result = str(eval(command)) 
    108             except Exception, e: 
    109                 result = str(e) 
    110  
    111         if not result: 
    112             result = 'no result' 
    113          
    114         return result 
     78        return self.console.handleConsoleCommand(command) 
    11579 
    11680    def onCommand(self, command): 
Note: See TracChangeset for help on using the changeset viewer.