~starkingdoms/starkingdoms

ref: 1d680e35fb246797bb2b96e25df5a045fbcdc526 starkingdoms/crates/unified/src/client/starguide/orbit.rs -rw-r--r-- 1.3 KiB
1d680e35ghostly_zsh fix: orbit background fills the screen as it should 17 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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>>,
) {
    let Some(image) = images.get_mut(&orbit_image.0) else {
        error!("Orbit prediction image not found");
        return
    };
    image.clear(&(Color::WHITE.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,
        });
    }
}