Config synchronizes across app
This commit is contained in:
+14
-23
@@ -1,9 +1,9 @@
|
||||
use anyhow::Result;
|
||||
use bytemuck::NoUninit;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use egui::{Color32, Pos2, Vec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub use crate::filesystem::Config;
|
||||
use crate::{emulator::SimId, filesystem::Persistence, window::DisplayMode};
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -116,38 +116,31 @@ pub struct AppConfig {
|
||||
#[serde(default = "default_save_data_location")]
|
||||
pub save_data_location: SaveDataLocation,
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn load(persistence: &Persistence) -> Self {
|
||||
if let Ok(config) = persistence.load_config(APP_CONFIG_FILENAME) {
|
||||
return config;
|
||||
}
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
power_preference: default_power_preference(),
|
||||
force_fallback: false,
|
||||
save_data_location: default_save_data_location(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save(&self, persistence: &Persistence) -> Result<()> {
|
||||
persistence.save_config(APP_CONFIG_FILENAME, &self)
|
||||
impl AppConfig {
|
||||
pub fn load(persistence: &Persistence) -> Config<Self> {
|
||||
persistence.config(APP_CONFIG_FILENAME)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, args: &CliArgs) -> bool {
|
||||
let mut updated = false;
|
||||
pub fn apply_updates(&mut self, args: &CliArgs) {
|
||||
if let Some(pref) = args.wgpu_power_preference {
|
||||
self.power_preference = pref.into();
|
||||
updated = true;
|
||||
}
|
||||
if let Some(force_fallback) = args.wgpu_force_fallback {
|
||||
self.force_fallback = force_fallback;
|
||||
updated = true;
|
||||
}
|
||||
if let Some(save_data_location) = args.save_data_location {
|
||||
self.save_data_location = save_data_location;
|
||||
updated = true;
|
||||
}
|
||||
updated
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,12 +164,8 @@ pub struct SimConfig {
|
||||
#[serde(default)]
|
||||
pub position: Option<Pos2>,
|
||||
}
|
||||
|
||||
impl SimConfig {
|
||||
pub fn load(persistence: &Persistence, sim_id: SimId) -> Self {
|
||||
if let Ok(config) = persistence.load_config(sim_config_filename(sim_id)) {
|
||||
return config;
|
||||
}
|
||||
impl Default for SimConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
display_mode: DisplayMode::Anaglyph,
|
||||
colors: COLOR_PRESETS[0],
|
||||
@@ -187,9 +176,11 @@ impl SimConfig {
|
||||
position: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save(&self, persistence: &Persistence, sim_id: SimId) -> Result<()> {
|
||||
persistence.save_config(sim_config_filename(sim_id), self)
|
||||
impl SimConfig {
|
||||
pub fn load(persistence: &Persistence, sim_id: SimId) -> Config<Self> {
|
||||
persistence.config(sim_config_filename(sim_id))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user