DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

de6cc1598b1f22b6bdf0e9f06e0753d0265f901f — skye 1 year, 5 months ago ea4c58c
feat(client): take cards from supply piles
2 files changed, 36 insertions(+), 7 deletions(-)

M client/src/plugins/game/card/mod.rs
M client/src/plugins/game/supply/mod.rs
M client/src/plugins/game/card/mod.rs => client/src/plugins/game/card/mod.rs +4 -5
@@ 33,6 33,9 @@ pub mod visual_card_kind {
    pub struct Supply(pub usize);
}

#[derive(Component, Clone)]
pub struct ClickedCard;

#[derive(Component)]
pub struct VisualCard {
    pub card: Card,


@@ 150,11 153,7 @@ fn on_spawn_card(
                OnPointer::<Out>::target_component_mut::<Transform>(|_out, transform| {
                    transform.translation.y -= 0.2;
                }),
                OnPointer::<Click>::target_component_mut::<VisualCard>(|click, card| {
                    if click.button == PointerButton::Primary {
                        println!("clickered");
                    }
                }),
                OnPointer::<Click>::target_insert(ClickedCard),
            )
        );
        commands.entity(entity).with_children(|parent| {

M client/src/plugins/game/supply/mod.rs => client/src/plugins/game/supply/mod.rs +32 -2
@@ 9,8 9,10 @@
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;

use crate::{plugins::GameActionCreateCallEvent, api::game::{Action, Command}, Global};

use super::{
    card::{visual_card_kind, VisualCard, VisualCardBundle},
    card::{visual_card_kind, VisualCard, VisualCardBundle, ClickedCard},
    GameData,
};



@@ 21,7 23,8 @@ impl Plugin for SupplyPlugin {
        app.add_event::<SpawnSupplyPilesEvent>()
            .add_event::<PositionSupplyPilesEvent>()
            .add_system(spawn_supply_piles.run_if(on_event::<SpawnSupplyPilesEvent>()))
            .add_system(position_supply_piles.run_if(on_event::<PositionSupplyPilesEvent>()));
            .add_system(position_supply_piles.run_if(on_event::<PositionSupplyPilesEvent>()))
            .add_system(handle_clicked_supply_pile);
    }
}



@@ 85,3 88,30 @@ fn position_supply_piles(
        offset += 1.0;
    }
}

fn handle_clicked_supply_pile(
    mut commands: Commands,
    mut card_query: Query<(Entity, &VisualCard, &visual_card_kind::Supply), (With<visual_card_kind::Supply>, With<ClickedCard>)>,
    mut gac_ev_w: EventWriter<GameActionCreateCallEvent>,
    game_data: Res<GameData>,
    global: Res<Global>,
) {
    let Ok((entity, card, card_kind)) = card_query.get_single() else {
        return;
    };

    commands.entity(entity).remove::<ClickedCard>();

    gac_ev_w.send(GameActionCreateCallEvent {
        action: Action::new(
            &game_data.game.as_ref().unwrap().id,
            &global.user.as_ref().unwrap().id,
            &global.user.as_ref().unwrap().id,
            &Command::TakeFromPile {
                index: card_kind.0,
                for_cost: card.card.cost,
            },
            fastrand::u64(u64::MIN..=u64::MAX),
        ),
    });
}