Formatted and fixed clippy with nightly
All checks were successful
Rust / rustfmt (pull_request) Successful in 19s
Rust / clippy (pull_request) Successful in 38s
Rust / build (pull_request) Successful in 2m17s

This commit is contained in:
Glaeder 2024-07-06 19:56:33 +02:00
parent ee49fb493f
commit 901d457f81
7 changed files with 21 additions and 21 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
/target /target
shell.nix *.nix
.vscode/ .vscode/

View file

@ -3,7 +3,7 @@ use comfy::*;
#[derive(Debug)] #[derive(Debug)]
pub struct Grid { pub struct Grid {
pub nodes: Vec<Vec2>, pub nodes: Vec<Vec2>,
pub connections: Vec<(usize, usize)>, pub connections: Vec<(usize, usize)>
} }
impl Default for Grid { impl Default for Grid {
@ -22,7 +22,7 @@ impl Grid {
vec2(-10.0, 0.0), vec2(-10.0, 0.0),
vec2(10.0, 10.0), vec2(10.0, 10.0),
], ],
connections: vec![(0, 1), (1, 2), (1, 3), (0, 4), (0, 5), (5, 1), (6, 7)], connections: vec![(0, 1), (1, 2), (1, 3), (0, 4), (0, 5), (5, 1), (6, 7)]
}; };
grid.sanitize(); grid.sanitize();

View file

@ -7,7 +7,7 @@ use player::Player;
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct HouseState { pub struct HouseState {
grid: Grid, grid: Grid,
player: Player, player: Player
} }
pub fn draw(state: &crate::State, _engine: &comfy::EngineContext) { pub fn draw(state: &crate::State, _engine: &comfy::EngineContext) {

View file

@ -7,7 +7,7 @@ pub struct Player {
position: Vec2, position: Vec2,
speed: f32, speed: f32,
connection: usize, connection: usize,
next_connections: Vec<usize>, next_connections: Vec<usize>
} }
impl Default for Player { impl Default for Player {
@ -16,7 +16,7 @@ impl Default for Player {
position: Default::default(), position: Default::default(),
speed: 10.0, speed: 10.0,
connection: 0, connection: 0,
next_connections: vec![1, 2, 3], next_connections: vec![1, 2, 3]
} }
} }
} }
@ -40,7 +40,7 @@ fn move_player(player: &mut Player, allowed_movement: (bool, bool, bool, bool))
allow_up_movement, allow_up_movement,
allow_down_movement, allow_down_movement,
allow_left_movement, allow_left_movement,
allow_right_movement, allow_right_movement
) = allowed_movement; ) = allowed_movement;
if allow_up_movement && is_key_down(KeyCode::Up) { if allow_up_movement && is_key_down(KeyCode::Up) {
@ -77,7 +77,7 @@ fn get_allowed_movement(player: &Player, grid: &Grid) -> (bool, bool, bool, bool
mut allow_up_movement, mut allow_up_movement,
mut allow_down_movement, mut allow_down_movement,
mut allow_left_movement, mut allow_left_movement,
mut allow_right_movement, mut allow_right_movement
) = get_allowed_connection_movement(&player.position, node_1, node_2); ) = get_allowed_connection_movement(&player.position, node_1, node_2);
for conn in &player.next_connections { for conn in &player.next_connections {
@ -89,26 +89,26 @@ fn get_allowed_movement(player: &Player, grid: &Grid) -> (bool, bool, bool, bool
next_allow_up_movement, next_allow_up_movement,
next_allow_down_movement, next_allow_down_movement,
next_allow_left_movement, next_allow_left_movement,
next_allow_right_movement, next_allow_right_movement
) = get_allowed_connection_movement(&player.position, next_node_1, next_node_2); ) = get_allowed_connection_movement(&player.position, next_node_1, next_node_2);
( (
allow_up_movement, allow_up_movement,
allow_down_movement, allow_down_movement,
allow_left_movement, allow_left_movement,
allow_right_movement, allow_right_movement
) = ( ) = (
allow_up_movement || next_allow_up_movement, allow_up_movement || next_allow_up_movement,
allow_down_movement || next_allow_down_movement, allow_down_movement || next_allow_down_movement,
allow_left_movement || next_allow_left_movement, allow_left_movement || next_allow_left_movement,
allow_right_movement || next_allow_right_movement, allow_right_movement || next_allow_right_movement
); );
} }
( (
allow_up_movement, allow_up_movement,
allow_down_movement, allow_down_movement,
allow_left_movement, allow_left_movement,
allow_right_movement, allow_right_movement
) )
} }
} }
@ -117,7 +117,7 @@ fn get_allowed_movement(player: &Player, grid: &Grid) -> (bool, bool, bool, bool
fn get_allowed_connection_movement( fn get_allowed_connection_movement(
player_position: &Vec2, player_position: &Vec2,
node_1: &Vec2, node_1: &Vec2,
node_2: &Vec2, node_2: &Vec2
) -> (bool, bool, bool, bool) { ) -> (bool, bool, bool, bool) {
let allow_left_movement = { let allow_left_movement = {
if node_1.x <= node_2.x { if node_1.x <= node_2.x {
@ -171,7 +171,7 @@ fn get_allowed_connection_movement(
allow_up_movement, allow_up_movement,
allow_down_movement, allow_down_movement,
allow_left_movement, allow_left_movement,
allow_right_movement, allow_right_movement
) )
} }

View file

@ -5,5 +5,6 @@ pub mod overworld;
pub enum Activity { pub enum Activity {
#[default] #[default]
House, House,
Overworld, #[allow(dead_code)]
Overworld
} }

View file

@ -2,19 +2,19 @@ use comfy::*;
use crate::{ use crate::{
activities::{house, overworld, Activity}, activities::{house, overworld, Activity},
State, State
}; };
pub fn update(state: &mut State, engine: &mut EngineContext) { pub fn update(state: &mut State, engine: &mut EngineContext) {
match state.activity { match state.activity {
Activity::House => house::update(state, engine), Activity::House => house::update(state, engine),
Activity::Overworld => overworld::update(state, engine), Activity::Overworld => overworld::update(state, engine)
} }
} }
pub fn draw(state: &State, engine: &EngineContext) { pub fn draw(state: &State, engine: &EngineContext) {
match state.activity { match state.activity {
Activity::House => house::draw(state, engine), Activity::House => house::draw(state, engine),
Activity::Overworld => overworld::draw(state, engine), Activity::Overworld => overworld::draw(state, engine)
} }
} }

View file

@ -1,8 +1,7 @@
mod activities; mod activities;
mod game; mod game;
use activities::house::HouseState; use activities::{house::HouseState, Activity};
use activities::Activity;
use comfy::*; use comfy::*;
const GAME_NAME: &str = "Powercreep"; const GAME_NAME: &str = "Powercreep";
@ -10,7 +9,7 @@ const GAME_NAME: &str = "Powercreep";
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct State { struct State {
activity: Activity, activity: Activity,
house: HouseState, house: HouseState
} }
impl GameLoop for State { impl GameLoop for State {