source: trunk/PARPG/run.py @ 62

Revision 62, 4.8 KB checked in by maximinus_parpg, 11 years ago (diff)

Large restructure of PC and NPC classes.
Data seperation is a lot cleaner.
Again some old Rio code removed.

  • 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",strip=False)))
80        eSet.setDefaultFontPath(str(TDS.readSetting("Font")))
81        eSet.setBitsPerPixel(int(TDS.readSetting("BitsPerPixel")))
82        eSet.setInitialVolume(float(TDS.readSetting("InitialVolume")))
83        eSet.setSDLRemoveFakeAlpha(int(TDS.readSetting("SDLRemoveFakeAlpha")))
84        eSet.setScreenWidth(int(TDS.readSetting("ScreenWidth")))
85        eSet.setScreenHeight(int(TDS.readSetting("ScreenHeight")))
86        eSet.setRenderBackend(str(TDS.readSetting("RenderBackend")))
87        eSet.setFullScreen(int(TDS.readSetting("FullScreen")))
88        try:
89            eSet.setWindowTitle(str(TDS.readSetting("WindowTitle")))
90            eSet.setWindowIcon(str(TDS.readSetting("WindowIcon")))
91        except:
92            pass           
93        try:
94            eSet.setImageChunkingSize(int(TDS.readSetting("ImageChunkSize")))
95        except:
96            pass
97
98    def initLogging(self):
99        """Initialize the LogManager"""
100        LogModules=TDS.readSetting("LogModules",type='list')
101        self.log=fifelog.LogManager(self.engine,
102                                      int(TDS.readSetting("LogToPrompt")),
103                                      int(TDS.readSetting("LogToFile")))
104        if(LogModules):
105            self.log.setVisibleModules(*LogModules)
106
107    def createListener(self):
108        # already created in constructor
109        pass
110
111    def _pump(self):
112        """Main game loop
113           There are in fact 2 main loops, this one and the one in World"""
114        if self.listener.quit:
115            self.breakRequested = True
116        else:
117            self.world.pump()
118
119def main():
120    """Application code starts from here"""
121    app=PARPG()
122    app.run()
123
124if __name__ == '__main__':
125    main()
126
Note: See TracBrowser for help on using the repository browser.