aboutsummaryrefslogtreecommitdiffstats
path: root/src/protocol.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol.rs')
-rw-r--r--src/protocol.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/protocol.rs b/src/protocol.rs
new file mode 100644
index 0000000..a9e2086
--- /dev/null
+++ b/src/protocol.rs
@@ -0,0 +1,47 @@
+use crate::shared::*;
+use bevy::prelude::*;
+use lightyear::prelude::*;
+use serde::Deserialize;
+use serde::Serialize;
+
+#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
+pub enum Inputs {
+ Teleport(Vec2),
+ None,
+}
+impl UserAction for Inputs {}
+
+#[derive(Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
+pub struct Message1(pub usize);
+
+#[message_protocol(protocol = "MyProtocol")]
+pub enum Messages {
+ Message1(Message1),
+}
+
+#[component_protocol(protocol = "MyProtocol")]
+pub enum Components {
+ #[sync(once)]
+ PlayerId(PlayerId),
+ PlayerPosition(PlayerPosition),
+ PlayerColor(PlayerColor),
+}
+
+#[derive(Channel)]
+struct Channel1;
+
+protocolize! {
+ Self = MyProtocol,
+ Message = Messages,
+ Component = Components,
+ Input = Inputs,
+}
+
+pub fn protocol() -> MyProtocol {
+ let mut protocol = MyProtocol::default();
+ protocol.add_channel::<Channel1>(ChannelSettings {
+ mode: ChannelMode::OrderedReliable(ReliableSettings::default()),
+ ..Default::default()
+ });
+ protocol
+}