Mercurial > fife-parpg
comparison clients/rio_de_hola/run.py @ 121:ae3b8139c7c7
* Applying settings patch by greyghost
* See: #274
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 05 Aug 2008 14:44:15 +0000 |
parents | 5f32bfdc4232 |
children | bb9902910067 |
comparison
equal
deleted
inserted
replaced
120:e21b1a26fa5f | 121:ae3b8139c7c7 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # coding: utf-8 | 2 # coding: utf-8 |
3 # This is the rio de hola client for FIFE. | 3 # This is the rio de hola client for FIFE. |
4 | 4 |
5 import sys, os, re, math, random | 5 import sys, os, re, math, random, shutil |
6 | 6 |
7 def _jp(path): | 7 def _jp(path): |
8 return os.path.sep.join(path.split('/')) | 8 return os.path.sep.join(path.split('/')) |
9 | 9 |
10 _paths = ('../../engine/swigwrappers/python', '../../engine/extensions') | 10 _paths = ('../../engine/swigwrappers/python', '../../engine/extensions') |
11 for p in _paths: | 11 for p in _paths: |
12 if p not in sys.path: | 12 if p not in sys.path: |
13 sys.path.append(_jp(p)) | 13 sys.path.append(_jp(p)) |
14 | 14 |
15 if not os.path.exists('settings.xml'): | |
16 shutil.copyfile('settings-dist.xml', 'settings.xml') | |
17 | |
15 import fife, fifelog | 18 import fife, fifelog |
16 from scripts import world | 19 from scripts import world |
17 from scripts.common import eventlistenerbase | 20 from scripts.common import eventlistenerbase |
18 from basicapplication import ApplicationBase | 21 from basicapplication import ApplicationBase |
19 import pychan | 22 import pychan |
20 import pychan.widgets as widgets | 23 import pychan.widgets as widgets |
21 import settings as TDS | 24 from settings import Setting |
22 | 25 |
26 TDS = Setting() | |
23 | 27 |
24 class ApplicationListener(eventlistenerbase.EventListenerBase): | 28 class ApplicationListener(eventlistenerbase.EventListenerBase): |
25 def __init__(self, engine, world): | 29 def __init__(self, engine, world): |
26 super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True) | 30 super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True) |
27 self.engine = engine | 31 self.engine = engine |
39 | 43 |
40 self.rootpanel = pychan.loadXML('gui/rootpanel.xml') | 44 self.rootpanel = pychan.loadXML('gui/rootpanel.xml') |
41 self.rootpanel.mapEvents({ | 45 self.rootpanel.mapEvents({ |
42 'quitButton' : self.onQuitButtonPress, | 46 'quitButton' : self.onQuitButtonPress, |
43 'aboutButton' : self.onAboutButtonPress, | 47 'aboutButton' : self.onAboutButtonPress, |
48 'optionsButton' : TDS.onOptionsPress | |
44 }) | 49 }) |
45 self.rootpanel.show() | 50 self.rootpanel.show() |
46 | 51 |
47 def keyPressed(self, evt): | 52 def keyPressed(self, evt): |
48 keyval = evt.getKey().getValue() | 53 keyval = evt.getKey().getValue() |
93 self.aboutWindow = pychan.loadXML('gui/help.xml') | 98 self.aboutWindow = pychan.loadXML('gui/help.xml') |
94 self.aboutWindow.mapEvents({ 'closeButton' : self.aboutWindow.hide }) | 99 self.aboutWindow.mapEvents({ 'closeButton' : self.aboutWindow.hide }) |
95 self.aboutWindow.distributeData({ 'helpText' : open("misc/infotext.txt").read() }) | 100 self.aboutWindow.distributeData({ 'helpText' : open("misc/infotext.txt").read() }) |
96 self.aboutWindow.show() | 101 self.aboutWindow.show() |
97 | 102 |
98 | |
99 class IslandDemo(ApplicationBase): | 103 class IslandDemo(ApplicationBase): |
100 def __init__(self): | 104 def __init__(self): |
101 super(IslandDemo,self).__init__() | 105 super(IslandDemo,self).__init__() |
102 pychan.init(self.engine, debug=TDS.PychanDebug) | 106 pychan.init(self.engine, debug=TDS.readSetting("PychanDebug", type='bool')) |
103 self.world = world.World(self.engine) | 107 self.world = world.World(self.engine) |
104 self.listener = ApplicationListener(self.engine, self.world) | 108 self.listener = ApplicationListener(self.engine, self.world) |
105 self.world.load(TDS.MapFile) | 109 self.world.load(str(TDS.readSetting("MapFile"))) |
106 | 110 |
107 self.soundmanager = self.engine.getSoundManager() | 111 self.soundmanager = self.engine.getSoundManager() |
108 self.soundmanager.init() | 112 self.soundmanager.init() |
109 | 113 |
110 if TDS.PlaySounds: | 114 if int(TDS.readSetting("PlaySounds")): |
111 # play track as background music | 115 # play track as background music |
112 emitter = self.soundmanager.createEmitter() | 116 emitter = self.soundmanager.createEmitter() |
113 id = self.engine.getSoundClipPool().addResourceFromFile('music/rio_de_hola.ogg') | 117 id = self.engine.getSoundClipPool().addResourceFromFile('music/rio_de_hola.ogg') |
114 emitter.setSoundClip(id) | 118 emitter.setSoundClip(id) |
115 emitter.setLooping(True) | 119 emitter.setLooping(True) |
116 emitter.play() | 120 emitter.play() |
121 | |
122 def loadSettings(self): | |
123 """ | |
124 Load the settings from a python file and load them into the engine. | |
125 Called in the ApplicationBase constructor. | |
126 """ | |
127 import settings | |
128 self.settings = settings | |
129 | |
130 engineSetting = self.engine.getSettings() | |
131 engineSetting.setDefaultFontGlyphs(str(TDS.readSetting("FontGlyphs", strip=False))) | |
132 engineSetting.setDefaultFontPath(str(TDS.readSetting("Font"))) | |
133 engineSetting.setDefaultFontSize(12) | |
134 engineSetting.setBitsPerPixel(int(TDS.readSetting("BitsPerPixel"))) | |
135 engineSetting.setInitialVolume(float(TDS.readSetting("InitialVolume"))) | |
136 engineSetting.setSDLRemoveFakeAlpha(int(TDS.readSetting("SDLRemoveFakeAlpha"))) | |
137 engineSetting.setScreenWidth(int(TDS.readSetting("ScreenWidth"))) | |
138 engineSetting.setScreenHeight(int(TDS.readSetting("ScreenHeight"))) | |
139 engineSetting.setRenderBackend(str(TDS.readSetting("RenderBackend"))) | |
140 engineSetting.setFullScreen(int(TDS.readSetting("FullScreen"))) | |
141 | |
142 try: | |
143 engineSetting.setWindowTitle(str(TDS.readSetting("WindowTitle"))) | |
144 engineSetting.setWindowIcon(str(TDS.readSetting("WindowIcon"))) | |
145 except: | |
146 pass | |
147 try: | |
148 engineSetting.setImageChunkingSize(int(TDS.readSetting("ImageChunkSize"))) | |
149 except: | |
150 pass | |
151 | |
152 def initLogging(self): | |
153 """ | |
154 Initialize the LogManager. | |
155 """ | |
156 LogModules = TDS.readSetting("LogModules", type='list') | |
157 self.log = fifelog.LogManager(self.engine, int(TDS.readSetting("LogToPrompt")), int(TDS.readSetting("LogToFile"))) | |
158 if LogModules: | |
159 self.log.setVisibleModules(*LogModules) | |
117 | 160 |
118 def createListener(self): | 161 def createListener(self): |
119 pass # already created in constructor | 162 pass # already created in constructor |
120 | 163 |
121 def _pump(self): | 164 def _pump(self): |
129 app = IslandDemo() | 172 app = IslandDemo() |
130 app.run() | 173 app.run() |
131 | 174 |
132 | 175 |
133 if __name__ == '__main__': | 176 if __name__ == '__main__': |
134 if TDS.ProfilingOn: | 177 if TDS.readSetting("ProfilingOn", type='bool'): |
135 import hotshot, hotshot.stats | 178 import hotshot, hotshot.stats |
136 print "Starting profiler" | 179 print "Starting profiler" |
137 prof = hotshot.Profile("fife.prof") | 180 prof = hotshot.Profile("fife.prof") |
138 prof.runcall(main) | 181 prof.runcall(main) |
139 prof.close() | 182 prof.close() |
141 stats = hotshot.stats.load("fife.prof") | 184 stats = hotshot.stats.load("fife.prof") |
142 stats.strip_dirs() | 185 stats.strip_dirs() |
143 stats.sort_stats('time', 'calls') | 186 stats.sort_stats('time', 'calls') |
144 stats.print_stats(20) | 187 stats.print_stats(20) |
145 else: | 188 else: |
146 if TDS.UsePsyco: | 189 if TDS.readSetting("UsePsyco", type='bool'): |
147 # Import Psyco if available | 190 # Import Psyco if available |
148 try: | 191 try: |
149 import psyco | 192 import psyco |
150 psyco.full() | 193 psyco.full() |
151 print "Psyco acceleration in use" | 194 print "Psyco acceleration in use" |