fix re-exports
This commit is contained in:
+12
-51
@@ -3,12 +3,12 @@ mod draw;
|
||||
mod logic;
|
||||
|
||||
use crate::{
|
||||
game::logic::{GameMode, GameState},
|
||||
resources::Resources,
|
||||
widgets::{button::Button, id_text_input::IdTextInput},
|
||||
widgets::*,
|
||||
};
|
||||
use macroquad::prelude::*;
|
||||
use sol_lib::{board::Board, generator::Puzzle};
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Game {
|
||||
@@ -16,18 +16,22 @@ pub struct Game {
|
||||
|
||||
volume: f32,
|
||||
|
||||
puzzle: Puzzle,
|
||||
state: GameState,
|
||||
debug: bool,
|
||||
|
||||
window_height: f32,
|
||||
window_width: f32,
|
||||
|
||||
puzzle: Puzzle,
|
||||
id_text: IdTextInput,
|
||||
reset_btn: ButtonWidget,
|
||||
next_btn: ButtonWidget,
|
||||
|
||||
current_board: Board,
|
||||
square_width: f32,
|
||||
num_squares: usize, // this is a constant = 4 for now.
|
||||
board_rect: Rect,
|
||||
squares: Vec<GameSquare>,
|
||||
state: GameState,
|
||||
|
||||
heading_rect: Rect,
|
||||
heading_font_size: f32,
|
||||
@@ -35,18 +39,12 @@ pub struct Game {
|
||||
|
||||
show_rules: bool,
|
||||
rules_text: String,
|
||||
rules_btn: Button,
|
||||
|
||||
id_text: IdTextInput,
|
||||
|
||||
reset_btn: Button,
|
||||
|
||||
next_btn: Button,
|
||||
rules_btn: ButtonWidget,
|
||||
|
||||
game_mode: GameMode,
|
||||
easy_btn: Button,
|
||||
medium_btn: Button,
|
||||
hard_btn: Button,
|
||||
easy_btn: ButtonWidget,
|
||||
medium_btn: ButtonWidget,
|
||||
hard_btn: ButtonWidget,
|
||||
}
|
||||
|
||||
struct GameSquare {
|
||||
@@ -58,40 +56,3 @@ struct GameSquare {
|
||||
i: 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::{Game, GameMode, constants};
|
||||
use crate::widgets::{button::Button, id_text_input::IdTextInput, *};
|
||||
use crate::widgets::*;
|
||||
use macroquad::{math, prelude::*};
|
||||
use sol_lib::board::piece::Piece;
|
||||
|
||||
@@ -93,7 +93,7 @@ impl Game {
|
||||
let bottom_row_y = board_width
|
||||
+ board_y
|
||||
+ 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.,
|
||||
bottom_row_y,
|
||||
btn_w_sq,
|
||||
@@ -101,7 +101,7 @@ impl Game {
|
||||
));
|
||||
let btn_next_x_offset =
|
||||
(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,
|
||||
bottom_row_y,
|
||||
btn_w_sq,
|
||||
@@ -120,7 +120,7 @@ impl Game {
|
||||
// Left column
|
||||
let left_column_x =
|
||||
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,
|
||||
board_y + self.board_rect.h - self.square_width + (self.square_width - btn_h) / 2.,
|
||||
btn_w,
|
||||
@@ -131,21 +131,21 @@ impl Game {
|
||||
let right_column_x = board_x
|
||||
+ board_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,
|
||||
board_y + self.square_width + (self.square_width - btn_h) / 2.,
|
||||
btn_w,
|
||||
btn_h,
|
||||
));
|
||||
|
||||
self.medium_btn = Button::new(Rect::new(
|
||||
self.medium_btn = ButtonWidget::new(Rect::new(
|
||||
right_column_x,
|
||||
board_y + 2. * self.square_width + (self.square_width - btn_h) / 2.,
|
||||
btn_w,
|
||||
btn_h,
|
||||
));
|
||||
|
||||
self.hard_btn = Button::new(Rect::new(
|
||||
self.hard_btn = ButtonWidget::new(Rect::new(
|
||||
right_column_x,
|
||||
board_y + 3. * self.square_width + (self.square_width - btn_h) / 2.,
|
||||
btn_w,
|
||||
|
||||
+43
-7
@@ -1,13 +1,49 @@
|
||||
use super::{Game, GameMode, GameSquare, GameState, constants};
|
||||
use crate::{
|
||||
resources::{Resources, SoundKind},
|
||||
widgets::{button::Button, *},
|
||||
};
|
||||
use super::{Game, GameSquare, constants};
|
||||
use crate::{resources::*, widgets::*};
|
||||
use core::fmt;
|
||||
use macroquad::prelude::*;
|
||||
use sol_lib::{
|
||||
board::BoardState,
|
||||
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 {
|
||||
fn get(&mut self, i: usize, j: usize) -> &mut GameSquare {
|
||||
@@ -72,7 +108,7 @@ impl Game {
|
||||
}
|
||||
|
||||
// PRESETS
|
||||
let mut clicked_game_mode_btn: Option<&Button> = None;
|
||||
let mut clicked_game_mode_btn: Option<&ButtonWidget> = None;
|
||||
if (self
|
||||
.easy_btn
|
||||
.handle_input(&self.resources.sound(&SoundKind::Mode), self.volume))
|
||||
@@ -295,7 +331,7 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MacroquadRandAdapter;
|
||||
struct MacroquadRandAdapter;
|
||||
impl RandomRange for MacroquadRandAdapter {
|
||||
fn gen_range(&self, min: usize, max: usize) -> usize {
|
||||
rand::gen_range(min, max)
|
||||
|
||||
+5
-2
@@ -1,5 +1,8 @@
|
||||
pub mod button;
|
||||
pub mod id_text_input;
|
||||
mod button;
|
||||
pub use button::*;
|
||||
|
||||
mod id_text_input;
|
||||
pub use id_text_input::*;
|
||||
|
||||
use macroquad::{
|
||||
audio::{self, Sound},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use macroquad::{audio::Sound, prelude::*};
|
||||
use crate::widgets::*;
|
||||
use macroquad::{audio::Sound, prelude::*};
|
||||
|
||||
pub struct Button {
|
||||
pub struct ButtonWidget {
|
||||
pub is_active: bool,
|
||||
is_down: bool,
|
||||
rect: Rect,
|
||||
@@ -12,7 +12,7 @@ pub struct ButtonInteraction {
|
||||
pub is_clicked: bool,
|
||||
}
|
||||
|
||||
impl Button {
|
||||
impl ButtonWidget {
|
||||
pub fn new(rect: Rect) -> Self {
|
||||
Self {
|
||||
is_down: false,
|
||||
@@ -121,7 +121,7 @@ impl Button {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Button {
|
||||
impl Default for ButtonWidget {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
is_active: Default::default(),
|
||||
|
||||
Reference in New Issue
Block a user