feat(floors): hide floors above #18

This commit is contained in:
Kristofers Solo 2025-01-18 16:58:43 +02:00
parent 4864ecca93
commit f08bd72038
6 changed files with 26 additions and 4 deletions

2
Cargo.lock generated
View File

@ -3157,7 +3157,7 @@ dependencies = [
[[package]]
name = "maze-ascension"
version = "1.1.1"
version = "1.1.2"
dependencies = [
"anyhow",
"bevy",

View File

@ -1,7 +1,7 @@
[package]
name = "maze-ascension"
authors = ["Kristofers Solo <dev@kristofers.xyz>"]
version = "1.1.1"
version = "1.1.2"
edition = "2021"
[dependencies]

View File

@ -1,6 +1,6 @@
use bevy::prelude::*;
#[derive(Debug, Reflect, Component, Deref, DerefMut)]
#[derive(Debug, Reflect, Component, Deref, DerefMut, PartialEq, Eq, PartialOrd, Ord)]
#[reflect(Component)]
pub struct Floor(pub u8);

19
src/floor/systems/hide.rs Normal file
View File

@ -0,0 +1,19 @@
use bevy::prelude::*;
use crate::floor::components::{CurrentFloor, Floor};
pub fn hide_upper_floors(
mut query: Query<(&mut Visibility, &Floor)>,
current_query: Query<&Floor, With<CurrentFloor>>,
) {
let Ok(current_floor) = current_query.get_single() else {
return;
};
for (mut visibility, floor) in query.iter_mut() {
if floor > current_floor {
*visibility = Visibility::Hidden
} else {
*visibility = Visibility::Visible
}
}
}

View File

@ -1,10 +1,12 @@
mod despawn;
mod hide;
mod movement;
mod spawn;
use crate::screens::Screen;
use bevy::prelude::*;
use despawn::despawn_floor;
use hide::hide_upper_floors;
use movement::{handle_floor_transition_events, move_floors};
use spawn::spawn_floor;
@ -16,6 +18,7 @@ pub(super) fn plugin(app: &mut App) {
despawn_floor,
handle_floor_transition_events,
move_floors,
hide_upper_floors,
)
.chain()
.run_if(in_state(Screen::Gameplay)),

View File

@ -74,7 +74,7 @@ pub fn handle_floor_transition_events(
}
for event in event_reader.read() {
let Some((current_entity, current_floor)) = current_query.get_single().ok() else {
let Ok((current_entity, current_floor)) = current_query.get_single() else {
continue;
};