Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new heck version in build scripts #466

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 15 additions & 18 deletions crates/valence_entity/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -208,16 +208,16 @@ 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 {
typ,
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,
Expand All @@ -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)),
Expand Down Expand Up @@ -296,9 +296,7 @@ fn build() -> anyhow::Result<TokenStream> {

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);
Expand Down Expand Up @@ -352,8 +350,7 @@ fn build() -> anyhow::Result<TokenStream> {
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,
Expand All @@ -365,7 +362,7 @@ fn build() -> anyhow::Result<TokenStream> {
}
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();
Expand Down Expand Up @@ -444,7 +441,7 @@ fn build() -> anyhow::Result<TokenStream> {
}

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();
Expand Down Expand Up @@ -523,7 +520,7 @@ fn build() -> anyhow::Result<TokenStream> {
.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! {
Expand All @@ -536,7 +533,7 @@ fn build() -> anyhow::Result<TokenStream> {
.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! {
Expand Down
66 changes: 31 additions & 35 deletions crates/valence_generated/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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,
Expand All @@ -93,7 +93,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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();
Expand Down Expand Up @@ -183,13 +183,13 @@ pub fn build() -> anyhow::Result<TokenStream> {
.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
Expand All @@ -203,7 +203,7 @@ pub fn build() -> anyhow::Result<TokenStream> {

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),
}
Expand Down Expand Up @@ -231,13 +231,13 @@ pub fn build() -> anyhow::Result<TokenStream> {
.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
Expand All @@ -255,7 +255,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
.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
Expand Down Expand Up @@ -285,7 +285,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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! {
Expand All @@ -299,11 +299,10 @@ pub fn build() -> anyhow::Result<TokenStream> {
.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! {
Expand All @@ -328,8 +327,8 @@ pub fn build() -> anyhow::Result<TokenStream> {
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,
}
Expand All @@ -338,14 +337,14 @@ pub fn build() -> anyhow::Result<TokenStream> {

let block_kind_variants = blocks
.iter()
.map(|b| ident(b.name.replace('.', "_").to_pascal_case()))
.map(|b| ident(b.name.to_pascal_case()))
.collect::<Vec<_>>();

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),
}
Expand All @@ -356,7 +355,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
.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,
}
Expand All @@ -367,11 +366,8 @@ pub fn build() -> anyhow::Result<TokenStream> {
.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,)*],
Expand All @@ -382,7 +378,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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! {
Expand All @@ -395,7 +391,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
.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! {
Expand All @@ -407,7 +403,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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! {
Expand All @@ -419,7 +415,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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
Expand All @@ -435,7 +431,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
.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),
Expand All @@ -447,7 +443,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
.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,
Expand All @@ -458,7 +454,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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! {
Expand All @@ -470,7 +466,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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! {
Expand All @@ -488,13 +484,13 @@ pub fn build() -> anyhow::Result<TokenStream> {

let prop_name_variants = prop_names
.iter()
.map(|&name| ident(name.replace('.', "_").to_pascal_case()))
.map(|&name| ident(name.to_pascal_case()))
.collect::<Vec<_>>();

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),
}
Expand All @@ -504,7 +500,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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,
}
Expand All @@ -521,13 +517,13 @@ pub fn build() -> anyhow::Result<TokenStream> {

let prop_value_variants = prop_values
.iter()
.map(|val| ident(val.replace('.', "_").to_pascal_case()))
.map(|val| ident(val.to_pascal_case()))
.collect::<Vec<_>>();

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),
}
Expand All @@ -537,7 +533,7 @@ pub fn build() -> anyhow::Result<TokenStream> {
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,
}
Expand Down
Loading
Loading