Small hand rework, simplest cards shuffle

This commit is contained in:
Rendo 2026-01-26 00:48:56 +05:00
commit 1f389f5285
5 changed files with 90 additions and 31 deletions

View file

@ -1,6 +1,9 @@
use bevy::prelude::*;
use crate::{animation::transform::AnimatedTransform, card::Hand};
use crate::{
animation::transform::AnimatedTransform,
card::{CardInHand, Hand, InsertCard},
};
#[derive(Component)]
pub struct DraggableCard;
@ -33,6 +36,7 @@ pub fn card_drag_start(
mut commands: Commands,
card_query: Query<(), With<DraggableCard>>,
dragged_option: Option<Single<&DraggedCard>>,
mut hand: Single<&mut Hand>,
) {
if dragged_option.is_some() {
return;
@ -44,7 +48,11 @@ pub fn card_drag_start(
commands
.entity(event.entity)
.insert(DraggedCard)
.remove_parent_in_place();
.remove::<CardInHand>();
if let Some(pos) = hand.0.iter().position(|ent| *ent == event.entity) {
hand.0.remove(pos);
}
}
pub fn card_drag(
@ -59,10 +67,10 @@ pub fn card_drag_end(
_: On<Pointer<DragEnd>>,
mut commands: Commands,
dragged: Single<Entity, With<DraggedCard>>,
hand: Single<Entity, With<Hand>>,
) {
commands.trigger(InsertCard(dragged.entity()));
commands
.entity(dragged.entity())
.remove::<DraggedCard>()
.set_parent_in_place(hand.entity());
.insert(CardInHand);
}