From 04b39e53a40490e10530cab0e76714e626c69d16 Mon Sep 17 00:00:00 2001 From: cool-mist Date: Fri, 23 Jan 2026 19:23:45 +0530 Subject: [PATCH] Add widgets, proper resources.rs --- README.md | 8 - cli/src/main.rs | 2 +- gui/src/game.rs | 83 +++++---- gui/src/game/constants.rs | 4 +- gui/src/game/draw.rs | 253 +++++++++++++++----------- gui/src/game/logic.rs | 251 ++++++++++++------------- gui/src/game/shadow.rs | 20 -- gui/src/game/sound.rs | 24 --- gui/src/game/texture.rs | 45 ----- gui/src/main.rs | 44 +---- gui/src/resources.rs | 110 +++++++++++ gui/src/{game/color.rs => widgets.rs} | 44 ++++- gui/src/{game => widgets}/button.rs | 76 ++++---- gui/src/widgets/id_text_input.rs | 76 ++++++++ lib/src/board.rs | 63 ++++++- lib/src/generator.rs | 47 +++-- lib/src/lib.rs | 1 - lib/src/solver.rs | 62 ------- 18 files changed, 675 insertions(+), 538 deletions(-) delete mode 100644 gui/src/game/shadow.rs delete mode 100644 gui/src/game/sound.rs delete mode 100644 gui/src/game/texture.rs create mode 100644 gui/src/resources.rs rename gui/src/{game/color.rs => widgets.rs} (59%) rename gui/src/{game => widgets}/button.rs (64%) create mode 100644 gui/src/widgets/id_text_input.rs delete mode 100644 lib/src/solver.rs diff --git a/README.md b/README.md index fd75d63..b4dc006 100644 --- a/README.md +++ b/README.md @@ -64,11 +64,3 @@ $ sol_cli --solve-board pb......br..p..p There are atleast 1 solutions to this puzzle ``` - -## Heuristics of current algorithm - -1. About 6-7 pieces on the board. -2. Select pieces to place based on its weight. - 3. Eg: Queen is too powerful, so it has lower weightage. - 4. Eg: Knights are confusing. More knights. - diff --git a/cli/src/main.rs b/cli/src/main.rs index bb63a7a..0731106 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -72,7 +72,7 @@ fn generate_puzzle(num_pieces: Option, num_solutions: Option) -> Optio "Generating a puzzle with {} pieces with a maximum of {} solutions", num_pieces, num_solutions ); - let gen_result = generator::generate(num_pieces, num_solutions, &RandRngImpl); + let gen_result = generator::generate_weighted_random(num_pieces, num_solutions, &RandRngImpl); gen_result.print_stats(); let Some(puzzle) = gen_result.puzzle() else { diff --git a/gui/src/game.rs b/gui/src/game.rs index 615ff0b..ac2b75d 100644 --- a/gui/src/game.rs +++ b/gui/src/game.rs @@ -1,55 +1,52 @@ -use std::{ - collections::HashMap, - fmt::{self, Display, Formatter}, - rc::Rc, -}; - -mod button; -mod color; pub mod constants; mod draw; mod logic; -mod shadow; -pub mod sound; -mod texture; -use button::Button; +use crate::{ + resources::Resources, + widgets::{button::Button, id_text_input::IdTextInput}, +}; use macroquad::prelude::*; use sol_lib::{board::Board, generator::Puzzle}; -use sound::Sounds; +use std::fmt::{self, Display, Formatter}; +#[derive(Default)] pub struct Game { - // The generated puzzle. We keep a copy of this to reset the game. + resources: Resources, + + volume: f32, + puzzle: Puzzle, - - // What is shown to the user - current_board: Board, - - // Constants througout the game - texture_res: Texture2D, - sounds: Sounds, - font: Rc, - num_squares: usize, - heading_text: String, - - // Update below on handle input state: GameState, debug: bool, - game_mode: GameMode, - // Update below on window resize - // Used for drawing the state - square_width: f32, window_height: f32, window_width: f32, + + current_board: Board, + square_width: f32, + num_squares: usize, // this is a constant = 4 for now. board_rect: Rect, squares: Vec, + heading_rect: Rect, heading_font_size: f32, - gp_btns: HashMap, - mode_btns: HashMap, - rules: bool, - rules_btn: Option