diff --git a/src/game/game_page.rs b/src/game/game_page.rs index fbb319b..8fefea8 100644 --- a/src/game/game_page.rs +++ b/src/game/game_page.rs @@ -41,8 +41,8 @@ pub struct GameLogic { pub score: u32, pub play: bool, pub current_char: Option, - pub hist_amount: i8, - pub future_amount: i8, + pub hist_amount: u8, + pub future_amount: u8, pub char_hist: Vec, pub char_future: Vec, pub correct: bool, @@ -54,11 +54,11 @@ impl Default for GameLogic { let dict: Dict = get_dict(); let start_t = Local::now(); let load_char: Vec = load_chars::load_files_to_vec(dict); - let loaded_settings = settings_struct::Settings::read_config(); + let loaded_settings = settings_struct::Settings::read_config().unwrap(); let mut h_vec = vec![]; let mut f_vec = vec![]; - let h_amount: i8 = 3; - let f_amount: i8 = 5; + let h_amount: u8 = loaded_settings.history_length; + let f_amount: u8 = loaded_settings.future_length; for _ in 0..h_amount { Vec::push(&mut h_vec, ' '); } @@ -79,7 +79,7 @@ impl Default for GameLogic { char_hist: h_vec, char_future: f_vec, correct: true, - settings: Result::expect(loaded_settings, "Did not find settings"), + settings: loaded_settings, } } } @@ -106,6 +106,9 @@ impl GameLogic { self.play = true; self.reset_char_vec(); } + pub fn update_settings(&mut self) { + self.settings = settings_struct::Settings::read_config().unwrap(); + } pub fn compare_pressed_char(&mut self, character: char) { self.char_hist.remove(0); self.char_hist.push(character); diff --git a/src/tui/pages.rs b/src/tui/pages.rs index 357650f..0fc2fa6 100644 --- a/src/tui/pages.rs +++ b/src/tui/pages.rs @@ -70,6 +70,8 @@ impl<'a> App<'a> { } KeyCode::Char('b') => { self.state = "game"; + self.gamestruct = game_page::GameLogic::default(); + self.gamestruct.reset(); } _ => {} }