From 5efbbd1ac9f5c6a120230aa3abb4041483a4620a Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Sun, 29 Dec 2024 20:10:52 -0800 Subject: [PATCH] face down top of deck card --- assets/cards.png | 4 +-- src/deck.rs | 2 +- src/play.rs | 2 +- src/setup.rs | 84 ++++++++++++++++++++++++++++++++---------------- 4 files changed, 61 insertions(+), 31 deletions(-) diff --git a/assets/cards.png b/assets/cards.png index 3982741..acf917d 100644 --- a/assets/cards.png +++ b/assets/cards.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c4b521a0d27da3e0ae57706b270c4d39489888229436333f9268c7788b685453 -size 7265 +oid sha256:9f4992d2580a024edb8154248f8e0457c327f9684491a5bc0edbcc697edc3fec +size 7617 diff --git a/src/deck.rs b/src/deck.rs index 31bf2c7..b815868 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -134,7 +134,7 @@ impl Card { assert!(num < 108, "Sprite index should be less than 108"); let size = UVec2 { x: 20, y: 32 }; - let layout = TextureAtlasLayout::from_grid(size, 9, 12, None, None); + let layout = TextureAtlasLayout::from_grid(size, 9, 13, None, None); ("cards.png".into(), layout, num) } diff --git a/src/play.rs b/src/play.rs index a7ea6d2..58d1179 100644 --- a/src/play.rs +++ b/src/play.rs @@ -19,7 +19,7 @@ impl Plugin for PlayPlugin { pub(crate) struct Selected; /// Where in the deck a card is -#[derive(Component)] +#[derive(Component, Clone, PartialEq)] pub(crate) struct DeckOrder(pub u8); /// Where on the board/table/play-space a card is diff --git a/src/setup.rs b/src/setup.rs index 304c20d..9a97898 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -33,7 +33,12 @@ pub(crate) struct AnimationStore { } /// Setup drawing our cards on the screen -pub(crate) fn setup_cards(mut commands: Commands, deck: Res) { +pub(crate) fn setup_cards( + mut commands: Commands, + deck: Res, + mut layouts: ResMut>, + server: Res, +) { let animation_player = AnimationPlayer::default(); commands .spawn(( @@ -43,6 +48,29 @@ pub(crate) fn setup_cards(mut commands: Commands, deck: Res) { animation_player, )) .with_children(|parent| { + // Top of card pile is a "face down" card + { + let top_card_transform = Transform { + translation: Vec3::new(-400.0, -200.0, 1.0), + ..default() + }; + let top_card_sprite = Sprite { + custom_size: Some(Vec2::new(80.0, 128.0)), + texture_atlas: Some(TextureAtlas { + index: 108, + layout: layouts.add(TextureAtlasLayout::from_grid( + UVec2 { x: 20, y: 32 }, + 9, + 13, + None, + None, + )), + }), + image: server.load("cards.png"), + ..default() + }; + parent.spawn((top_card_transform, top_card_sprite, Visibility::Inherited)); + } Deck::iter_shuffled() .enumerate() .for_each(|(i, this_card)| { @@ -53,7 +81,7 @@ pub(crate) fn setup_cards(mut commands: Commands, deck: Res) { .clone(); let this_sprite = Sprite { custom_size: Some(Vec2::new(80.0, 128.0)), - ..this + ..this.clone() }; let order = play::DeckOrder(i as u8); @@ -69,31 +97,33 @@ pub(crate) fn setup_cards(mut commands: Commands, deck: Res) { // Spawn card with a simple Transform parent so we can adjust the Z-axis for // card ordering - parent.spawn(Transform::default()).with_children(|parent| { - let mut child = parent.spawn_empty(); - let entity_id = child.id(); - let animation_target = AnimationTarget { - id: animation_target_id, - player: entity_id, - }; - child - .insert(( - animation_player, - animation_target, - name, - order, - this_card, - this_sprite, - this_transform, - visibility, - )) - .observe(play::place_card) - .observe(debug::set_debug_card) - .observe(debug::hide_debug_card) - .observe(play::play_selected_animation) - .observe(play::stop_selected_animation) - .observe(play::toggle_selected); - }); + parent + .spawn((Transform::default(), Visibility::Inherited)) + .with_children(|parent| { + let mut child = parent.spawn_empty(); + let entity_id = child.id(); + let animation_target = AnimationTarget { + id: animation_target_id, + player: entity_id, + }; + child + .insert(( + animation_player, + animation_target, + name, + order, + this_card, + this_sprite, + this_transform, + visibility, + )) + .observe(play::place_card) + .observe(debug::set_debug_card) + .observe(debug::hide_debug_card) + .observe(play::play_selected_animation) + .observe(play::stop_selected_animation) + .observe(play::toggle_selected); + }); }); }); }