diff --git a/main.py b/main.py index e748434..ffaeead 100644 --- a/main.py +++ b/main.py @@ -10,10 +10,10 @@ ### Python imports ### +import os import platform os_name = platform.system() if os_name == "Windows": - import os os.environ['KIVY_TEXT'] = 'pil' ### Kivy imports ### diff --git a/screens/game.py b/screens/game.py index 60ed338..02a4575 100644 --- a/screens/game.py +++ b/screens/game.py @@ -22,16 +22,25 @@ from tools.path import ( PATH_TEXT_FONT, PATH_IMAGES, - PATH_SCREENS + PATH_MUSICS, + PATH_SOUNDS ) from tools import ( music_mixer, sound_mixer, game, + USER_DATA ) from tools.kivy_tools import ( ImprovedScreen ) +from tools.game_tools import ( + load_sounds +) +from tools.constants import ( + MUSIC_LIST, + SOUND_LIST +) ############# @@ -100,16 +109,22 @@ def __init__(self, **kw): def preload(self, *_): - # Load the kv content - # Builder.load_file(PATH_SCREENS + "game.kv", encoding="utf-8") - # Load the night camp background self.night_camp_background = Loader.image( PATH_IMAGES + "night_camp.png") + # Load the day camp background self.day_camp_background = Loader.image( PATH_IMAGES + "day_camp.png") + # Load the musics and sounds + new_musics = load_sounds( + MUSIC_LIST, PATH_MUSICS, USER_DATA.music_volume) + new_sounds = load_sounds(SOUND_LIST, PATH_SOUNDS, + USER_DATA.sound_effects_volume) + music_mixer.add_sounds(new_musics) + sound_mixer.add_sounds(new_sounds) + # Preload the class super().preload() diff --git a/tools/__init__.py b/tools/__init__.py index 28a477b..b0e4c2a 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -28,7 +28,8 @@ from tools.constants import ( USER_DATA, MUSIC_LIST, - SOUND_LIST + SOUND_LIST, + START_MUSIC_LIST ) from tools.postrias import Game @@ -39,8 +40,8 @@ ############### # Load the dictionnaries -MUSIC_DICT = load_sounds(MUSIC_LIST, PATH_MUSICS, USER_DATA.music_volume) -SOUND_DICT = load_sounds(SOUND_LIST, PATH_SOUNDS, +MUSIC_DICT = load_sounds(START_MUSIC_LIST, PATH_MUSICS, USER_DATA.music_volume) +SOUND_DICT = load_sounds([], PATH_SOUNDS, USER_DATA.sound_effects_volume) # Create the mixer diff --git a/tools/constants.py b/tools/constants.py index c3fe330..a0f1d97 100644 --- a/tools/constants.py +++ b/tools/constants.py @@ -152,6 +152,6 @@ def change_language(self, language): TEXT_FONT_COLOR = (50 / 255, 50 / 255, 50 / 255, 1) ### Musics ### -MUSIC_LIST = ["cinematic_dramatic.mp3", - "game_music.mp3", "time_of_the_apocalypse.mp3"] +MUSIC_LIST = ["game_music.mp3", "time_of_the_apocalypse.mp3"] SOUND_LIST = ["decision.wav", "decree.wav", "guillotine.wav"] +START_MUSIC_LIST = ["cinematic_dramatic.mp3",] diff --git a/tools/game_tools/sound.py b/tools/game_tools/sound.py index 6282579..0f705a6 100644 --- a/tools/game_tools/sound.py +++ b/tools/game_tools/sound.py @@ -10,7 +10,7 @@ from kivy.core.audio import SoundLoader -from tools.constants import FPS, MUSIC_LIST +from tools.constants import FPS ############### @@ -63,6 +63,17 @@ def __init__(self, dict_music, volume): self.dico_frame_state = dico_frame_state self.volume = volume + def add_sounds(self, sound_dict): + for sound_name in sound_dict: + self.dico_frame_state[sound_name] = 0 + self.musics[sound_name] = sound_dict[sound_name] + self.musics[sound_name].volume = self.volume + + def add_sound(self, sound, sound_name): + self.dico_frame_state[sound_name] = 0 + self.musics[sound_name] = sound + self.musics[sound_name].volume = self.volume + def fade_out(self, name, duration, mode="linear"): if mode == "exp": self.instructions.append(("exp_fade_out", name, duration)) diff --git a/tools/kivy_tools/screen.py b/tools/kivy_tools/screen.py index 33c591a..8d8a8e5 100644 --- a/tools/kivy_tools/screen.py +++ b/tools/kivy_tools/screen.py @@ -138,6 +138,8 @@ def on_pre_enter(self, *args): if not self.is_loaded: self.preload() + self.update_font_ratio() + def on_enter(self, *args): """ Initialize the screen when it is opened.