use bevy::window::WindowResized;
use crate::{ecs::{StarguideCamera, StarguideOrbitImage}, prelude::*};
use bevy::render::render_resource::Extent3d;
pub fn starguide_orbit_plugin(app: &mut App) {
app
.add_systems(Update, (update_orbits, window_resize));
}
fn update_orbits(
orbit_image: Res<StarguideOrbitImage>,
mut images: ResMut<Assets<Image>>,
camera: Single<&Camera, With<StarguideCamera>>,
) {
let Some(image) = images.get_mut(&orbit_image.0) else {
error!("Orbit prediction image not found");
return
};
image.clear(&(Color::BLACK.to_srgba().to_u8_array()));
for i in 0..100 {
image.set_color_at(i, 100, Color::linear_rgb(1.0, 0.0, 0.0)).unwrap();
}
}
fn window_resize(
orbit_image: Res<StarguideOrbitImage>,
mut images: ResMut<Assets<Image>>,
mut resize_ev: MessageReader<WindowResized>,
camera: Single<&Camera, With<StarguideCamera>>,
) {
let Some(image) = images.get_mut(&orbit_image.0) else {
error!("Orbit prediction image not found");
return
};
for _ in resize_ev.read() {
let Some(UVec2 {x: width, y: height}) = camera.physical_target_size() else {
continue
};
image.resize(Extent3d {
width: width,
height: height,
depth_or_array_layers: 1,
});
}
}