Changeset 803


Ignore:
Timestamp:
03/07/11 22:33:40 (9 years ago)
Author:
aspidites
Message:

Patch by Aspidites:

  • added comments to default settings file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/active/character_customization/game/parpg/settings.py

    r802 r803  
    2525    interface used with this class is arguably more convenient that 
    2626    ConfigParser's. 
     27 
     28    Default Settings may be generated by envoking this module from the 
     29    command line: 
     30        python -m settings.py [system] [data_directory] 
     31 
     32    where [system] is one of local, windows, or linux (mac coming soon), 
     33    and data_directory is the base path for the data files to be loaded. 
     34 
     35    Both [system] and [data_directory] are option. If omitted, both 
     36    default to whichever what is reasonable based on the system settings.py 
     37    is run on 
    2738""" 
    2839 
     
    3142import platform 
    3243 
    33 #TODO: prevent new sections from being created if an option hasn't been defined 
    34 #TODO: update documentation for Settings' __init__, read, and write methods 
    3544class Section(object): 
    3645    """ An object that represents a section in a settings file. 
     
    4453        in the settings file. Options that do not exist on assignment 
    4554        are created dynamcially. 
     55 
     56        Values are automatically converted to the appropriate python type.  
     57        Options that begin and end with brackets([, ]) are converted to lists, 
     58        and options that are double-quoted (") are converted to strings.  
     59        Section also recognizes booleans regardless of case, in addition to the 
     60        literals 'yes' and 'no' of any case. Except in the case of  
     61        double-quoted strings, extra white-space is trimmed, so you need not  
     62        worry. For example: 
     63            foo = bar 
     64        is equivalent to : 
     65            foo    =         baz 
    4666    """ 
    4767    def __init__(self, name): 
     
    6585        if value.startswith('[') and value.endswith(']'): 
    6686            value = [item.strip() for item in value[1:-1].split(',')] 
    67         elif value.lower() == 'true': 
     87        elif value.lower() == 'true' or value.lower() == 'yes': 
    6888            value = True 
    69         elif value.lower() == 'false': 
     89        elif value.lower() == 'false' or value.lower() == 'no': 
    7090            value = False 
    7191        elif value.isdigit(): 
     
    81101 
    82102    def __getattribute__(self, option): 
     103        """ Returns the option's value""" 
    83104        # Remove leading and trailing quotes from strings that have them 
    84105        return_value = object.__getattribute__(self, option) 
     
    110131        """ initializes a new settings object. 
    111132 
    112             @param paths: Either a string representing a path to a settings  
    113                           file or a list of such strings. If a single  
    114                           string is given, settings sections and options are  
    115                           simply read from it. If a list is given, each file  
    116                           is parsed sequentially with the next file's  
    117                           options taking precedence over the previous one's.  
    118                           Consider: 
    119                               files = ['foo.cfg' ,'bar.cfg'] 
    120                               config = Config(files) 
    121                           First, foo.cfg is read, then, if similar options  
    122                           in bar.cfg exist, they overwrite the ones  
    123                           previously set by foo.cfg. 
    124             @type paths: either a string or list 
    125             @ivar settings_file: Python object representing the settings 
    126                                file. Its purpose is to preserve the order of  
    127                                each section and its options on read and write. 
    128             @type settings_file: list 
    129         """ 
     133            Examples: 
     134                paths = ['/etc/parpg', '/home/user_name/.config/parpg'] 
     135                settings = Settings(*paths) 
     136                 
     137                paths = {'system': '/etc/parpg',  
     138                         'user': '/home/user_name/.config/parpg'} 
     139                settings = Settings(**paths) 
     140 
     141                settings = Settings('.') 
     142 
     143            @param system_path: Path to the system settings file. 
     144            @type system_path: string (must be a valid path) 
     145 
     146            @param user_path: Path to the user settings file. Options that 
     147                              are missing from this file are propogated  
     148                              from the system settings file and saved on 
     149                              request 
     150            @type user_path: string (must be a valid path) 
     151             
     152            @param suffix: Suffix of the settings file that will be generated. 
     153            @type suffix: string 
     154        """ 
     155 
     156        if not suffix.startswith('.'): 
     157            suffix = '.' + suffix 
    130158 
    131159        self.suffix = suffix 
     
    150178        """ 
    151179        if name in ['get', 'set']: 
    152             raise AttributeError("{0} is not a valid method. Please consult " 
    153                                  "Settings' documentation for a list of " 
    154                                  " available methods.".format(name)) 
     180            raise AttributeError("{0} is deprecated. Please consult Settings' " 
     181                                  "documentation for information on how to " 
     182                                  "create/modify sections and their respective " 
     183                                  "options".format(name)) 
    155184        else: 
    156185            if not self.__dict__.has_key(name): 
     
    165194            and paths 
    166195 
    167             @param path: name of file to be parsed.  
    168             @type path: string 
     196            @param filenames: name of files to be parsed.  
     197            @type path: string or list 
    169198        """ 
    170199         
     
    194223            sections and options 
    195224 
    196             @param path: Name of file to save to. By default, this is  
    197                              last file that was read when the Setings object 
    198                              was created. 
     225            @param filename: Name of file to save to. By default, this is 
     226                             the user settings file. 
    199227            @type path: string 
    200228        """ 
     
    229257                            new_option = True 
    230258                    if new_option: 
     259                        while self.settings_file[start_of_section].startswith('#'): 
     260                            print self.settings_file[start_of_section] 
     261                            start_of_section += 1 
     262 
    231263                        self.settings_file.insert(start_of_section, template) 
    232264 
     
    245277        return sections 
    246278 
    247 #TODO: organize and comment the default settings 
     279#TODO: Change saves and screenshots directory to somewhere in the user's path, not the system's 
    248280DEFAULT_SETTINGS = """\ 
     281# Options marked with ? are untested/unknown 
    249282[fife] 
    250 VideoDriver = 
     283 
     284# directory where all other data directories reside 
     285 
     286# Game window's title (string) DO NOT EDIT! 
     287WindowTitle = PARPG Techdemo 2 
     288 
     289# Icon to use for the game window's border (filename) DO NOT EDIT! 
     290WindowIcon = window_icon.png 
     291 
     292# Video driver to use. (?) 
     293VideoDriver = "" 
     294 
     295# Backend to use for graphics (OpenGL|SDL) 
     296RenderBackend = OpenGL  
     297 
     298# Run the game in fullscreen mode or not. (True|False) 
    251299FullScreen = False 
     300 
     301# Screen Resolution's width. Not used if FullScreen is set to False (800|1024|etc) 
     302ScreenWidth = 1024 
     303 
     304# Screen Resolution's height. Not used if FullScreen is set to False (600|768|etc) 
     305ScreenHeight = 768 
     306 
     307# Screen DPI? (?) 
     308BitsPerPixel = 0 
     309 
     310# ? (?) 
     311SDLRemoveFakeAlpha = 1 
     312 
     313# Subdirectory to load icons from (path) 
     314IconsDirectory = icons 
     315 
     316# ? ([R, G, B]?) 
     317ColorKey = [250, 0, 250] 
     318 
     319# ? (True|False) 
     320ColorKeyEnabled = False 
     321 
     322# Turn on sound effects and music (True|False) 
    252323EnableSound = True 
    253 RenderBackend = OpenGL 
    254 ColorKey = [250, 0, 250] 
    255 ColorKeyEnabled = False 
    256 ScreenWidth = 1024 
    257 ScreenHeight = 768 
    258 BitsPerPixel = 0 
     324 
     325# Initial volume of sound effects and music (0.0-100.0?) 
    259326InitialVolume = 5.0 
    260 ImageChunkSize = 256 
    261 SDLRemoveFakeAlpha = 1 
    262 WindowTitle = PARPG Techdemo 2 
     327 
     328# Characters to use to render fonts. DO NOT EDIT! 
     329FontGlyphs = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\"" 
     330 
     331# Subdirectory to load fronts from (path) 
    263332FontsDirectory = fonts 
     333 
     334# Font to load when game starts 
    264335Font = oldtypewriter.ttf 
    265 FontGlyphs = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\"" 
    266 IconsDirectory = icons 
    267 WindowIcon = window_icon.png 
     336 
     337# Size of in-game fonts 
    268338DefaultFontSize = 12 
     339 
     340# ? (?) 
    269341LogModules = [controller] 
     342 
     343# ? (?) 
    270344PychanDebug = False 
    271 LogToPrompt = 0 
    272 LogToFile = 0 
     345 
     346# use Psyco Acceperation (True|False) 
    273347UsePsyco = False 
     348 
     349# ? (?) 
    274350ProfilingOn = False 
    275 ImageChunkSize = 256 
     351 
     352# Lighting Model to use (0-2) 
    276353Lighting = 0 
    277354 
    278355[parpg] 
     356 
     357# Subdirectory to load maps from (path) 
    279358MapsDirectory = maps 
     359 
     360# YAML file that contains the available maps (filename) 
     361MapsFile = maps.yaml 
     362 
     363# Map to load when game starts (filename) 
     364Map = Mall 
     365 
     366# ? (filename) 
     367AllAgentsFile = all_agents.yaml 
     368 
     369# Subdirectory to load objects from (path) 
    280370ObjectsDirectory = objects 
     371 
     372# YAML file that contains the database of availabel objects (filename) 
     373ObjectDatabaseFile = object_database.yaml 
     374 
     375# Subdirectory to load dialogues from (path) 
    281376DialoguesDirectory = dialogue 
     377 
     378# Subdirectory to load quests from (path) 
    282379QuestsDirectory = quests 
     380 
     381# Subdirectory to save screenshots to 
    283382ScreenshotsDirectory = screenshots 
     383 
     384# Subdirectory where gui files are loaded from (path) 
    284385GuiDirectory = gui 
     386 
     387# Subdirectory where cursors are loaded from (path) 
    285388CursorDirectory = cursors 
    286389 
    287 MapsFile = maps.yaml 
    288 AllAgentsFile = all_agents.yaml 
    289 ObjectDatabaseFile = object_database.yaml 
    290  
    291 Map = Mall 
     390# File to use for default cursor (filename) 
    292391CursorDefault = cursor_plain.png 
     392 
     393# File to use for up cursor (filename) 
    293394CursorUp = cursor_up.png 
     395 
     396# File to use for right cursor (filename) 
    294397CursorRight = cursor_right.png 
     398 
     399# File to use for down cursor (filename) 
    295400CursorDown = cursor_down.png 
     401 
     402# File to use for left cursor (filename) 
    296403CursorLeft = cursor_left.png 
     404 
     405# Player walk speed (digit) 
    297406PCSpeed = 3\ 
    298407""" 
     
    314423 
    315424    default_settings = DEFAULT_SETTINGS.split('\n') 
    316     default_settings.insert(1, 'DataDirectory = {0}'.format(data_dir)) 
     425    default_settings.insert(4, 'DataDirectory = {0}'.format(data_dir)) 
    317426 
    318427    with open('system.cfg', 'w') as f: 
Note: See TracChangeset for help on using the changeset viewer.