Fix clippy warnings
This commit is contained in:
parent
864a9ca3d5
commit
31c6c4858f
14
src/gui.rs
14
src/gui.rs
|
@ -53,13 +53,13 @@ pub struct UIState {
|
||||||
}
|
}
|
||||||
impl UIState {
|
impl UIState {
|
||||||
pub fn new(width: usize, height: usize, tile_size: usize, top_offset: usize) -> Self {
|
pub fn new(width: usize, height: usize, tile_size: usize, top_offset: usize) -> Self {
|
||||||
return Self {
|
Self {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
tile_size,
|
tile_size,
|
||||||
top_offset,
|
top_offset,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
pub fn update_dimensions(&mut self, width: usize, height: usize) {
|
pub fn update_dimensions(&mut self, width: usize, height: usize) {
|
||||||
self.width = width;
|
self.width = width;
|
||||||
|
@ -91,12 +91,12 @@ impl UIState {
|
||||||
let (x, y) = self.pixel_screen_scale(x, y);
|
let (x, y) = self.pixel_screen_scale(x, y);
|
||||||
let x = x + self.letterbox.0;
|
let x = x + self.letterbox.0;
|
||||||
let y = y + self.letterbox.1;
|
let y = y + self.letterbox.1;
|
||||||
return (x, y);
|
(x, y)
|
||||||
}
|
}
|
||||||
pub fn pixel_screen_scale(&self, x: usize, y: usize) -> (f32, f32) {
|
pub fn pixel_screen_scale(&self, x: usize, y: usize) -> (f32, f32) {
|
||||||
let x = x as f32;
|
let x = x as f32;
|
||||||
let y = y as f32;
|
let y = y as f32;
|
||||||
return (x * self.scale, y * self.scale);
|
(x * self.scale, y * self.scale)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,10 +113,10 @@ pub struct GameUI {
|
||||||
impl GameUI {
|
impl GameUI {
|
||||||
pub fn new(settings: UIState) -> Self {
|
pub fn new(settings: UIState) -> Self {
|
||||||
let set = settings;
|
let set = settings;
|
||||||
return Self {
|
Self {
|
||||||
state: set,
|
state: set,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
pub fn is_valid_position(&self, x: usize, y: usize) -> bool {
|
pub fn is_valid_position(&self, x: usize, y: usize) -> bool {
|
||||||
if x < self.state.width && y < self.state.height {
|
if x < self.state.width && y < self.state.height {
|
||||||
|
@ -145,6 +145,6 @@ impl GameUI {
|
||||||
if !self.is_valid_position(x, y) {
|
if !self.is_valid_position(x, y) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
return Some((x, y));
|
Some((x, y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl Highlighter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.move_highlight(&interface, event_handler);
|
self.move_highlight(interface, event_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_highlight(&mut self, interface: &UIState, event_handler: &mut Events<GUIEvent>) {
|
fn move_highlight(&mut self, interface: &UIState, event_handler: &mut Events<GUIEvent>) {
|
||||||
|
|
|
@ -51,18 +51,18 @@ impl SettingsMenu {
|
||||||
|
|
||||||
root_ui().window(hash!(), vec2(0., 0.), vec2(screen_width, screen_height), |ui| {
|
root_ui().window(hash!(), vec2(0., 0.), vec2(screen_width, screen_height), |ui| {
|
||||||
draw_rectangle(0f32, 0f32, screen_width, screen_height, background_color);
|
draw_rectangle(0f32, 0f32, screen_width, screen_height, background_color);
|
||||||
ui.push_skin(&exit_button_skin);
|
ui.push_skin(exit_button_skin);
|
||||||
if widgets::Button::new("").size(vec2(50.0, 50.0)).position(vec2(0f32, 0f32)).ui(ui) {
|
if widgets::Button::new("").size(vec2(50.0, 50.0)).position(vec2(0f32, 0f32)).ui(ui) {
|
||||||
event_handler.add(GUIEvent::CloseSettings)
|
event_handler.add(GUIEvent::CloseSettings)
|
||||||
}
|
}
|
||||||
ui.pop_skin();
|
ui.pop_skin();
|
||||||
ui.push_skin(&skin);
|
ui.push_skin(skin);
|
||||||
let half_screen_width = screen_width * 0.5;
|
let half_screen_width = screen_width * 0.5;
|
||||||
|
|
||||||
render_counter(
|
render_counter(
|
||||||
&mut self.width,
|
&mut self.width,
|
||||||
ui,
|
ui,
|
||||||
&textures,
|
textures,
|
||||||
vec2(half_screen_width, 100f32),
|
vec2(half_screen_width, 100f32),
|
||||||
"Minefield Width",
|
"Minefield Width",
|
||||||
MIN_MINEFIELD_WIDTH,
|
MIN_MINEFIELD_WIDTH,
|
||||||
|
@ -71,7 +71,7 @@ impl SettingsMenu {
|
||||||
render_counter(
|
render_counter(
|
||||||
&mut self.height,
|
&mut self.height,
|
||||||
ui,
|
ui,
|
||||||
&textures,
|
textures,
|
||||||
vec2(half_screen_width, 200f32),
|
vec2(half_screen_width, 200f32),
|
||||||
"Minefield Height",
|
"Minefield Height",
|
||||||
MIN_MINEFIELD_HEIGHT,
|
MIN_MINEFIELD_HEIGHT,
|
||||||
|
@ -80,7 +80,7 @@ impl SettingsMenu {
|
||||||
render_counter(
|
render_counter(
|
||||||
&mut self.mines,
|
&mut self.mines,
|
||||||
ui,
|
ui,
|
||||||
&textures,
|
textures,
|
||||||
vec2(half_screen_width, 300f32),
|
vec2(half_screen_width, 300f32),
|
||||||
"Mines",
|
"Mines",
|
||||||
1,
|
1,
|
||||||
|
@ -113,15 +113,13 @@ impl SettingsMenu {
|
||||||
{
|
{
|
||||||
event_handler.add(GUIEvent::SwitchLanguage(Language::Japanese));
|
event_handler.add(GUIEvent::SwitchLanguage(Language::Japanese));
|
||||||
}
|
}
|
||||||
} else {
|
} else if widgets::Button::new("Japanese")
|
||||||
if widgets::Button::new("Japanese")
|
|
||||||
.size(vec2(BUTTON_SIZE, BUTTON_SIZE))
|
.size(vec2(BUTTON_SIZE, BUTTON_SIZE))
|
||||||
.position(vec2(language_button_x, BUTTON_MENU_Y))
|
.position(vec2(language_button_x, BUTTON_MENU_Y))
|
||||||
.ui(ui)
|
.ui(ui)
|
||||||
{
|
{
|
||||||
event_handler.add(GUIEvent::SwitchLanguage(Language::English));
|
event_handler.add(GUIEvent::SwitchLanguage(Language::English));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let ModifyMode::Question = self.board_modify_mode {
|
if let ModifyMode::Question = self.board_modify_mode {
|
||||||
if widgets::Button::new("ON")
|
if widgets::Button::new("ON")
|
||||||
.size(vec2(BUTTON_SIZE, BUTTON_SIZE))
|
.size(vec2(BUTTON_SIZE, BUTTON_SIZE))
|
||||||
|
@ -131,8 +129,7 @@ impl SettingsMenu {
|
||||||
self.board_modify_mode = ModifyMode::Flag;
|
self.board_modify_mode = ModifyMode::Flag;
|
||||||
event_handler.add(GUIEvent::SetQuestionMode(ModifyMode::Flag));
|
event_handler.add(GUIEvent::SetQuestionMode(ModifyMode::Flag));
|
||||||
}
|
}
|
||||||
} else {
|
} else if widgets::Button::new("OFF")
|
||||||
if widgets::Button::new("OFF")
|
|
||||||
.size(vec2(BUTTON_SIZE, BUTTON_SIZE))
|
.size(vec2(BUTTON_SIZE, BUTTON_SIZE))
|
||||||
.position(vec2(question_button_x, BUTTON_MENU_Y))
|
.position(vec2(question_button_x, BUTTON_MENU_Y))
|
||||||
.ui(ui)
|
.ui(ui)
|
||||||
|
@ -140,7 +137,6 @@ impl SettingsMenu {
|
||||||
self.board_modify_mode = ModifyMode::Question;
|
self.board_modify_mode = ModifyMode::Question;
|
||||||
event_handler.add(GUIEvent::SetQuestionMode(ModifyMode::Question));
|
event_handler.add(GUIEvent::SetQuestionMode(ModifyMode::Question));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,12 +168,10 @@ fn render_counter(count: &mut usize, ui: &mut Ui, textures: &TextureStore, posit
|
||||||
if widgets::Button::new("-")
|
if widgets::Button::new("-")
|
||||||
.size(vec2(COUNTER_BUTTON_HEIGHT, COUNTER_BUTTON_HEIGHT))
|
.size(vec2(COUNTER_BUTTON_HEIGHT, COUNTER_BUTTON_HEIGHT))
|
||||||
.position(position - vec2(COUNTER_BUTTON_HEIGHT + COUNTER_BUTTON_MARGIN, -BUTTON_OFFSET_HEIGHT))
|
.position(position - vec2(COUNTER_BUTTON_HEIGHT + COUNTER_BUTTON_MARGIN, -BUTTON_OFFSET_HEIGHT))
|
||||||
.ui(ui)
|
.ui(ui) && *count > min
|
||||||
{
|
{
|
||||||
if *count > min {
|
|
||||||
*count -= 1;
|
*count -= 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if widgets::Button::new("++")
|
if widgets::Button::new("++")
|
||||||
.size(vec2(COUNTER_BUTTON_HEIGHT, COUNTER_BUTTON_HEIGHT))
|
.size(vec2(COUNTER_BUTTON_HEIGHT, COUNTER_BUTTON_HEIGHT))
|
||||||
.position(
|
.position(
|
||||||
|
|
|
@ -7,9 +7,9 @@ pub const HEIGHT: usize = 23 * 2;
|
||||||
|
|
||||||
use super::{texture_store::TextureStore, UIState};
|
use super::{texture_store::TextureStore, UIState};
|
||||||
|
|
||||||
pub fn draw_seven_segment(ui_state: &UIState, ui: &mut Ui, textures: &TextureStore, val: &Vec<usize>, x: usize, y: usize) {
|
pub fn draw_seven_segment(ui_state: &UIState, ui: &mut Ui, textures: &TextureStore, val: &[usize], x: usize, y: usize) {
|
||||||
for (n, digit) in val.iter().enumerate() {
|
for (n, digit) in val.iter().enumerate() {
|
||||||
let (scaled_width, scaled_height) = ui_state.pixel_screen_scale(WIDTH as usize, HEIGHT);
|
let (scaled_width, scaled_height) = ui_state.pixel_screen_scale(WIDTH, HEIGHT);
|
||||||
let (pos_x, pos_y) = ui_state.pixel_screen_offset(n * WIDTH + x, y);
|
let (pos_x, pos_y) = ui_state.pixel_screen_offset(n * WIDTH + x, y);
|
||||||
|
|
||||||
widgets::Texture::new(textures.numbers[*digit])
|
widgets::Texture::new(textures.numbers[*digit])
|
||||||
|
@ -19,7 +19,7 @@ pub fn draw_seven_segment(ui_state: &UIState, ui: &mut Ui, textures: &TextureSto
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_seven_segment_unscaled(ui: &mut Ui, textures: &TextureStore, val: &Vec<usize>, x: usize, y: usize) {
|
pub fn draw_seven_segment_unscaled(ui: &mut Ui, textures: &TextureStore, val: &[usize], x: usize, y: usize) {
|
||||||
for (n, digit) in val.iter().enumerate() {
|
for (n, digit) in val.iter().enumerate() {
|
||||||
let (pos_x, pos_y) = ((n * WIDTH + x) as f32, y as f32);
|
let (pos_x, pos_y) = ((n * WIDTH + x) as f32, y as f32);
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,9 @@ impl TextureStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_tiles(&self) -> &Vec<Texture2D> {
|
pub fn get_tiles(&self) -> &Vec<Texture2D> {
|
||||||
return match self.lang {
|
match self.lang {
|
||||||
Language::English => &self.english_tiles,
|
Language::English => &self.english_tiles,
|
||||||
Language::Japanese => &self.japanese_tiles,
|
Language::Japanese => &self.japanese_tiles,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl GUITop {
|
||||||
const HEIGHT: usize = 35;
|
const HEIGHT: usize = 35;
|
||||||
let pos_y = (ui_state.top_offset - HEIGHT) / 2;
|
let pos_y = (ui_state.top_offset - HEIGHT) / 2;
|
||||||
let pos_x = (13 * 2 * 2 - WIDTH) / 2;
|
let pos_x = (13 * 2 * 2 - WIDTH) / 2;
|
||||||
let (scaled_width, scaled_height) = ui_state.pixel_screen_scale(WIDTH as usize, HEIGHT);
|
let (scaled_width, scaled_height) = ui_state.pixel_screen_scale(WIDTH, HEIGHT);
|
||||||
let (pos_x, pos_y) = ui_state.pixel_screen_offset(pos_x, pos_y);
|
let (pos_x, pos_y) = ui_state.pixel_screen_offset(pos_x, pos_y);
|
||||||
if widgets::Button::new(textures.cog)
|
if widgets::Button::new(textures.cog)
|
||||||
.size(vec2(scaled_width, scaled_height))
|
.size(vec2(scaled_width, scaled_height))
|
||||||
|
@ -69,9 +69,9 @@ impl GUITop {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.timer.render(&ui_state, game_logic.get_time(), ui, &textures);
|
self.timer.render(ui_state, game_logic.get_time(), ui, textures);
|
||||||
self.smile.render(&ui_state, ui, event_handler, &textures);
|
self.smile.render(ui_state, ui, event_handler, textures);
|
||||||
self.flag_counter.render(&ui_state, game_logic.board.remaining_flags(), ui, &textures);
|
self.flag_counter.render(ui_state, game_logic.board.remaining_flags(), ui, textures);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl Minesweeper {
|
||||||
self.board.modify(x, y, &mut self.events)
|
self.board.modify(x, y, &mut self.events)
|
||||||
}
|
}
|
||||||
pub fn get_time(&self) -> Option<f64> {
|
pub fn get_time(&self) -> Option<f64> {
|
||||||
return self.timer.elapsed();
|
self.timer.elapsed()
|
||||||
}
|
}
|
||||||
pub fn highlight(&mut self, x: usize, y: usize) {
|
pub fn highlight(&mut self, x: usize, y: usize) {
|
||||||
if self.state == GameState::Playing || self.state == GameState::Empty {
|
if self.state == GameState::Playing || self.state == GameState::Empty {
|
||||||
|
|
|
@ -109,11 +109,11 @@ impl GameBoard {
|
||||||
self.flags -= 1;
|
self.flags -= 1;
|
||||||
match self.modify_mode {
|
match self.modify_mode {
|
||||||
ModifyMode::Flag => {
|
ModifyMode::Flag => {
|
||||||
event_handler.add(GameEvent::FlagTile(x, y, tile.clone()));
|
event_handler.add(GameEvent::FlagTile(x, y, tile));
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
ModifyMode::Question => {
|
ModifyMode::Question => {
|
||||||
event_handler.add(GameEvent::QuestionTile(x, y, tile.clone()));
|
event_handler.add(GameEvent::QuestionTile(x, y, tile));
|
||||||
|
|
||||||
Some(TileModifier::Unsure)
|
Some(TileModifier::Unsure)
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ impl GameBoard {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.flags += 1;
|
self.flags += 1;
|
||||||
event_handler.add(GameEvent::FlagTile(x, y, tile.clone()));
|
event_handler.add(GameEvent::FlagTile(x, y, tile));
|
||||||
Some(TileModifier::Flagged)
|
Some(TileModifier::Flagged)
|
||||||
};
|
};
|
||||||
if let Some(tile) = self.get_tile_mut(x, y) {
|
if let Some(tile) = self.get_tile_mut(x, y) {
|
||||||
|
@ -136,8 +136,8 @@ impl GameBoard {
|
||||||
if let BoardState::Ungenerated = self.state {
|
if let BoardState::Ungenerated = self.state {
|
||||||
self.generate(x, y);
|
self.generate(x, y);
|
||||||
}
|
}
|
||||||
let &tile = &self.tiles[x][y];
|
let tile = self.tiles[x][y];
|
||||||
if let Some(_) = tile.modifier {
|
if tile.modifier.is_some() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
if tile.swept {
|
if tile.swept {
|
||||||
|
@ -145,10 +145,10 @@ impl GameBoard {
|
||||||
}
|
}
|
||||||
self.tiles[x][y].swept = true;
|
self.tiles[x][y].swept = true;
|
||||||
self.revealed_tiles += 1;
|
self.revealed_tiles += 1;
|
||||||
event_handler.add(GameEvent::RevealTile(x, y, self.tiles[x][y].clone()));
|
event_handler.add(GameEvent::RevealTile(x, y, self.tiles[x][y]));
|
||||||
|
|
||||||
if tile.state == TileState::Mine {
|
if tile.state == TileState::Mine {
|
||||||
event_handler.add(GameEvent::Lose(x, y, tile.clone()));
|
event_handler.add(GameEvent::Lose(x, y, tile));
|
||||||
|
|
||||||
event_handler.add(GameEvent::GameEnd(self.clone()));
|
event_handler.add(GameEvent::GameEnd(self.clone()));
|
||||||
return Some(GameState::GameOver);
|
return Some(GameState::GameOver);
|
||||||
|
@ -157,7 +157,7 @@ impl GameBoard {
|
||||||
|
|
||||||
let mut scan_list = VecDeque::from([(x, y)]);
|
let mut scan_list = VecDeque::from([(x, y)]);
|
||||||
let mut revealed: usize = 0;
|
let mut revealed: usize = 0;
|
||||||
while scan_list.len() > 0 {
|
while !scan_list.is_empty() {
|
||||||
for &scan_location in ADJACENT_WITHOUT_CENTER.iter() {
|
for &scan_location in ADJACENT_WITHOUT_CENTER.iter() {
|
||||||
if let Some((x, y)) = scan_list.front() {
|
if let Some((x, y)) = scan_list.front() {
|
||||||
if let Some(old_tile) = self.get_tile(*x, *y) {
|
if let Some(old_tile) = self.get_tile(*x, *y) {
|
||||||
|
@ -179,7 +179,7 @@ impl GameBoard {
|
||||||
scan_list.push_back((x, y));
|
scan_list.push_back((x, y));
|
||||||
tile.swept = true;
|
tile.swept = true;
|
||||||
revealed += 1;
|
revealed += 1;
|
||||||
event_handler.add(GameEvent::RevealTile(x, y, tile.clone()));
|
event_handler.add(GameEvent::RevealTile(x, y, *tile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ impl GameBoard {
|
||||||
let y = macroquad::rand::gen_range(0, height);
|
let y = macroquad::rand::gen_range(0, height);
|
||||||
let mut tile = &mut self.tiles[x][y];
|
let mut tile = &mut self.tiles[x][y];
|
||||||
|
|
||||||
if tile.state == TileState::Mine || tile.safe == true {
|
if tile.state == TileState::Mine || tile.safe {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl Tile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn highlight(&mut self) {
|
pub fn highlight(&mut self) {
|
||||||
if self.swept == false {
|
if !self.swept {
|
||||||
self.highlighted = true;
|
self.highlighted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,7 @@ impl Timer {
|
||||||
if let TimerState::Frozen = self.state {
|
if let TimerState::Frozen = self.state {
|
||||||
return Some(self.old);
|
return Some(self.old);
|
||||||
}
|
}
|
||||||
if let Some(time) = self.start_time {
|
self.start_time.map(|time| get_time() - time)
|
||||||
Some(get_time() - time)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn stop(&mut self) {
|
pub fn stop(&mut self) {
|
||||||
self.old = self.elapsed().unwrap_or(0f64);
|
self.old = self.elapsed().unwrap_or(0f64);
|
||||||
|
|
|
@ -12,8 +12,8 @@ mod sprite_loader;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let width = (30 * 32) as i32;
|
let width = 30 * 32;
|
||||||
let height = (16 * 32) as i32 + 100;
|
let height = 16 * 32 + 100;
|
||||||
Window::from_config(
|
Window::from_config(
|
||||||
Conf {
|
Conf {
|
||||||
sample_count: 2,
|
sample_count: 2,
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl<E> Events<E> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next(&mut self) -> Option<E> {
|
pub fn next(&mut self) -> Option<E> {
|
||||||
if self.events.len() > 0 {
|
if !self.events.is_empty() {
|
||||||
self.events.pop()
|
self.events.pop()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in a new issue