mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Save settings when the game closes
Former-commit-id: 0190f45ddbd87ec6ae2e4d4d959672d22e560907
This commit is contained in:
parent
278a08c127
commit
74a7f815cf
@ -81,12 +81,15 @@ pub trait PlayState {
|
||||
fn main() {
|
||||
// Set up the global state.
|
||||
let mut settings = Settings::load();
|
||||
// Save settings to add new fields or create the file if it is not already there
|
||||
// TODO: Handle this result.
|
||||
settings.save_to_file();
|
||||
|
||||
let window = Window::new(&settings).expect("Failed to create window!");
|
||||
|
||||
let mut global_state = GlobalState {
|
||||
audio: AudioFrontend::new(&settings.audio),
|
||||
window,
|
||||
settings,
|
||||
};
|
||||
|
||||
|
||||
// Initialize logging.
|
||||
let term_log_level = std::env::var_os("VOXYGEN_LOG")
|
||||
.and_then(|env| env.to_str().map(|s| s.to_owned()))
|
||||
@ -97,13 +100,13 @@ fn main() {
|
||||
WriteLogger::new(
|
||||
log::LevelFilter::Info,
|
||||
Config::default(),
|
||||
File::create(&settings.log.file).unwrap(),
|
||||
File::create(&global_state.settings.log.file).unwrap(),
|
||||
),
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
// Set up panic handler to relay swish panic messages to the user
|
||||
let settings_clone = settings.clone();
|
||||
let settings_clone = global_state.settings.clone();
|
||||
let default_hook = panic::take_hook();
|
||||
panic::set_hook(Box::new(move |panic_info| {
|
||||
let panic_info_payload = panic_info.payload();
|
||||
@ -164,16 +167,10 @@ fn main() {
|
||||
default_hook(panic_info);
|
||||
}));
|
||||
|
||||
if settings.audio.audio_device == None {
|
||||
settings.audio.audio_device = Some(AudioFrontend::get_default_device());
|
||||
if global_state.settings.audio.audio_device == None {
|
||||
global_state.settings.audio.audio_device = Some(AudioFrontend::get_default_device());
|
||||
}
|
||||
|
||||
let mut global_state = GlobalState {
|
||||
audio: AudioFrontend::new(&settings.audio),
|
||||
window,
|
||||
settings,
|
||||
};
|
||||
|
||||
// Set up the initial play state.
|
||||
let mut states: Vec<Box<dyn PlayState>> = vec![Box::new(MainMenuState::new(&mut global_state))];
|
||||
states
|
||||
@ -231,4 +228,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Save settings to add new fields or create the file if it is not already there
|
||||
// TODO: Handle this result.
|
||||
global_state.settings.save_to_file();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user