Changeset 248

Show
Ignore:
Timestamp:
01/05/07 04:06:01 (5 years ago)
Author:
mg
Message:

Make music files configurable in an .ini file.

Location:
trunk/src/pyspacewar
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/pyspacewar/music/README.txt

    r247 r248  
    33 
    44If you want you, you can take your favourite tunes and place them in this 
    5 directory, with the following names: 
    6  
    7   demo.ogg 
    8   game.ogg 
    9   gravitywars.ogg 
    10  
     5directory, then put their file names in music.ini. 
  • trunk/src/pyspacewar/ui.py

    r247 r248  
    19951995    def _load_music(self): 
    19961996        """Load music files.""" 
    1997         self.music_files = { 
    1998                 'demo': find('music', 'demo.ogg'), 
    1999                 'game': find('music', 'game.ogg'), 
    2000                 'gravitywars': find('music', 'gravitywars.ogg'), 
    2001             } 
     1997        config = ConfigParser.RawConfigParser() 
     1998        config.add_section('music') 
     1999        config.read([find('music', 'music.ini')]) 
     2000        self.music_files = {} 
     2001        for what in ['demo', 'game', 'gravitywars']: 
     2002            if config.has_option('music', what): 
     2003                filename = config.get('music', what) 
     2004                if filename: 
     2005                    self.music_files[what] = find('music', filename) 
    20022006 
    20032007    def play_music(self, which): 
     
    20132017                pygame.mixer.music.play(-1) 
    20142018            except pygame.error: 
    2015                 # Don't print warnings while I don't have any music actually 
    2016                 # bundled with pyspacewar 
    2017                 # print "pyspacewar: could not load %s" % filename 
     2019                print "pyspacewar: could not load %s" % filename 
    20182020                pygame.mixer.music.stop() 
    20192021        self.now_playing = which