@@ 58,7 58,7 @@ pub struct Player;
#[derive(Component, Debug, Clone, Copy)]
pub struct Planet;
#[derive(Component, Debug, Clone, Copy)]
-pub struct Part;
+pub struct Part(pub bool); // Part(attached)
#[derive(Component, Debug, Clone, Copy)]
pub struct ServerId(pub u32);
@@ 51,7 51,7 @@ pub fn start() {
translation: Translation3::new(0.0, 0.0, 0.0),
rotation: Rotation2::new(0.0),
scale: Scale3::new(25.0, 25.0, 1.0),
- }, Texture { name: "hearty.svg".to_string() }, Player, Part));
+ }, Texture { name: "hearty.svg".to_string() }, Player, Part(false)));
let event_loop = EventLoop::new().unwrap();
event_loop.set_control_flow(ControlFlow::Wait);
@@ 13,6 13,29 @@ pub mod ws;
#[path = "ws_native.rs"]
pub mod ws;
+fn texture_name(part_type: PartType, attached: bool) -> String {
+ use PartType::*;
+ if attached {
+ match part_type {
+ Placeholder => panic!("AHHHH PLACEHOLDER PANIC"),
+ Hearty => "hearty.svg",
+ Cargo => "cargo_on.svg",
+ Hub => "hub_on.svg",
+ LandingThruster => "landingthruster_on.svg",
+ LandingThrusterSuspension => "landingleg.svg",
+ }.to_string()
+ } else {
+ match part_type {
+ Placeholder => panic!("AHHHH PLACEHOLDER PANIC"),
+ Hearty => "hearty.svg",
+ Cargo => "cargo_off.svg",
+ Hub => "hub_off.svg",
+ LandingThruster => "landingthruster_off.svg",
+ LandingThrusterSuspension => "landingleg.svg",
+ }.to_string()
+ }
+}
+
pub fn process_packets(
world: &mut World,
send_packet_events: &mut Events<SendPacket>,
@@ 39,7 62,7 @@ pub fn process_packets(
scale: Scale3::new(25.0, 25.0, 1.0),
}, Texture {
name: "hearty.svg".to_string(),
- }, ServerId(player.0), Part));
+ }, ServerId(player.0), Part(false)));
}
}
SpawnPlayer { id, username } => {
@@ 50,24 73,16 @@ pub fn process_packets(
scale: Scale3::new(25.0, 25.0, 1.0),
}, Texture {
name: "hearty.svg".to_string(),
- }, ServerId(*id), Part));
+ }, ServerId(*id), Part(false)));
}
SpawnPart { id, part } => {
- use PartType::*;
world.spawn((Transform {
translation: Translation3::new(part.transform.x, part.transform.y, 0.0),
rotation: Rotation2::new(part.transform.rot),
scale: Scale3::new(25.0, 25.0, 1.0),
}, Texture {
- name: match part.part_type {
- Placeholder => panic!("AHHHH PLACEHOLDER PANIC"),
- Hearty => "hearty.svg",
- Cargo => "cargo_off.svg",
- Hub => "hub_off.svg",
- LandingThruster => "landingthruster_off.svg",
- LandingThrusterSuspension => "landingleg.svg",
- }.to_string()
- }, ServerId(*id), Part));
+ name: texture_name(part.part_type, part.flags.attached),
+ }, ServerId(*id), Part(part.flags.attached)));
}
PartPositions { parts } => {
for (id, part) in parts {
@@ 90,12 105,20 @@ pub fn process_packets(
camera.y = -part.transform.y;
}
}
- let mut part_query = world.query_filtered::<(&ServerId, &mut Transform), With<Part>>();
- for (server_id, mut transform) in part_query.iter_mut(world) {
+ let mut part_query = world.query::<(Entity, &ServerId, &mut Transform, &mut Texture, &mut Part)>();
+ for (entity, server_id, mut transform, mut texture, mut bevy_part) in part_query.iter_mut(world) {
if server_id.0 == *id {
transform.translation.x = part.transform.x;
transform.translation.y = part.transform.y;
transform.rotation = Rotation2::new(part.transform.rot);
+
+ if part.flags.attached && !bevy_part.0 {
+ texture.name = texture_name(part.part_type, part.flags.attached);
+ bevy_part.0 = true;
+ } else if !part.flags.attached && bevy_part.0 {
+ texture.name = texture_name(part.part_type, part.flags.attached);
+ bevy_part.0 = false;
+ }
}
}
}
@@ 339,11 339,9 @@ impl ApplicationHandler for App {
_ => return,
};
let camera = self.world.get_resource::<Camera>().unwrap();
- tracing::info!("{}, {}", self.mouse_pos.x, self.mouse_pos.y);
let view = camera.to_cursor_matrix();
let pos = view * Vector3::new(self.mouse_pos.x as f32, self.mouse_pos.y as f32, 1.0);
let pos = pos / pos.z;
- tracing::info!("{}, {}", pos.x, pos.y);
self.send_packet_events.send(SendPacket(Packet::PlayerMouseInput {
x: pos.x,
y: pos.y,