Mercurial > rinkhals
comparison gamelib/level.py @ 412:1e24eedbf40f
Implement non-gui parts of level loading communication
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 11:34:12 +0000 |
parents | e83ec14163f2 |
children | a356e57529ea |
comparison
equal
deleted
inserted
replaced
411:03d5cb669298 | 412:1e24eedbf40f |
---|---|
8 | 8 |
9 class Level(object): | 9 class Level(object): |
10 """Container for level details""" | 10 """Container for level details""" |
11 | 11 |
12 def __init__(self, level_name): | 12 def __init__(self, level_name): |
13 level_info = None | 13 self.level_file = None |
14 default_map = '%s.tga' % level_name | 14 default_map = '%s.tga' % level_name |
15 for poss_file in ['levels/%s.conf' % level_name, '%s.conf' % level_name, | 15 for poss_file in ['levels/%s.conf' % level_name, '%s.conf' % level_name, |
16 'levels/%s' % level_name, level_name]: | 16 'levels/%s' % level_name, level_name]: |
17 cand = data.filepath(poss_file) | 17 cand = data.filepath(poss_file) |
18 if os.path.exists(cand): | 18 if os.path.exists(cand): |
19 level_info = cand | 19 self.level_file = cand |
20 break | 20 break |
21 if not level_info: | 21 if not self.level_file: |
22 raise RuntimeError('Unable to load %s' % level_name) | 22 raise RuntimeError('Unable to load %s' % level_name) |
23 # Load the level info file | 23 # Load the level info file |
24 # setup defaults | 24 # setup defaults |
25 defaults = { | 25 defaults = { |
26 'map' : default_map, | 26 'map' : default_map, |
36 } | 36 } |
37 # Add default fox weightings | 37 # Add default fox weightings |
38 for animal, prob in DEFAULT_FOX_WEIGHTINGS: | 38 for animal, prob in DEFAULT_FOX_WEIGHTINGS: |
39 defaults[animal.CONFIG_NAME] = prob | 39 defaults[animal.CONFIG_NAME] = prob |
40 config = RawConfigParser(defaults) | 40 config = RawConfigParser(defaults) |
41 config.read(level_info) | 41 config.read(self.level_file) |
42 # NB. This assumes the level file is correctly formatted. No provision | 42 # NB. This assumes the level file is correctly formatted. No provision |
43 # is made for missing sections or incorrectly specified values. | 43 # is made for missing sections or incorrectly specified values. |
44 # i.e. Things may blow up | 44 # i.e. Things may blow up |
45 map_file = config.get('Level', 'map') | 45 map_file = config.get('Level', 'map') |
46 self.map = data.filepath('levels/%s' % map_file) | 46 self.map = data.filepath('levels/%s' % map_file) |