Mercurial > pyntnclick
comparison gamelib/sound.py @ 111:18ffaaaa27e7
Add explicit check for sound file existence (my pygame 1.9 returns a valid sound object even when the path does not exist).
author | Simon Cross <simon@simonx> |
---|---|
date | Tue, 24 Aug 2010 14:43:33 +0200 |
parents | 5213b45fcc7e |
children | 3b293e3b8829 |
comparison
equal
deleted
inserted
replaced
110:545dee3bd8e9 | 111:18ffaaaa27e7 |
---|---|
1 # Sound management for Suspended Sentence | 1 # Sound management for Suspended Sentence |
2 | 2 |
3 # This re-implements some of the albow.resource code to | 3 # This re-implements some of the albow.resource code to |
4 # a) work around an annoying bugs | 4 # a) work around an annoying bugs |
5 # b) add some missing functionality (disable_sound) | 5 # b) add some missing functionality (disable_sound) |
6 | |
7 import os | |
6 | 8 |
7 from albow.resource import _resource_path, dummy_sound | 9 from albow.resource import _resource_path, dummy_sound |
8 | 10 |
9 sound_cache = {} | 11 sound_cache = {} |
10 | 12 |
12 if sound_cache is None: | 14 if sound_cache is None: |
13 return dummy_sound | 15 return dummy_sound |
14 path = _resource_path("sounds", names) | 16 path = _resource_path("sounds", names) |
15 sound = sound_cache.get(path) | 17 sound = sound_cache.get(path) |
16 if not sound: | 18 if not sound: |
19 if not os.path.isfile(path): | |
20 missing_sound("File does not exist", path) | |
21 return dummy_sound | |
17 try: | 22 try: |
18 from pygame.mixer import Sound | 23 from pygame.mixer import Sound |
19 except ImportError, e: | 24 except ImportError, e: |
20 no_sound(e) | 25 no_sound(e) |
21 return dummy_sound | 26 return dummy_sound |