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