Changeset 544


Ignore:
Timestamp:
06/17/10 14:16:47 (10 years ago)
Author:
beliar
Message:

Moving classes from run.py to scripts/parpg.py.

Location:
trunk/game
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/run.py

    r541 r544  
    1717 
    1818from scripts.common import utils 
     19 
     20from fife import fife 
     21print "Using the FIFE python module found here: ", os.path.dirname(fife.__file__) 
     22from fife.extensions.fife_settings import Setting 
     23from scripts.parpg import PARPGApplication 
     24 
    1925# add paths to the swig extensions 
    2026utils.addPaths ('../../engine/swigwrappers/python', '../../engine/extensions') 
     
    2430    shutil.copyfile('settings-dist.xml', 'settings.xml') 
    2531 
    26 from fife import fife 
    27 from fife.extensions import fife_compat, fifelog, pychan 
    28 from fife.extensions.basicapplication import ApplicationBase 
    29 from fife.extensions.fife_settings import Setting 
    30  
    31 from scripts import world 
    32 from scripts import engine 
    33 from scripts import console 
    34 from scripts.engine import Engine 
    35 from scripts.common import eventlistenerbase 
    3632#from settings import Setting 
    3733 
     
    4541   /scripts/engine.py. All fife stuff goes in /scripts/world.py""" 
    4642 
    47 class ApplicationListener(eventlistenerbase.EventListenerBase): 
    48     def __init__(self, engine, world, model): 
    49         """Initialise the instance. 
    50            @type engine: fife.Engine 
    51            @param engine: ??? 
    52            @type world: world.World 
    53            @param world: ??? 
    54            @type model: engine.Engine 
    55            @param model: an instance of PARPG's engine""" 
    56         super(ApplicationListener, self).__init__(engine, 
    57                                                   reg_keys=True,reg_cmd=True, 
    58                                                   reg_mouse=False,  
    59                                                   reg_console=True, 
    60                                                   reg_widget=True) 
    61         self.engine = engine 
    62         self.world = world 
    63         self.model = model 
    64         engine.getEventManager().setNonConsumableKeys([fife.Key.ESCAPE,]) 
    65         self.quit = False 
    66         self.aboutWindow = None 
    67         self.console=console.Console(self) 
    68  
    69     def quitGame(self): 
    70         """Forces a quit game on next cycle. 
    71            @return: None""" 
    72         self.quit = True 
    73  
    74     def onConsoleCommand(self, command): 
    75         """ 
    76         Called on every console comand, delegates calls  to the a console 
    77         object, implementing the callbacks 
    78         @type command: string 
    79         @param command: the command to run 
    80         @return: result 
    81         """ 
    82         return self.console.handleConsoleCommand(command) 
    83  
    84     def onCommand(self, command): 
    85         """Enables the game to be closed via the 'X' button on the window frame 
    86            @type command: fife.Command 
    87            @param command: The command to read. 
    88            @return: None""" 
    89         if(command.getCommandType() == fife.CMD_QUIT_GAME): 
    90             self.quit = True 
    91             command.consume() 
    92  
    93 class PARPG(ApplicationBase): 
    94     """Main Application class 
    95        We use an MVC data model. 
    96        self.world is our view,self.engine is our model 
    97        This file is the minimal controller""" 
    98     def __init__(self): 
    99         """Initialise the instance. 
    100            @return: None""" 
    101         super(PARPG, self).__init__() 
    102         self.world = world.World(self.engine) 
    103         self.model = engine.Engine(self.world) 
    104         self.model.readObjectDB(str(TDS.get("PARPG", "ObjectDatabaseFile"))) 
    105         self.world.data = self.model 
    106         self.world.initHud() 
    107         self.listener = ApplicationListener(self.engine, self.world, self.model) 
    108         self.world.quitFunction = self.listener.quitGame 
    109         self.model.loadMap("main-map", str(TDS.get("PARPG", "MapFile"))) 
    110         pychan.init(self.engine, debug = True) 
    111  
    112     def createListener(self): 
    113         """@return: None""" 
    114         # already created in constructor 
    115         # but if we don't put one here, Fife gets all fussy :-) 
    116         pass 
    117  
    118     def _pump(self): 
    119         """Main game loop. 
    120            There are in fact 2 main loops, this one and the one in World. 
    121            @return: None""" 
    122         if self.listener.quit: 
    123             self.breakRequested = True 
    124         else: 
    125             self.model.pump() 
    126             self.world.pump() 
    127  
    12843def main(): 
    12944    """Application code starts from here""" 
    130     app = PARPG() 
     45    app = PARPGApplication(TDS) 
    13146    app.run() 
    13247 
Note: See TracChangeset for help on using the changeset viewer.