Changeset 828
- Timestamp:
- 04/03/11 22:43:05 (9 years ago)
- Location:
- trunk/game
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/game/dialogue_demo.py
r818 r828 87 87 """ 88 88 dialogue_dir = os.path.join(settings.system_path, 89 settings.parpg.Dialogues Directory)89 settings.parpg.DialoguesPath) 90 90 dialogue_files = [file_name for file_name in os.listdir(dialogue_dir) 91 91 if file_name.endswith('.yaml')] -
trunk/game/parpg/application.py
r818 r828 15 15 16 16 import os 17 import sys 17 18 18 19 from fife import fife … … 22 23 23 24 from parpg import console 25 from parpg.font import PARPGFont 24 26 from parpg.gamemodel import GameModel 25 27 from parpg.mainmenuview import MainMenuView … … 113 115 self._setting = setting 114 116 self.engine = fife.Engine() 115 fonts_dir = os.path.join(self._setting.system_path,116 self._setting.fife.FontsDirectory)117 self.fonts_directory = fonts_dir118 117 self.loadSettings() 119 118 self.engine.init() … … 136 135 self.model.getDialogues() 137 136 self.view = MainMenuView(self.engine, self.model) 138 self.loadFonts( self.fonts_directory)137 self.loadFonts() 139 138 self.event_listener = EventListener(self.engine) 140 139 self.controllers = [] … … 150 149 #self.model.changeMap(start_map) 151 150 152 def loadFonts(self, fonts_directory): 153 file_names = os.listdir(fonts_directory) 154 for file_name in file_names: 155 base_name, extension = os.path.splitext(file_name) 156 if extension == '.fontdef': 157 file_path = os.path.join(fonts_directory, file_name) 158 pychan.loadFonts(file_path) 151 def loadFonts(self): 152 # add the fonts path to the system path to import font definitons 153 sys.path.insert(0, os.path.join(self._setting.system_path, 154 self._setting.fife.FontsPath)) 155 from oldtypewriter import fontdefs 156 157 for fontdef in fontdefs: 158 pychan.internal.get_manager().addFont(PARPGFont(fontdef, 159 self._setting)) 160 159 161 160 162 def loadSettings(self): … … 166 168 engineSetting = self.engine.getSettings() 167 169 engineSetting.setDefaultFontGlyphs(self._setting.fife.FontGlyphs) 168 engineSetting.setDefaultFontPath(os.path.join(self.fonts_directory, 169 self._setting.fife.Font)) 170 engineSetting.setDefaultFontPath(os.path.join(self._setting.system_path, 171 self._setting.fife.FontsPath, 172 self._setting.fife.Font)) 170 173 engineSetting.setDefaultFontSize(self._setting.fife.DefaultFontSize) 171 174 engineSetting.setBitsPerPixel(self._setting.fife.BitsPerPixel) … … 185 188 engineSetting.setWindowTitle(self._setting.fife.WindowTitle) 186 189 engineSetting.setWindowIcon(os.path.join(self._setting.system_path, 187 self._setting.fife.Icons Directory,190 self._setting.fife.IconsPath, 188 191 self._setting.fife.WindowIcon)) 189 192 -
trunk/game/parpg/controllerbase.py
r818 r828 85 85 @return: None""" 86 86 image = os.path.join(self.model.settings.system_path, 87 self.model.settings.parpg.Gui Directory,88 self.model.settings.parpg.Cursor Directory,87 self.model.settings.parpg.GuiPath, 88 self.model.settings.parpg.CursorPath, 89 89 self.model.settings.parpg.CursorDefault) 90 90 self.setMouseCursor(image, image) -
trunk/game/parpg/gamemodel.py
r818 r828 63 63 self.savegame = None 64 64 quests_directory = os.path.join(self.settings.system_path, 65 self.settings.parpg.Quests Directory)65 self.settings.parpg.QuestsPath) 66 66 self.game_state = GameState(quests_dir=quests_directory) 67 67 #self.game_state.quest_engine = … … 80 80 # set values from settings 81 81 maps_file = os.path.join(self.settings.system_path, 82 self.settings.parpg.Maps Directory,82 self.settings.parpg.MapsPath, 83 83 self.settings.parpg.MapsFile) 84 84 self.game_state.maps_file = maps_file 85 85 all_agents_file = os.path.join(self.settings.system_path, 86 self.settings.parpg.Maps Directory,86 self.settings.parpg.MapsPath, 87 87 self.settings.parpg.AllAgentsFile) 88 88 self.all_agents_file = all_agents_file 89 89 objects_dir = os.path.join(self.settings.system_path, 90 self.settings.parpg.Objects Directory)90 self.settings.parpg.ObjectsPath) 91 91 self.objects_directory = objects_dir 92 92 object_db_file = os.path.join(self.objects_directory, … … 94 94 self.object_db_file = object_db_file 95 95 dialogues_dir = os.path.join(self.settings.system_path, 96 self.settings.parpg.Dialogues Directory)96 self.settings.parpg.DialoguesPath) 97 97 self.dialogues_directory = dialogues_dir 98 98 self.dialogues = {} -
trunk/game/parpg/gamescenecontroller.py
r818 r828 137 137 settings = self.model.settings 138 138 screenshot_directory = os.path.join(settings.user_path, 139 settings.parpg.Screenshots Directory)139 settings.parpg.ScreenshotsPath) 140 140 # try to create the screenshots directory 141 141 try: … … 258 258 direction[1] -= 1 259 259 image = os.path.join(settings.system_path, 260 settings.parpg.Gui Directory,261 settings.parpg.Cursor Directory,260 settings.parpg.GuiPath, 261 settings.parpg.CursorPath, 262 262 settings.parpg.CursorUp) 263 263 … … 267 267 direction[1] += 1 268 268 image = os.path.join(settings.system_path, 269 settings.parpg.Gui Directory,270 settings.parpg.Cursor Directory,269 settings.parpg.GuiPath, 270 settings.parpg.CursorPath, 271 271 settings.parpg.CursorRight) 272 272 … … 276 276 direction[1] += 1 277 277 image = os.path.join(settings.system_path, 278 settings.parpg.Gui Directory,279 settings.parpg.Cursor Directory,278 settings.parpg.GuiPath, 279 settings.parpg.CursorPath, 280 280 settings.parpg.CursorDown) 281 281 … … 285 285 direction[1] -= 1 286 286 image = os.path.join(settings.system_path, 287 settings.parpg.Gui Directory,288 settings.parpg.Cursor Directory,287 settings.parpg.GuiPath, 288 settings.parpg.CursorPath, 289 289 settings.parpg.CursorLeft) 290 290 -
trunk/game/parpg/gui/filebrowser.py
r818 r828 38 38 self.engine = engine 39 39 self.settings = settings 40 print self.settings.parpg.Saves Directory40 print self.settings.parpg.SavesPath 41 41 self.file_selected = file_selected 42 42 … … 49 49 self.extensions = extensions 50 50 self.path = os.path.join(self.settings.user_path, 51 self.settings.parpg.Saves Directory)51 self.settings.parpg.SavesPath) 52 52 self.dir_list = [] 53 53 self.file_list = [] … … 66 66 self._widget = pychan.loadXML(self.gui_xml_path) 67 67 self._widget.mapEvents({ 68 'dirList' : self._set Directory,68 'dirList' : self._setPath, 69 69 'selectButton' : self._selectFile, 70 70 'closeButton' : self.close 71 71 }) 72 self._set Directory()72 self._setPath() 73 73 if self.save_file: 74 74 self._file_entry = widgets.TextField(name='saveField', text=u'') … … 77 77 self._widget.show() 78 78 79 def _set Directory(self):80 """ Directorychange callback."""79 def _setPath(self): 80 """Path change callback.""" 81 81 selection = self._widget.collectData('dirList') 82 82 if not (selection < 0): -
trunk/game/parpg/gui/hud.py
r818 r828 275 275 self.stopActions() 276 276 xml_path = os.path.join(self.settings.system_path, 277 self.settings.parpg.Gui Directory,277 self.settings.parpg.GuiPath, 278 278 'savebrowser.xml') 279 279 save_browser = FileBrowser(self.engine, … … 320 320 self.stopActions() 321 321 xml_path = os.path.join(self.settings.system_path, 322 self.settings.parpg.Gui Directory,322 self.settings.parpg.GuiPath, 323 323 'loadbrowser.xml') 324 324 load_browser = FileBrowser(self.engine, -
trunk/game/parpg/mainmenuview.py
r818 r828 83 83 @return: None""" 84 84 xml_path = os.path.join(self.model.settings.system_path, 85 self.model.settings.parpg.Gui Directory,85 self.model.settings.parpg.GuiPath, 86 86 'loadbrowser.xml') 87 87 load_browser = FileBrowser(self.engine, -
trunk/game/parpg/settings.py
r819 r828 44 44 import platform 45 45 46 #TODO: add logging to replace print statements 46 47 class Section(object): 47 48 """ An object that represents a section in a settings file. … … 129 130 and the options defined within those sections. 130 131 """ 131 def __init__(self, system_path='', user_path='', s uffix='.cfg'):132 def __init__(self, system_path='', user_path='', settings_path='', suffix='.cfg'): 132 133 """ initializes a new settings object. If no paths are given, they are 133 134 guessed based on whatever platform the script was run on. … … 163 164 self.settings_file = '' 164 165 165 if not system_path and not user_path: 166 167 self.paths = {} 168 if not system_path and not user_path and not settings_path: 166 169 # use platform-specific values as paths 167 self.paths = {}168 self.paths['system'], self.paths['user']= self.platform_paths()170 (self.paths['system'], self.paths['user'], 171 self.paths['settings']) = self.platform_paths() 169 172 else: 170 self.paths = {'system': system_path, 'user': user_path} 173 # convert supplied paths to absolute paths 174 abs_paths = [os.path.expanduser(path) 175 for path in [system_path, user_path, settings_path]] 176 (self.paths['system'], self.paths['user'], 177 self.paths['settings']) = abs_paths 171 178 172 179 self.read() … … 193 200 def platform_paths(self, system=None): 194 201 if system is None: 195 system = platform.system() 202 system = platform.system().lower() 196 203 197 if system .lower()== 'linux':198 return (os.path.join(os. environ['XDG_DATA_DIRS'].split(':')[0],199 200 os.path.join(os. environ['XDG_CONFIG_HOME'], 'parpg'))201 elif system .lower()== 'windows':204 if system == 'linux': 205 return (os.path.join(os.sep, 'usr', 'share', 'parpg'), 206 os.path.join(os.environ['XDG_CONFIG_HOME'], 'parpg'), 207 os.path.join(os.sep, 'etc', 'parpg')) 208 elif system == 'windows': 202 209 return (os.path.join(os.environ['PROGRAMFILES'], 'PARPG'), 203 os.path.join(os.environ['USERDATA'], 'PARPG')) 210 os.path.join(os.environ['USERDATA'], 'PARPG'), 211 os.path.join(os.environ['PROGRAMFILES'], 'PARPG')) 204 212 else: 213 # TODO: determine values for Mac 205 214 return None 206 215 … … 216 225 217 226 if filenames is None: 218 filenames = [os.path.join(self.paths[ key],219 ' {0}{1}'.format(key, self.suffix))220 for key in self.paths.keys()221 if self.paths[key] is not None]227 filenames = [os.path.join(self.paths['settings'], 228 'system{0}'.format(self.suffix)), 229 os.path.join(self.paths['user'], 230 'user{0}'.format(self.suffix))] 222 231 elif hasattr(filenames, 'split'): 223 232 filenames = [filenames] … … 225 234 for filename in filenames: 226 235 section = None 236 227 237 try: 228 238 self.settings_file = open(filename, 'r').readlines() 229 except IOError: 230 pass 239 except IOError as (errno, strerror): 240 if errno == 2: 241 if os.path.basename(filename).startswith('system'): 242 print ('{0} could not be found. Please supply a ' 243 'different path or generate a system settings ' 244 'file with:\n' 245 'python2 -m parpg.settings').format(filename) 246 sys.exit(1) 247 else: 248 print 'Error No. {0}: {1} {2}'.format(errno, filename, strerror) 249 sys.exit(1) 231 250 232 251 for line in self.settings_file: … … 339 358 340 359 # Subdirectory to load icons from (path) 341 Icons Directory= icons360 IconsPath = icons 342 361 343 362 # ? ([R, G, B]) … … 357 376 358 377 # Subdirectory to load fronts from (path) 359 Fonts Directory= fonts378 FontsPath = fonts 360 379 361 380 # Font to load when game starts … … 383 402 384 403 # System subdirectory to load maps from (path) 385 Maps Directory= maps404 MapsPath = maps 386 405 387 406 # YAML file that contains the available maps (filename) … … 395 414 396 415 # System subdirectory to load objects from (path) 397 Objects Directory= objects416 ObjectsPath = objects 398 417 399 418 # YAML file that contains the database of availabel objects (filename) … … 401 420 402 421 # System subdirectory to load dialogues from (path) 403 Dialogues Directory= dialogue422 DialoguesPath = dialogue 404 423 405 424 # System subdirectory to load quests from (path) 406 Quests Directory= quests425 QuestsPath = quests 407 426 408 427 # User subdirectory to save screenshots to 409 Screenshots Directory= screenshots428 ScreenshotsPath = screenshots 410 429 411 430 # User subdirectory to save games to 412 Saves Directory= saves431 SavesPath = saves 413 432 414 433 # System subdirectory where gui files are loaded from (path) 415 Gui Directory= gui434 GuiPath = gui 416 435 417 436 # System subdirectory where cursors are loaded from (path) 418 Cursor Directory= cursors437 CursorPath = cursors 419 438 420 439 # File to use for default cursor (filename) -
trunk/game/run.py
r818 r828 1 #!/usr/bin/env python2 2 1 #!/usr/bin/env python2 3 2 # This program is free software: you can redistribute it and/or modify 4 3 # it under the terms of the GNU General Public License as published by … … 19 18 20 19 from optparse import OptionParser 21 from parpg.settings import Settings22 20 23 # Python 2.6 or lower24 21 parser = OptionParser(description='PARPG Launcher Script') 25 parser.add_option('-p', '--paths', nargs=2,26 default='.',27 help='One or more paths to load settings from')28 22 parser.add_option('-f', '--logfile', 29 23 help='Name of log file to save to') 30 24 parser.add_option('-l', '--loglevel', default='critical', 31 25 help='desired output level for log file') 26 parser.add_option('-m', '--module', 27 help='location of the parpg module') 32 28 opts, args = parser.parse_args() 33 29 30 if not args: 31 #TODO: display usage message 32 sys.exit(1) 33 34 34 35 # initialize settings 35 settings = Settings(*opts.paths) 36 if opts.module: 37 sys.path.insert(0, opts.module) 38 39 from parpg.settings import Settings 40 41 settings = Settings(*args) 36 42 37 43 levels = {'debug': logging.DEBUG, … … 46 52 47 53 try: 48 sys.path.insert(0, settings.parpg.FifePath) 54 sys.path.insert(0, settings.parpg.FifePath) 49 55 except AttributeError: 50 56 logger.warning('[parpg] section has no FifePath option') … … 52 58 try: 53 59 from fife import fife 54 from parpg.application import PARPGApplication55 56 from parpg.common import utils57 60 except ImportError: 58 #TODO: pay attention to which module actually failed59 61 logger.critical("Could not import fife module. Please install fife or add " 60 62 "'FifePath' to the [parpg] section of your settings file") 61 63 sys.exit(1) 64 65 from parpg.application import PARPGApplication 66 from parpg.common import utils 62 67 63 68 # enable psyco if available and in settings file -
trunk/game/system.cfg
r818 r828 30 30 31 31 # Subdirectory to load icons from (path) 32 Icons Directory= icons32 IconsPath = icons 33 33 34 34 # ? ([R, G, B]) … … 48 48 49 49 # Subdirectory to load fronts from (path) 50 Fonts Directory= fonts50 FontsPath = fonts 51 51 52 52 # Font to load when game starts 53 #TODO: make it so that the font name is supplied instead of the filename 53 54 Font = oldtypewriter.ttf 54 55 … … 74 75 75 76 # System subdirectory to load maps from (path) 76 Maps Directory= maps77 MapsPath = maps 77 78 78 79 # YAML file that contains the available maps (filename) … … 86 87 87 88 # System subdirectory to load objects from (path) 88 Objects Directory= objects89 ObjectsPath = objects 89 90 90 91 # YAML file that contains the database of availabel objects (filename) … … 92 93 93 94 # System subdirectory to load dialogues from (path) 94 Dialogues Directory= dialogue95 DialoguesPath = dialogue 95 96 96 97 # System subdirectory to load quests from (path) 97 Quests Directory= quests98 QuestsPath = quests 98 99 99 100 # User subdirectory to save screenshots to 100 Screenshots Directory= screenshots101 ScreenshotsPath = screenshots 101 102 102 103 # User subdirectory to save games to 103 Saves Directory= saves104 SavesPath = saves 104 105 105 106 # System subdirectory where gui files are loaded from (path) 106 Gui Directory= gui107 GuiPath = gui 107 108 108 109 # System subdirectory where cursors are loaded from (path) 109 Cursor Directory= cursors110 CursorPath = cursors 110 111 111 112 # File to use for default cursor (filename)
Note: See TracChangeset
for help on using the changeset viewer.