source: trunk/PARPG/run.py @ 66

Revision 66, 4.9 KB checked in by maximinus_parpg, 11 years ago (diff)

OK, you win Bretzel...
Lots of small annoying PEP 8 standards correction.

  • Property svn:executable set to *
Line 
1#!/usr/bin/python
2
3#   This program is free software: you can redistribute it and/or modify
4#   it under the terms of the GNU General Public License as published by
5#   the Free Software Foundation, either version 3 of the License, or
6#   (at your option) any later version.
7
8#   This program is distributed in the hope that it will be useful,
9#   but WITHOUT ANY WARRANTY; without even the implied warranty of
10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11#   GNU General Public License for more details.
12
13#   You should have received a copy of the GNU General Public License
14#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16import sys, os, shutil
17
18from scripts.common import utils
19# add paths to the swig extensions
20utils.addPaths ('../../engine/swigwrappers/python', '../../engine/extensions')
21
22import fife_compat
23import fife,fifelog
24from scripts import world
25from scripts import engine
26from scripts.common import eventlistenerbase
27from basicapplication import ApplicationBase
28from settings import Setting
29
30TDS = Setting()
31
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
37class ApplicationListener(eventlistenerbase.EventListenerBase):
38    def __init__(self, engine, world):
39        super(ApplicationListener, self).__init__(engine,
40                                                  regKeys=True,regCmd=True,
41                                                  regMouse=False, 
42                                                  regConsole=True,
43                                                  regWidget=True)
44        self.engine = engine
45        self.world = world
46        engine.getEventManager().setNonConsumableKeys([fife.Key.ESCAPE,])
47        self.quit = False
48        self.aboutWindow = None
49
50    def quitGame(self):
51        """Forces a quit game on next cycle"""
52        self.quit = True
53
54    def onCommand(self, command):
55        """Enables the game to be closed via the 'X' button on the window frame"""
56        if(command.getCommandType() == fife.CMD_QUIT_GAME):
57            self.quit = True
58            command.consume()
59
60class PARPG(ApplicationBase):
61    """Main Application class
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"""
65    def __init__(self):
66        super(PARPG,self).__init__()
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
71        self.model.loadMap(str(TDS.readSetting("MapFile")))   
72
73    def loadSettings(self):
74        """Load the settings from a python file and load them into the engine.
75           Called in the ApplicationBase constructor."""
76        import settings
77        self.settings = settings
78        eSet=self.engine.getSettings()
79        eSet.setDefaultFontGlyphs(str(TDS.readSetting("FontGlyphs",
80                                                      strip=False)))
81        eSet.setDefaultFontPath(str(TDS.readSetting("Font")))
82        eSet.setBitsPerPixel(int(TDS.readSetting("BitsPerPixel")))
83        eSet.setInitialVolume(float(TDS.readSetting("InitialVolume")))
84        eSet.setSDLRemoveFakeAlpha(int(TDS.readSetting("SDLRemoveFakeAlpha")))
85        eSet.setScreenWidth(int(TDS.readSetting("ScreenWidth")))
86        eSet.setScreenHeight(int(TDS.readSetting("ScreenHeight")))
87        eSet.setRenderBackend(str(TDS.readSetting("RenderBackend")))
88        eSet.setFullScreen(int(TDS.readSetting("FullScreen")))
89        try:
90            eSet.setWindowTitle(str(TDS.readSetting("WindowTitle")))
91            eSet.setWindowIcon(str(TDS.readSetting("WindowIcon")))
92        except:
93            pass           
94        try:
95            eSet.setImageChunkingSize(int(TDS.readSetting("ImageChunkSize")))
96        except:
97            pass
98
99    def initLogging(self):
100        """Initialize the LogManager"""
101        LogModules = TDS.readSetting("LogModules",type='list')
102        self.log = fifelog.LogManager(self.engine,
103                                      int(TDS.readSetting("LogToPrompt")),
104                                      int(TDS.readSetting("LogToFile")))
105        if(LogModules):
106            self.log.setVisibleModules(*LogModules)
107
108    def createListener(self):
109        # already created in constructor
110        # but if we don't put here, Fife gets bitchy :-)
111        pass
112
113    def _pump(self):
114        """Main game loop
115           There are in fact 2 main loops, this one and the one in World"""
116        if self.listener.quit:
117            self.breakRequested = True
118        else:
119            self.world.pump()
120
121def main():
122    """Application code starts from here"""
123    app = PARPG()
124    app.run()
125
126if __name__ == '__main__':
127    main()
128
Note: See TracBrowser for help on using the repository browser.