source: trunk/game/run.py @ 674

Revision 674, 3.3 KB checked in by technomage, 9 years ago (diff)

Patch by Technomage

  • Modified the sha-bang line (#!) of the top-level entry scripts to search for python2 rather than python, since some linux systems now default to python 3.x which would break PARPG on those systems.
  • Some general cleanup of the dialogue_demo.py script.
  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#!/usr/bin/env python2
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 os
17import shutil
18import imp
19import sys
20
21#Check if config.py exists. Get 'fife_path' from config
22try:
23        import config
24        sys.path.append(config.fife_path)
25except:
26        pass
27
28try:
29        from fife import fife
30        print "Using the FIFE python module found here: ", \
31                os.path.dirname(fife.__file__)
32except ImportError:
33        print "====================================================================== \n\
34FIFE was not found in path. \n\
35Try installing FIFE or creating config.py in the PARPG root directory, \n\
36with a variable pointing to the 'python' subdirectory \n\
37fife_path='<path_to_your_FIFE>' \n\
38Example: fife_path='../fife/engine/python/' \n\
39======================================================================"
40
41from scripts.parpg import PARPGApplication
42from scripts.common.utils import loadSettings
43
44from scripts.common import utils
45
46# add paths to the swig extensions
47utils.addPaths ('../../engine/swigwrappers/python', '../../engine/extensions')
48utils.addPaths ('./lib', './lib/extensions')
49
50
51"""This folder holds the main meta-data for PARPG. This file should be
52   minimal, since folding code into the controller with MVC is usually bad
53   All game and logic and data is held held and referenced in
54   /scripts/engine.py. All fife stuff goes in /scripts/world.py"""
55
56def main_is_frozen():
57    """returns True when running the exe,
58    and False when running from a script. """
59    return (hasattr(sys, "frozen") or # new py2exe
60            hasattr(sys, "importers") # old py2exe
61            or imp.is_frozen("__main__")) # tools/freeze
62
63def get_main_dir():
64    """returns the directory name of the script
65    or the directory name of the exe"""
66    if main_is_frozen():
67        return os.path.dirname(sys.executable)
68    return os.path.dirname(sys.argv[0])
69
70
71def main():
72    """Application code starts from here"""
73    if not main_is_frozen():
74        version = loadSettings().get("PARPG", "SettingsVersion")
75        dist_version = loadSettings("./settings-dist.xml").get("PARPG", "SettingsVersion")
76        if (version != dist_version):
77            print "Newer settings-dist.xml found, renaming settings.xml to settings-old.xml"
78            shutil.copyfile('./settings.xml', './settings-old.xml')
79            shutil.copyfile('./settings-dist.xml', './settings.xml')
80    app = PARPGApplication(loadSettings())
81    app.run()
82
83if __name__ == '__main__':
84    if loadSettings().get("FIFE", "UsePsyco"):
85        # Import Psyco if available
86        try:
87            import psyco
88            psyco.full()
89            print "Psyco acceleration in use"
90        except ImportError:
91            print "Psyco acceleration not used"
92    else:
93        print "Psyco acceleration not used"
94    main()
95
Note: See TracBrowser for help on using the repository browser.