aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/player.rs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-18 03:28:49 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-18 03:28:49 +0100
commitab675360c0005718a3c9b8b5e7962af897269c04 (patch)
treebfae0eafd5c5fa29c12d544f3075adfd5b96cbc5 /src/shared/player.rs
parente40eab9143fd881add48aba1e4ea1e1283c72cff (diff)
chore: play with network settings
Diffstat (limited to 'src/shared/player.rs')
-rw-r--r--src/shared/player.rs45
1 files changed, 45 insertions, 0 deletions
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);