mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-24 23:11:29 +11:00
d3ed3123ca
## Description This should _temporarily_ fix the heck issue described in #324 until https://github.com/withoutboats/heck/issues/42 is fixed downstream. When it is fixed downstream, this commit should get reverted. Fixes #324
38 lines
940 B
Rust
38 lines
940 B
Rust
use heck::ToPascalCase;
|
|
use proc_macro2::TokenStream;
|
|
use quote::quote;
|
|
use serde::Deserialize;
|
|
use valence_build_utils::ident;
|
|
|
|
#[derive(Deserialize)]
|
|
struct Packet {
|
|
name: String,
|
|
side: String,
|
|
state: String,
|
|
id: i32,
|
|
}
|
|
|
|
pub fn build() -> anyhow::Result<TokenStream> {
|
|
let packets: Vec<Packet> =
|
|
serde_json::from_str(include_str!("../../../extracted/packets.json"))?;
|
|
|
|
let mut consts = TokenStream::new();
|
|
|
|
for packet in packets {
|
|
let stripped_name = packet.name.strip_suffix("Packet").unwrap_or(&packet.name);
|
|
|
|
let name_ident = ident(stripped_name.replace('.', "_").to_pascal_case());
|
|
let id = packet.id;
|
|
|
|
let doc = format!("Side: {}\nState: {}", packet.side, packet.state);
|
|
|
|
consts.extend([quote! {
|
|
#[doc = #doc]
|
|
#[allow(non_upper_case_globals)]
|
|
pub(crate) const #name_ident: i32 = #id;
|
|
}]);
|
|
}
|
|
|
|
Ok(consts)
|
|
}
|