diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/ability.rs | 1 | ||||
-rw-r--r-- | src/shared/health_event.rs | 1 | ||||
-rw-r--r-- | src/shared/imperative.rs | 3 | ||||
-rw-r--r-- | src/shared/player.rs | 45 | ||||
-rw-r--r-- | src/shared/projectile.rs | 13 |
5 files changed, 62 insertions, 1 deletions
diff --git a/src/shared/ability.rs b/src/shared/ability.rs index 8ef0c29..9639afe 100644 --- a/src/shared/ability.rs +++ b/src/shared/ability.rs @@ -1,3 +1,4 @@ +use crate::shared::player::*; use crate::shared::projectile::*; use crate::shared::*; diff --git a/src/shared/health_event.rs b/src/shared/health_event.rs index 9932599..10af4ed 100644 --- a/src/shared/health_event.rs +++ b/src/shared/health_event.rs @@ -1,3 +1,4 @@ +use crate::shared::player::*; use crate::shared::*; #[derive(Message, Serialize, Deserialize, PartialEq, Clone, Debug)] diff --git a/src/shared/imperative.rs b/src/shared/imperative.rs index bd604f8..afdf244 100644 --- a/src/shared/imperative.rs +++ b/src/shared/imperative.rs @@ -1,9 +1,10 @@ use crate::shared::ability::*; +use crate::shared::player::*; use crate::shared::*; use serde::Deserialize; use serde::Serialize; -#[derive(Component, Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] +#[derive(Component, Message, Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] pub enum Imperative { Idle, WalkTo(Vec2), diff --git a/src/shared/player.rs b/src/shared/player.rs new file mode 100644 index 0000000..a886499 --- /dev/null +++ b/src/shared/player.rs @@ -0,0 +1,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); diff --git a/src/shared/projectile.rs b/src/shared/projectile.rs index f944e8a..772f5d9 100644 --- a/src/shared/projectile.rs +++ b/src/shared/projectile.rs @@ -1,3 +1,4 @@ +use crate::shared::player::*; use crate::shared::*; #[derive(Bundle)] @@ -6,6 +7,18 @@ pub struct ProjectileBundle { pub replicate: Replicate, } +impl ProjectileBundle { + pub fn new(projectile: Projectile) -> Self { + ProjectileBundle { + projectile, + replicate: Replicate { + replication_group: ReplicationGroup::default().set_priority(1.), + ..Default::default() + }, + } + } +} + #[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)] pub struct Projectile { |