From d091b6474bd288852ab0beb94aba9c33289dcfda Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 19 Nov 2025 21:32:37 +0500 Subject: [PATCH 1/2] Image --- src/lofpara_atlas.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lofpara_atlas.rs b/src/lofpara_atlas.rs index 542b35f..7746282 100644 --- a/src/lofpara_atlas.rs +++ b/src/lofpara_atlas.rs @@ -1,18 +1,32 @@ use bevy::prelude::*; #[derive(Resource)] -pub struct LofparaAtlas(TextureAtlasLayout); +pub struct LofparaAtlasLayout(pub TextureAtlasLayout); + +#[derive(Resource)] +pub struct LofparaAtlasImage(Handle); + +impl LofparaAtlasImage { + pub fn get(&self) -> Handle { + return self.0.clone(); + } +} pub struct LofparaAtlasPlugin; impl Plugin for LofparaAtlasPlugin { fn build(&self, app: &mut App) { - let mut atlas = TextureAtlasLayout::new_empty(UVec2::new(1920, 1080)); + let mut atlas_layout = TextureAtlasLayout::new_empty(UVec2::new(1920, 1080)); //Card, index = 0 - atlas.add_texture(URect::new(0, 0, 258, 363)); + atlas_layout.add_texture(URect::new(0, 0, 258, 363)); //Cardholder, index = 1 - atlas.add_texture(URect::new(259, 0, 166, 166)); + atlas_layout.add_texture(URect::new(259, 0, 166, 166)); - app.insert_resource(LofparaAtlas(atlas)); + app.insert_resource(LofparaAtlasLayout(atlas_layout)) + .add_systems(Startup, startup_image); } } + +fn startup_image(mut commands: Commands, asset_server: Res) { + commands.insert_resource(LofparaAtlasImage(asset_server.load("atlas.png"))); +} From 47972f0f6c7baa52fd6f9b37d70e734abc4a4c8d Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 19 Nov 2025 22:25:00 +0500 Subject: [PATCH 2/2] Lofpara atlas complete --- src/cards/hand.rs | 4 ++++ src/cards/mod.rs | 29 +++++++++++++++++++++++++++++ src/lofpara_atlas.rs | 31 +++++++++++++++++++++---------- src/main.rs | 1 + 4 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 src/cards/hand.rs create mode 100644 src/cards/mod.rs diff --git a/src/cards/hand.rs b/src/cards/hand.rs new file mode 100644 index 0000000..d2b9322 --- /dev/null +++ b/src/cards/hand.rs @@ -0,0 +1,4 @@ +use bevy::prelude::*; + +#[derive(Component)] +pub struct Hand; diff --git a/src/cards/mod.rs b/src/cards/mod.rs new file mode 100644 index 0000000..3fb6364 --- /dev/null +++ b/src/cards/mod.rs @@ -0,0 +1,29 @@ +use crate::lofpara_atlas::*; +use bevy::prelude::*; + +pub mod hand; + +#[derive(Component)] +pub struct Card; + +#[derive(Event)] +pub struct CreateCard { + parent: Option, +} + +pub fn on_create_card( + event: On, + mut commands: Commands, + 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: () }) + },*/ + )); +} diff --git a/src/lofpara_atlas.rs b/src/lofpara_atlas.rs index 7746282..86e8e42 100644 --- a/src/lofpara_atlas.rs +++ b/src/lofpara_atlas.rs @@ -1,7 +1,13 @@ use bevy::prelude::*; #[derive(Resource)] -pub struct LofparaAtlasLayout(pub TextureAtlasLayout); +pub struct LofparaAtlasLayout(Handle); + +impl LofparaAtlasLayout { + pub fn get(&self) -> Handle { + return self.0.clone(); + } +} #[derive(Resource)] pub struct LofparaAtlasImage(Handle); @@ -16,17 +22,22 @@ pub struct LofparaAtlasPlugin; impl Plugin for LofparaAtlasPlugin { fn build(&self, app: &mut App) { - let mut atlas_layout = TextureAtlasLayout::new_empty(UVec2::new(1920, 1080)); - //Card, index = 0 - atlas_layout.add_texture(URect::new(0, 0, 258, 363)); - //Cardholder, index = 1 - atlas_layout.add_texture(URect::new(259, 0, 166, 166)); - - app.insert_resource(LofparaAtlasLayout(atlas_layout)) - .add_systems(Startup, startup_image); + app.add_systems(Startup, startup_image); } } -fn startup_image(mut commands: Commands, asset_server: Res) { +fn startup_image( + mut commands: Commands, + asset_server: Res, + mut atlas_layouts: ResMut>, +) { commands.insert_resource(LofparaAtlasImage(asset_server.load("atlas.png"))); + + let mut atlas_layout = TextureAtlasLayout::new_empty(UVec2::new(1920, 1080)); + //Card, index = 0 + atlas_layout.add_texture(URect::new(0, 0, 258, 363)); + //Cardholder, index = 1 + atlas_layout.add_texture(URect::new(259, 0, 166, 166)); + + commands.insert_resource(LofparaAtlasLayout(atlas_layouts.add(atlas_layout))); } diff --git a/src/main.rs b/src/main.rs index cff54c9..5c7e7cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use bevy::prelude::*; use crate::lofpara_atlas::LofparaAtlasPlugin; +mod cards; mod lofpara_atlas; fn main() {