From d3ed3123ca726b5eee5a0ead0b8731e578b047ae Mon Sep 17 00:00:00 2001 From: AviiNL Date: Fri, 28 Apr 2023 13:53:10 +0200 Subject: [PATCH] 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 --- crates/valence_block/build.rs | 66 +++++++++++--------- crates/valence_core/build/item.rs | 22 +++---- crates/valence_core/build/packet_id.rs | 2 +- crates/valence_core/build/sound.rs | 10 +-- crates/valence_core/build/translation_key.rs | 2 +- crates/valence_entity/build.rs | 33 +++++----- 6 files changed, 71 insertions(+), 64 deletions(-) diff --git a/crates/valence_block/build.rs b/crates/valence_block/build.rs index ddae3b7..14b4d1d 100644 --- a/crates/valence_block/build.rs +++ b/crates/valence_block/build.rs @@ -86,7 +86,7 @@ fn build() -> anyhow::Result { let kind_to_translation_key_arms = blocks .iter() .map(|b| { - let kind = ident(b.name.to_pascal_case()); + let kind = ident(b.name.replace('.', "_").to_pascal_case()); let translation_key = &b.translation_key; quote! { Self::#kind => #translation_key, @@ -97,7 +97,7 @@ fn build() -> anyhow::Result { let state_to_kind_arms = blocks .iter() .map(|b| { - let name = ident(b.name.to_pascal_case()); + let name = ident(b.name.replace('.', "_").to_pascal_case()); let mut token_stream = TokenStream::new(); let min_id = b.min_state_id(); @@ -191,13 +191,13 @@ fn build() -> anyhow::Result { .iter() .filter(|&b| !b.properties.is_empty()) .map(|b| { - let block_kind_name = ident(b.name.to_pascal_case()); + let block_kind_name = ident(b.name.replace('.', "_").to_pascal_case()); let arms = b .properties .iter() .map(|p| { - let prop_name = ident(p.name.to_pascal_case()); + let prop_name = ident(p.name.replace('.', "_").to_pascal_case()); let min_state_id = b.min_state_id(); let product: u16 = b .properties @@ -211,7 +211,7 @@ fn build() -> anyhow::Result { let arms = p.values.iter().enumerate().map(|(i, v)| { let value_idx = i as u16; - let value_name = ident(v.to_pascal_case()); + let value_name = ident(v.replace('.', "_").to_pascal_case()); quote! { #value_idx => Some(PropValue::#value_name), } @@ -239,13 +239,13 @@ fn build() -> anyhow::Result { .iter() .filter(|&b| !b.properties.is_empty()) .map(|b| { - let block_kind_name = ident(b.name.to_pascal_case()); + let block_kind_name = ident(b.name.replace('.', "_").to_pascal_case()); let arms = b .properties .iter() .map(|p| { - let prop_name = ident(p.name.to_pascal_case()); + let prop_name = ident(p.name.replace('.', "_").to_pascal_case()); let min_state_id = b.min_state_id(); let product: u16 = b .properties @@ -263,7 +263,7 @@ fn build() -> anyhow::Result { .enumerate() .map(|(i, v)| { let val_idx = i as u16; - let val_name = ident(v.to_pascal_case()); + let val_name = ident(v.replace('.', "_").to_pascal_case()); quote! { PropValue::#val_name => Self(self.0 - (self.0 - #min_state_id) / #product % #values_count * #product @@ -293,7 +293,7 @@ fn build() -> anyhow::Result { let default_block_states = blocks .iter() .map(|b| { - let name = ident(b.name.to_shouty_snake_case()); + let name = ident(b.name.replace('.', "_").to_shouty_snake_case()); let state = b.default_state_id; let doc = format!("The default block state for `{}`.", b.name); quote! { @@ -307,10 +307,11 @@ fn build() -> anyhow::Result { .iter() .filter(|b| b.wall_variant_id.is_some()) .map(|b| { - let block_name = ident(b.name.to_shouty_snake_case()); + let block_name = ident(b.name.replace('.', "_").to_shouty_snake_case()); let wall_block_name = ident( blocks[b.wall_variant_id.unwrap() as usize] .name + .replace('.', "_") .to_shouty_snake_case(), ); quote! { @@ -335,8 +336,8 @@ fn build() -> anyhow::Result { let kind_to_state_arms = blocks .iter() .map(|b| { - let kind = ident(b.name.to_pascal_case()); - let state = ident(b.name.to_shouty_snake_case()); + let kind = ident(b.name.replace('.', "_").to_pascal_case()); + let state = ident(b.name.replace('.', "_").to_shouty_snake_case()); quote! { BlockKind::#kind => BlockState::#state, } @@ -345,14 +346,14 @@ fn build() -> anyhow::Result { let block_kind_variants = blocks .iter() - .map(|b| ident(b.name.to_pascal_case())) + .map(|b| ident(b.name.replace('.', "_").to_pascal_case())) .collect::>(); let block_kind_from_str_arms = blocks .iter() .map(|b| { let name = &b.name; - let name_ident = ident(name.to_pascal_case()); + let name_ident = ident(name.replace('.', "_").to_pascal_case()); quote! { #name => Some(BlockKind::#name_ident), } @@ -363,7 +364,7 @@ fn build() -> anyhow::Result { .iter() .map(|b| { let name = &b.name; - let name_ident = ident(name.to_pascal_case()); + let name_ident = ident(name.replace('.', "_").to_pascal_case()); quote! { BlockKind::#name_ident => #name, } @@ -374,8 +375,11 @@ fn build() -> anyhow::Result { .iter() .filter(|&b| !b.properties.is_empty()) .map(|b| { - let name = ident(b.name.to_pascal_case()); - let prop_names = b.properties.iter().map(|p| ident(p.name.to_pascal_case())); + let name = ident(b.name.replace('.', "_").to_pascal_case()); + let prop_names = b + .properties + .iter() + .map(|p| ident(p.name.replace('.', "_").to_pascal_case())); quote! { Self::#name => &[#(PropName::#prop_names,)*], @@ -386,7 +390,7 @@ fn build() -> anyhow::Result { let block_kind_to_item_kind_arms = blocks .iter() .map(|block| { - let name = ident(block.name.to_pascal_case()); + let name = ident(block.name.replace('.', "_").to_pascal_case()); let item_id = block.item_id; quote! { @@ -399,7 +403,7 @@ fn build() -> anyhow::Result { .iter() .filter(|block| block.item_id != 0) .map(|block| { - let name = ident(block.name.to_pascal_case()); + let name = ident(block.name.replace('.', "_").to_pascal_case()); let item_id = block.item_id; quote! { @@ -411,7 +415,7 @@ fn build() -> anyhow::Result { let block_kind_from_raw_arms = blocks .iter() .map(|block| { - let name = ident(block.name.to_pascal_case()); + let name = ident(block.name.replace('.', "_").to_pascal_case()); let id = block.id; quote! { @@ -423,7 +427,7 @@ fn build() -> anyhow::Result { let block_entity_kind_variants = block_entity_types .iter() .map(|block_entity| { - let name = ident(block_entity.name.to_pascal_case()); + let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); let doc = format!( "The block entity type `{}` (ID {}).", block_entity.name, block_entity.id @@ -439,7 +443,7 @@ fn build() -> anyhow::Result { .iter() .map(|block_entity| { let id = block_entity.id; - let name = ident(block_entity.name.to_pascal_case()); + let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); quote! { #id => Some(Self::#name), @@ -451,7 +455,7 @@ fn build() -> anyhow::Result { .iter() .map(|block_entity| { let id = block_entity.id; - let name = ident(block_entity.name.to_pascal_case()); + let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); quote! { Self::#name => #id, @@ -462,7 +466,7 @@ fn build() -> anyhow::Result { let block_entity_kind_from_ident_arms = block_entity_types .iter() .map(|block_entity| { - let name = ident(block_entity.name.to_pascal_case()); + let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); let ident = &block_entity.ident; quote! { @@ -474,7 +478,7 @@ fn build() -> anyhow::Result { let block_entity_kind_to_ident_arms = block_entity_types .iter() .map(|block_entity| { - let name = ident(block_entity.name.to_pascal_case()); + let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); let ident = &block_entity.ident; quote! { @@ -492,13 +496,13 @@ fn build() -> anyhow::Result { let prop_name_variants = prop_names .iter() - .map(|&name| ident(name.to_pascal_case())) + .map(|&name| ident(name.replace('.', "_").to_pascal_case())) .collect::>(); let prop_name_from_str_arms = prop_names .iter() .map(|&name| { - let ident = ident(name.to_pascal_case()); + let ident = ident(name.replace('.', "_").to_pascal_case()); quote! { #name => Some(PropName::#ident), } @@ -508,7 +512,7 @@ fn build() -> anyhow::Result { let prop_name_to_str_arms = prop_names .iter() .map(|&name| { - let ident = ident(name.to_pascal_case()); + let ident = ident(name.replace('.', "_").to_pascal_case()); quote! { PropName::#ident => #name, } @@ -525,13 +529,13 @@ fn build() -> anyhow::Result { let prop_value_variants = prop_values .iter() - .map(|val| ident(val.to_pascal_case())) + .map(|val| ident(val.replace('.', "_").to_pascal_case())) .collect::>(); let prop_value_from_str_arms = prop_values .iter() .map(|val| { - let ident = ident(val.to_pascal_case()); + let ident = ident(val.replace('.', "_").to_pascal_case()); quote! { #val => Some(PropValue::#ident), } @@ -541,7 +545,7 @@ fn build() -> anyhow::Result { let prop_value_to_str_arms = prop_values .iter() .map(|val| { - let ident = ident(val.to_pascal_case()); + let ident = ident(val.replace('.', "_").to_pascal_case()); quote! { PropValue::#ident => #val, } diff --git a/crates/valence_core/build/item.rs b/crates/valence_core/build/item.rs index 84315f3..e8ebc15 100644 --- a/crates/valence_core/build/item.rs +++ b/crates/valence_core/build/item.rs @@ -36,7 +36,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| { let id = &item.id; - let name = ident(item.name.to_pascal_case()); + let name = ident(item.name.replace('.', "_").to_pascal_case()); quote! { #id => Some(Self::#name), @@ -48,7 +48,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| { let id = &item.id; - let name = ident(item.name.to_pascal_case()); + let name = ident(item.name.replace('.', "_").to_pascal_case()); quote! { Self::#name => #id, @@ -60,7 +60,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| { let str_name = &item.name; - let name = ident(str_name.to_pascal_case()); + let name = ident(str_name.replace('.', "_").to_pascal_case()); quote! { #str_name => Some(Self::#name), } @@ -71,7 +71,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| { let str_name = &item.name; - let name = ident(str_name.to_pascal_case()); + let name = ident(str_name.replace('.', "_").to_pascal_case()); quote! { Self::#name => #str_name, } @@ -81,7 +81,7 @@ pub fn build() -> anyhow::Result { let item_kind_to_translation_key_arms = items .iter() .map(|item| { - let name = ident(item.name.to_pascal_case()); + let name = ident(item.name.replace('.', "_").to_pascal_case()); let translation_key = &item.translation_key; quote! { Self::#name => #translation_key, @@ -91,13 +91,13 @@ pub fn build() -> anyhow::Result { let item_kind_variants = items .iter() - .map(|item| ident(item.name.to_pascal_case())) + .map(|item| ident(item.name.replace('.', "_").to_pascal_case())) .collect::>(); let item_kind_to_max_stack_arms = items .iter() .map(|item| { - let name = ident(item.name.to_pascal_case()); + let name = ident(item.name.replace('.', "_").to_pascal_case()); let max_stack = item.max_stack; quote! { @@ -110,7 +110,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| match &item.food { Some(food_component) => { - let name = ident(item.name.to_pascal_case()); + let name = ident(item.name.replace('.', "_").to_pascal_case()); let hunger = food_component.hunger; let saturation = food_component.saturation; let always_edible = food_component.always_edible; @@ -136,7 +136,7 @@ pub fn build() -> anyhow::Result { .iter() .filter(|item| item.max_durability != 0) .map(|item| { - let name = ident(item.name.to_pascal_case()); + let name = ident(item.name.replace('.', "_").to_pascal_case()); let max_durability = item.max_durability; quote! { @@ -149,7 +149,7 @@ pub fn build() -> anyhow::Result { .iter() .filter(|item| item.enchantability != 0) .map(|item| { - let name = ident(item.name.to_pascal_case()); + let name = ident(item.name.replace('.', "_").to_pascal_case()); let ench = item.enchantability; quote! { @@ -162,7 +162,7 @@ pub fn build() -> anyhow::Result { .iter() .filter(|item| item.fireproof) .map(|item| { - let name = ident(item.name.to_pascal_case()); + let name = ident(item.name.replace('.', "_").to_pascal_case()); quote! { Self::#name => true, diff --git a/crates/valence_core/build/packet_id.rs b/crates/valence_core/build/packet_id.rs index 31168c8..bf610a3 100644 --- a/crates/valence_core/build/packet_id.rs +++ b/crates/valence_core/build/packet_id.rs @@ -21,7 +21,7 @@ pub fn build() -> anyhow::Result { for packet in packets { let stripped_name = packet.name.strip_suffix("Packet").unwrap_or(&packet.name); - let name_ident = ident(stripped_name.to_pascal_case()); + let name_ident = ident(stripped_name.replace('.', "_").to_pascal_case()); let id = packet.id; let doc = format!("Side: {}\nState: {}", packet.side, packet.state); diff --git a/crates/valence_core/build/sound.rs b/crates/valence_core/build/sound.rs index ac30789..e4e260e 100644 --- a/crates/valence_core/build/sound.rs +++ b/crates/valence_core/build/sound.rs @@ -20,7 +20,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|sound| { let id = &sound.id; - let name = ident(sound.name.to_pascal_case()); + let name = ident(sound.name.replace('.', "_").to_pascal_case()); quote! { #id => Some(Self::#name), @@ -32,7 +32,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|sound| { let id = &sound.id; - let name = ident(sound.name.to_pascal_case()); + let name = ident(sound.name.replace('.', "_").to_pascal_case()); quote! { Self::#name => #id, @@ -44,7 +44,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|sound| { let str_name = &sound.name; - let name = ident(str_name.to_pascal_case()); + let name = ident(str_name.replace('.', "_").to_pascal_case()); quote! { #str_name => Some(Self::#name), } @@ -55,7 +55,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|sound| { let str_name = &sound.name; - let name = ident(str_name.to_pascal_case()); + let name = ident(str_name.replace('.', "_").to_pascal_case()); quote! { Self::#name => ident!(#str_name), } @@ -64,7 +64,7 @@ pub fn build() -> anyhow::Result { let sound_variants = sounds .iter() - .map(|sound| ident(sound.name.to_pascal_case())) + .map(|sound| ident(sound.name.replace('.', "_").to_pascal_case())) .collect::>(); Ok(quote! { diff --git a/crates/valence_core/build/translation_key.rs b/crates/valence_core/build/translation_key.rs index ee7c999..d0f4e36 100644 --- a/crates/valence_core/build/translation_key.rs +++ b/crates/valence_core/build/translation_key.rs @@ -24,7 +24,7 @@ pub fn build() -> anyhow::Result { let translation_key_consts = translations .iter() .map(|translation| { - let const_id = ident(translation.key.to_shouty_snake_case()); + let const_id = ident(translation.key.replace('.', "_").to_shouty_snake_case()); let key = &translation.key; let english_translation = &translation.english_translation; let doc = format!("\"{}\"", escape(english_translation)); diff --git a/crates/valence_entity/build.rs b/crates/valence_entity/build.rs index 1c21e85..cdbe12c 100644 --- a/crates/valence_entity/build.rs +++ b/crates/valence_entity/build.rs @@ -189,7 +189,7 @@ impl Value { quote!(None) } Value::Facing(f) => { - let variant = ident(f.to_pascal_case()); + let variant = ident(f.replace('.', "_").to_pascal_case()); quote!(valence_core::direction::Direction::#variant) } Value::OptionalUuid(uuid) => { @@ -208,7 +208,7 @@ impl Value { quote!(valence_nbt::Compound::default()) } Value::Particle(p) => { - let variant = ident(p.to_pascal_case()); + let variant = ident(p.replace('.', "_").to_pascal_case()); quote!(valence_core::packet::s2c::play::particle::Particle::#variant) } Value::VillagerData { @@ -216,8 +216,8 @@ impl Value { profession, level, } => { - let typ = ident(typ.to_pascal_case()); - let profession = ident(profession.to_pascal_case()); + let typ = ident(typ.replace('.', "_").to_pascal_case()); + let profession = ident(profession.replace('.', "_").to_pascal_case()); quote! { crate::VillagerData { kind: crate::VillagerKind::#typ, @@ -231,24 +231,24 @@ impl Value { quote!(None) } Value::EntityPose(p) => { - let variant = ident(p.to_pascal_case()); + let variant = ident(p.replace('.', "_").to_pascal_case()); quote!(crate::Pose::#variant) } Value::CatVariant(c) => { - let variant = ident(c.to_pascal_case()); + let variant = ident(c.replace('.', "_").to_pascal_case()); quote!(crate::CatKind::#variant) } Value::FrogVariant(f) => { - let variant = ident(f.to_pascal_case()); + let variant = ident(f.replace('.', "_").to_pascal_case()); quote!(crate::FrogKind::#variant) } Value::OptionalGlobalPos(_) => quote!(()), Value::PaintingVariant(p) => { - let variant = ident(p.to_pascal_case()); + let variant = ident(p.replace('.', "_").to_pascal_case()); quote!(crate::PaintingKind::#variant) } Value::SnifferState(s) => { - let state = ident(s.to_pascal_case()); + let state = ident(s.replace('.', "_").to_pascal_case()); quote!(crate::SnifferState::#state) } Value::Vector3f { x, y, z } => quote!(glam::f32::Vec3::new(#x, #y, #z)), @@ -297,7 +297,9 @@ fn build() -> anyhow::Result { for (entity_name, entity) in entities.clone() { let entity_name_ident = ident(&entity_name); - let stripped_shouty_entity_name = strip_entity_suffix(&entity_name).to_shouty_snake_case(); + let stripped_shouty_entity_name = strip_entity_suffix(&entity_name) + .replace('.', "_") + .to_shouty_snake_case(); let stripped_shouty_entity_name_ident = ident(&stripped_shouty_entity_name); let stripped_snake_entity_name = strip_entity_suffix(&entity_name).to_snake_case(); let stripped_snake_entity_name_ident = ident(&stripped_snake_entity_name); @@ -351,7 +353,8 @@ fn build() -> anyhow::Result { let snake_entity_name_ident = ident(entity_name.to_snake_case()); let stripped_snake_entity_name_ident = ident(stripped_entity_name.to_snake_case()); - let pascal_entity_name_ident = ident(entity_name.to_pascal_case()); + let pascal_entity_name_ident = + ident(entity_name.replace('.', "_").to_pascal_case()); bundle_fields.extend([quote! { pub #snake_entity_name_ident: super::#stripped_snake_entity_name_ident::#pascal_entity_name_ident, @@ -363,7 +366,7 @@ fn build() -> anyhow::Result { } MarkerOrField::Field { entity_name, field } => { let snake_field_name = field.name.to_snake_case(); - let pascal_field_name = field.name.to_pascal_case(); + let pascal_field_name = field.name.replace('.', "_").to_pascal_case(); let pascal_field_name_ident = ident(&pascal_field_name); let stripped_entity_name = strip_entity_suffix(entity_name); let stripped_snake_entity_name = stripped_entity_name.to_snake_case(); @@ -444,7 +447,7 @@ fn build() -> anyhow::Result { } for field in &entity.fields { - let pascal_field_name_ident = ident(field.name.to_pascal_case()); + let pascal_field_name_ident = ident(field.name.replace('.', "_").to_pascal_case()); let snake_field_name = field.name.to_snake_case(); let inner_type = field.default_value.field_type(); let default_expr = field.default_value.default_expr(); @@ -522,7 +525,7 @@ fn build() -> anyhow::Result { .entity_status .into_iter() .map(|(name, code)| { - let name = ident(name.to_pascal_case()); + let name = ident(name.replace('.', "_").to_pascal_case()); let code = code as isize; quote! { @@ -535,7 +538,7 @@ fn build() -> anyhow::Result { .entity_animation .into_iter() .map(|(name, code)| { - let name = ident(name.to_pascal_case()); + let name = ident(name.replace('.', "_").to_pascal_case()); let code = code as isize; quote! {