source: trunk/game/run.py @ 473

Revision 473, 6.4 KB checked in by maximinus_parpg, 10 years ago (diff)

Added chewies patch to make parpg FIFE 0.3.0 compatible.
Thanks to the FIFE devs for all their work!
You now need FIFE 0.3.0 to run parpg.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#!/usr/bin/env 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, re
17
18from scripts.common import utils
19# add paths to the swig extensions
20utils.addPaths ('../../engine/swigwrappers/python', '../../engine/extensions')
21utils.addPaths ('./lib', './lib/extensions')
22
23if not os.path.exists('settings.xml'):
24    shutil.copyfile('settings-dist.xml', 'settings.xml')
25
26from fife import fife
27from fife.extensions import fife_compat, fifelog, pychan
28from fife.extensions.basicapplication import ApplicationBase
29
30from scripts import world
31from scripts import engine
32from scripts import console
33from scripts.engine import Engine
34from scripts.common import eventlistenerbase
35from settings import Setting
36
37TDS = Setting()
38
39"""This folder holds the main meta-data for PARPG. This file should be
40   minimal, since folding code into the controller with MVC is usually bad
41   All game and logic and data is held held and referenced in
42   /scripts/engine.py. All fife stuff goes in /scripts/world.py"""
43
44class ApplicationListener(eventlistenerbase.EventListenerBase):
45    def __init__(self, engine, world, model):
46        """Initialise the instance.
47           @type engine: fife.Engine
48           @param engine: ???
49           @type world: world.World
50           @param world: ???
51           @type model: engine.Engine
52           @param model: an instance of PARPG's engine"""
53        super(ApplicationListener, self).__init__(engine,
54                                                  reg_keys=True,reg_cmd=True,
55                                                  reg_mouse=False, 
56                                                  reg_console=True,
57                                                  reg_widget=True)
58        self.engine = engine
59        self.world = world
60        self.model = model
61        engine.getEventManager().setNonConsumableKeys([fife.Key.ESCAPE,])
62        self.quit = False
63        self.aboutWindow = None
64        self.console=console.Console(self)
65
66    def quitGame(self):
67        """Forces a quit game on next cycle.
68           @return: None"""
69        self.quit = True
70
71    def onConsoleCommand(self, command):
72        """
73        Called on every console comand, delegates calls  to the a console
74        object, implementing the callbacks
75        @type command: string
76        @param command: the command to run
77        @return: result
78        """
79
80        return self.console.handleConsoleCommand(command)
81
82    def onCommand(self, command):
83        """Enables the game to be closed via the 'X' button on the window frame
84           @type command: fife.Command
85           @param command: The command to read.
86           @return: None"""
87        if(command.getCommandType() == fife.CMD_QUIT_GAME):
88            self.quit = True
89            command.consume()
90
91class PARPG(ApplicationBase):
92    """Main Application class
93       We use an MVC data model.
94       self.world is our view,self.engine is our model
95       This file is the minimal controller"""
96    def __init__(self):
97        """Initialise the instance.
98           @return: None"""
99        super(PARPG,self).__init__()
100        self.world = world.World(self.engine)
101        self.model = engine.Engine(self.world)
102        self.world.data = self.model
103        self.world.initHud()
104        self.listener = ApplicationListener(self.engine,self.world,self.model)
105        self.world.quitFunction = self.listener.quitGame
106        self.model.loadMap("main-map", str(TDS.readSetting("MapFile")))
107        pychan.init(self.engine, debug = True)
108
109    def loadSettings(self):
110        """Load the settings from a python file and load them into the engine.
111           Called in the ApplicationBase constructor.
112           @return: None"""
113        import settings
114        self.settings = settings
115        e_set = self.engine.getSettings()
116        e_set.setDefaultFontGlyphs(str(TDS.readSetting("FontGlyphs",
117                                                      strip=False)))
118        e_set.setDefaultFontPath(str(TDS.readSetting("Font")))
119        e_set.setDefaultFontSize(int(TDS.readSetting("FontSize", default=12)))
120        e_set.setBitsPerPixel(int(TDS.readSetting("BitsPerPixel")))
121        e_set.setInitialVolume(float(TDS.readSetting("InitialVolume")))
122        e_set.setSDLRemoveFakeAlpha(int(TDS.readSetting("SDLRemoveFakeAlpha")))
123        e_set.setScreenWidth(int(TDS.readSetting("ScreenWidth")))
124        e_set.setScreenHeight(int(TDS.readSetting("ScreenHeight")))
125        e_set.setRenderBackend(str(TDS.readSetting("RenderBackend")))
126        e_set.setFullScreen(int(TDS.readSetting("FullScreen")))
127        try:
128            e_set.setWindowTitle(str(TDS.readSetting("WindowTitle")))
129            e_set.setWindowIcon(str(TDS.readSetting("WindowIcon")))
130        except:
131            pass           
132        try:
133            e_set.setImageChunkingSize(int(TDS.readSetting("ImageChunkSize")))
134        except:
135            pass
136
137    def initLogging(self):
138        """Initialize the LogManager.
139           @return: None"""
140        LogModules = TDS.readSetting("LogModules",type='list')
141        self.log = fifelog.LogManager(self.engine,
142                                      int(TDS.readSetting("LogToPrompt")),
143                                      int(TDS.readSetting("LogToFile")))
144        if(LogModules):
145            self.log.setVisibleModules(*LogModules)
146
147    def createListener(self):
148        """@return: None"""
149        # already created in constructor
150        # but if we don't put one here, Fife gets all fussy :-)
151        pass
152
153    def _pump(self):
154        """Main game loop.
155           There are in fact 2 main loops, this one and the one in World.
156           @return: None"""
157        if self.listener.quit:
158            self.breakRequested = True
159        else:
160            self.model.pump()
161            self.world.pump()
162
163def main():
164    """Application code starts from here"""
165    app = PARPG()
166    app.run()
167
168if __name__ == '__main__':
169    main()
170
Note: See TracBrowser for help on using the repository browser.