use crate::component::{PartType, PlanetType};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct ProtoTransform {
pub x: f32,
pub y: f32,
pub rot: f32,
}
#[macro_export]
macro_rules! proto_transform {
($e:expr) => {
$crate::packet::ProtoTransform {
x: $e.translation.x,
y: $e.translation.y,
rot: $e.rotation.to_euler(bevy::math::EulerRot::ZYX).0,
}
};
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Planet {
pub planet_type: PlanetType,
pub transform: ProtoTransform,
pub radius: f32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Part {
pub part_type: PartType,
pub transform: ProtoTransform,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum MessageType {
Server,
Error,
Chat,
Direct,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum Packet {
// serverbound
ClientLogin {
username: String,
jwt: Option<String>,
},
SendMessage {
target: Option<String>,
content: String,
},
PlayerInput {
up: bool,
down: bool,
left: bool,
right: bool,
},
// clientbound
SpawnPlayer {
id: u32,
username: String,
},
PlayerList {
players: Vec<(u32, String)>,
},
PlanetPositions {
planets: Vec<(u32, Planet)>,
},
PartPositions {
parts: Vec<(u32, Part)>,
},
PlayerLeave {
id: u32,
},
Message {
message_type: MessageType,
actor: String,
content: String,
},
}