mirror of
https://github.com/kristoferssolo/maze-ascension.git
synced 2025-10-21 19:20:34 +00:00
chore: fix clippy warnings
This commit is contained in:
parent
5c14631e53
commit
518077e8fd
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
floor::components::{CurrentFloor, Floor},
|
floor::components::{CurrentFloor, Floor},
|
||||||
maze::{components::MazeConfig, events::MazeEvent, GlobalMazeConfig, MazePluginLoaded},
|
maze::{components::MazeConfig, events::MazeEvent, GlobalMazeConfig, MazePluginLoaded},
|
||||||
player::events::RespawnPlayer,
|
player::events::PlayerEvent,
|
||||||
};
|
};
|
||||||
use bevy::{prelude::*, window::PrimaryWindow};
|
use bevy::{prelude::*, window::PrimaryWindow};
|
||||||
use bevy_egui::{
|
use bevy_egui::{
|
||||||
@ -65,8 +65,8 @@ pub(crate) fn maze_controls_ui(world: &mut World) {
|
|||||||
config: maze_config,
|
config: maze_config,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(mut event_writer) = world.get_resource_mut::<Events<RespawnPlayer>>() {
|
if let Some(mut event_writer) = world.get_resource_mut::<Events<PlayerEvent>>() {
|
||||||
event_writer.send(RespawnPlayer);
|
event_writer.send(PlayerEvent::Respawn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,6 @@ pub(super) fn plugin(app: &mut App) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_level_command(world: &mut World) {
|
pub fn spawn_level_command(world: &mut World) {
|
||||||
world.insert_resource(MazePluginLoaded);
|
|
||||||
let _ = world.run_system_once(systems::setup::setup);
|
let _ = world.run_system_once(systems::setup::setup);
|
||||||
|
world.insert_resource(MazePluginLoaded);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,10 +5,10 @@ use crate::maze::{
|
|||||||
use hexlab::{GeneratorType, HexMaze, MazeBuilder};
|
use hexlab::{GeneratorType, HexMaze, MazeBuilder};
|
||||||
|
|
||||||
pub(super) fn generate_maze(config: &MazeConfig) -> MazeResult<HexMaze> {
|
pub(super) fn generate_maze(config: &MazeConfig) -> MazeResult<HexMaze> {
|
||||||
Ok(MazeBuilder::new()
|
MazeBuilder::new()
|
||||||
.with_radius(config.radius)
|
.with_radius(config.radius)
|
||||||
.with_seed(config.seed)
|
.with_seed(config.seed)
|
||||||
.with_generator(GeneratorType::RecursiveBacktracking)
|
.with_generator(GeneratorType::RecursiveBacktracking)
|
||||||
.build()
|
.build()
|
||||||
.map_err(|_| MazeError::generation_failed(config.radius, config.seed))?)
|
.map_err(|_| MazeError::generation_failed(config.radius, config.seed))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ pub(super) fn spawn_maze_tiles(
|
|||||||
) {
|
) {
|
||||||
commands.entity(parent_entity).with_children(|parent| {
|
commands.entity(parent_entity).with_children(|parent| {
|
||||||
for tile in maze.values() {
|
for tile in maze.values() {
|
||||||
spawn_single_hex_tile(parent, &assets, tile, maze_config, global_config);
|
spawn_single_hex_tile(parent, assets, tile, maze_config, global_config);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
use super::{
|
use super::{common::generate_maze, spawn::spawn_maze_tiles};
|
||||||
common::generate_maze,
|
|
||||||
spawn::{spawn_maze_tiles, spawn_single_hex_tile},
|
|
||||||
};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
floor::components::Floor,
|
floor::components::Floor,
|
||||||
maze::{
|
maze::{
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug, Event)]
|
#[derive(Debug, Event)]
|
||||||
pub(crate) struct RespawnPlayer;
|
pub enum PlayerEvent {
|
||||||
|
Spawn,
|
||||||
|
Respawn,
|
||||||
|
Despawn,
|
||||||
|
}
|
||||||
|
|||||||
@ -5,11 +5,11 @@ mod systems;
|
|||||||
|
|
||||||
use bevy::{ecs::system::RunSystemOnce, prelude::*};
|
use bevy::{ecs::system::RunSystemOnce, prelude::*};
|
||||||
use components::Player;
|
use components::Player;
|
||||||
use events::RespawnPlayer;
|
use events::PlayerEvent;
|
||||||
|
|
||||||
pub(super) fn plugin(app: &mut App) {
|
pub(super) fn plugin(app: &mut App) {
|
||||||
app.register_type::<Player>()
|
app.register_type::<Player>()
|
||||||
.add_event::<RespawnPlayer>()
|
.add_event::<PlayerEvent>()
|
||||||
.add_plugins(systems::plugin);
|
.add_plugins(systems::plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use bevy::prelude::*;
|
|||||||
|
|
||||||
use crate::player::components::Player;
|
use crate::player::components::Player;
|
||||||
|
|
||||||
pub(crate) fn despawn_players(commands: &mut Commands, query: &Query<Entity, With<Player>>) {
|
pub(super) fn despawn_players(commands: &mut Commands, query: &Query<Entity, With<Player>>) {
|
||||||
for entity in query.iter() {
|
for entity in query.iter() {
|
||||||
commands.entity(entity).despawn_recursive();
|
commands.entity(entity).despawn_recursive();
|
||||||
}
|
}
|
||||||
|
|||||||
53
src/player/systems/event_handler.rs
Normal file
53
src/player/systems/event_handler.rs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
use crate::{
|
||||||
|
floor::components::CurrentFloor,
|
||||||
|
maze::{components::MazeConfig, GlobalMazeConfig},
|
||||||
|
player::{components::Player, events::PlayerEvent},
|
||||||
|
};
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
use super::{despawn::despawn_players, respawn::respawn_player, spawn::spawn_player};
|
||||||
|
|
||||||
|
pub(crate) fn handle_player_events(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
mut event_reader: EventReader<PlayerEvent>,
|
||||||
|
maze_config_query: Query<&MazeConfig, With<CurrentFloor>>,
|
||||||
|
player_query: Query<Entity, With<Player>>,
|
||||||
|
global_config: Res<GlobalMazeConfig>,
|
||||||
|
) {
|
||||||
|
for event in event_reader.read() {
|
||||||
|
match event {
|
||||||
|
PlayerEvent::Spawn => {
|
||||||
|
let Ok(maze_config) = maze_config_query.get_single() else {
|
||||||
|
warn!(
|
||||||
|
"Failed to get maze configuration for current floor - cannot spawn player"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
spawn_player(
|
||||||
|
&mut commands,
|
||||||
|
&mut meshes,
|
||||||
|
&mut materials,
|
||||||
|
maze_config,
|
||||||
|
&global_config,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
PlayerEvent::Respawn => {
|
||||||
|
let Ok(maze_config) = maze_config_query.get_single() else {
|
||||||
|
warn!("Failed to get maze configuration for current floor - cannot respawn player");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
respawn_player(
|
||||||
|
&mut commands,
|
||||||
|
&mut meshes,
|
||||||
|
&mut materials,
|
||||||
|
&player_query,
|
||||||
|
maze_config,
|
||||||
|
&global_config,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
PlayerEvent::Despawn => despawn_players(&mut commands, &player_query),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -24,7 +24,7 @@ pub(super) fn player_input(
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(tile) = maze.0.get_tile(¤t_pos) else {
|
let Some(tile) = maze.0.get_tile(current_pos) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,15 @@
|
|||||||
pub mod despawn;
|
mod despawn;
|
||||||
|
mod event_handler;
|
||||||
mod input;
|
mod input;
|
||||||
mod movement;
|
mod movement;
|
||||||
pub mod respawn;
|
mod respawn;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
pub mod spawn;
|
mod spawn;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use event_handler::handle_player_events;
|
||||||
use input::player_input;
|
use input::player_input;
|
||||||
use movement::player_movement;
|
use movement::player_movement;
|
||||||
use respawn::respawn_player;
|
|
||||||
|
|
||||||
use crate::maze::MazePluginLoaded;
|
|
||||||
|
|
||||||
pub(super) fn plugin(app: &mut App) {
|
pub(super) fn plugin(app: &mut App) {
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
@ -18,8 +17,7 @@ pub(super) fn plugin(app: &mut App) {
|
|||||||
(
|
(
|
||||||
player_input,
|
player_input,
|
||||||
player_movement.after(player_input),
|
player_movement.after(player_input),
|
||||||
respawn_player,
|
handle_player_events,
|
||||||
)
|
),
|
||||||
.run_if(resource_exists::<MazePluginLoaded>),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,14 +20,14 @@ pub(super) fn player_movement(
|
|||||||
maze_config_query: Query<&MazeConfig, With<CurrentFloor>>,
|
maze_config_query: Query<&MazeConfig, With<CurrentFloor>>,
|
||||||
) {
|
) {
|
||||||
let Ok(maze_config) = maze_config_query.get_single() else {
|
let Ok(maze_config) = maze_config_query.get_single() else {
|
||||||
error!("Failed to get maze configuration for current floor - cannot move player");
|
warn!("Failed to get maze configuration for current floor - cannot move player");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (mut target, speed, mut current_hex, mut transform) in query.iter_mut() {
|
for (mut target, speed, mut current_hex, mut transform) in query.iter_mut() {
|
||||||
if let Some(target_hex) = target.0 {
|
if let Some(target_hex) = target.0 {
|
||||||
let current_pos = transform.translation;
|
let current_pos = transform.translation;
|
||||||
let target_pos = calculate_target_position(&maze_config, target_hex, current_pos.y);
|
let target_pos = calculate_target_position(maze_config, target_hex, current_pos.y);
|
||||||
|
|
||||||
if should_complete_movement(current_pos, target_pos) {
|
if should_complete_movement(current_pos, target_pos) {
|
||||||
transform.translation = target_pos;
|
transform.translation = target_pos;
|
||||||
|
|||||||
@ -1,33 +1,18 @@
|
|||||||
|
use super::{despawn::despawn_players, spawn::spawn_player};
|
||||||
use crate::{
|
use crate::{
|
||||||
floor::components::CurrentFloor,
|
|
||||||
maze::{components::MazeConfig, GlobalMazeConfig},
|
maze::{components::MazeConfig, GlobalMazeConfig},
|
||||||
player::{components::Player, events::RespawnPlayer},
|
player::components::Player,
|
||||||
};
|
};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use super::{despawn::despawn_players, spawn::spawn_player};
|
pub(super) fn respawn_player(
|
||||||
|
commands: &mut Commands,
|
||||||
pub(crate) fn respawn_player(
|
meshes: &mut ResMut<Assets<Mesh>>,
|
||||||
mut commands: Commands,
|
materials: &mut ResMut<Assets<StandardMaterial>>,
|
||||||
query: Query<Entity, With<Player>>,
|
query: &Query<Entity, With<Player>>,
|
||||||
maze_config_query: Query<&MazeConfig, With<CurrentFloor>>,
|
maze_config: &MazeConfig,
|
||||||
mut event_reader: EventReader<RespawnPlayer>,
|
global_config: &GlobalMazeConfig,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
||||||
global_config: Res<GlobalMazeConfig>,
|
|
||||||
) {
|
) {
|
||||||
let Ok(maze_config) = maze_config_query.get_single() else {
|
despawn_players(commands, query);
|
||||||
error!("Failed to get maze configuration for current floor - cannot respawn player");
|
spawn_player(commands, meshes, materials, maze_config, global_config);
|
||||||
return;
|
|
||||||
};
|
|
||||||
for _ in event_reader.read() {
|
|
||||||
despawn_players(&mut commands, &query);
|
|
||||||
spawn_player(
|
|
||||||
&mut commands,
|
|
||||||
&mut meshes,
|
|
||||||
&mut materials,
|
|
||||||
&maze_config,
|
|
||||||
&global_config,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,29 +1,6 @@
|
|||||||
|
use crate::player::events::PlayerEvent;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
pub(crate) fn setup(mut event_writer: EventWriter<PlayerEvent>) {
|
||||||
floor::components::CurrentFloor,
|
event_writer.send(PlayerEvent::Spawn);
|
||||||
maze::{components::MazeConfig, GlobalMazeConfig},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::spawn::spawn_player;
|
|
||||||
|
|
||||||
pub(crate) fn setup(
|
|
||||||
mut commands: Commands,
|
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
||||||
maze_config_query: Query<&MazeConfig, With<CurrentFloor>>,
|
|
||||||
global_config: Res<GlobalMazeConfig>,
|
|
||||||
) {
|
|
||||||
let Ok(maze_config) = maze_config_query.get_single() else {
|
|
||||||
error!("Failed to get maze configuration for current floor - cannot spawn player");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
spawn_player(
|
|
||||||
&mut commands,
|
|
||||||
&mut meshes,
|
|
||||||
&mut materials,
|
|
||||||
&maze_config,
|
|
||||||
&global_config,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user