Add translation keys to block kind

This commit is contained in:
Ryan 2022-08-06 16:50:50 -07:00
parent 9c67978e06
commit cd110c3cbb

View file

@ -64,6 +64,17 @@ pub fn build() -> anyhow::Result<TokenStream> {
let max_state_id = blocks.iter().map(|b| b.max_state_id()).max().unwrap();
let kind_to_translation_key_arms = blocks
.iter()
.map(|b| {
let kind = ident(b.name.to_pascal_case());
let translation_key = &b.translation_key;
quote! {
Self::#kind => #translation_key,
}
})
.collect::<TokenStream>();
let state_to_kind_arms = blocks
.iter()
.map(|b| {
@ -551,6 +562,12 @@ pub fn build() -> anyhow::Result<TokenStream> {
}
}
pub const fn translation_key(self) -> &'static str {
match self {
#kind_to_translation_key_arms
}
}
/// An array of all block kinds.
pub const ALL: [Self; #block_kind_count] = [#(Self::#block_kind_variants,)*];
}