drop
This commit is contained in:
@@ -13,14 +13,15 @@ pub fn plugin(_app: &mut App) {}
|
||||
pub fn handle_pick_up(
|
||||
mut commands: Commands,
|
||||
// current action
|
||||
mut action: Query<(&PlayerAction, &mut Item), With<Player>>,
|
||||
mut player_query: Query<(&PlayerAction, &Transform, &mut Item), With<Player>>,
|
||||
mut vis_query: Query<&mut Visibility>,
|
||||
children: Query<&mut Children>,
|
||||
|
||||
mut item_transform: Query<&mut Transform, (With<Interact>, Without<Player>)>,
|
||||
// current interactable
|
||||
mut interaction_opportunity: ResMut<InteractionOpportunity>,
|
||||
) {
|
||||
let (action, mut item) = single_mut!(action);
|
||||
let (action, transform, mut item) = single_mut!(player_query);
|
||||
if *action == PlayerAction::PickUp {
|
||||
// take out the interaction, because we are picking it up
|
||||
let Some(target) = interaction_opportunity.0.take() else {
|
||||
@@ -44,36 +45,37 @@ pub fn handle_pick_up(
|
||||
commands.entity(collider).remove::<ColliderDisabled>();
|
||||
}
|
||||
}
|
||||
// for simplicities sake, set the transform of the item that is dropped to that of the player
|
||||
let mut item_transform = item_transform.get_mut(dropped).unwrap();
|
||||
*item_transform = *transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_drop(// mut commands: Commands,
|
||||
// // current action
|
||||
// mut action: Query<(&PlayerAction, &Transform, &mut Item), With<Player>>,
|
||||
// mut vis_query: Query<&mut Visibility>,
|
||||
// mut item_transform: Query<&mut Transform, With<Interact>>,
|
||||
// children: Query<&mut Children>,
|
||||
pub fn handle_drop(
|
||||
mut commands: Commands,
|
||||
// current action
|
||||
mut player_query: Query<(&PlayerAction, &Transform, &mut Item), With<Player>>,
|
||||
mut vis_query: Query<&mut Visibility>,
|
||||
mut item_transform: Query<&mut Transform, (With<Interact>, Without<Player>)>,
|
||||
children: Query<&mut Children>,
|
||||
) {
|
||||
// let (action, transform, mut item) = single_mut!(action);
|
||||
// if *action == PlayerAction::Drop {
|
||||
// if let Ok(mut vis) = vis_query.get_mut(target) {
|
||||
// *vis = Visibility::Hidden;
|
||||
// }
|
||||
// if let Ok(colliders) = children.get(target) {
|
||||
// for &collider in colliders {
|
||||
// commands.entity(collider).insert(ColliderDisabled);
|
||||
// }
|
||||
// }
|
||||
// if let Some(dropped) = replaced {
|
||||
// if let Ok(mut vis) = vis_query.get_mut(dropped) {
|
||||
// *vis = Visibility::Visible;
|
||||
// }
|
||||
// if let Ok(colliders) = children.get(dropped) {
|
||||
// for &collider in colliders {
|
||||
// commands.entity(collider).remove::<ColliderDisabled>();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
let (action, transform, mut item) = single_mut!(player_query);
|
||||
if *action == PlayerAction::Drop {
|
||||
let Some(item) = item.take() else {
|
||||
return;
|
||||
};
|
||||
if let Ok(mut vis) = vis_query.get_mut(item) {
|
||||
*vis = Visibility::Visible;
|
||||
}
|
||||
if let Ok(colliders) = children.get(item) {
|
||||
for &collider in colliders {
|
||||
commands.entity(collider).remove::<ColliderDisabled>();
|
||||
}
|
||||
}
|
||||
|
||||
// for simplicities sake, set the transform of the item that is dropped to that of the player
|
||||
let mut item_transform = item_transform.get_mut(item).unwrap();
|
||||
*item_transform = *transform;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::GameState;
|
||||
use crate::player::toolbar::Item;
|
||||
use crate::player::{Player, PlayerAction};
|
||||
use crate::util::{single, single_mut};
|
||||
use crate::player::Player;
|
||||
use crate::util::single;
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use bevy_egui::{EguiContexts, EguiPlugin, egui};
|
||||
use bevy_rapier3d::prelude::*;
|
||||
|
||||
@@ -9,6 +9,12 @@ use super::Player;
|
||||
#[derive(Component, Default, Debug)]
|
||||
pub struct Item(Option<Entity>);
|
||||
|
||||
impl Item {
|
||||
pub fn take(&mut self) -> Option<Entity> {
|
||||
self.0.take()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Default, Debug)]
|
||||
pub struct ItemIcon(Handle<Image>);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user