summaryrefslogtreecommitdiff
path: root/server/src/protocol.rs
blob: 9e6717a3c2d15859755d8b6f4aa3a97f10fd7380 (plain)
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
59
60
61
62
63
64
65
use crate::recipes::Gamedata;
use glam::{IVec2, Vec2};
use serde::{Deserialize, Serialize};

pub type PlayerID = usize;
pub type ItemID = usize;
pub type ItemIndex = usize;
pub type TileIndex = usize;
pub type RecipeIndex = usize;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum PacketS {
    Join { name: String },
    Leave,
    Position { pos: Vec2, rot: f32 },
    Interact { pos: IVec2, edge: bool },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum PacketC {
    Init {
        data: Gamedata,
        id: PlayerID,
    },
    AddPlayer {
        id: PlayerID,
        name: String,
        hand: Option<(ItemID, ItemIndex)>,
    },
    RemovePlayer {
        id: PlayerID,
    },
    Position {
        player: PlayerID,
        pos: Vec2,
        rot: f32,
    },
    TakeItem {
        item: ItemID,
        player: PlayerID,
    },
    PutItem {
        item: ItemID,
        pos: IVec2,
    },
    ProduceItem {
        id: ItemID,
        pos: IVec2,
        kind: ItemIndex,
    },
    ConsumeItem {
        id: ItemID,
        pos: IVec2,
    },
    SetActive {
        tile: IVec2,
        progress: Option<f32>,
    },
    UpdateMap {
        pos: IVec2,
        tile: TileIndex,
    },
}