diff --git a/src/main.rs b/src/main.rs index f7048d7..4752ce5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,9 +75,13 @@ fn main() { #[derive(Component)] struct Star; +#[derive(Component)] +struct AnswerButton; + #[derive(Component)] struct Player { target_rotation: Option, + target_cons_name: Option, } fn star_setup( @@ -130,14 +134,13 @@ fn star_setup( ..default() }, Player { - target_rotation: Some(Quat::from_rotation_y(-1.5)) + target_rotation: None, + target_cons_name: None, }, )); } fn cons_setup(mut sky: ResMut) { - info!("setup"); - sky.content = get_cons().unwrap(); } @@ -146,8 +149,6 @@ fn get_stars() -> std::io::Result> { let mut data = String::new(); file.read_to_string(&mut data)?; - info!("###"); - let stars: Vec = serde_json::from_str(&data).unwrap(); Ok(stars) @@ -158,8 +159,6 @@ fn get_cons() -> std::io::Result> { let mut data = String::new(); file.read_to_string(&mut data)?; - info!("###"); - let sky_data: Vec = serde_json::from_str(&data).unwrap(); Ok(sky_data) @@ -203,7 +202,7 @@ fn player_rotate( keys: Res>, mut query: Query<(&mut Player, &mut Transform)>, // Query to get Player and Transform sky: Res, // Res to access the Sky resource - //mut commands: Commands, + mut text_query: Query<&mut Text, With>, ) { for (mut player, mut transform) in query.iter_mut() { // If the space key was just pressed @@ -217,6 +216,14 @@ fn player_rotate( // Store the target rotation in the player component player.target_rotation = Some(target_rotation); + player.target_cons_name = Some(constellation.name.clone()); + + + info!("constellation : {}", constellation.name); + + for mut text in &mut text_query { + text.sections[0].value = constellation.name.clone(); + } } } @@ -289,7 +296,7 @@ fn ui_setup(mut commands: Commands, asset_server: Res) { // Spawn the button and its text as children of the container let button = commands.spawn(button_node).id(); - let button_text = commands.spawn(button_text_node).id(); + let button_text = commands.spawn((button_text_node, AnswerButton)).id(); commands.entity(button).push_children(&[button_text]); commands.entity(container).push_children(&[button]);