parse game event at compile time
This commit is contained in:
1 parent
624fa750e7
commit
82386a57c4
9 files changed
+52
-28
No files matched your search
@@ -0,0 +1,27 @@
|
||||
use heck::ToPascalCase;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
use crate::ident;
|
||||
|
||||
pub(crate) fn build() -> TokenStream {
|
||||
println!("cargo:rerun-if-changed=assets/game_event.json");
|
||||
|
||||
let game_event: Vec<String> =
|
||||
serde_json::from_str(include_str!("../../assets/game_event.json"))
|
||||
.expect("Failed to parse game_event.json");
|
||||
let mut variants = TokenStream::new();
|
||||
|
||||
for event in game_event.iter() {
|
||||
let name = ident(event.to_pascal_case());
|
||||
variants.extend([quote! {
|
||||
#name,
|
||||
}]);
|
||||
}
|
||||
quote! {
|
||||
#[repr(u8)]
|
||||
pub enum GameEvent {
|
||||
#variants
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user