summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/benoit/benoit/application.rs2
-rw-r--r--source/benoit/benoit/application/handle_keys.rs (renamed from source/benoit/benoit/application/handle_key.rs)2
-rw-r--r--source/benoit/benoit/application/initialise.rs9
-rw-r--r--source/benoit/benoit/application/poll_events.rs2
-rw-r--r--source/benoit/benoit/configuration.rs1
-rw-r--r--source/benoit/benoit/configuration/default.rs43
-rw-r--r--source/benoit/benoit/configuration/load.rs17
7 files changed, 59 insertions, 17 deletions
diff --git a/source/benoit/benoit/application.rs b/source/benoit/benoit/application.rs
index f6cb60f..51d0602 100644
--- a/source/benoit/benoit/application.rs
+++ b/source/benoit/benoit/application.rs
@@ -29,7 +29,7 @@ use sdl2::render::WindowCanvas;
pub mod colour;
pub mod draw;
pub mod dump;
-pub mod handle_key;
+pub mod handle_keys;
pub mod initialise;
pub mod poll_events;
pub mod render_row;
diff --git a/source/benoit/benoit/application/handle_key.rs b/source/benoit/benoit/application/handle_keys.rs
index e28cef5..25f3ea9 100644
--- a/source/benoit/benoit/application/handle_key.rs
+++ b/source/benoit/benoit/application/handle_keys.rs
@@ -28,7 +28,7 @@ extern crate sdl2;
use sdl2::keyboard::Scancode;
impl Application {
- pub fn handle_key(&mut self, scan_code: Scancode) -> bool {
+ pub fn handle_keys(&mut self, scan_code: Scancode) -> bool {
match scan_code {
Scancode::Escape => return true,
Scancode::X => self.dump(self.dump_path.clone()),
diff --git a/source/benoit/benoit/application/initialise.rs b/source/benoit/benoit/application/initialise.rs
index 3de87e7..4e9386f 100644
--- a/source/benoit/benoit/application/initialise.rs
+++ b/source/benoit/benoit/application/initialise.rs
@@ -24,9 +24,16 @@
use crate::benoit::application::Application;
use crate::benoit::configuration::Configuration;
+use std::env::args;
+
impl Application {
pub fn initialise() -> Application {
- let configuration = Configuration::load("./Benoit.toml");
+ let mut arguments = args();
+
+ let configuration = match arguments.nth(0x1) {
+ Some(path) => Configuration::load(path.as_str()),
+ None => Configuration::default(),
+ };
let sdl = sdl2::init().expect("unable to initialise sdl2");
let sdl_video = sdl.video().expect("unable to initialise video");
diff --git a/source/benoit/benoit/application/poll_events.rs b/source/benoit/benoit/application/poll_events.rs
index e89f003..ed26b05 100644
--- a/source/benoit/benoit/application/poll_events.rs
+++ b/source/benoit/benoit/application/poll_events.rs
@@ -39,7 +39,7 @@ impl Application {
scancode: scan_code,
keymod: _,
repeat: _,
- } => self.handle_key(scan_code.unwrap()),
+ } => self.handle_keys(scan_code.unwrap()),
Event::Quit { .. } => true,
_ => false,
};
diff --git a/source/benoit/benoit/configuration.rs b/source/benoit/benoit/configuration.rs
index f7c19e0..6783f21 100644
--- a/source/benoit/benoit/configuration.rs
+++ b/source/benoit/benoit/configuration.rs
@@ -21,6 +21,7 @@
If not, see <https://www.gnu.org/licenses/>.
*/
+pub mod default;
pub mod load;
pub struct Configuration {
diff --git a/source/benoit/benoit/configuration/default.rs b/source/benoit/benoit/configuration/default.rs
new file mode 100644
index 0000000..ddc6578
--- /dev/null
+++ b/source/benoit/benoit/configuration/default.rs
@@ -0,0 +1,43 @@
+/*
+ Copyright 2021, 2023 Gabriel Bjørnager Jensen.
+
+ This file is part of Benoit.
+
+ Benoit is free software: you can redistribute it
+ and/or modify it under the terms of the GNU
+ Affero General Public License as published by
+ the Free Software Foundation, either version 3
+ of the License, or (at your option) any later
+ version.
+
+ Benoit is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without
+ even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU
+ Affero General Public License along with Benoit.
+ If not, see <https://www.gnu.org/licenses/>.
+*/
+
+use crate::benoit::configuration::Configuration;
+
+impl Configuration {
+ pub fn default() -> Configuration {
+ return Configuration {
+ thread_count: 0x2,
+
+ canvas_width: 0x100,
+ canvas_height: 0x100,
+ scale: 0x1,
+
+ position_x: 0.0,
+ position_y: 0.0,
+ zoom: 1.0,
+ maximum_iteration_count: 0x100,
+
+ dump_path: "./image.webp".to_string(),
+ };
+ }
+}
diff --git a/source/benoit/benoit/configuration/load.rs b/source/benoit/benoit/configuration/load.rs
index 51db6b1..c9b0512 100644
--- a/source/benoit/benoit/configuration/load.rs
+++ b/source/benoit/benoit/configuration/load.rs
@@ -29,22 +29,13 @@ use std::fs::read;
use std::str::FromStr;
use toml::{Table, Value};
+use std::time::Duration;
+
impl Configuration {
pub fn load(path: &str) -> Configuration {
- let mut configuration = Configuration {
- thread_count: 0x2,
-
- canvas_width: 0x100,
- canvas_height: 0x100,
- scale: 0x1,
+ eprintln!("loading configuration at \"{path}\"");
- position_x: 0.0,
- position_y: 0.0,
- zoom: 1.0,
- maximum_iteration_count: 0x100,
-
- dump_path: "./image.webp".to_string(),
- };
+ let mut configuration = Configuration::default();
let configuration_text = match read(path) {
Ok(content) => String::from_utf8_lossy(&content).to_string(),