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
|
use crate::shared::*;
#[derive(Bundle)]
pub struct PlayerBundle {
id: PlayerId,
position: PlayerPosition,
color: PlayerColor,
imperative: Imperative,
cooldown: Cooldown,
health: Health,
champion: Champion,
replicate: Replicate,
}
impl PlayerBundle {
pub fn new(id: ClientId, position: Vec2, color: Color) -> Self {
let mut replicate = Replicate {
replication_group: ReplicationGroup::default().set_priority(10.),
..Default::default()
};
replicate.enable_replicate_once::<PlayerId>();
replicate.enable_replicate_once::<PlayerColor>();
replicate.target::<Cooldown>(NetworkTarget::Single(id));
replicate.target::<Champion>(NetworkTarget::Single(id));
PlayerBundle {
id: PlayerId(id),
position: PlayerPosition(position),
color: PlayerColor(color),
imperative: Imperative::Idle,
cooldown: Cooldown::default(),
health: Health::default(),
champion: Champion::default(),
replicate,
}
}
}
#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
pub struct PlayerId(pub ClientId);
#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
pub struct PlayerPosition(pub Vec2);
#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct PlayerColor(pub Color);
|