From e83c2641dc13328c28e35be97d0ae5eab8c6201d Mon Sep 17 00:00:00 2001 From: IoaNNUwU <106328960+IoaNNUwU@users.noreply.github.com> Date: Thu, 17 Aug 2023 03:29:23 +0200 Subject: [PATCH] Use new heck version in build scripts (#466) # Objective - Update to heck 0.5.0-rc.1 - Revert the changes in #326 - Fixes #464 --- Cargo.toml | 2 +- crates/valence_entity/build.rs | 33 ++++++------- crates/valence_generated/build/block.rs | 66 ++++++++++++------------- crates/valence_generated/build/item.rs | 22 ++++----- crates/valence_generated/build/sound.rs | 10 ++-- crates/valence_lang/build.rs | 2 +- 6 files changed, 64 insertions(+), 71 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 695dc2503..68ed34eab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -127,7 +127,7 @@ flate2 = "1.0.24" flume = "0.10.14" fs_extra = "1.2.0" glam = "0.23.0" -heck = "0.4.0" +heck = "0.5.0-rc.1" hmac = "0.12.1" image = "0.24.6" indexmap = "1.9.3" diff --git a/crates/valence_entity/build.rs b/crates/valence_entity/build.rs index 3f0fb4e13..590f763db 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.replace('.', "_").to_pascal_case()); + let variant = ident(f.to_pascal_case()); quote!(valence_protocol::Direction::#variant) } Value::OptionalUuid(uuid) => { @@ -208,7 +208,7 @@ impl Value { quote!(valence_nbt::Compound::default()) } Value::Particle(p) => { - let variant = ident(p.replace('.', "_").to_pascal_case()); + let variant = ident(p.to_pascal_case()); quote!(valence_protocol::packets::play::particle_s2c::Particle::#variant) } Value::VillagerData { @@ -216,8 +216,8 @@ impl Value { profession, level, } => { - let typ = ident(typ.replace('.', "_").to_pascal_case()); - let profession = ident(profession.replace('.', "_").to_pascal_case()); + let typ = ident(typ.to_pascal_case()); + let profession = ident(profession.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.replace('.', "_").to_pascal_case()); + let variant = ident(p.to_pascal_case()); quote!(crate::Pose::#variant) } Value::CatVariant(c) => { - let variant = ident(c.replace('.', "_").to_pascal_case()); + let variant = ident(c.to_pascal_case()); quote!(crate::CatKind::#variant) } Value::FrogVariant(f) => { - let variant = ident(f.replace('.', "_").to_pascal_case()); + let variant = ident(f.to_pascal_case()); quote!(crate::FrogKind::#variant) } Value::OptionalGlobalPos(_) => quote!(()), Value::PaintingVariant(p) => { - let variant = ident(p.replace('.', "_").to_pascal_case()); + let variant = ident(p.to_pascal_case()); quote!(crate::PaintingKind::#variant) } Value::SnifferState(s) => { - let state = ident(s.replace('.', "_").to_pascal_case()); + let state = ident(s.to_pascal_case()); quote!(crate::SnifferState::#state) } Value::Vector3f { x, y, z } => quote!(valence_math::Vec3::new(#x, #y, #z)), @@ -296,9 +296,7 @@ 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) - .replace('.', "_") - .to_shouty_snake_case(); + let stripped_shouty_entity_name = strip_entity_suffix(&entity_name).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); @@ -352,8 +350,7 @@ 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.replace('.', "_").to_pascal_case()); + let pascal_entity_name_ident = ident(entity_name.to_pascal_case()); bundle_fields.extend([quote! { pub #snake_entity_name_ident: super::#stripped_snake_entity_name_ident::#pascal_entity_name_ident, @@ -365,7 +362,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.replace('.', "_").to_pascal_case(); + let pascal_field_name = field.name.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 +441,7 @@ fn build() -> anyhow::Result { } for field in &entity.fields { - let pascal_field_name_ident = ident(field.name.replace('.', "_").to_pascal_case()); + let pascal_field_name_ident = ident(field.name.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(); @@ -523,7 +520,7 @@ fn build() -> anyhow::Result { .entity_status .into_iter() .map(|(name, code)| { - let name = ident(name.replace('.', "_").to_pascal_case()); + let name = ident(name.to_pascal_case()); let code = code as isize; quote! { @@ -536,7 +533,7 @@ fn build() -> anyhow::Result { .entity_animation .into_iter() .map(|(name, code)| { - let name = ident(name.replace('.', "_").to_pascal_case()); + let name = ident(name.to_pascal_case()); let code = code as isize; quote! { diff --git a/crates/valence_generated/build/block.rs b/crates/valence_generated/build/block.rs index ec6658f8e..eddc9bf06 100644 --- a/crates/valence_generated/build/block.rs +++ b/crates/valence_generated/build/block.rs @@ -82,7 +82,7 @@ pub fn build() -> anyhow::Result { let kind_to_translation_key_arms = blocks .iter() .map(|b| { - let kind = ident(b.name.replace('.', "_").to_pascal_case()); + let kind = ident(b.name.to_pascal_case()); let translation_key = &b.translation_key; quote! { Self::#kind => #translation_key, @@ -93,7 +93,7 @@ pub fn build() -> anyhow::Result { let state_to_kind_arms = blocks .iter() .map(|b| { - let name = ident(b.name.replace('.', "_").to_pascal_case()); + let name = ident(b.name.to_pascal_case()); let mut token_stream = TokenStream::new(); let min_id = b.min_state_id(); @@ -183,13 +183,13 @@ pub fn build() -> anyhow::Result { .iter() .filter(|&b| !b.properties.is_empty()) .map(|b| { - let block_kind_name = ident(b.name.replace('.', "_").to_pascal_case()); + let block_kind_name = ident(b.name.to_pascal_case()); let arms = b .properties .iter() .map(|p| { - let prop_name = ident(p.name.replace('.', "_").to_pascal_case()); + let prop_name = ident(p.name.to_pascal_case()); let min_state_id = b.min_state_id(); let product: u16 = b .properties @@ -203,7 +203,7 @@ pub fn build() -> anyhow::Result { let arms = p.values.iter().enumerate().map(|(i, v)| { let value_idx = i as u16; - let value_name = ident(v.replace('.', "_").to_pascal_case()); + let value_name = ident(v.to_pascal_case()); quote! { #value_idx => Some(PropValue::#value_name), } @@ -231,13 +231,13 @@ pub fn build() -> anyhow::Result { .iter() .filter(|&b| !b.properties.is_empty()) .map(|b| { - let block_kind_name = ident(b.name.replace('.', "_").to_pascal_case()); + let block_kind_name = ident(b.name.to_pascal_case()); let arms = b .properties .iter() .map(|p| { - let prop_name = ident(p.name.replace('.', "_").to_pascal_case()); + let prop_name = ident(p.name.to_pascal_case()); let min_state_id = b.min_state_id(); let product: u16 = b .properties @@ -255,7 +255,7 @@ pub fn build() -> anyhow::Result { .enumerate() .map(|(i, v)| { let val_idx = i as u16; - let val_name = ident(v.replace('.', "_").to_pascal_case()); + let val_name = ident(v.to_pascal_case()); quote! { PropValue::#val_name => Self(self.0 - (self.0 - #min_state_id) / #product % #values_count * #product @@ -285,7 +285,7 @@ pub fn build() -> anyhow::Result { let default_block_states = blocks .iter() .map(|b| { - let name = ident(b.name.replace('.', "_").to_shouty_snake_case()); + let name = ident(b.name.to_shouty_snake_case()); let state = b.default_state_id; let doc = format!("The default block state for `{}`.", b.name); quote! { @@ -299,11 +299,10 @@ pub fn build() -> anyhow::Result { .iter() .filter(|b| b.wall_variant_id.is_some()) .map(|b| { - let block_name = ident(b.name.replace('.', "_").to_shouty_snake_case()); + let block_name = ident(b.name.to_shouty_snake_case()); let wall_block_name = ident( blocks[b.wall_variant_id.unwrap() as usize] .name - .replace('.', "_") .to_shouty_snake_case(), ); quote! { @@ -328,8 +327,8 @@ pub fn build() -> anyhow::Result { let kind_to_state_arms = blocks .iter() .map(|b| { - let kind = ident(b.name.replace('.', "_").to_pascal_case()); - let state = ident(b.name.replace('.', "_").to_shouty_snake_case()); + let kind = ident(b.name.to_pascal_case()); + let state = ident(b.name.to_shouty_snake_case()); quote! { BlockKind::#kind => BlockState::#state, } @@ -338,14 +337,14 @@ pub fn build() -> anyhow::Result { let block_kind_variants = blocks .iter() - .map(|b| ident(b.name.replace('.', "_").to_pascal_case())) + .map(|b| ident(b.name.to_pascal_case())) .collect::>(); let block_kind_from_str_arms = blocks .iter() .map(|b| { let name = &b.name; - let name_ident = ident(name.replace('.', "_").to_pascal_case()); + let name_ident = ident(name.to_pascal_case()); quote! { #name => Some(BlockKind::#name_ident), } @@ -356,7 +355,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|b| { let name = &b.name; - let name_ident = ident(name.replace('.', "_").to_pascal_case()); + let name_ident = ident(name.to_pascal_case()); quote! { BlockKind::#name_ident => #name, } @@ -367,11 +366,8 @@ pub fn build() -> anyhow::Result { .iter() .filter(|&b| !b.properties.is_empty()) .map(|b| { - let name = ident(b.name.replace('.', "_").to_pascal_case()); - let prop_names = b - .properties - .iter() - .map(|p| ident(p.name.replace('.', "_").to_pascal_case())); + let name = ident(b.name.to_pascal_case()); + let prop_names = b.properties.iter().map(|p| ident(p.name.to_pascal_case())); quote! { Self::#name => &[#(PropName::#prop_names,)*], @@ -382,7 +378,7 @@ pub fn build() -> anyhow::Result { let block_kind_to_item_kind_arms = blocks .iter() .map(|block| { - let name = ident(block.name.replace('.', "_").to_pascal_case()); + let name = ident(block.name.to_pascal_case()); let item_id = block.item_id; quote! { @@ -395,7 +391,7 @@ pub fn build() -> anyhow::Result { .iter() .filter(|block| block.item_id != 0) .map(|block| { - let name = ident(block.name.replace('.', "_").to_pascal_case()); + let name = ident(block.name.to_pascal_case()); let item_id = block.item_id; quote! { @@ -407,7 +403,7 @@ pub fn build() -> anyhow::Result { let block_kind_from_raw_arms = blocks .iter() .map(|block| { - let name = ident(block.name.replace('.', "_").to_pascal_case()); + let name = ident(block.name.to_pascal_case()); let id = block.id; quote! { @@ -419,7 +415,7 @@ pub fn build() -> anyhow::Result { let block_entity_kind_variants = block_entity_types .iter() .map(|block_entity| { - let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); + let name = ident(block_entity.name.to_pascal_case()); let doc = format!( "The block entity type `{}` (ID {}).", block_entity.name, block_entity.id @@ -435,7 +431,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|block_entity| { let id = block_entity.id; - let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); + let name = ident(block_entity.name.to_pascal_case()); quote! { #id => Some(Self::#name), @@ -447,7 +443,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|block_entity| { let id = block_entity.id; - let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); + let name = ident(block_entity.name.to_pascal_case()); quote! { Self::#name => #id, @@ -458,7 +454,7 @@ pub fn build() -> anyhow::Result { let block_entity_kind_from_ident_arms = block_entity_types .iter() .map(|block_entity| { - let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); + let name = ident(block_entity.name.to_pascal_case()); let ident = &block_entity.ident; quote! { @@ -470,7 +466,7 @@ pub fn build() -> anyhow::Result { let block_entity_kind_to_ident_arms = block_entity_types .iter() .map(|block_entity| { - let name = ident(block_entity.name.replace('.', "_").to_pascal_case()); + let name = ident(block_entity.name.to_pascal_case()); let ident = &block_entity.ident; quote! { @@ -488,13 +484,13 @@ pub fn build() -> anyhow::Result { let prop_name_variants = prop_names .iter() - .map(|&name| ident(name.replace('.', "_").to_pascal_case())) + .map(|&name| ident(name.to_pascal_case())) .collect::>(); let prop_name_from_str_arms = prop_names .iter() .map(|&name| { - let ident = ident(name.replace('.', "_").to_pascal_case()); + let ident = ident(name.to_pascal_case()); quote! { #name => Some(PropName::#ident), } @@ -504,7 +500,7 @@ pub fn build() -> anyhow::Result { let prop_name_to_str_arms = prop_names .iter() .map(|&name| { - let ident = ident(name.replace('.', "_").to_pascal_case()); + let ident = ident(name.to_pascal_case()); quote! { PropName::#ident => #name, } @@ -521,13 +517,13 @@ pub fn build() -> anyhow::Result { let prop_value_variants = prop_values .iter() - .map(|val| ident(val.replace('.', "_").to_pascal_case())) + .map(|val| ident(val.to_pascal_case())) .collect::>(); let prop_value_from_str_arms = prop_values .iter() .map(|val| { - let ident = ident(val.replace('.', "_").to_pascal_case()); + let ident = ident(val.to_pascal_case()); quote! { #val => Some(PropValue::#ident), } @@ -537,7 +533,7 @@ pub fn build() -> anyhow::Result { let prop_value_to_str_arms = prop_values .iter() .map(|val| { - let ident = ident(val.replace('.', "_").to_pascal_case()); + let ident = ident(val.to_pascal_case()); quote! { PropValue::#ident => #val, } diff --git a/crates/valence_generated/build/item.rs b/crates/valence_generated/build/item.rs index b2dad4710..dd5ae0c16 100644 --- a/crates/valence_generated/build/item.rs +++ b/crates/valence_generated/build/item.rs @@ -38,7 +38,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| { let id = &item.id; - let name = ident(item.name.replace('.', "_").to_pascal_case()); + let name = ident(item.name.to_pascal_case()); quote! { #id => Some(Self::#name), @@ -50,7 +50,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| { let id = &item.id; - let name = ident(item.name.replace('.', "_").to_pascal_case()); + let name = ident(item.name.to_pascal_case()); quote! { Self::#name => #id, @@ -62,7 +62,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| { let str_name = &item.name; - let name = ident(str_name.replace('.', "_").to_pascal_case()); + let name = ident(str_name.to_pascal_case()); quote! { #str_name => Some(Self::#name), } @@ -73,7 +73,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| { let str_name = &item.name; - let name = ident(str_name.replace('.', "_").to_pascal_case()); + let name = ident(str_name.to_pascal_case()); quote! { Self::#name => #str_name, } @@ -83,7 +83,7 @@ pub fn build() -> anyhow::Result { let item_kind_to_translation_key_arms = items .iter() .map(|item| { - let name = ident(item.name.replace('.', "_").to_pascal_case()); + let name = ident(item.name.to_pascal_case()); let translation_key = &item.translation_key; quote! { Self::#name => #translation_key, @@ -93,13 +93,13 @@ pub fn build() -> anyhow::Result { let item_kind_variants = items .iter() - .map(|item| ident(item.name.replace('.', "_").to_pascal_case())) + .map(|item| ident(item.name.to_pascal_case())) .collect::>(); let item_kind_to_max_stack_arms = items .iter() .map(|item| { - let name = ident(item.name.replace('.', "_").to_pascal_case()); + let name = ident(item.name.to_pascal_case()); let max_stack = item.max_stack; quote! { @@ -112,7 +112,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|item| match &item.food { Some(food_component) => { - let name = ident(item.name.replace('.', "_").to_pascal_case()); + let name = ident(item.name.to_pascal_case()); let hunger = food_component.hunger; let saturation = food_component.saturation; let always_edible = food_component.always_edible; @@ -138,7 +138,7 @@ pub fn build() -> anyhow::Result { .iter() .filter(|item| item.max_durability != 0) .map(|item| { - let name = ident(item.name.replace('.', "_").to_pascal_case()); + let name = ident(item.name.to_pascal_case()); let max_durability = item.max_durability; quote! { @@ -151,7 +151,7 @@ pub fn build() -> anyhow::Result { .iter() .filter(|item| item.enchantability != 0) .map(|item| { - let name = ident(item.name.replace('.', "_").to_pascal_case()); + let name = ident(item.name.to_pascal_case()); let ench = item.enchantability; quote! { @@ -164,7 +164,7 @@ pub fn build() -> anyhow::Result { .iter() .filter(|item| item.fireproof) .map(|item| { - let name = ident(item.name.replace('.', "_").to_pascal_case()); + let name = ident(item.name.to_pascal_case()); quote! { Self::#name => true, diff --git a/crates/valence_generated/build/sound.rs b/crates/valence_generated/build/sound.rs index 9e2b71835..ea48630ce 100644 --- a/crates/valence_generated/build/sound.rs +++ b/crates/valence_generated/build/sound.rs @@ -21,7 +21,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|sound| { let id = &sound.id; - let name = ident(sound.name.replace('.', "_").to_pascal_case()); + let name = ident(sound.name.to_pascal_case()); quote! { #id => Some(Self::#name), @@ -33,7 +33,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|sound| { let id = &sound.id; - let name = ident(sound.name.replace('.', "_").to_pascal_case()); + let name = ident(sound.name.to_pascal_case()); quote! { Self::#name => #id, @@ -48,7 +48,7 @@ pub fn build() -> anyhow::Result { let path_name = &sound.name; let ident_name = format!("minecraft:{}", &sound.name); - let name = ident(path_name.replace('.', "_").to_pascal_case()); + let name = ident(path_name.to_pascal_case()); quote! { #ident_name => Some(Self::#name), } @@ -59,7 +59,7 @@ pub fn build() -> anyhow::Result { .iter() .map(|sound| { let str_name = &sound.name; - let name = ident(str_name.replace('.', "_").to_pascal_case()); + let name = ident(str_name.to_pascal_case()); quote! { Self::#name => ident!(#str_name), } @@ -68,7 +68,7 @@ pub fn build() -> anyhow::Result { let sound_variants = sounds .iter() - .map(|sound| ident(sound.name.replace('.', "_").to_pascal_case())) + .map(|sound| ident(sound.name.to_pascal_case())) .collect::>(); Ok(quote! { diff --git a/crates/valence_lang/build.rs b/crates/valence_lang/build.rs index 697512521..c87311ff0 100644 --- a/crates/valence_lang/build.rs +++ b/crates/valence_lang/build.rs @@ -17,7 +17,7 @@ fn build() -> anyhow::Result { let translation_key_consts = translations .iter() .map(|translation| { - let const_id = ident(translation.key.replace('.', "_").to_shouty_snake_case()); + let const_id = ident(translation.key.to_shouty_snake_case()); let key = &translation.key; let english_translation = &translation.english_translation; let doc = format!("\"{}\"", escape(english_translation));