valence/crates/valence_core/build/packet_id.rs
AviiNL d3ed3123ca
Temp fix for heck with unicode enabled (#326)
## 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
2023-04-28 11:53:10 +00:00

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)
}