source: trunk/game/run.py @ 401

Revision 401, 6.3 KB checked in by Kaydeth_parpg, 10 years ago (diff)

Ticket #113: Patch by Kaydeth. First version of a windows packaging script made with the NSIS scripting language. Had to add a new icon file because the installer will only accept files saved with a ".ico" suffix. Also updated run.py to look for all the FIFE dependencies in a lib subdirectory.

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