Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings into the game #11

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/game/game_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub struct GameLogic {
pub score: u32,
pub play: bool,
pub current_char: Option<char>,
pub hist_amount: i8,
pub future_amount: i8,
pub hist_amount: u8,
pub future_amount: u8,
pub char_hist: Vec<char>,
pub char_future: Vec<char>,
pub correct: bool,
Expand All @@ -54,11 +54,11 @@ impl Default for GameLogic {
let dict: Dict<bool> = get_dict();
let start_t = Local::now();
let load_char: Vec<char> = 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, ' ');
}
Expand All @@ -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,
}
}
}
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/tui/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ impl<'a> App<'a> {
}
KeyCode::Char('b') => {
self.state = "game";
self.gamestruct = game_page::GameLogic::default();
self.gamestruct.reset();
}
_ => {}
}
Expand Down