fix re-exports

This commit is contained in:
cool-mist
2026-01-24 16:52:05 +05:30
parent 04b39e53a4
commit 52fb443d5b
5 changed files with 71 additions and 71 deletions
+12 -51
View File
@@ -3,12 +3,12 @@ mod draw;
mod logic; mod logic;
use crate::{ use crate::{
game::logic::{GameMode, GameState},
resources::Resources, resources::Resources,
widgets::{button::Button, id_text_input::IdTextInput}, widgets::*,
}; };
use macroquad::prelude::*; use macroquad::prelude::*;
use sol_lib::{board::Board, generator::Puzzle}; use sol_lib::{board::Board, generator::Puzzle};
use std::fmt::{self, Display, Formatter};
#[derive(Default)] #[derive(Default)]
pub struct Game { pub struct Game {
@@ -16,18 +16,22 @@ pub struct Game {
volume: f32, volume: f32,
puzzle: Puzzle,
state: GameState,
debug: bool, debug: bool,
window_height: f32, window_height: f32,
window_width: f32, window_width: f32,
puzzle: Puzzle,
id_text: IdTextInput,
reset_btn: ButtonWidget,
next_btn: ButtonWidget,
current_board: Board, current_board: Board,
square_width: f32, square_width: f32,
num_squares: usize, // this is a constant = 4 for now. num_squares: usize, // this is a constant = 4 for now.
board_rect: Rect, board_rect: Rect,
squares: Vec<GameSquare>, squares: Vec<GameSquare>,
state: GameState,
heading_rect: Rect, heading_rect: Rect,
heading_font_size: f32, heading_font_size: f32,
@@ -35,18 +39,12 @@ pub struct Game {
show_rules: bool, show_rules: bool,
rules_text: String, rules_text: String,
rules_btn: Button, rules_btn: ButtonWidget,
id_text: IdTextInput,
reset_btn: Button,
next_btn: Button,
game_mode: GameMode, game_mode: GameMode,
easy_btn: Button, easy_btn: ButtonWidget,
medium_btn: Button, medium_btn: ButtonWidget,
hard_btn: Button, hard_btn: ButtonWidget,
} }
struct GameSquare { struct GameSquare {
@@ -58,40 +56,3 @@ struct GameSquare {
i: usize, i: usize,
j: usize, j: usize,
} }
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum GameMode {
Easy,
Medium,
Hard,
}
impl Default for GameMode {
fn default() -> Self {
GameMode::Medium
}
}
#[derive(Copy, Clone)]
enum GameState {
SelectSource(Option<(usize, usize)>),
SelectTarget((usize, usize)),
GameOver((usize, usize)),
}
impl Default for GameState {
fn default() -> Self {
GameState::SelectSource(None)
}
}
impl Display for GameState {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
GameState::SelectSource(Some(x)) => write!(f, "Select Source [ {}, {} ]", x.0, x.1),
GameState::SelectSource(None) => write!(f, "Select Source [ ]"),
GameState::SelectTarget(x) => write!(f, "Select Target [ {}, {} ]", x.0, x.1),
GameState::GameOver(x) => write!(f, "Game Over [ {}, {} ]", x.0, x.1),
}
}
}
+7 -7
View File
@@ -1,5 +1,5 @@
use super::{Game, GameMode, constants}; use super::{Game, GameMode, constants};
use crate::widgets::{button::Button, id_text_input::IdTextInput, *}; use crate::widgets::*;
use macroquad::{math, prelude::*}; use macroquad::{math, prelude::*};
use sol_lib::board::piece::Piece; use sol_lib::board::piece::Piece;
@@ -93,7 +93,7 @@ impl Game {
let bottom_row_y = board_width 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;
self.reset_btn = Button::new(Rect::new( self.reset_btn = ButtonWidget::new(Rect::new(
board_x + (self.square_width - btn_w_sq) / 2., board_x + (self.square_width - btn_w_sq) / 2.,
bottom_row_y, bottom_row_y,
btn_w_sq, btn_w_sq,
@@ -101,7 +101,7 @@ impl Game {
)); ));
let btn_next_x_offset = let btn_next_x_offset =
(self.board_rect.w - self.square_width) + (self.square_width - btn_w_sq) / 2.; (self.board_rect.w - self.square_width) + (self.square_width - btn_w_sq) / 2.;
self.next_btn = Button::new(Rect::new( self.next_btn = ButtonWidget::new(Rect::new(
board_x + btn_next_x_offset, board_x + btn_next_x_offset,
bottom_row_y, bottom_row_y,
btn_w_sq, btn_w_sq,
@@ -120,7 +120,7 @@ impl Game {
// Left column // Left column
let left_column_x = let left_column_x =
board_x - constants::BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER * self.square_width - btn_w; board_x - constants::BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER * self.square_width - btn_w;
self.rules_btn = Button::new(Rect::new( self.rules_btn = ButtonWidget::new(Rect::new(
left_column_x, left_column_x,
board_y + self.board_rect.h - self.square_width + (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,
@@ -131,21 +131,21 @@ impl Game {
let right_column_x = board_x let right_column_x = board_x
+ board_width + board_width
+ constants::BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER * self.square_width; + constants::BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER * self.square_width;
self.easy_btn = Button::new(Rect::new( self.easy_btn = ButtonWidget::new(Rect::new(
right_column_x, 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,
)); ));
self.medium_btn = Button::new(Rect::new( self.medium_btn = ButtonWidget::new(Rect::new(
right_column_x, 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,
)); ));
self.hard_btn = Button::new(Rect::new( self.hard_btn = ButtonWidget::new(Rect::new(
right_column_x, 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,
+43 -7
View File
@@ -1,13 +1,49 @@
use super::{Game, GameMode, GameSquare, GameState, constants}; use super::{Game, GameSquare, constants};
use crate::{ use crate::{resources::*, widgets::*};
resources::{Resources, SoundKind}, use core::fmt;
widgets::{button::Button, *},
};
use macroquad::prelude::*; use macroquad::prelude::*;
use sol_lib::{ use sol_lib::{
board::BoardState, board::BoardState,
generator::{self, Puzzle, RandomRange}, generator::{self, Puzzle, RandomRange},
}; };
use std::fmt::{Display, Formatter};
#[derive(Copy, Clone)]
pub enum GameState {
SelectSource(Option<(usize, usize)>),
SelectTarget((usize, usize)),
GameOver((usize, usize)),
}
impl Default for GameState {
fn default() -> Self {
GameState::SelectSource(None)
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum GameMode {
Easy,
Medium,
Hard,
}
impl Default for GameMode {
fn default() -> Self {
GameMode::Medium
}
}
impl Display for GameState {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
GameState::SelectSource(Some(x)) => write!(f, "Select Source [ {}, {} ]", x.0, x.1),
GameState::SelectSource(None) => write!(f, "Select Source [ ]"),
GameState::SelectTarget(x) => write!(f, "Select Target [ {}, {} ]", x.0, x.1),
GameState::GameOver(x) => write!(f, "Game Over [ {}, {} ]", x.0, x.1),
}
}
}
impl Game { impl Game {
fn get(&mut self, i: usize, j: usize) -> &mut GameSquare { fn get(&mut self, i: usize, j: usize) -> &mut GameSquare {
@@ -72,7 +108,7 @@ impl Game {
} }
// PRESETS // PRESETS
let mut clicked_game_mode_btn: Option<&Button> = None; let mut clicked_game_mode_btn: Option<&ButtonWidget> = None;
if (self if (self
.easy_btn .easy_btn
.handle_input(&self.resources.sound(&SoundKind::Mode), self.volume)) .handle_input(&self.resources.sound(&SoundKind::Mode), self.volume))
@@ -295,7 +331,7 @@ impl Game {
} }
} }
pub struct MacroquadRandAdapter; struct MacroquadRandAdapter;
impl RandomRange for MacroquadRandAdapter { impl RandomRange for MacroquadRandAdapter {
fn gen_range(&self, min: usize, max: usize) -> usize { fn gen_range(&self, min: usize, max: usize) -> usize {
rand::gen_range(min, max) rand::gen_range(min, max)
+5 -2
View File
@@ -1,5 +1,8 @@
pub mod button; mod button;
pub mod id_text_input; pub use button::*;
mod id_text_input;
pub use id_text_input::*;
use macroquad::{ use macroquad::{
audio::{self, Sound}, audio::{self, Sound},
+4 -4
View File
@@ -1,7 +1,7 @@
use macroquad::{audio::Sound, prelude::*};
use crate::widgets::*; use crate::widgets::*;
use macroquad::{audio::Sound, prelude::*};
pub struct Button { pub struct ButtonWidget {
pub is_active: bool, pub is_active: bool,
is_down: bool, is_down: bool,
rect: Rect, rect: Rect,
@@ -12,7 +12,7 @@ pub struct ButtonInteraction {
pub is_clicked: bool, pub is_clicked: bool,
} }
impl Button { impl ButtonWidget {
pub fn new(rect: Rect) -> Self { pub fn new(rect: Rect) -> Self {
Self { Self {
is_down: false, is_down: false,
@@ -121,7 +121,7 @@ impl Button {
} }
} }
impl Default for Button { impl Default for ButtonWidget {
fn default() -> Self { fn default() -> Self {
Self { Self {
is_active: Default::default(), is_active: Default::default(),