mirror of
https://github.com/Pumpkin-MC/Pumpkin
synced 2025-04-11 18:19:33 +00:00
* Major grammar sweep * Remove extra backtick * Use more specific terminology for chunk data storage * Forgor to cargofmt * Fix typo "thier" * Fix typo "clousures" * Try new terminology * Forgor to cargofmt * Use "Subchunks" instead of "Heterogeneous" for ChunkBlocks variant * Fix variable name * Forgor to change comment
52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
use heck::ToPascalCase;
|
|
use proc_macro2::TokenStream;
|
|
use quote::{format_ident, quote};
|
|
|
|
pub(crate) fn build() -> TokenStream {
|
|
println!("cargo:rerun-if-changed=../assets/status_effects.json");
|
|
|
|
let chunk_status: Vec<String> =
|
|
serde_json::from_str(include_str!("../../assets/status_effects.json"))
|
|
.expect("Failed to parse status_effects.json");
|
|
let mut variants = TokenStream::new();
|
|
let mut type_from_name = TokenStream::new();
|
|
let mut type_to_name = TokenStream::new();
|
|
|
|
for status in chunk_status.iter() {
|
|
let const_ident = format_ident!("{}", status.to_pascal_case());
|
|
let resource_name = status.to_lowercase();
|
|
|
|
variants.extend([quote! {
|
|
#const_ident,
|
|
}]);
|
|
type_from_name.extend(quote! {
|
|
#resource_name => Some(Self::#const_ident),
|
|
});
|
|
type_to_name.extend(quote! {
|
|
Self::#const_ident => #resource_name,
|
|
});
|
|
}
|
|
quote! {
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub enum EffectType {
|
|
#variants
|
|
}
|
|
|
|
impl EffectType {
|
|
#[doc = r" Try to parse an `EffectType` from a resource location string."]
|
|
pub fn from_name(name: &str) -> Option<Self> {
|
|
match name {
|
|
#type_from_name
|
|
_ => None
|
|
}
|
|
}
|
|
|
|
pub const fn to_name(&self) -> &'static str {
|
|
match self {
|
|
#type_to_name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|