diff --git a/Cargo.lock b/Cargo.lock index 69ee6f4e22a2e5a2e60f737cb3da05d87144a3a3..a6585b02f210f29ebacb18ca0b48f6f2143c0a27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2414,6 +2414,7 @@ checksum = "f7cd331da7327ecb5727449abb3a63654bd92003bf9a95eed8c9b0d4a93098eb" dependencies = [ "bevy", "bevy_kira_audio", + "serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 241f06520e667393bc53de889689aec2daeefc86..dd2c6a4cf6ff55da172a371e4d4e21e0f7af749b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ serde = "1.0.147" serde_json = "1.0.87" iyes_loopless = "0.9.1" -micro_musicbox = { version = "0.5.0", features = ["mp3"] } +micro_musicbox = { version = "0.5.0", features = ["mp3", "serde"] } micro_banimate = { version = "0.2.1", features = ["ecs_tilemap"] } kayak_ui = { rev = "c8437b382b0cd1ce950c15cacd170a1c7c7fe5dc", git = "https://github.com/StarArawn/kayak_ui" } diff --git a/game_core/src/main.rs b/game_core/src/main.rs index 989e47b5866955f205d626c4b5b4bbf3d62d300c..eb9f88b076fba7affba1a9400cc36e8c73018719 100644 --- a/game_core/src/main.rs +++ b/game_core/src/main.rs @@ -4,6 +4,8 @@ use game_core::system::flow::AppState; use iyes_loopless::prelude::AppLooplessStateExt; fn main() { + let options = game_core::persistance::fs_utils::read_config_file(); + App::new() .add_loopless_state(AppState::Preload) .add_plugins(game_core::system::resources::InitAppPlugins) @@ -20,5 +22,6 @@ fn main() { .add_plugins(game_core::ui::AdventUIPlugins) .add_plugin(game_core::persistance::PersistencePlugin) .add_plugin(bevy_prototype_lyon::plugin::ShapePlugin) + .insert_resource(options.map(|opts| opts.audio.clone()).unwrap_or_default()) .run(); } diff --git a/game_core/src/persistance/fs_utils.rs b/game_core/src/persistance/fs_utils.rs index 2097a5864ef5e2db0e7605e3029095f27edb16f6..f5b9a76f21a8750cc8f7ac53a78a767e63b0159c 100644 --- a/game_core/src/persistance/fs_utils.rs +++ b/game_core/src/persistance/fs_utils.rs @@ -1,5 +1,8 @@ use std::path::PathBuf; +use micro_musicbox::prelude::AudioSettings; +use serde::{Deserialize, Serialize}; + pub const AUTOSAVE_NAME: &str = "autosave.json"; pub fn get_root_save_dir() -> Option<PathBuf> { @@ -15,3 +18,23 @@ pub fn has_auto_save() -> bool { .map(|dir: PathBuf| dir.join(AUTOSAVE_NAME).exists()) .unwrap_or(false) } + +#[derive(Serialize, Deserialize)] +pub struct Options { + pub audio: AudioSettings, +} + +pub fn read_config_file() -> Option<Options> { + let root_dir = get_root_save_dir()?; + let save_path = root_dir.join("config.toml"); + + let file = std::fs::read(save_path).ok()?; + toml::from_slice(file.as_slice()).ok() +} + +pub fn save_config_file(options: Options) -> Option<()> { + let root_dir = get_root_save_dir()?; + let save_path = root_dir.join("config.toml"); + + std::fs::write(save_path, toml::to_string_pretty(&options).ok()?).ok() +} diff --git a/game_core/src/ui/widgets/settings_panel.rs b/game_core/src/ui/widgets/settings_panel.rs index 56caf573aa9acefbe0dc8e5c94e8fdcac8cf592f..eafbf71377eb5894c74ae821d2bde5fb61977400 100644 --- a/game_core/src/ui/widgets/settings_panel.rs +++ b/game_core/src/ui/widgets/settings_panel.rs @@ -7,6 +7,7 @@ use kayak_ui::widgets::{ use micro_musicbox::prelude::AudioSettings; use crate::assets::AssetHandles; +use crate::persistance::fs_utils::{save_config_file, Options}; use crate::persistance::{fs_utils, LoadFileEvent}; use crate::system::flow::AppState; use crate::ui::components::*; @@ -174,6 +175,9 @@ pub fn render_settings_panel( AudioSettings, >| { settings.music_volume = (settings.music_volume - 0.05).max(0.0); + save_config_file(Options { + audio: *settings + }); })} /> <BackgroundBundle @@ -204,6 +208,9 @@ pub fn render_settings_panel( AudioSettings, >| { settings.music_volume = (settings.music_volume + 0.05).min(1.0); + save_config_file(Options { + audio: *settings + }); })} /> </BackgroundBundle> diff --git a/game_core/src/world/hunger.rs b/game_core/src/world/hunger.rs index 34d42e3856f5e9abe27bb94bccc26dc93ff96e2e..67fd48b6a58a368ef61caa3bc7cdcba797ccbc12 100644 --- a/game_core/src/world/hunger.rs +++ b/game_core/src/world/hunger.rs @@ -49,7 +49,7 @@ impl HungerState { pub struct StarvationMarker; pub const PLAYER_FOOD_TARGET: usize = 25; -pub const TOWN_FOOD_TARGET: usize = 75; +pub const TOWN_FOOD_TARGET: usize = 125; pub fn process_player_hunger_ticks( world_ticks: EventReader<WorldTickEvent>,