class SoundEffect: """Class wrapping ``pygame.mixer.Sound`` with the ability to enable/disable sound globally Use this instead of ``pygame.mixer.Sound``. The interface is fully transparent. """ def __init__(self, source, ui_config): self._ui_config = ui_config if ui_config.sound_on: self.sound = Sound(source) def play(self, loops=0, maxtime=0, fade_ms=0): if self._ui_config: self.sound.play(loops, maxtime, fade_ms) def stop(self): if self._ui_config: self.sound.stop() def fadeout(self, time): if self._ui_config: self.sound.fadeout(time) def set_volume(self, value): if self._ui_config: self.sound.set_volume(value) def get_volume(self): if self._ui_config: return self.sound.get_volume() def get_num_channels(self): if self._ui_config: return self.sound.get_num_channels() def get_length(self): if self._ui_config: return self.get_length() def get_raw(self): if self._ui_config: return self.sound.get_raw()
class Sound: """Class wrapping ``pygame.mixer.Sound`` with the ability to enable/disable sound globally Use this instead of ``pygame.mixer.Sound``. The interface is fully transparent. """ def __init__(self, source): if config.SOUND: self.sound = OldSound(source) def play(self, loops=0, maxtime=0, fade_ms=0): if config.SOUND: self.sound.play(loops, maxtime, fade_ms) def stop(self): if config.SOUND: self.sound.stop() def fadeout(self, time): if config.SOUND: self.sound.fadeout(time) def set_volume(self, value): if config.SOUND: self.sound.set_volume(value) def get_volume(self): if config.SOUND: return self.sound.get_volume() def get_num_channels(self): if config.SOUND: return self.sound.get_num_channels() def get_length(self): if config.SOUND: return self.get_length() def get_raw(self): if config.SOUND: return self.sound.get_raw()