Remove some generics & make some typedefs.

This commit is contained in:
Tangent Wantwight 2020-05-30 20:08:02 -04:00
parent eee34eb3ff
commit dacb031443

View file

@ -4,16 +4,18 @@ use serde_json::Value;
pub mod server; pub mod server;
pub type PlayerId = usize; pub type PlayerId = usize;
pub type PlayerInput = Value;
pub type GameState = Value;
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
#[serde(tag = "t")] #[serde(tag = "t")]
pub enum ClientMessage<I = Value, S = Value> { pub enum ClientMessage {
#[serde(rename = "s")] #[serde(rename = "s")]
SetState { s: S }, SetState { s: GameState },
#[serde(rename = "i")] #[serde(rename = "i")]
Input { i: I }, Input { i: PlayerInput },
#[serde(rename = "g")] #[serde(rename = "g")]
GetState { c: usize, s: S }, GetState { c: usize, s: GameState },
} }
#[derive(Serialize, Debug, Clone)] #[derive(Serialize, Debug, Clone)]
@ -24,16 +26,16 @@ pub struct Meta {
#[derive(Serialize, Debug, Clone)] #[derive(Serialize, Debug, Clone)]
#[serde(tag = "t")] #[serde(tag = "t")]
pub enum ServerMessage<I = Vec<Value>, S = Value> { pub enum ServerMessage {
#[serde(rename = "m")] #[serde(rename = "m")]
Meta { Meta {
#[serde(flatten)] #[serde(flatten)]
m: Meta, m: Meta,
}, },
#[serde(rename = "s")] #[serde(rename = "s")]
SetState { u: Option<PlayerId>, s: S }, SetState { u: Option<PlayerId>, s: GameState },
#[serde(rename = "i")] #[serde(rename = "i")]
Input { i: I }, Input { i: Vec<PlayerInput> },
#[serde(rename = "g")] #[serde(rename = "g")]
GetState { c: usize }, GetState { c: usize },
} }