Adjust everything relative to the board
This commit is contained in:
@@ -6,17 +6,18 @@ Goal: Generate 'hard' puzzles.
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
- Install Rust from [here](https://www.rust-lang.org/tools/install).
|
- `cargo install --git https://github.com/cool-mist/sol_chess sol_chess`
|
||||||
- Run `cargo install --git https://github.com/cool-mist/sol_chess` to install the tool.
|
|
||||||
- This installs 2 binaries: `sol_chess` and `sol_cli`.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
- Run `sol_chess` to start a windowed GUI game.
|
- Run `sol_chess` to start a windowed GUI game.
|
||||||
- Run `sol_cli` to start the CLI tool.
|
|
||||||
|
## Update
|
||||||
|
|
||||||
|
- `cargo install --git https://github.com/cool-mist/sol_chess sol_chess --force`
|
||||||
|
|
||||||
## CLI Usage
|
## CLI Usage
|
||||||
|
|
||||||
|
- `cargo install --git https://github.com/cool-mist/sol_chess sol_cli`
|
||||||
|
- Run `sol_cli` to start the CLI tool.
|
||||||
|
|
||||||
- Generate a puzzle
|
- Generate a puzzle
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -21,9 +21,15 @@ pub const BUTTON_HEIGHT_MULTIPLIER: f32 = 0.08;
|
|||||||
// Width of the button relative to the 'board size'
|
// Width of the button relative to the 'board size'
|
||||||
pub const BUTTON_WIDTH_MULTIPLIER: f32 = 0.20;
|
pub const BUTTON_WIDTH_MULTIPLIER: f32 = 0.20;
|
||||||
|
|
||||||
// Gap between the bottom of the row and the first row of buttons
|
// Gap between the bottom of the board and the first row of buttons
|
||||||
pub const BOTTOM_BUTTON_ROW_OFFSET_MULTIPLIER: f32 = 0.3;
|
pub const BOTTOM_BUTTON_ROW_OFFSET_MULTIPLIER: f32 = 0.3;
|
||||||
|
|
||||||
|
// Gap between the right of the board and the first row of buttons
|
||||||
|
pub const BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER: f32 = 0.3;
|
||||||
|
|
||||||
|
// Gap between the top of the board and the heading
|
||||||
|
pub const TOP_HEADING_OFFSET_MULTIPLIER: f32 = 0.5;
|
||||||
|
|
||||||
pub const HEADING_TEXT: &str = "Solitaire Chess";
|
pub const HEADING_TEXT: &str = "Solitaire Chess";
|
||||||
pub const RESET_BUTTON_TEXT: &str = "RESET";
|
pub const RESET_BUTTON_TEXT: &str = "RESET";
|
||||||
pub const NEXT_BUTTON_TEXT: &str = "NEXT";
|
pub const NEXT_BUTTON_TEXT: &str = "NEXT";
|
||||||
|
|||||||
+19
-10
@@ -48,7 +48,7 @@ impl Game {
|
|||||||
let dims = measure_text(self.heading_text.as_str(), Some(&self.font), f, 1.0);
|
let dims = measure_text(self.heading_text.as_str(), Some(&self.font), f, 1.0);
|
||||||
self.heading_rect = Rect::new(
|
self.heading_rect = Rect::new(
|
||||||
board_x + (board_width - dims.width) / 2.0,
|
board_x + (board_width - dims.width) / 2.0,
|
||||||
(board_y - dims.height) / 2.0,
|
board_y - dims.height - constants::TOP_HEADING_OFFSET_MULTIPLIER * self.square_width,
|
||||||
dims.width,
|
dims.width,
|
||||||
dims.height,
|
dims.height,
|
||||||
);
|
);
|
||||||
@@ -80,26 +80,28 @@ impl Game {
|
|||||||
|
|
||||||
self.squares = rects;
|
self.squares = rects;
|
||||||
|
|
||||||
|
// Buttons
|
||||||
let btn_h = constants::BUTTON_HEIGHT_MULTIPLIER * min_dimension;
|
let btn_h = constants::BUTTON_HEIGHT_MULTIPLIER * min_dimension;
|
||||||
let btn_w = board_width * constants::BUTTON_WIDTH_MULTIPLIER;
|
let btn_w = board_width * constants::BUTTON_WIDTH_MULTIPLIER;
|
||||||
let btn_y = board_width
|
|
||||||
|
// Bottom row
|
||||||
|
let bottom_row_y = board_width
|
||||||
+ board_y
|
+ board_y
|
||||||
+ constants::BOTTOM_BUTTON_ROW_OFFSET_MULTIPLIER * self.square_width;
|
+ constants::BOTTOM_BUTTON_ROW_OFFSET_MULTIPLIER * self.square_width;
|
||||||
let btn_reset_x_offset =
|
let btn_reset_x_offset =
|
||||||
(self.board_rect.w - self.square_width) + (self.square_width - btn_w) / 2.;
|
(self.board_rect.w - self.square_width) + (self.square_width - btn_w) / 2.;
|
||||||
let reset_btn = Button::new(
|
let reset_btn = Button::new(
|
||||||
constants::RESET_BUTTON_TEXT,
|
constants::RESET_BUTTON_TEXT,
|
||||||
Rect::new(board_x + btn_reset_x_offset, btn_y, btn_w, btn_h),
|
Rect::new(board_x + btn_reset_x_offset, bottom_row_y, btn_w, btn_h),
|
||||||
UiColor::Yellow,
|
UiColor::Yellow,
|
||||||
self.sounds.button.clone(),
|
self.sounds.button.clone(),
|
||||||
self.font.clone(),
|
self.font.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let btn_next_x_offset =
|
let btn_next_x_offset =
|
||||||
(self.board_rect.w - 2. * self.square_width) + (self.square_width - btn_w) / 2.;
|
(self.board_rect.w - 2. * self.square_width) + (self.square_width - btn_w) / 2.;
|
||||||
let mut next_btn = Button::new(
|
let mut next_btn = Button::new(
|
||||||
constants::NEXT_BUTTON_TEXT,
|
constants::NEXT_BUTTON_TEXT,
|
||||||
Rect::new(board_x + btn_next_x_offset, btn_y, btn_w, btn_h),
|
Rect::new(board_x + btn_next_x_offset, bottom_row_y, btn_w, btn_h),
|
||||||
UiColor::Green,
|
UiColor::Green,
|
||||||
self.sounds.button.clone(),
|
self.sounds.button.clone(),
|
||||||
self.font.clone(),
|
self.font.clone(),
|
||||||
@@ -110,11 +112,14 @@ impl Game {
|
|||||||
self.gp_btns.insert(ButtonAction::Next, next_btn);
|
self.gp_btns.insert(ButtonAction::Next, next_btn);
|
||||||
self.gp_btns.insert(ButtonAction::Reset, reset_btn);
|
self.gp_btns.insert(ButtonAction::Reset, reset_btn);
|
||||||
|
|
||||||
|
// Left column
|
||||||
|
let left_column_x =
|
||||||
|
board_x - constants::BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER * self.square_width - btn_w;
|
||||||
let rules_button = Button::new(
|
let rules_button = Button::new(
|
||||||
constants::RULES_BUTTON_TEXT,
|
constants::RULES_BUTTON_TEXT,
|
||||||
Rect::new(
|
Rect::new(
|
||||||
(board_x - btn_w) / 2.,
|
left_column_x,
|
||||||
board_y + (self.square_width - btn_h) / 2.,
|
board_y + self.board_rect.h - self.square_width + (self.square_width - btn_h) / 2.,
|
||||||
btn_w,
|
btn_w,
|
||||||
btn_h,
|
btn_h,
|
||||||
),
|
),
|
||||||
@@ -124,10 +129,14 @@ impl Game {
|
|||||||
);
|
);
|
||||||
self.rules_btn = Some(rules_button);
|
self.rules_btn = Some(rules_button);
|
||||||
|
|
||||||
|
// Right column
|
||||||
|
let right_column_x = board_x
|
||||||
|
+ board_width
|
||||||
|
+ constants::BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER * self.square_width;
|
||||||
let easy_btn = Button::new(
|
let easy_btn = Button::new(
|
||||||
constants::EASY_BUTTON_TEXT,
|
constants::EASY_BUTTON_TEXT,
|
||||||
Rect::new(
|
Rect::new(
|
||||||
(board_x - btn_w) / 2.,
|
right_column_x,
|
||||||
board_y + self.square_width + (self.square_width - btn_h) / 2.,
|
board_y + self.square_width + (self.square_width - btn_h) / 2.,
|
||||||
btn_w,
|
btn_w,
|
||||||
btn_h,
|
btn_h,
|
||||||
@@ -140,7 +149,7 @@ impl Game {
|
|||||||
let medium_btn = Button::new(
|
let medium_btn = Button::new(
|
||||||
constants::MEDIUM_BUTTON_TEXT,
|
constants::MEDIUM_BUTTON_TEXT,
|
||||||
Rect::new(
|
Rect::new(
|
||||||
(board_x - btn_w) / 2.,
|
right_column_x,
|
||||||
board_y + 2. * self.square_width + (self.square_width - btn_h) / 2.,
|
board_y + 2. * self.square_width + (self.square_width - btn_h) / 2.,
|
||||||
btn_w,
|
btn_w,
|
||||||
btn_h,
|
btn_h,
|
||||||
@@ -153,7 +162,7 @@ impl Game {
|
|||||||
let hard_button = Button::new(
|
let hard_button = Button::new(
|
||||||
constants::HARD_BUTTON_TEXT,
|
constants::HARD_BUTTON_TEXT,
|
||||||
Rect::new(
|
Rect::new(
|
||||||
(board_x - btn_w) / 2.,
|
right_column_x,
|
||||||
board_y + 3. * self.square_width + (self.square_width - btn_h) / 2.,
|
board_y + 3. * self.square_width + (self.square_width - btn_h) / 2.,
|
||||||
btn_w,
|
btn_w,
|
||||||
btn_h,
|
btn_h,
|
||||||
|
|||||||
Reference in New Issue
Block a user