42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
use crate::{features::inventory::ui::open_inventory, prelude::*};
|
|
use components::*;
|
|
|
|
pub mod components;
|
|
pub mod ui;
|
|
|
|
pub struct InventoryPlugin;
|
|
|
|
impl Plugin for InventoryPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.init_resource::<Inventory>();
|
|
|
|
app.add_systems(Update, buttons.run_if(in_state(AppState::GameScreen)));
|
|
}
|
|
}
|
|
|
|
fn buttons(
|
|
mut commands: Commands,
|
|
mut interaction_query: Query<(&Interaction, &ButtonType), (Changed<Interaction>, With<Button>)>,
|
|
itemstack_query: Query<&ItemStack>,
|
|
root_query: Query<(Entity, &RootMarker)>,
|
|
game_config: Res<GameConfig>,
|
|
) {
|
|
for (interaction, button_type) in &mut interaction_query {
|
|
match *interaction {
|
|
Interaction::Pressed => match button_type {
|
|
ButtonType::InventoryOpen => {
|
|
open_inventory(&mut commands, itemstack_query, &game_config);
|
|
}
|
|
ButtonType::InventoryClose => {
|
|
for (entity, root) in root_query.iter() {
|
|
match *root {
|
|
RootMarker::Inventory => commands.entity(entity).despawn(),
|
|
}
|
|
}
|
|
}
|
|
},
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|