actually apply the preferences from the .toml file

This commit is contained in:
yuni 2024-04-30 23:41:37 +02:00
parent c56ae18f5a
commit 3a0b3dc1c3
3 changed files with 31 additions and 15 deletions

View file

@ -11,7 +11,7 @@
# User preferences for the game OutFly.
# See https://codeberg.org/hut/outfly
# fullscreen_mode may be "borderless", "true", or "sized"
# fullscreen_mode may be "borderless", "legacy", or "sized"
fullscreen_mode = "borderless"
# window_mode may be "windowed", or "fullscreen"

View file

@ -45,9 +45,11 @@ Options:
Note: borderless fullscreen is the default, but it crashes on some systems.";
fn main() {
let prefs = var::load_prefs();
let mut opt = CommandLineOptions {
window_mode_fullscreen: WindowMode::BorderlessFullscreen,
window_mode_initial: WindowMode::BorderlessFullscreen,
window_mode_fullscreen: prefs.get_fullscreen_mode(),
window_mode_initial: prefs.get_window_mode(),
use_gl: prefs.render_mode_is_gl(),
};
let args: Vec<String> = env::args().collect();
@ -67,7 +69,7 @@ fn main() {
return;
}
else if arg == "--gl" {
env::set_var("WGPU_BACKEND", "gl");
opt.use_gl = true;
}
else if arg == "--windowed" {
opt.window_mode_initial = WindowMode::Windowed;
@ -93,6 +95,10 @@ fn main() {
}
}
}
if opt.use_gl {
env::set_var("WGPU_BACKEND", "gl");
}
let mut app = App::new();
app.insert_resource(opt);
@ -101,7 +107,9 @@ fn main() {
mode: bevy_embedded_assets::PluginMode::ReplaceDefault
});
app.add_plugins(OutFlyPlugin).run();
app.add_plugins(OutFlyPlugin);
app.insert_resource(prefs);
app.run();
}
pub struct OutFlyPlugin;
@ -127,8 +135,6 @@ impl Plugin for OutFlyPlugin {
skeleton::SkeletonPlugin,
world::WorldPlugin,
));
var::load_prefs();
}
}
@ -136,6 +142,7 @@ impl Plugin for OutFlyPlugin {
pub struct CommandLineOptions {
window_mode_fullscreen: WindowMode,
window_mode_initial: WindowMode,
use_gl: bool,
}
fn setup(

View file

@ -11,6 +11,7 @@
// This module manages variables, settings, as well as evaluating
// "if"-conditions in chats.
use bevy::window::WindowMode;
use bevy::prelude::*;
use std::collections::HashMap;
use serde::Deserialize;
@ -30,7 +31,7 @@ pub const TOKEN_NEGATE: &str = "~";
pub const DEFAULT_CHAT_SPEED: f32 = 10.0;
#[derive(Resource, Deserialize, Debug)]
#[derive(Resource, Deserialize, Debug, Default)]
#[serde(default)]
pub struct Preferences {
pub fullscreen_mode: String,
@ -41,15 +42,23 @@ pub struct Preferences {
pub source_file: Option<String>,
}
impl Default for Preferences {
fn default() -> Self {
Self {
fullscreen_mode: "borderless".to_string(),
window_mode: "fullscreen".to_string(),
render_mode: "vulkan".to_string(),
source_file: None,
impl Preferences {
pub fn get_fullscreen_mode(&self) -> WindowMode {
match self.fullscreen_mode.as_str() {
"legacy" => WindowMode::Fullscreen,
"sized" => WindowMode::SizedFullscreen,
_ => WindowMode::BorderlessFullscreen,
}
}
pub fn get_window_mode(&self) -> WindowMode {
match self.window_mode.as_str() {
"fullscreen" => self.get_fullscreen_mode(),
_ => WindowMode::Windowed,
}
}
pub fn render_mode_is_gl(&self) -> bool {
return self.render_mode == "gl";
}
}
fn file_is_readable(file_path: &str) -> bool {