M crates/unified/assets/config/planets.pc.toml => crates/unified/assets/config/planets.pc.toml +2 -2
@@ 4,7 4,7 @@ sprite = "textures/sun.png"
radius = 20_000.0 # m
mass = 16_000_000.0 # kg
default_transform = [0.0, 0.0, 0.0]
-special_sprite_properties = { DrawAsCircle = { Oklcha = { lightness = 10.0, chroma = 0.058, hue = 104.26, alpha = 1.0 } } }
+special_sprite_properties = { ForceColor = { Oklcha = { lightness = 10.0, chroma = 0.058, hue = 104.26, alpha = 1.0 } } }
[[planets]]
name = "Mercury"
@@ 77,4 77,4 @@ name = "Pluto"
sprite = "textures/pluto.png"
radius = 186.8 # m
mass = 22.075_947_755_1 # kg
-default_transform = [11_844_600.0, 0.0, 0.0]>
\ No newline at end of file
+default_transform = [11_844_600.0, 0.0, 0.0]
M crates/unified/src/client/mod.rs => crates/unified/src/client/mod.rs +4 -1
@@ 6,6 6,7 @@ mod net;
mod starfield;
mod ui;
mod planet;
+mod zoom;
use crate::client::incoming_particles::replicated_particles_plugin;
use crate::client::incoming_parts::incoming_parts_plugin;
@@ 13,6 14,7 @@ use planet::incoming_planets::incoming_planets_plugin;
use crate::client::key_input::key_input_plugin;
use crate::client::starfield::starfield_plugin;
use crate::client::ui::ui_plugin;
+use crate::client::zoom::zoom_plugin;
use crate::ecs::{CursorWorldCoordinates, MainCamera, Part, Player};
use aeronet_websocket::client::WebSocketClient;
use bevy::core_pipeline::bloom::Bloom;
@@ 49,7 51,8 @@ impl Plugin for ClientPlugin {
.add_plugins(key_input_plugin)
.add_plugins(starfield_plugin)
.add_plugins(ui_plugin)
- .add_plugins(replicated_particles_plugin);
+ .add_plugins(replicated_particles_plugin)
+ .add_plugins(zoom_plugin);
}
}
M crates/unified/src/client/starfield.rs => crates/unified/src/client/starfield.rs +17 -8
@@ 4,7 4,7 @@ use bevy::{
ecs::{
event::EventReader,
query::{With, Without},
- system::{Commands, Query, Res},
+ system::{Commands, Query, Res, Single},
},
image::Image,
math::{Vec2, Vec3},
@@ 15,12 15,12 @@ use bevy::{
use crate::{
client::Me,
- ecs::{StarfieldBack, StarfieldFront, StarfieldMid},
+ ecs::{MainCamera, StarfieldBack, StarfieldFront, StarfieldMid},
};
-const BACK_STARFIELD_SIZE: f32 = 256.0;
-const MID_STARFIELD_SIZE: f32 = 384.0;
-const FRONT_STARFIELD_SIZE: f32 = 512.0;
+pub const BACK_STARFIELD_SIZE: f32 = 256.0;
+pub const MID_STARFIELD_SIZE: f32 = 384.0;
+pub const FRONT_STARFIELD_SIZE: f32 = 512.0;
pub fn starfield_plugin(app: &mut App) {
app.add_systems(Startup, setup_starfield)
@@ 165,14 165,15 @@ pub fn resize_starfield(
),
>,
mut resize_event: EventReader<WindowResized>,
+ camera: Single<&Transform, With<MainCamera>>,
) {
for event in resize_event.read() {
starfield_back.single_mut().unwrap().custom_size =
- Some(Vec2::new(event.width, event.height) + Vec2::splat(BACK_STARFIELD_SIZE * 2.0));
+ Some(Vec2::new(event.width, event.height) * camera.scale.z + Vec2::splat(BACK_STARFIELD_SIZE * 2.0));
starfield_mid.single_mut().unwrap().custom_size =
- Some(Vec2::new(event.width, event.height) + Vec2::splat(MID_STARFIELD_SIZE * 2.0));
+ Some(Vec2::new(event.width, event.height) * camera.scale.z + Vec2::splat(MID_STARFIELD_SIZE * 2.0));
starfield_front.single_mut().unwrap().custom_size =
- Some(Vec2::new(event.width, event.height) + Vec2::splat(FRONT_STARFIELD_SIZE * 2.0));
+ Some(Vec2::new(event.width, event.height) * camera.scale.z + Vec2::splat(FRONT_STARFIELD_SIZE * 2.0));
}
}
@@ 204,6 205,8 @@ pub fn update_starfield(
Without<StarfieldMid>,
),
>,
+ window: Single<&Window>,
+ camera: Single<&Transform, (With<MainCamera>, Without<Me>, Without<StarfieldFront>, Without<StarfieldMid>, Without<StarfieldBack>)>,
player: Query<&Transform, (With<Me>, Without<StarfieldFront>)>,
) {
let Some(player) = player.iter().next() else {
@@ 215,11 218,17 @@ pub fn update_starfield(
//starfield_pos.translation = (player.translation / STARFIELD_SIZE).round() * STARFIELD_SIZE;
starfield_back_pos.translation = player.translation
+ (-player.translation / 3.0) % BACK_STARFIELD_SIZE
+ + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % BACK_STARFIELD_SIZE
+ + Vec3::new(0.0, BACK_STARFIELD_SIZE, 0.0)
- Vec3::new(0.0, 0.0, 5.0);
starfield_mid_pos.translation = player.translation
+ (-player.translation / 2.5) % MID_STARFIELD_SIZE
+ + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % MID_STARFIELD_SIZE
+ + Vec3::new(0.0, MID_STARFIELD_SIZE, 0.0)
- Vec3::new(0.0, 0.0, 4.5);
starfield_front_pos.translation = player.translation
+ (-player.translation / 2.0) % FRONT_STARFIELD_SIZE
+ + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % FRONT_STARFIELD_SIZE
+ + Vec3::new(0.0, FRONT_STARFIELD_SIZE, 0.0)
- Vec3::new(0.0, 0.0, 4.0);
}
A crates/unified/src/client/zoom.rs => crates/unified/src/client/zoom.rs +74 -0
@@ 0,0 1,74 @@
+use bevy::{input::mouse::{MouseScrollUnit, MouseWheel}, prelude::*};
+
+use crate::{client::{starfield::{BACK_STARFIELD_SIZE, FRONT_STARFIELD_SIZE, MID_STARFIELD_SIZE}, Me}, ecs::{MainCamera, StarfieldBack, StarfieldFront, StarfieldMid}};
+
+pub fn zoom_plugin(app: &mut App) {
+ app.add_systems(Update, on_scroll);
+}
+
+fn on_scroll(
+ mut scroll_events: EventReader<MouseWheel>,
+ window: Single<&Window>,
+ starfield_back: Single<
+ (&mut Sprite, &mut Transform),
+ (
+ With<StarfieldBack>,
+ Without<StarfieldMid>,
+ Without<StarfieldFront>,
+ ),
+ >,
+ starfield_mid: Single<
+ (&mut Sprite, &mut Transform),
+ (
+ With<StarfieldMid>,
+ Without<StarfieldBack>,
+ Without<StarfieldFront>,
+ ),
+ >,
+ starfield_front: Single<
+ (&mut Sprite, &mut Transform),
+ (
+ With<StarfieldFront>,
+ Without<StarfieldBack>,
+ Without<StarfieldMid>,
+ ),
+ >,
+ mut camera: Single<&mut Transform, (With<MainCamera>, Without<Me>, Without<StarfieldFront>, Without<StarfieldMid>, Without<StarfieldBack>)>,
+ player: Single<&Transform, (With<Me>, Without<StarfieldFront>, Without<StarfieldMid>, Without<StarfieldBack>, Without<MainCamera>)>,
+) {
+ let (mut starfield_back, mut starfield_back_pos) = starfield_back.into_inner();
+ let (mut starfield_mid, mut starfield_mid_pos) = starfield_mid.into_inner();
+ let (mut starfield_front, mut starfield_front_pos) = starfield_front.into_inner();
+ for event in scroll_events.read() {
+ match event.unit {
+ MouseScrollUnit::Line | MouseScrollUnit::Pixel => {
+ if event.y > 0.0 {
+ camera.scale *= 0.97;
+ } else {
+ camera.scale *= 1.03;
+ }
+ starfield_back.custom_size =
+ Some(window.size() * camera.scale.z + Vec2::splat(BACK_STARFIELD_SIZE * 2.0));
+ starfield_mid.custom_size =
+ Some(window.size() * camera.scale.z + Vec2::splat(MID_STARFIELD_SIZE * 2.0));
+ starfield_front.custom_size =
+ Some(window.size() * camera.scale.z + Vec2::splat(FRONT_STARFIELD_SIZE * 2.0));
+ starfield_back_pos.translation = player.translation
+ + (-player.translation / 3.0) % BACK_STARFIELD_SIZE
+ + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % BACK_STARFIELD_SIZE
+ + Vec3::new(0.0, BACK_STARFIELD_SIZE, 0.0)
+ - Vec3::new(0.0, 0.0, 5.0);
+ starfield_mid_pos.translation = player.translation
+ + (-player.translation / 2.5) % MID_STARFIELD_SIZE
+ + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % MID_STARFIELD_SIZE
+ + Vec3::new(0.0, MID_STARFIELD_SIZE, 0.0)
+ - Vec3::new(0.0, 0.0, 4.5);
+ starfield_front_pos.translation = player.translation
+ + (-player.translation / 2.0) % FRONT_STARFIELD_SIZE
+ + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)*camera.scale.z/2.0) % FRONT_STARFIELD_SIZE
+ + Vec3::new(0.0, FRONT_STARFIELD_SIZE, 0.0)
+ - Vec3::new(0.0, 0.0, 4.0);
+ }
+ }
+ }
+}