Skip to content

Commit

Permalink
Rest
Browse files Browse the repository at this point in the history
  • Loading branch information
d-e-s-o committed Oct 26, 2023
1 parent 8beae18 commit 4b46ea9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::keys;


#[derive(Default, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct Config {
/// Settings pertaining keyboard handling.
pub keyboard: keys::Config,
Expand Down
5 changes: 5 additions & 0 deletions src/game/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde::Serialize;


#[derive(Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct Config {
/// The level the game starts at.
pub start_level: u16,
Expand All @@ -17,6 +18,9 @@ pub struct Config {
pub field_height: i16,
/// The number of upcoming stones to show.
pub preview_stone_count: u8,
/// Whether or not the AI is enabled initially.
#[serde(default)]
pub enable_ai: bool,
}

impl Default for Config {
Expand All @@ -27,6 +31,7 @@ impl Default for Config {
field_width: 10,
field_height: 20,
preview_stone_count: 1,
enable_ai: false,
}
}
}
8 changes: 7 additions & 1 deletion src/game/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,16 @@ impl Game {
font,
);

let ai = if config.enable_ai {
Self::create_ai(&field, &preview)
} else {
None
};

let slf = Self {
field,
preview,
ai: None,
ai,
next_tick: Some(Self::next_tick(Instant::now(), score.level())),
score,
};
Expand Down
1 change: 1 addition & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::Tick;


#[derive(Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct Config {
/// The auto-repeat timeout, in milliseconds.
auto_repeat_timeout_ms: u32,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use crate::rand::Rng;
use crate::rect::Rect;

pub use crate::config::Config;
pub use crate::game::Config as GameConfig;
pub use crate::game::Game;
pub use crate::opengl::Renderer;
pub use crate::opengl::Window;
Expand Down

0 comments on commit 4b46ea9

Please sign in to comment.