diff options
Diffstat (limited to 'azalea-chat/src/text_component.rs')
| -rwxr-xr-x | azalea-chat/src/text_component.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs index 44bcbcf1..42932d0e 100755 --- a/azalea-chat/src/text_component.rs +++ b/azalea-chat/src/text_component.rs @@ -1,4 +1,4 @@ -use crate::{base_component::BaseComponent, style::ChatFormatting, Component}; +use crate::{base_component::BaseComponent, style::ChatFormatting, FormattedText}; use serde::{ser::SerializeMap, Serialize, Serializer, __private::ser::FlatMapSerializer}; use std::fmt::Display; @@ -26,7 +26,7 @@ impl Serialize for TextComponent { const LEGACY_FORMATTING_CODE_SYMBOL: char = 'ยง'; -/// Convert a legacy color code string into a Component +/// Convert a legacy color code string into a FormattedText /// Technically in Minecraft this is done when displaying the text, but AFAIK /// it's the same as just doing it in TextComponent pub fn legacy_color_code_to_text_component(legacy_color_code: &str) -> TextComponent { @@ -41,12 +41,9 @@ pub fn legacy_color_code_to_text_component(legacy_color_code: &str) -> TextCompo while i < legacy_color_code.chars().count() { if legacy_color_code.chars().nth(i).unwrap() == LEGACY_FORMATTING_CODE_SYMBOL { let formatting_code = legacy_color_code.chars().nth(i + 1); - let formatting_code = match formatting_code { - Some(formatting_code) => formatting_code, - None => { - i += 1; - continue; - } + let Some(formatting_code) = formatting_code else { + i += 1; + continue; }; if let Some(formatter) = ChatFormatting::from_code(formatting_code) { if components.is_empty() || !components.last().unwrap().text.is_empty() { @@ -98,18 +95,18 @@ impl TextComponent { } } - fn get(self) -> Component { - Component::Text(self) + fn get(self) -> FormattedText { + FormattedText::Text(self) } } impl Display for TextComponent { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { // this contains the final string will all the ansi escape codes - for component in Component::Text(self.clone()).into_iter() { + for component in FormattedText::Text(self.clone()).into_iter() { let component_text = match &component { - Component::Text(c) => c.text.to_string(), - Component::Translatable(c) => c.read()?.to_string(), + FormattedText::Text(c) => c.text.to_string(), + FormattedText::Translatable(c) => c.read()?.to_string(), }; f.write_str(&component_text)?; |
