aboutsummaryrefslogtreecommitdiffstats
path: root/src/protocol.rs
blob: bdc2098099b3b15597b23f0043251c99f853a560 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::shared::activation::*;
use crate::shared::area_of_effect::*;
use crate::shared::buffs::*;
use crate::shared::champion::*;
use crate::shared::cooldown::*;
use crate::shared::faction::*;
use crate::shared::health::*;
use crate::shared::health_event::*;
use crate::shared::imperative::*;
use crate::shared::name::*;
use crate::shared::player::*;
use crate::shared::projectile::*;
use crate::shared::shape::*;
use crate::shared::stats::*;
use crate::shared::tower::*;
use lightyear::prelude::*;
use serde::Deserialize;
use serde::Serialize;

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub enum Inputs {
    None,
}
impl UserAction for Inputs {}

#[derive(Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Spawn {
    pub champion: Champion,
    pub faction: Faction,
    pub name: String,
}

#[derive(Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct HealthChanged(pub HealthEvent);

#[message_protocol(protocol = "MyProtocol")]
pub enum Messages {
    Spawn(Spawn),
    HealthChanged(HealthChanged),
    Imperative(Imperative),
    Activation(Activation),
}

#[component_protocol(protocol = "MyProtocol")]
pub enum Components {
    PlayerId(PlayerId),
    PlayerPosition(PlayerPosition),
    PlayerColor(PlayerColor),
    Projectile(Projectile),
    ProjectileColor(ProjectileColor),
    Cooldown(Cooldown),
    Health(Health),
    Champion(Champion),
    EffectiveStats(EffectiveStats),
    AreaOfEffect(AreaOfEffect),
    Buffs(Buffs),
    Shape(Shape),
    Tower(Tower),
    Faction(Faction),
    Name(Name_),
}

#[derive(Channel)]
pub struct Input;

protocolize! {
    Self = MyProtocol,
    Message = Messages,
    Component = Components,
    Input = Inputs,
}

pub fn protocol() -> MyProtocol {
    let mut protocol = MyProtocol::default();
    protocol.add_channel::<Input>(ChannelSettings {
        mode: ChannelMode::OrderedReliable(Default::default()),
        ..Default::default()
    });
    protocol
}