From cd110c3cbb67ee9bcd587deec13bafdce57078a4 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 6 Aug 2022 16:50:50 -0700 Subject: [PATCH] Add translation keys to block kind --- build/block.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/build/block.rs b/build/block.rs index f76c9eb..fa76a7c 100644 --- a/build/block.rs +++ b/build/block.rs @@ -64,6 +64,17 @@ pub fn build() -> anyhow::Result { 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::(); + let state_to_kind_arms = blocks .iter() .map(|b| { @@ -551,6 +562,12 @@ pub fn build() -> anyhow::Result { } } + 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,)*]; }