diff options
| author | Arne Dußin | 2020-11-09 21:15:35 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-09 21:15:35 +0100 |
| commit | b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f (patch) | |
| tree | bb9de75363ade9f2f27ebdb60507dbefb36afc35 /src/main.rs | |
| parent | e08cb85528e6b72d5f3b2fbeb79b581fa7a4e461 (diff) | |
| download | graf_karto-b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f.tar.gz graf_karto-b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f.zip | |
Add configuration options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 28 |
1 files changed, 27 insertions, 1 deletions
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(); |
