Give the message structs friendlier field names on the Rust side, because Serde lets us do that

This commit is contained in:
Tangent Wantwight 2020-06-08 19:50:56 -04:00
parent c199e14435
commit a7dc49996f
2 changed files with 33 additions and 10 deletions

View file

@ -15,11 +15,22 @@ pub type GameState = Value;
#[serde(tag = "t")]
pub enum ClientMessage {
#[serde(rename = "s")]
SetState { s: GameState },
SetState {
#[serde(rename = "s")]
new_state: GameState
},
#[serde(rename = "i")]
Input { i: PlayerInput },
Input {
#[serde(rename = "i")]
local_input: PlayerInput
},
#[serde(rename = "g")]
GetState { c: usize, s: GameState },
GetState {
#[serde(rename = "c")]
cookie: usize,
#[serde(rename = "s")]
state: GameState
},
}
#[derive(Serialize, Debug, Clone)]
@ -34,12 +45,24 @@ pub enum ServerMessage {
#[serde(rename = "m")]
Meta {
#[serde(flatten)]
m: Meta,
#[serde(rename = "m")]
meta: Meta,
},
#[serde(rename = "s")]
SetState { u: Option<PlayerId>, s: GameState },
SetState {
#[serde(rename = "u")]
player_id: Option<PlayerId>,
#[serde(rename = "s")]
state: GameState
},
#[serde(rename = "i")]
Input { i: Vec<PlayerInput> },
Input {
#[serde(rename = "i")]
total_input: Vec<PlayerInput>
},
#[serde(rename = "g")]
GetState { c: usize },
GetState {
#[serde(rename = "c")]
cookie: usize
},
}

View file

@ -16,14 +16,14 @@ const CHANNEL_BUFFER: usize = 200;
pub async fn greet(sink: &mut Sender<ServerMessage>) -> Result<()> {
let mut greeting = iter(vec![
ServerMessage::Meta {
m: Meta {
meta: Meta {
version: "Unstable",
helo: Some("Dedicated base2020 server".into()),
},
},
ServerMessage::SetState {
u: Some(0),
s: json!({}),
player_id: Some(0),
state: json!({}),
},
])
.map(Ok);