From c609a7d6028e7ca47636b6755c631655ec5e1142 Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 19 Nov 2025 22:29:51 +0500 Subject: [PATCH 1/2] Card creation --- src/cards/mod.rs | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/cards/mod.rs b/src/cards/mod.rs index 3fb6364..1c7e3f8 100644 --- a/src/cards/mod.rs +++ b/src/cards/mod.rs @@ -17,13 +17,34 @@ pub fn on_create_card( atlas_layout: Res, atlas_sprite: Res, ) { - commands.spawn(( - Card, - Transform::from_xyz(0., 0., 0.), - /*Sprite { - image: atlas_sprite.get(), - image_mode: SpriteImageMode::Auto, - texture_atlas: Some(TextureAtlas { layout: , index: () }) - },*/ - )); + if let Some(parent) = event.parent { + commands.spawn(( + Card, + Transform::from_xyz(0., 0., 0.), + Sprite { + image: atlas_sprite.get(), + image_mode: SpriteImageMode::Auto, + texture_atlas: Some(TextureAtlas { + layout: atlas_layout.get(), + index: 0, + }), + ..default() + }, + ChildOf(parent), + )); + } else { + commands.spawn(( + Card, + Transform::from_xyz(0., 0., 0.), + Sprite { + image: atlas_sprite.get(), + image_mode: SpriteImageMode::Auto, + texture_atlas: Some(TextureAtlas { + layout: atlas_layout.get(), + index: 0, + }), + ..default() + }, + )); + } } From 1031e0602488102e9bf027f32f79996ab05a40d4 Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 19 Nov 2025 22:31:34 +0500 Subject: [PATCH 2/2] Cards plugin --- src/cards/mod.rs | 8 ++++++++ src/main.rs | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cards/mod.rs b/src/cards/mod.rs index 1c7e3f8..37ed5ec 100644 --- a/src/cards/mod.rs +++ b/src/cards/mod.rs @@ -3,6 +3,14 @@ use bevy::prelude::*; pub mod hand; +pub struct CardsPlugin; + +impl Plugin for CardsPlugin { + fn build(&self, app: &mut App) { + app.add_observer(on_create_card); + } +} + #[derive(Component)] pub struct Card; diff --git a/src/main.rs b/src/main.rs index 5c7e7cc..6396925 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,11 @@ use bevy::prelude::*; +use crate::cards::CardsPlugin; use crate::lofpara_atlas::LofparaAtlasPlugin; mod cards; mod lofpara_atlas; fn main() { - App::new().add_plugins((DefaultPlugins, LofparaAtlasPlugin)); + App::new().add_plugins((DefaultPlugins, LofparaAtlasPlugin, CardsPlugin)); }