use bevy::{ ecs::system::SystemId, prelude::* }; use crate::{ card::Card, hand::Hand, properties::TestProperty }; pub mod card; pub mod hand; pub mod animal; pub mod properties; pub mod plugins; pub mod asset_preloader; /*#[derive(Component)] pub struct JustUpdated; #[derive(Resource)] pub struct Systems { pub update_hand_dimensions: SystemId }*/ pub fn setup(mut commands: Commands,asset_server: Res) { let hand_img: Handle = asset_server.load("sprites/hand_9s.png"); commands.spawn(Camera2d); commands.spawn( ( Hand{name: "Rendo".to_string()}, Sprite { image: hand_img, image_mode: SpriteImageMode::Sliced(TextureSlicer { border: BorderRect::square(4.), center_scale_mode: SliceScaleMode::Stretch, sides_scale_mode: SliceScaleMode::Stretch, ..default() }), ..default() }, Transform::from_xyz(0., -300., 0.) ) ); } pub fn setup_board() { } /*pub fn setup( mut commands: Commands, asset_server: Res, ) { let updhd_id = commands.register_system(update_hand_dimensions); commands.insert_resource(Systems { update_hand_dimensions: updhd_id }); commands.spawn(Camera2d); commands.spawn(( Hand::new("Player1".to_string()), Transform::from_xyz(0., -300., 0.), Sprite { image: asset_server.load("sprites/hand_9s.png"), image_mode: SpriteImageMode::Sliced(TextureSlicer { border: BorderRect::square(4.), center_scale_mode: SliceScaleMode::Stretch, sides_scale_mode: SliceScaleMode::Stretch, ..default() }), ..default() }, )); } pub fn test_setup_hand( mut commands: Commands, asset_server: Res, //systems: Res, query: Single> ) { let hand_id = query.into_inner(); for _ in 0..4 { create_card(&mut commands, &asset_server, Some(hand_id)); } } pub fn create_card( commands: &mut Commands, asset_server: &Res, hand_entity: Option, //systems: &Res ) { let mut card = commands.spawn(( Card, TestProperty, Transform::from_xyz(0., 0., 0.), Sprite::from_image(asset_server.load("sprites/card_back_placeholder.png")) )); if let Some(hand) = hand_entity { card.set_parent(hand); commands.entity(hand).insert(JustUpdated); //commands.run_system(systems.update_hand_dimensions); } } pub fn update_hand_dimensions( mut commands: Commands, p_query: Single<(Entity, &mut Sprite, &Children), (Added, With)>, mut c_query: Query<(&mut Transform, &Sprite), (With, Without)>, assets: Res> ) { let mut hand = p_query.into_inner(); let mut counter = 0.; let mut hand_total_width = 0.; let mut hand_height = 0.; for &child_id in hand.2.iter() { let Ok(mut child) = c_query.get_mut(child_id) else { continue; }; let sprite_size = assets.get(child.1.image.id()).unwrap().size_f32(); let hor_margin = Vec2::new(4., 0.); let ver_margin = Vec2::new(0., 4.); hand_total_width += sprite_size.x + hor_margin.x; hand_height = sprite_size.y + ver_margin.y * 2.; child.0.translation = Vec3::from((ver_margin + (sprite_size + hor_margin) * counter, 0.)); counter += 1.; } hand.1.custom_size = Some(Vec2::new(hand_total_width, hand_height)); commands.entity(hand.0).remove::(); } */