aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-chat/src')
-rw-r--r--azalea-chat/src/component.rs13
-rw-r--r--azalea-chat/src/style.rs2
-rw-r--r--azalea-chat/src/translatable_component.rs98
3 files changed, 19 insertions, 94 deletions
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs
index 87886e96..30b0ed9d 100644
--- a/azalea-chat/src/component.rs
+++ b/azalea-chat/src/component.rs
@@ -76,19 +76,22 @@ impl FormattedText {
/// Render all components into a single `String`, using your custom
/// closures to drive styling, text transformation, and final cleanup.
///
- /// # Type params
+ /// # Type parameters
+ ///
/// - `F`: `(running, component, default) -> (prefix, suffix)` for
/// per-component styling
/// - `S`: `&str -> String` for text tweaks (escaping, mapping, etc.)
/// - `C`: `&final_running_style -> String` for any trailing cleanup
///
- /// # Args
- /// - `style_formatter`: how to open/close each component’s style
- /// - `text_formatter`: how to turn raw text into output text
+ /// # Arguments
+ ///
+ /// - `style_formatter`: how to open/close each component's style
+ /// - `text_formatter`: how to turn raw text into output text
/// - `cleanup_formatter`: emit after all components (e.g. reset codes)
- /// - `default_style`: where to reset when a component’s `reset` is true
+ /// - `default_style`: where to reset when a component's `reset` is true
///
/// # Example
+ ///
/// ```rust
/// use azalea_chat::{FormattedText, DEFAULT_STYLE};
/// use serde::de::Deserialize;
diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs
index c43b7791..514944f1 100644
--- a/azalea-chat/src/style.rs
+++ b/azalea-chat/src/style.rs
@@ -497,7 +497,7 @@ impl Style {
}
/// Returns a new style that is a merge of self and other.
- /// For any field that `other` does not specify (is None), self’s value is
+ /// For any field that `other` does not specify (is None), self's value is
/// used.
pub fn merged_with(&self, other: &Style) -> Style {
Style {
diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs
index 13afe6b7..ae1d80bc 100644
--- a/azalea-chat/src/translatable_component.rs
+++ b/azalea-chat/src/translatable_component.rs
@@ -2,7 +2,10 @@ use std::fmt::{self, Display};
use serde::{Deserialize, Serialize};
#[cfg(feature = "simdnbt")]
-use simdnbt::ToNbtTag;
+use simdnbt::{
+ ToNbtTag,
+ owned::{NbtList, NbtTag},
+};
use crate::{FormattedText, base_component::BaseComponent, text_component::TextComponent};
@@ -49,93 +52,12 @@ pub struct TranslatableComponent {
}
#[cfg(feature = "simdnbt")]
-fn serialize_args_as_nbt(args: Vec<PrimitiveOrComponent>) -> simdnbt::owned::NbtList {
- let tags: Vec<simdnbt::owned::NbtTag> = args.into_iter().map(|arg| arg.to_nbt_tag()).collect();
-
- if let Some(first_element) = tags.first() {
- let tags = tags.clone();
- let homogenous_list = match first_element {
- simdnbt::owned::NbtTag::Byte(_) => tags
- .into_iter()
- .map(|tag| tag.into_byte())
- .collect::<Option<Vec<i8>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::Short(_) => tags
- .into_iter()
- .map(|tag| tag.into_short())
- .collect::<Option<Vec<i16>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::Int(_) => tags
- .into_iter()
- .map(|tag| tag.into_int())
- .collect::<Option<Vec<i32>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::Long(_) => tags
- .into_iter()
- .map(|tag| tag.into_long())
- .collect::<Option<Vec<i64>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::Float(_) => tags
- .into_iter()
- .map(|tag| tag.into_float())
- .collect::<Option<Vec<f32>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::Double(_) => tags
- .into_iter()
- .map(|tag| tag.into_double())
- .collect::<Option<Vec<f64>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::ByteArray(_) => tags
- .into_iter()
- .map(|tag| tag.into_byte_array())
- .collect::<Option<Vec<Vec<u8>>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::String(_) => tags
- .into_iter()
- .map(|tag| tag.into_string())
- .collect::<Option<Vec<simdnbt::Mutf8String>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::List(_) => tags
- .into_iter()
- .map(|tag| tag.into_list())
- .collect::<Option<Vec<simdnbt::owned::NbtList>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::Compound(_) => tags
- .into_iter()
- .map(|tag| tag.into_compound())
- .collect::<Option<Vec<simdnbt::owned::NbtCompound>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::IntArray(_) => tags
- .into_iter()
- .map(|tag| tag.into_int_array())
- .collect::<Option<Vec<Vec<i32>>>>()
- .map(simdnbt::owned::NbtList::from),
- simdnbt::owned::NbtTag::LongArray(_) => tags
- .into_iter()
- .map(|tag| tag.into_long_array())
- .collect::<Option<Vec<Vec<i64>>>>()
- .map(simdnbt::owned::NbtList::from),
- };
-
- if let Some(homogenous_list) = homogenous_list {
- return homogenous_list;
- }
- }
-
- let mut compounds = Vec::with_capacity(tags.len());
- for tag in tags {
- let compound = if let simdnbt::owned::NbtTag::Compound(compound) = tag {
- compound
- } else {
- let mut compound = simdnbt::owned::NbtCompound::new();
- compound.insert("", tag);
- compound
- };
-
- compounds.push(compound);
- }
-
- compounds.into()
+fn serialize_args_as_nbt(args: Vec<PrimitiveOrComponent>) -> NbtList {
+ let tags = args
+ .into_iter()
+ .map(|arg| arg.to_nbt_tag())
+ .collect::<Vec<NbtTag>>();
+ NbtList::from(tags)
}
#[cfg(feature = "simdnbt")]