~starkingdoms/starkingdoms

8d0982f2463479ae31f1098fe71e0510220b4c2f — ghostly_zsh 16 days ago 8cd3d04
fix: orbit indicator is a line
M crates/unified/src/client/rendering/mod.rs => crates/unified/src/client/rendering/mod.rs +5 -2
@@ 2,7 2,7 @@ use bevy::anti_alias::fxaa::Fxaa;
use bevy::app::{App, Startup};
use bevy::core_pipeline::tonemapping::DebandDither;
use bevy::post_process::bloom::Bloom;
use crate::ecs::{GameplayState, MainCamera, StarguideCamera, Me, MAIN_LAYER};
use crate::ecs::{GameplayState, MAIN_LAYER, MAIN_STAR_LAYERS, MainCamera, Me, StarguideCamera};
use crate::prelude::*;

pub fn render_plugin(app: &mut App) {


@@ 12,7 12,7 @@ pub fn render_plugin(app: &mut App) {
}


pub fn setup_graphics(mut commands: Commands) {
pub fn setup_graphics(mut config_store: ResMut<GizmoConfigStore>, mut commands: Commands) {
    commands
        .spawn(Camera2d)
        .insert(Camera {


@@ 24,6 24,9 @@ pub fn setup_graphics(mut commands: Commands) {
        .insert(DebandDither::Enabled)
        .insert(Fxaa::default())
        .insert(MainCamera);
    for (_, config, _) in config_store.iter_mut() {
        config.render_layers = MAIN_STAR_LAYERS.clone();
    }
}

fn follow_camera(

M crates/unified/src/client/starguide/init.rs => crates/unified/src/client/starguide/init.rs +4 -5
@@ 19,20 19,19 @@ pub fn init_starguide(
    window: Single<&Window, With<PrimaryWindow>>,
    mut commands: Commands,
) {
    commands.spawn((Camera2d::default(), Camera {
    /*commands.spawn((Camera2d::default(), Camera {
        is_active: false,
        clear_color: ClearColorConfig::Custom(Color::linear_rgba(0.0, 0.0, 0.0, 1.0)),
        order: 0,
        ..default()
    }))
    .insert(ORBIT_LAYER)
    .insert(OrbitCamera);
    .insert(OrbitCamera);*/

    commands.spawn((Camera2d::default(), Camera {
        is_active: false,
        //clear_color: ClearColorConfig::None,
        clear_color: ClearColorConfig::Custom(Color::linear_rgba(0.0, 0.0, 0.0, 1.0)),
        order: 1,
        ..default()
    }))
    .insert(Bloom::default())


@@ 41,7 40,7 @@ pub fn init_starguide(
    .insert(STARGUIDE_LAYER)
    .insert(StarguideCamera);

    let image = Image::new_fill(
    /*let image = Image::new_fill(
        Extent3d {
            width: window.width() as u32,
            height: window.height() as u32,


@@ 54,7 53,7 @@ pub fn init_starguide(
    let handle = images.add(image);
    commands.spawn((Sprite::from_image(handle.clone()), STARGUIDE_LAYER, StarguideOrbit))
        .insert(Transform::from_xyz(0.0, 0.0, -10.0));
    commands.insert_resource(StarguideOrbitImage(handle));
    commands.insert_resource(StarguideOrbitImage(handle));*/
}

pub fn player_init(

M crates/unified/src/client/starguide/input.rs => crates/unified/src/client/starguide/input.rs +2 -2
@@ 35,12 35,12 @@ fn on_click(
fn starguide_drag(
    drag: ResMut<StarguideDrag>,
    mut camera: Single<&mut Transform, With<StarguideCamera>>,
    mut orbit: Single<&mut Transform, (With<StarguideOrbit>, Without<StarguideCamera>)>,
    //mut orbit: Single<&mut Transform, (With<StarguideOrbit>, Without<StarguideCamera>)>,
    cursor: Res<CursorWorldCoordinates>,
) {
    if !drag.is_dragging { return }
    let Some(cursor) = cursor.0 else { return };

    camera.translation = drag.init_camera_pos.extend(0.0) - (cursor - drag.init_cursor_pos).extend(0.0);
    orbit.translation = drag.init_camera_pos.extend(0.0) - (cursor - drag.init_cursor_pos).extend(0.0);
    //orbit.translation = drag.init_camera_pos.extend(0.0) - (cursor - drag.init_cursor_pos).extend(0.0);
}

M crates/unified/src/client/starguide/orbit.rs => crates/unified/src/client/starguide/orbit.rs +20 -17
@@ 7,27 7,28 @@ use bevy::render::render_resource::Extent3d;

pub fn starguide_orbit_plugin(app: &mut App) {
    app
        .add_systems(Update, (update_orbits, window_resize));
        .add_systems(Update, (update_orbits));
}

fn update_orbits(
    orbit_image: Res<StarguideOrbitImage>,
    mut images: ResMut<Assets<Image>>,
    //orbit_image: Res<StarguideOrbitImage>,
    //mut images: ResMut<Assets<Image>>,
    camera: Single<(&Camera, &GlobalTransform, &Projection), With<StarguideCamera>>,
    me: Single<(&Transform, &LinearVelocity), (With<Me>, Without<StarguideCamera>)>,
    orbit: Single<&Transform, (With<StarguideOrbit>, Without<Me>, Without<StarguideCamera>)>,
    //orbit: Single<&Transform, (With<StarguideOrbit>, Without<Me>, Without<StarguideCamera>)>,
    mut gizmos: Gizmos,
    world_config: Res<WorldConfigResource>,
    planets: Query<(&Mass, &Planet, &Transform)>,
) {
    let Some(image) = images.get_mut(&orbit_image.0) else {
    /*let Some(image) = images.get_mut(&orbit_image.0) else {
        error!("Orbit prediction image not found");
        return
    };
    };*/
    let Some(world_config) = &world_config.config else {
        return;
    };
    let Projection::Orthographic(ref projection) = camera.2.clone() else { return };
    image.clear(&(Color::BLACK.to_srgba().to_u8_array()));
    //image.clear(&(Color::BLACK.to_srgba().to_u8_array()));

    let mut p_mass = 0.0;
    let mut p_transform = Transform::default();


@@ 60,25 61,27 @@ fn update_orbits(
    let f_y = -2.0*a*e_y;

    // 200 steps in the revolution
    for i in 0..400 {
        let theta = (i as f32) / 200.0 * 2.0*PI;
    let mut last_pos = Vec2::ZERO;
    for i in 0..200 {
        let theta = 2.0*PI*(i as f32)/200.0;
        let r = (1.0/2.0) * ((f_x*f_x + f_y*f_y - 4.0*a*a) / (-2.0*a - f_x*theta.cos() - f_y*theta.sin()));

        // convert r to image coords
        let pos = Vec2::new(r*theta.cos(), r*theta.sin());
        let pos = pos + p_transform.translation.truncate() - orbit.translation.truncate();
        let pos = Vec2::new(r*theta.cos(), r*theta.sin()) + p_transform.translation.truncate();
        /*let pos = pos + p_transform.translation.truncate() - orbit.translation.truncate();
        let pos = Vec2::new(pos.x, -pos.y);
        let pos = pos / projection.scale;
        let pos = pos + image.size_f32()/2.0;
        let pos = pos.as_uvec2();
        let pos = pos + image.size_f32()/2.0;*/

        if !(pos.x >= image.size().x || pos.y >= image.size().y) {
            image.set_color_at(pos.x, pos.y, Color::linear_rgb(1.0, 0.0, 0.0)).unwrap();
        //if !(pos.x as u32 >= image.size().x || pos.y as u32 >= image.size().y) && i != 0 {
        if i != 0 {
            gizmos.line_2d(last_pos, pos, Color::linear_rgb(1.0, 0.0, 0.0));
        }
        last_pos = pos;
    }
}

fn window_resize(
/*fn window_resize(
    orbit_image: Res<StarguideOrbitImage>,
    mut images: ResMut<Assets<Image>>,
    mut resize_ev: MessageReader<WindowResized>,


@@ 98,4 101,4 @@ fn window_resize(
            depth_or_array_layers: 1,
        });
    }
}
}*/

M crates/unified/src/client/zoom.rs => crates/unified/src/client/zoom.rs +8 -8
@@ 52,7 52,7 @@ fn on_scroll(
            Without<StarfieldBack>,
        ),
    >,
    mut orbit_camera: Single<
    /*mut orbit_camera: Single<
        &mut Camera,
        (
            With<OrbitCamera>,


@@ 63,7 63,7 @@ fn on_scroll(
            Without<StarfieldMid>,
            Without<StarfieldBack>,
        ),
    >,
    >,*/
    mut camera: Single<
        (&mut Camera, &mut Projection),
        (


@@ 86,7 86,7 @@ fn on_scroll(
            Without<MainCamera>,
        ),
    >,
    mut starguide_orbit: Single<
    /*mut starguide_orbit: Single<
        &mut Transform,
        (
            With<StarguideOrbit>,


@@ 98,7 98,7 @@ fn on_scroll(
            Without<OrbitCamera>,
            Without<StarguideCamera>,
        ),
    >,
    >,*/
) {
    let (mut starfield_back, mut starfield_back_pos, mut visibility_back, size_back) =
        starfield_back.into_inner();


@@ 117,15 117,15 @@ fn on_scroll(
                    camera_projection.scale *= 1.03;
                    starguide_projection.scale *= 1.03;
                }
                starguide_orbit.scale = Vec3::splat(starguide_projection.scale);
                //starguide_orbit.scale = Vec3::splat(starguide_projection.scale);

                if camera_projection.scale > 20.0 && matches!(gameplay_state.get(), GameplayState::Main) {
                    camera.0.is_active = false;
                    starguide_camera.0.is_active = true;
                    orbit_camera.is_active = true;
                    //orbit_camera.is_active = true;

                    starguide_camera.2.translation = player.translation;
                    starguide_orbit.translation = player.translation;
                    //starguide_orbit.translation = player.translation;
                    gameplay_next_state.set(GameplayState::Starguide);

                    starfield_back.image_mode = SpriteImageMode::Auto;


@@ 138,7 138,7 @@ fn on_scroll(
                    camera.0.is_active = true;
                    gameplay_next_state.set(GameplayState::Main);
                    starguide_camera.0.is_active = false;
                    orbit_camera.is_active = false;
                    //orbit_camera.is_active = false;

                    if matches!(*visibility_back, Visibility::Hidden) {
                        if let Some(size_back) = size_back {