~starkingdoms/starkingdoms

ref: 02df8a053b6bfd7d2ee9fbdbd60fe29137b63a7c starkingdoms/server/src/packet.rs -rw-r--r-- 1.2 KiB
02df8a05 — core Merge branch 'bevy_rewrite' of gitlab.com:starkingdoms.tk/starkingdoms.tk into bevy_rewrite 2 years 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
47
48
49
50
51
52
53
54
55
56
57
58
use serde::{Deserialize, Serialize};
use crate::component::{PartType, PlanetType};

#[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)]
#[serde(tag = "t", content = "c")]
pub enum Packet {
    // serverbound
    ClientLogin {
        username: String,
        jwt: Option<String>,
    },
    // clientbound
    SpawnPlayer {
        id: u32,
        username: String,
    },
    PlayerList {
        players: Vec<(u32, String)>,
    },
    PlanetPositions {
        planets: Vec<(u32, Planet)>
    },
    PartPositions {
        parts: Vec<(u32, Part)>
    },
    PlayerLeave {
        id: u32,
    },
}