mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
support legacy hex colors
This commit is contained in:
parent
4a1fdf0121
commit
8dff973d26
2 changed files with 36 additions and 4 deletions
|
@ -19,6 +19,7 @@ write down most non-trivial breaking changes.
|
||||||
- `FormattedText::to_html` and `FormattedText::to_custom_format`.
|
- `FormattedText::to_html` and `FormattedText::to_custom_format`.
|
||||||
- Add auto-reconnecting which is enabled by default.
|
- Add auto-reconnecting which is enabled by default.
|
||||||
- The pathfinder no longer avoids slabs, stairs, and dirt path blocks.
|
- The pathfinder no longer avoids slabs, stairs, and dirt path blocks.
|
||||||
|
- Non-standard legacy hex colors like `§#ff0000` are now supported in azalea-chat.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -37,3 +38,4 @@ write down most non-trivial breaking changes.
|
||||||
- Block shapes and some properties were using data from `1.20.3-pre4` due to using an old data generator (Pixlyzer), which has now been replaced with the data generator from [Pumpkin](https://github.com/Pumpkin-MC/Extractor).
|
- Block shapes and some properties were using data from `1.20.3-pre4` due to using an old data generator (Pixlyzer), which has now been replaced with the data generator from [Pumpkin](https://github.com/Pumpkin-MC/Extractor).
|
||||||
- No more chunk errors when the client joins another world with the same name but different height.
|
- No more chunk errors when the client joins another world with the same name but different height.
|
||||||
- Mining now cancels correctly and doesn't flag Grim.
|
- Mining now cancels correctly and doesn't flag Grim.
|
||||||
|
- azalea-chat now handles legacy color codes correctly when parsing from NBT.
|
||||||
|
|
|
@ -2,7 +2,11 @@ use std::fmt::Display;
|
||||||
|
|
||||||
use serde::{__private::ser::FlatMapSerializer, Serialize, Serializer, ser::SerializeMap};
|
use serde::{__private::ser::FlatMapSerializer, Serialize, Serializer, ser::SerializeMap};
|
||||||
|
|
||||||
use crate::{FormattedText, base_component::BaseComponent, style::ChatFormatting};
|
use crate::{
|
||||||
|
FormattedText,
|
||||||
|
base_component::BaseComponent,
|
||||||
|
style::{ChatFormatting, TextColor},
|
||||||
|
};
|
||||||
|
|
||||||
/// A component that contains text that's the same in all locales.
|
/// A component that contains text that's the same in all locales.
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
|
@ -69,13 +73,26 @@ pub fn legacy_color_code_to_text_component(legacy_color_code: &str) -> TextCompo
|
||||||
i += 1;
|
i += 1;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if let Some(formatter) = ChatFormatting::from_code(formatting_code) {
|
if formatting_code == '#' {
|
||||||
|
let color = legacy_color_code
|
||||||
|
.chars()
|
||||||
|
.skip(i + 1)
|
||||||
|
// 7 to include the #
|
||||||
|
.take(7)
|
||||||
|
.collect::<String>();
|
||||||
|
|
||||||
|
if components.is_empty() || !components.last().unwrap().text.is_empty() {
|
||||||
|
components.push(TextComponent::new("".to_string()));
|
||||||
|
}
|
||||||
|
let style = &mut components.last_mut().unwrap().base.style;
|
||||||
|
style.color = TextColor::parse(color);
|
||||||
|
|
||||||
|
i += 6;
|
||||||
|
} else if let Some(formatter) = ChatFormatting::from_code(formatting_code) {
|
||||||
if components.is_empty() || !components.last().unwrap().text.is_empty() {
|
if components.is_empty() || !components.last().unwrap().text.is_empty() {
|
||||||
components.push(TextComponent::new("".to_string()));
|
components.push(TextComponent::new("".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let style = &mut components.last_mut().unwrap().base.style;
|
let style = &mut components.last_mut().unwrap().base.style;
|
||||||
// if the formatter is a reset, then we need to reset the style to the default
|
|
||||||
style.apply_formatting(&formatter);
|
style.apply_formatting(&formatter);
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -213,4 +230,17 @@ mod tests {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_legacy_color_code_with_rgb() {
|
||||||
|
let component = TextComponent::new("§#Ff0000This is a test message".to_string()).get();
|
||||||
|
assert_eq!(
|
||||||
|
component.to_ansi(),
|
||||||
|
format!(
|
||||||
|
"{RED}This is a test message{RESET}",
|
||||||
|
RED = Ansi::rgb(0xff0000),
|
||||||
|
RESET = Ansi::RESET
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue