Changeset 747


Ignore:
Timestamp:
02/26/11 04:05:23 (9 years ago)
Author:
aspidites
Message:

Patch by Aspidites:

  • started integrating settings.py into current modules.
Location:
branches/active/character_customization/game
Files:
3 edited

Legend:

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

    r746 r747  
    7878            @param option: name of the option whose value is being requested 
    7979        """ 
    80         return self.__dict__[option] 
     80        try: 
     81            return self.__dict__[option] 
     82        except KeyError: 
     83            return None 
    8184 
    8285    def options(self): 
     
    8790            options.pop('name') 
    8891 
    89         return options 
    90  
    91 #TODO: remember config filenames 
    92 #TODO: remove hard-coded settings filename 
     92        return options.keys() 
     93 
     94#TODO: remember config filenames/paths 
     95#TODO: remove hard-coded settings filename/path 
    9396class Settings(object): 
    9497    """ An object that represents a settings file, its sectons, 
     
    116119        self.config_file = '' 
    117120 
    118         if len(filenames) == 0: 
    119             self.filenames = self.defaultPaths() 
     121        if hasattr(filenames, 'split'): 
     122            self.read(filenames) 
    120123        else: 
    121             self.filenames = filenames 
    122  
    123         if hasattr(self.filenames, 'split'): 
    124             self.read(self.filenames) 
    125         else: 
    126             for filename in self.filenames: 
     124            for filename in filenames: 
    127125                self.read(filename) 
    128126 
     
    209207 
    210208    # backward compatibility methods 
    211     def get(self, section, option): 
     209    def get(self, section, option, default=None): 
    212210        """ Returns the value of the requested option located in the 
    213211            requested section. 
     
    220218            @param option: the option being requested 
    221219            @type section: string 
    222         """ 
    223         return getattr(getattr(self, section), option) 
     220            @param default: the default value to return if a section's option 
     221                is not defined 
     222            @type section: any valid object 
     223        """ 
     224        value = getattr(getattr(self, section), option) 
     225        if value is None and default is not None: 
     226            return default 
     227        else: 
     228            return value 
    224229 
    225230    def getScreenWidth(self): 
     
    228233    def getScreenHeight(self): 
    229234        return self.FIFE.ScreenHeight 
    230  
    231 if __name__ == '__main__': 
    232     a = Settings() 
    233     a = Settings('test.ini', 'test2.ini') 
  • branches/active/character_customization/game/run.py

    r736 r747  
    1919import sys 
    2020 
     21""" Module never used 
    2122#Check if config.py exists. Get 'fife_path' from config 
    2223try: 
     
    3839Example: fife_path='../fife/engine/python/' \n\ 
    3940======================================================================" 
     41""" 
    4042 
     43from parpg.settings import Settings 
    4144from parpg.application import PARPGApplication 
    42 from parpg.common.utils import loadSettings 
    4345 
    4446from parpg.common import utils 
     
    7173def main(): 
    7274    """Application code starts from here""" 
    73     if not main_is_frozen(): 
    74         version = loadSettings().get("PARPG", "SettingsVersion") 
    75         dist_version = loadSettings("./settings-dist.xml").get("PARPG", "SettingsVersion") 
    76         if (version != dist_version): 
    77             print "Newer settings-dist.xml found, renaming settings.xml to settings-old.xml" 
    78             shutil.copyfile('./settings.xml', './settings-old.xml') 
    79             shutil.copyfile('./settings-dist.xml', './settings.xml') 
    80     app = PARPGApplication(loadSettings()) 
     75    app = PARPGApplication(settings) 
    8176    app.run() 
    8277 
    8378if __name__ == '__main__': 
    84     if loadSettings().get("FIFE", "UsePsyco"): 
     79    #TODO: properly wrap this with option_parser 
     80    if '-c' in sys.argv: 
     81        settings = Settings(*sys.argv[sys.argv.index('-c') + 1:]) 
     82    else: 
     83        settings = Settings('./settings.ini') 
     84 
     85    if settings.fife.UsePsyco: 
    8586        # Import Psyco if available 
    8687        try: 
     
    9394        print "Psyco acceleration not used" 
    9495    main() 
    95  
  • branches/active/character_customization/game/settings.ini

    r746 r747  
    2323 
    2424[parpg] 
     25FIFEPath =  
    2526SettingsVersion = 2011-02-21 
    2627Map = Mall 
Note: See TracChangeset for help on using the changeset viewer.