38 lines
837 B
Python
38 lines
837 B
Python
import pygame
|
|
from common import SingletonMeta
|
|
|
|
|
|
class BackgroundSound(pygame.mixer.Sound, metaclass=SingletonMeta):
|
|
def __init__(self, filename):
|
|
super().__init__(filename)
|
|
self.set_volume(0.5)
|
|
self._muted = False
|
|
self._played = False
|
|
|
|
def play(self):
|
|
if not self._played:
|
|
super().play(loops=-1)
|
|
self._played = True
|
|
|
|
def mute(self):
|
|
self._muted = True
|
|
self.set_volume(0)
|
|
|
|
def unmute(self):
|
|
self._muted = False
|
|
self.set_volume(0.5)
|
|
|
|
@property
|
|
def muted(self):
|
|
return self._muted
|
|
|
|
@muted.setter
|
|
def muted(self, value):
|
|
if value:
|
|
self.mute()
|
|
else:
|
|
self.unmute()
|
|
|
|
def toggle_mute(self):
|
|
self.muted = not self.muted
|