From b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Mon, 9 Nov 2020 21:15:35 +0100 Subject: Add configuration options --- src/main.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index a72b172..11cdcfe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +pub mod button; +pub mod config; pub mod editor; pub mod grid; pub mod map_data; @@ -6,15 +8,39 @@ pub mod svg; pub mod tool; pub mod transform; +use config::Config; use editor::Editor; use raylib::prelude::*; +use std::io; use transform::Transform; +pub const CONFIG_FILE: &str = "config.ron"; + fn main() { let (mut rl, thread) = raylib::init().resizable().title("Hello there!").build(); rl.set_target_fps(120); - let mut editor = Editor::new(&mut rl, &thread); + // Load the configuration file, if available. + let config = match Config::from_file(CONFIG_FILE) { + Ok(config) => config, + Err(err) => { + /* Create a default config file if it doesn't exist, otherwise leave the incorrectly + * formatted/corrupted or otherwise unreadable file alone. + */ + let config = Config::default(); + if err.kind() == io::ErrorKind::NotFound { + println!("Could not find a configuration file. Creating default."); + config.write_file(CONFIG_FILE); + } else { + println!("Could not read configuration file: {}", err); + println!("Using defaults for this run."); + } + + config + } + }; + + let mut editor = Editor::new(&mut rl, &thread, config); let mut transform = Transform::new(); let mut last_mouse_pos = rl.get_mouse_position(); -- cgit v1.2.3-70-g09d2