comparison src/parpg/application.py @ 12:d60f1dab8469

Fixed resource path dependencies issue that caused PARPG to crash on start. * PARPG should now run without issue (system installation not tested). * Utilized FIFE's VFS module to remove path dependencies from most PARPG modules. * The new parpg.vfs module is a singleton with a single global variable, VFS, which is a reference to the global VFS instance. Although a singleton is not ideal it should be replaced once PARPG's core code is refactored. * The parpg.vfs singleton is initialized in the parpg.applicaiton.PARPGApplication class with the absolute path to the data directory via the parpg.settings module and corresponding configuration file. * A new DataPath entry was added to the default system configuration file template under the [parpg] section to support the new parpg.vfs module. * Updated the parpg-assets subrepo to revision 3 to fix some dialog file format issues (for details see commit message for parpg-assets). * Fixed a few bugs in the parpg.dialogueparsers.YAMLDialogueParser class related to exception handling.
author M. George Hansen <technopolitica@gmail.com>
date Mon, 06 Jun 2011 15:56:14 -1000
parents 1fd2201f5c36
children 94cb5843dcbb
comparison
equal deleted inserted replaced
11:4706e0194af3 12:d60f1dab8469
19 from fife import fife 19 from fife import fife
20 from fife.extensions import pychan 20 from fife.extensions import pychan
21 from fife.extensions.serializers.xmlanimation import XMLAnimationLoader 21 from fife.extensions.serializers.xmlanimation import XMLAnimationLoader
22 from fife.extensions.basicapplication import ApplicationBase 22 from fife.extensions.basicapplication import ApplicationBase
23 23
24 from parpg import console 24 from parpg import console, vfs
25 from parpg.font import PARPGFont 25 from parpg.font import PARPGFont
26 from parpg.gamemodel import GameModel 26 from parpg.gamemodel import GameModel
27 from parpg.mainmenuview import MainMenuView 27 from parpg.mainmenuview import MainMenuView
28 from parpg.mainmenucontroller import MainMenuController 28 from parpg.mainmenucontroller import MainMenuController
29 from parpg.common.listeners.event_listener import EventListener 29 from parpg.common.listeners.event_listener import EventListener
114 @return: None""" 114 @return: None"""
115 self._setting = setting 115 self._setting = setting
116 self.engine = fife.Engine() 116 self.engine = fife.Engine()
117 self.loadSettings() 117 self.loadSettings()
118 self.engine.init() 118 self.engine.init()
119 # KLUDGE M. George Hansen 2011-06-04: See parpg/vfs.py.
120 vfs.VFS = self.engine.getVFS()
121 vfs.VFS.addNewSource(setting.parpg.DataPath)
119 self._animationloader = XMLAnimationLoader(self.engine.getImagePool(), 122 self._animationloader = XMLAnimationLoader(self.engine.getImagePool(),
120 self.engine.getVFS()) 123 self.engine.getVFS())
121 self.engine.getAnimationPool().addResourceLoader(self._animationloader) 124 self.engine.getAnimationPool().addResourceLoader(self._animationloader)
122 125
123 pychan.init(self.engine, debug = True) 126 pychan.init(self.engine, debug = True)
131 self.model.readMapFiles() 134 self.model.readMapFiles()
132 self.model.readObjectDB() 135 self.model.readObjectDB()
133 self.model.getAgentImportFiles() 136 self.model.getAgentImportFiles()
134 self.model.readAllAgents() 137 self.model.readAllAgents()
135 self.model.getDialogues() 138 self.model.getDialogues()
139 # KLUDGE M. George Hansen 2011-06-04: Hack to allow loaded PyChan XML
140 # scripts to locate their resources.
141 os.chdir(setting.parpg.DataPath)
136 self.view = MainMenuView(self.engine, self.model) 142 self.view = MainMenuView(self.engine, self.model)
137 self.loadFonts() 143 self.loadFonts()
138 self.event_listener = EventListener(self.engine) 144 self.event_listener = EventListener(self.engine)
139 self.controllers = [] 145 self.controllers = []
140 controller = MainMenuController(self.engine, self.view, self.model, 146 controller = MainMenuController(self.engine, self.view, self.model,
148 #start_map = self._setting.fife.get("PARPG", "Map") 154 #start_map = self._setting.fife.get("PARPG", "Map")
149 #self.model.changeMap(start_map) 155 #self.model.changeMap(start_map)
150 156
151 def loadFonts(self): 157 def loadFonts(self):
152 # add the fonts path to the system path to import font definitons 158 # add the fonts path to the system path to import font definitons
153 sys.path.insert(0, os.path.join(self._setting.system_path, 159 sys.path.insert(0, os.path.join(self._setting.parpg.DataPath, 'fonts'))
154 self._setting.fife.FontsPath))
155 from oldtypewriter import fontdefs 160 from oldtypewriter import fontdefs
156 161
157 for fontdef in fontdefs: 162 for fontdef in fontdefs:
158 pychan.internal.get_manager().addFont(PARPGFont(fontdef, 163 pychan.internal.get_manager().addFont(PARPGFont(fontdef,
159 self._setting)) 164 self._setting))
165 Called in the ApplicationBase constructor. 170 Called in the ApplicationBase constructor.
166 """ 171 """
167 172
168 engineSetting = self.engine.getSettings() 173 engineSetting = self.engine.getSettings()
169 engineSetting.setDefaultFontGlyphs(self._setting.fife.FontGlyphs) 174 engineSetting.setDefaultFontGlyphs(self._setting.fife.FontGlyphs)
170 engineSetting.setDefaultFontPath(os.path.join(self._setting.system_path, 175 engineSetting.setDefaultFontPath(
171 self._setting.fife.FontsPath, 176 '{0}/fonts/{1}'.format(self._setting.parpg.DataPath,
172 self._setting.fife.Font)) 177 self._setting.fife.Font)
178 )
173 engineSetting.setDefaultFontSize(self._setting.fife.DefaultFontSize) 179 engineSetting.setDefaultFontSize(self._setting.fife.DefaultFontSize)
174 engineSetting.setBitsPerPixel(self._setting.fife.BitsPerPixel) 180 engineSetting.setBitsPerPixel(self._setting.fife.BitsPerPixel)
175 engineSetting.setInitialVolume(self._setting.fife.InitialVolume) 181 engineSetting.setInitialVolume(self._setting.fife.InitialVolume)
176 engineSetting.setSDLRemoveFakeAlpha(self._setting.fife.SDLRemoveFakeAlpha) 182 engineSetting.setSDLRemoveFakeAlpha(self._setting.fife.SDLRemoveFakeAlpha)
177 engineSetting.setScreenWidth(self._setting.fife.ScreenWidth) 183 engineSetting.setScreenWidth(self._setting.fife.ScreenWidth)
184 190
185 engineSetting.setColorKey(*[int(digit) 191 engineSetting.setColorKey(*[int(digit)
186 for digit in self._setting.fife.ColorKey]) 192 for digit in self._setting.fife.ColorKey])
187 193
188 engineSetting.setWindowTitle(self._setting.fife.WindowTitle) 194 engineSetting.setWindowTitle(self._setting.fife.WindowTitle)
189 engineSetting.setWindowIcon(os.path.join(self._setting.system_path, 195 engineSetting.setWindowIcon(
190 self._setting.fife.IconsPath, 196 '/'.join(['gui/icons', self._setting.fife.WindowIcon])
191 self._setting.fife.WindowIcon)) 197 )
192 198
193 def createListener(self): 199 def createListener(self):
194 """ __init__ takes care of creating an event listener, so 200 """ __init__ takes care of creating an event listener, so
195 basicapplication's createListener is harmful. Without 201 basicapplication's createListener is harmful. Without
196 overriding it, the program quit's on esc press, rather than 202 overriding it, the program quit's on esc press, rather than