mirror of
https://github.com/kristoferssolo/maze-ascension.git
synced 2025-10-21 19:20:34 +00:00
fix(floor): spawning
This commit is contained in:
parent
86bbee8cb8
commit
f8ea1edd87
@ -19,7 +19,9 @@ pub struct DespawnFloor {
|
|||||||
pub floor: u8,
|
pub floor: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Reflect, Event)]
|
#[derive(Debug, Reflect, Event, Default)]
|
||||||
pub struct TransitionFloor {
|
pub enum TransitionFloor {
|
||||||
pub floor: u8,
|
#[default]
|
||||||
|
Ascend,
|
||||||
|
Descent,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,36 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{floor::events::TransitionFloor, maze::events::SpawnMaze};
|
use crate::{
|
||||||
|
floor::{
|
||||||
|
components::{CurrentFloor, Floor},
|
||||||
|
events::TransitionFloor,
|
||||||
|
},
|
||||||
|
maze::events::SpawnMaze,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub(super) fn spawn_floor(
|
||||||
|
mut commands: Commands,
|
||||||
|
query: Query<(Entity, &Floor), With<CurrentFloor>>,
|
||||||
|
mut event_reader: EventReader<TransitionFloor>,
|
||||||
|
) {
|
||||||
|
let Ok((entity, floor)) = query.get_single() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
pub(super) fn spawn_floor(mut commands: Commands, mut event_reader: EventReader<TransitionFloor>) {
|
|
||||||
for event in event_reader.read() {
|
for event in event_reader.read() {
|
||||||
let floor = event.floor;
|
dbg!(event);
|
||||||
|
let floor = match event {
|
||||||
|
TransitionFloor::Ascend => *floor.increase(),
|
||||||
|
TransitionFloor::Descent => *floor.decrease(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if floor == 1 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
info!("Creating level for floor {}", floor);
|
info!("Creating level for floor {}", floor);
|
||||||
|
|
||||||
|
commands.entity(entity).remove::<CurrentFloor>();
|
||||||
commands.trigger(SpawnMaze { floor, ..default() });
|
commands.trigger(SpawnMaze { floor, ..default() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
|
use super::components::MazeConfig;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use super::components::MazeConfig;
|
#[derive(Debug, Reflect, Event)]
|
||||||
|
|
||||||
#[derive(Debug, Reflect, Event, Default)]
|
|
||||||
pub struct SpawnMaze {
|
pub struct SpawnMaze {
|
||||||
pub floor: u8,
|
pub floor: u8,
|
||||||
pub config: MazeConfig,
|
pub config: MazeConfig,
|
||||||
@ -18,3 +17,12 @@ pub struct RespawnMaze {
|
|||||||
pub struct DespawnMaze {
|
pub struct DespawnMaze {
|
||||||
pub floor: u8,
|
pub floor: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for SpawnMaze {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
floor: 1,
|
||||||
|
config: MazeConfig::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use crate::maze::{components::MazeConfig, events::SpawnMaze};
|
use crate::maze::events::SpawnMaze;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
pub(crate) fn setup(mut commands: Commands) {
|
pub(crate) fn setup(mut commands: Commands) {
|
||||||
let config = MazeConfig::default();
|
commands.trigger(SpawnMaze::default());
|
||||||
commands.trigger(SpawnMaze { floor: 1, config });
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ pub(super) fn spawn_maze(
|
|||||||
) {
|
) {
|
||||||
let SpawnMaze { floor, config } = trigger.event();
|
let SpawnMaze { floor, config } = trigger.event();
|
||||||
if maze_query.iter().any(|(_, f, _)| f.0 == *floor) {
|
if maze_query.iter().any(|(_, f, _)| f.0 == *floor) {
|
||||||
|
warn!("Floor {} already exists, skipping creation", floor);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,28 +1,24 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
floor::{
|
floor::{components::CurrentFloor, events::TransitionFloor},
|
||||||
components::{CurrentFloor, Floor},
|
|
||||||
events::TransitionFloor,
|
|
||||||
},
|
|
||||||
maze::components::MazeConfig,
|
maze::components::MazeConfig,
|
||||||
player::components::{CurrentPosition, Player},
|
player::components::{CurrentPosition, Player},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(super) fn ascend_player(
|
pub(super) fn ascend_player(
|
||||||
query: Query<&CurrentPosition, With<Player>>,
|
query: Query<&CurrentPosition, With<Player>>,
|
||||||
maze_config_query: Query<(&MazeConfig, &Floor), With<CurrentFloor>>,
|
maze_config_query: Query<&MazeConfig, With<CurrentFloor>>,
|
||||||
mut event_writer: EventWriter<TransitionFloor>,
|
mut event_writer: EventWriter<TransitionFloor>,
|
||||||
) {
|
) {
|
||||||
let Ok((config, floor)) = maze_config_query.get_single() else {
|
let Ok(config) = maze_config_query.get_single() else {
|
||||||
|
warn!("Failed to get maze configuration for current floor - cannot ascend player");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
for current_hex in query.iter() {
|
for current_hex in query.iter() {
|
||||||
if current_hex.0 == config.end_pos {
|
if current_hex.0 == config.end_pos {
|
||||||
event_writer.send(TransitionFloor {
|
event_writer.send(TransitionFloor::Ascend);
|
||||||
floor: *floor.increase(),
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,14 +15,13 @@ pub(super) fn descend_player(
|
|||||||
mut event_writer: EventWriter<TransitionFloor>,
|
mut event_writer: EventWriter<TransitionFloor>,
|
||||||
) {
|
) {
|
||||||
let Ok((config, floor)) = maze_config_query.get_single() else {
|
let Ok((config, floor)) = maze_config_query.get_single() else {
|
||||||
|
warn!("Failed to get maze configuration for current floor - cannot descend player");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
for current_hex in query.iter() {
|
for current_hex in query.iter() {
|
||||||
if current_hex.0 == config.start_pos && floor.0 != 1 {
|
if current_hex.0 == config.start_pos && floor.0 != 1 {
|
||||||
event_writer.send(TransitionFloor {
|
event_writer.send(TransitionFloor::Descent);
|
||||||
floor: *floor.decrease(),
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ mod descend;
|
|||||||
mod input;
|
mod input;
|
||||||
mod movement;
|
mod movement;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
|
mod transition_floor;
|
||||||
|
|
||||||
use crate::maze::MazePluginLoaded;
|
use crate::maze::MazePluginLoaded;
|
||||||
use ascend::ascend_player;
|
use ascend::ascend_player;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user