From 150ab8cdabf83117a07e0c9697d6c7682548c78b Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Sun, 6 Oct 2024 10:38:42 +0200 Subject: [PATCH] cleaned up --- src/main.rs | 184 +++++++++++++++++++++++++--------------------------- 1 file changed, 89 insertions(+), 95 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8510b3f..cb66767 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,4 @@ -//! A simple 3D scene with light shining over a cube sitting on a plane. - use bevy::prelude::*; -//use bevy::render::*; use bevy::math::*; use std::fs::File; use std::io::Read; @@ -10,6 +7,10 @@ use std::f64::consts::PI; use rand::seq::SliceRandom; use rand::RngCore; +const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15); +const WRONG_BUTTON: Color = Color::srgb(0.50, 0.15, 0.15); +const RIGHT_BUTTON: Color = Color::srgb(0.15, 0.50, 0.15); + #[derive(Serialize, Deserialize, Debug, Clone)] struct StarData { #[serde(rename = "Dec")] @@ -23,30 +24,30 @@ struct StarData { #[serde(rename = "V")] v: String, #[serde(rename = "C")] - constellation: Option, // Optional field + constellation: Option, #[serde(rename = "F")] - f: Option, // Optional field + f: Option, #[serde(rename = "B")] - bayer_designation: Option, // Optional field + bayer_designation: Option, #[serde(rename = "N")] - name: Option, // Optional field + name: Option, } #[derive(Resource, Default)] struct Sky { - content: Vec, // or use a specific array size, e.g., [String; 10] + content: Vec, } #[derive(Serialize, Deserialize, Debug, Clone)] struct Constellation { #[serde(rename = "Name")] - name: String, // Name of the constellation + name: String, #[serde(rename = "RAh")] - rah: f64, // Right Ascension of the constellation in hours + rah: f64, #[serde(rename = "DEd")] - dec: f64, // Declination of the constellation in degrees - stars: Vec, // List of stars in the constellation - lines: Vec<[u32; 2]>, // Star connection lines as pairs of star IDs + dec: f64, + stars: Vec, + lines: Vec<[u32; 2]>, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -60,19 +61,6 @@ struct StarPos { dec: f64, } -fn main() { - App::new() - .add_plugins(DefaultPlugins) - .insert_resource(Sky::default()) - .add_systems(Startup, star_setup) - .add_systems(Startup, cons_setup) - .add_systems(Startup, ui_setup) - .add_systems(Update, player_rotate) - .add_systems(Update, button_system) - .run(); -} - - #[derive(Component)] struct Star; @@ -85,6 +73,18 @@ struct Player { target_cons_name: Option, } +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .insert_resource(Sky::default()) + .add_systems(Startup, star_setup) + .add_systems(Startup, cons_setup) + .add_systems(Startup, ui_setup) + .add_systems(Update, player_rotate) + .add_systems(Update, button_system) + .run(); +} + fn star_setup( mut commands: Commands, mut meshes: ResMut>, @@ -141,10 +141,6 @@ fn star_setup( )); } -fn cons_setup(mut sky: ResMut) { - sky.content = get_cons().unwrap(); -} - fn get_stars() -> std::io::Result> { let mut file = File::open("data/stars.json")?; let mut data = String::new(); @@ -155,16 +151,6 @@ fn get_stars() -> std::io::Result> { Ok(stars) } -fn get_cons() -> std::io::Result> { - let mut file = File::open("data/constellations.json")?; - let mut data = String::new(); - file.read_to_string(&mut data)?; - - let sky_data: Vec = serde_json::from_str(&data).unwrap(); - - Ok(sky_data) -} - fn star_position(star_data: StarData) -> Vec3 { // Convert declination to decimal degrees let text_ra = star_data.ra; @@ -199,64 +185,21 @@ fn celestial_to_cartesian(rah: f64, ded: f64) -> Vec3 { Vec3::new(x, y, z) } -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 text_query: Query<&mut Text, With>, - mut button_query: Query<(&mut BackgroundColor, &mut BorderColor), With