Persistent game volume settings
This commit is contained in:
parent
0cc0401b66
commit
49c8222e26
@ -33,14 +33,14 @@ extern crate approx; // For the macro `relative_eq!`
|
||||
extern crate log; // For the `info!`, `warn!`, etc. macros
|
||||
|
||||
pub(crate) mod asset_manager;
|
||||
pub(crate) mod coord_convert;
|
||||
pub(crate) mod discord;
|
||||
pub(crate) mod global_resource_package;
|
||||
pub(crate) mod model;
|
||||
pub(crate) mod persistent;
|
||||
pub(crate) mod project_constants;
|
||||
pub(crate) mod rendering;
|
||||
pub(crate) mod scenes;
|
||||
pub(crate) mod model;
|
||||
pub(crate) mod coord_convert;
|
||||
|
||||
/// This is the game logic entrypoint. Despite being async,
|
||||
/// this is expected to block the main thread for rendering and stuff.
|
||||
@ -84,6 +84,8 @@ pub async fn entrypoint(force_recreate_savefiles: bool) {
|
||||
project_constants.target_fps,
|
||||
&project_constants,
|
||||
event_loop_discord_tx,
|
||||
&mut settings,
|
||||
&mut save_state,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
@ -10,12 +10,15 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PersistentGameSettings {
|
||||
// TODO: Add data here.
|
||||
pub volume: Option<f32>,
|
||||
}
|
||||
|
||||
// Add any default values here.
|
||||
impl Default for PersistentGameSettings {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
Self {
|
||||
volume: Some(0.5),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@
|
||||
use std::cell::RefCell;
|
||||
|
||||
use crate::discord::DiscordChannel;
|
||||
use crate::persistent::save_state::GameSaveState;
|
||||
use crate::persistent::settings::PersistentGameSettings;
|
||||
use crate::project_constants::ProjectConstants;
|
||||
use crate::rendering::core_renderer_sm::{PreloadState, RenderBackendStates};
|
||||
use crate::rendering::screens::sm_failure_screen;
|
||||
@ -25,6 +27,8 @@ pub async fn handle_graphics_blocking<ConfigBuilder>(
|
||||
target_frames_per_second: u32,
|
||||
constants: &ProjectConstants,
|
||||
discord_signaling: DiscordChannel,
|
||||
game_settings: &mut PersistentGameSettings,
|
||||
save_state: &mut GameSaveState
|
||||
) where
|
||||
ConfigBuilder: FnOnce(&mut RaylibBuilder),
|
||||
{
|
||||
@ -58,6 +62,8 @@ pub async fn handle_graphics_blocking<ConfigBuilder>(
|
||||
&raylib_thread,
|
||||
constants,
|
||||
audio_subsystem,
|
||||
game_settings,
|
||||
save_state,
|
||||
);
|
||||
|
||||
// Handle loading the resources and rendering the loading screen
|
||||
@ -119,6 +125,8 @@ pub async fn handle_graphics_blocking<ConfigBuilder>(
|
||||
&discord_signaling,
|
||||
&global_resources,
|
||||
constants,
|
||||
game_settings,
|
||||
save_state,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
@ -10,7 +10,7 @@ use raylib::{
|
||||
use crate::{
|
||||
discord::{DiscordChannel, DiscordRpcSignal},
|
||||
global_resource_package::GlobalResources,
|
||||
project_constants::ProjectConstants,
|
||||
project_constants::ProjectConstants, persistent::settings::PersistentGameSettings,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -35,10 +35,11 @@ impl MainMenu {
|
||||
raylib_handle: &mut RaylibHandle,
|
||||
thread: &RaylibThread,
|
||||
constants: &ProjectConstants,
|
||||
game_settings: &mut PersistentGameSettings
|
||||
) -> Self {
|
||||
Self {
|
||||
has_updated_discord_rpc: false,
|
||||
volume_percentage: 0.5,
|
||||
volume_percentage: game_settings.volume.unwrap_or(0.5),
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,6 +51,7 @@ impl MainMenu {
|
||||
global_resources: &GlobalResources,
|
||||
constants: &ProjectConstants,
|
||||
audio_subsystem: &mut RaylibAudio,
|
||||
game_settings: &mut PersistentGameSettings
|
||||
) -> MenuStateSignal {
|
||||
// Handle updating discord RPC
|
||||
if !self.has_updated_discord_rpc {
|
||||
@ -296,6 +298,8 @@ impl MainMenu {
|
||||
} else if self.volume_percentage <= 0.0 {
|
||||
self.volume_percentage = 0.0;
|
||||
}
|
||||
audio_subsystem.set_master_volume(self.volume_percentage);
|
||||
game_settings.volume = Some(self.volume_percentage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,6 +334,8 @@ impl MainMenu {
|
||||
} else if self.volume_percentage <= 0.0 {
|
||||
self.volume_percentage = 0.0;
|
||||
}
|
||||
audio_subsystem.set_master_volume(self.volume_percentage);
|
||||
game_settings.volume = Some(self.volume_percentage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ use raylib::prelude::*;
|
||||
|
||||
use crate::{
|
||||
discord::DiscordChannel, global_resource_package::GlobalResources,
|
||||
project_constants::ProjectConstants,
|
||||
project_constants::ProjectConstants, persistent::{save_state::GameSaveState, settings::PersistentGameSettings},
|
||||
};
|
||||
|
||||
use self::{
|
||||
@ -38,11 +38,13 @@ impl SceneRenderDelegate {
|
||||
rl_thread: &RaylibThread,
|
||||
constants: &ProjectConstants,
|
||||
audio_subsystem: RaylibAudio,
|
||||
game_settings: &mut PersistentGameSettings,
|
||||
save_state: &mut GameSaveState
|
||||
) -> Self {
|
||||
// Init some scenes
|
||||
let scene_test_fox = TestFoxScene::new(raylib, rl_thread);
|
||||
let scene_playable = PlayableScene::new(raylib, rl_thread, constants);
|
||||
let scene_main_menu = MainMenu::new(raylib, rl_thread, constants);
|
||||
let scene_main_menu = MainMenu::new(raylib, rl_thread, constants, game_settings);
|
||||
|
||||
Self {
|
||||
menu_control_signal: MenuStateSignal::DoMainMenu,
|
||||
@ -64,6 +66,8 @@ impl SceneRenderDelegate {
|
||||
discord: &DiscordChannel,
|
||||
global_resources: &GlobalResources,
|
||||
constants: &ProjectConstants,
|
||||
game_settings: &mut PersistentGameSettings,
|
||||
save_state: &mut GameSaveState
|
||||
) {
|
||||
// Render the main menu if in it, otherwise, render the game
|
||||
match self.menu_control_signal {
|
||||
@ -96,6 +100,7 @@ impl SceneRenderDelegate {
|
||||
global_resources,
|
||||
constants,
|
||||
&mut self.audio_subsystem,
|
||||
game_settings
|
||||
)
|
||||
.await;
|
||||
|
||||
|
Reference in New Issue
Block a user