1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 18:24:05 +02:00

show server send messages as chat

This commit is contained in:
Robin Appelman 2024-03-29 16:26:43 +01:00
commit 217211f2fb
12 changed files with 785 additions and 45 deletions

View file

@ -247,39 +247,43 @@ pub struct SayText2Message {
pub text: MaybeUtf8String,
}
fn to_plain_text(text: &str) -> String {
// 1: normal, 2: old colors, 3: team, 4: location, 5 achievement, 6 custom
let mut text = text.replace(|c| c <= char::from(6), "");
// 7: 6-char hex
while let Some(pos) = text.chars().enumerate().find_map(|(index, c)| {
if c == char::from(7) {
Some(index)
} else {
None
}
}) {
text = text
.chars()
.take(pos)
.chain(text.chars().skip(pos + 7))
.collect();
}
// 9: 8-char hex
while let Some(pos) = text.chars().enumerate().find_map(|(index, c)| {
if c == char::from(9) {
Some(index)
} else {
None
}
}) {
text = text
.chars()
.take(pos)
.chain(text.chars().skip(pos + 9))
.collect();
}
text
}
impl SayText2Message {
pub fn plain_text(&self) -> String {
// 1: normal, 2: old colors, 3: team, 4: location, 5 achievement, 6 custom
let mut text = self.text.to_string().replace(|c| c <= char::from(6), "");
// 7: 6-char hex
while let Some(pos) = text.chars().enumerate().find_map(|(index, c)| {
if c == char::from(7) {
Some(index)
} else {
None
}
}) {
text = text
.chars()
.take(pos)
.chain(text.chars().skip(pos + 7))
.collect();
}
// 9: 8-char hex
while let Some(pos) = text.chars().enumerate().find_map(|(index, c)| {
if c == char::from(9) {
Some(index)
} else {
None
}
}) {
text = text
.chars()
.take(pos)
.chain(text.chars().skip(pos + 9))
.collect();
}
text
to_plain_text(self.text.as_ref())
}
}
@ -364,6 +368,12 @@ pub struct TextMessage {
pub substitute: [MaybeUtf8String; 4],
}
impl TextMessage {
pub fn plain_text(&self) -> String {
to_plain_text(self.text.as_ref())
}
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(BitRead, BitWrite, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ResetHudMessage {