diff application.py @ 2:06145a6ee387

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 7a89ea5404b1
children 708a6f651c31
line wrap: on
line diff
--- a/application.py	Tue May 31 02:46:20 2011 -0700
+++ b/application.py	Mon Jun 06 15:56:14 2011 -1000
@@ -21,7 +21,7 @@
 from fife.extensions.serializers.xmlanimation import XMLAnimationLoader
 from fife.extensions.basicapplication import ApplicationBase
 
-from parpg import console
+from parpg import console, vfs
 from parpg.font import PARPGFont
 from parpg.gamemodel import GameModel
 from parpg.mainmenuview import MainMenuView
@@ -116,6 +116,9 @@
         self.engine = fife.Engine()
         self.loadSettings()
         self.engine.init()
+        # KLUDGE M. George Hansen 2011-06-04: See parpg/vfs.py.
+        vfs.VFS = self.engine.getVFS()
+        vfs.VFS.addNewSource(setting.parpg.DataPath)
         self._animationloader = XMLAnimationLoader(self.engine.getImagePool(),
                                                    self.engine.getVFS())
         self.engine.getAnimationPool().addResourceLoader(self._animationloader)
@@ -133,6 +136,9 @@
         self.model.getAgentImportFiles()
         self.model.readAllAgents()
         self.model.getDialogues()
+        # KLUDGE M. George Hansen 2011-06-04: Hack to allow loaded PyChan XML
+        #     scripts to locate their resources.
+        os.chdir(setting.parpg.DataPath)
         self.view = MainMenuView(self.engine, self.model)
         self.loadFonts()
         self.event_listener = EventListener(self.engine)
@@ -150,8 +156,7 @@
 
     def loadFonts(self):
         # add the fonts path to the system path to import font definitons
-        sys.path.insert(0, os.path.join(self._setting.system_path, 
-                                        self._setting.fife.FontsPath))
+        sys.path.insert(0, os.path.join(self._setting.parpg.DataPath, 'fonts'))
         from oldtypewriter import fontdefs
 
         for fontdef in fontdefs:
@@ -167,9 +172,10 @@
 
         engineSetting = self.engine.getSettings()
         engineSetting.setDefaultFontGlyphs(self._setting.fife.FontGlyphs)
-        engineSetting.setDefaultFontPath(os.path.join(self._setting.system_path,
-                                                   self._setting.fife.FontsPath,
-                                                   self._setting.fife.Font))
+        engineSetting.setDefaultFontPath(
+            '{0}/fonts/{1}'.format(self._setting.parpg.DataPath,
+                                   self._setting.fife.Font)
+        )
         engineSetting.setDefaultFontSize(self._setting.fife.DefaultFontSize)
         engineSetting.setBitsPerPixel(self._setting.fife.BitsPerPixel)
         engineSetting.setInitialVolume(self._setting.fife.InitialVolume)
@@ -186,9 +192,9 @@
                                     for digit in self._setting.fife.ColorKey])
 
         engineSetting.setWindowTitle(self._setting.fife.WindowTitle)
-        engineSetting.setWindowIcon(os.path.join(self._setting.system_path, 
-                                                 self._setting.fife.IconsPath,
-                                                 self._setting.fife.WindowIcon))
+        engineSetting.setWindowIcon(
+            '/'.join(['gui/icons', self._setting.fife.WindowIcon])
+        )
 
     def createListener(self):
         """ __init__ takes care of creating an event listener, so