Changeset 58 for trunk/PARPG/run.py


Ignore:
Timestamp:
05/11/09 13:42:45 (11 years ago)
Author:
maximinus_parpg
Message:

Made it so we only have one keycheck function (sanity at last!)
A few more Rio oddities removed.
Some minor script clean-up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PARPG/run.py

    r54 r58  
    2121 
    2222import fife_compat 
    23 import fife, fifelog 
     23import fife,fifelog 
    2424from scripts import world 
    2525from scripts import engine 
     
    3030TDS = Setting() 
    3131 
     32# This folder holds the main meta-data for PARPG. This file should be 
     33# minimal, since folding code into the controller with MVC is usually bad 
     34# All game and logic and data is held held and referenced in /scripts/engine.py 
     35# All fife stuff goes in /scripts/world.py 
     36 
    3237class ApplicationListener(eventlistenerbase.EventListenerBase): 
    33     def __init__(self, engine, world): 
     38    def __init__(self,engine,world): 
    3439        super(ApplicationListener, self).__init__(engine, 
    35                                                   regKeys=True,regCmd=True, regMouse=False,  
    36                                                   regConsole=True, regWidget=True) 
    37         self.engine = engine 
    38         self.world = world 
     40                                                  regKeys=True,regCmd=True, 
     41                                                  regMouse=False,  
     42                                                  regConsole=True, 
     43                                                  regWidget=True) 
     44        self.engine=engine 
     45        self.world=world 
    3946        engine.getEventManager().setNonConsumableKeys([fife.Key.ESCAPE,]) 
    40         self.quit = False 
    41         self.aboutWindow = None 
     47        self.quit=False 
     48        self.aboutWindow=None 
    4249 
    43     def keyPressed(self, evt): 
    44         """Function to deal with keypress events 
    45            @param evt: The event that was captured""" 
    46         keyval = evt.getKey().getValue() 
    47         if keyval == fife.Key.ESCAPE: 
    48             self.quit = True 
    49         evt.consume() 
    50            
    51     def onCommand(self, command): 
     50    def quitGame(self): 
     51        """Forces a quit game on next cycle""" 
     52        self.quit=True 
     53 
     54    def onCommand(self,command): 
    5255        """Enables the game to be closed via the 'X' button on the window frame""" 
    53         self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME) 
    54         if self.quit: 
     56        if(command.getCommandType()==fife.CMD_QUIT_GAME): 
     57            self.quit=True 
    5558            command.consume() 
    5659 
    5760class PARPG(ApplicationBase): 
    5861    """Main Application class 
    59        We use an MV data model. 
    60        self.world is our view 
    61        self.engine is our model""" 
     62       We use an MVC data model. 
     63       self.world is our view,self.engine is our model 
     64       This file is the minimal controller""" 
    6265    def __init__(self): 
    6366        super(PARPG,self).__init__() 
    64         self.world = world.World(self.engine) 
    65         self.model = engine.Engine(self.world) 
    66         self.listener = ApplicationListener(self.engine, self.world) 
     67        self.world=world.World(self.engine) 
     68        self.model=engine.Engine(self.world) 
     69        self.listener=ApplicationListener(self.engine,self.world) 
     70        self.world.quitFunction=self.listener.quitGame 
    6771        self.model.loadMap(str(TDS.readSetting("MapFile"))) 
    6872 
     
    7175           Called in the ApplicationBase constructor.""" 
    7276        import settings 
    73         self.settings = settings 
    74  
    75         eSet = self.engine.getSettings() 
     77        self.settings=settings 
     78        eSet=self.engine.getSettings() 
    7679        eSet.setDefaultFontGlyphs(str(TDS.readSetting("FontGlyphs",strip=False))) 
    7780        eSet.setDefaultFontPath(str(TDS.readSetting("Font"))) 
     
    9598    def initLogging(self): 
    9699        """Initialize the LogManager""" 
    97         LogModules = TDS.readSetting("LogModules",type='list') 
    98         self.log = fifelog.LogManager(self.engine, 
     100        LogModules=TDS.readSetting("LogModules",type='list') 
     101        self.log=fifelog.LogManager(self.engine, 
    99102                                      int(TDS.readSetting("LogToPrompt")), 
    100103                                      int(TDS.readSetting("LogToFile"))) 
    101         if LogModules: 
     104        if(LogModules): 
    102105            self.log.setVisibleModules(*LogModules) 
    103106 
     
    116119def main(): 
    117120    """Application code starts from here""" 
    118     app = PARPG() 
     121    app=PARPG() 
    119122    app.run() 
    120123 
Note: See TracChangeset for help on using the changeset viewer.