aboutsummaryrefslogtreecommitdiff
path: root/minecraft-chat/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-12-10 18:03:28 +0000
committermat <github@matdoes.dev>2021-12-10 18:03:28 +0000
commit0dce5f56ce8c4ec0eb3ee4eb6c09b20956242dfa (patch)
tree08c4d0de7f7a14238823f5666b8702329ac6cf52 /minecraft-chat/src
parentf9f7e3498e63d6553b67cefc3958c98f009b33a2 (diff)
downloadazalea-drasl-0dce5f56ce8c4ec0eb3ee4eb6c09b20956242dfa.tar.xz
add formatting to some motds
Diffstat (limited to 'minecraft-chat/src')
-rw-r--r--minecraft-chat/src/base_component.rs2
-rw-r--r--minecraft-chat/src/component.rs18
-rw-r--r--minecraft-chat/src/lib.rs1
-rw-r--r--minecraft-chat/src/splitter.rs7
-rw-r--r--minecraft-chat/src/text_component.rs2
-rw-r--r--minecraft-chat/src/translatable_component.rs4
6 files changed, 21 insertions, 13 deletions
diff --git a/minecraft-chat/src/base_component.rs b/minecraft-chat/src/base_component.rs
index 30e66173..40fb3909 100644
--- a/minecraft-chat/src/base_component.rs
+++ b/minecraft-chat/src/base_component.rs
@@ -1,6 +1,6 @@
use crate::{component::Component, style::Style};
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub struct BaseComponent {
// implements mutablecomponent
pub siblings: Vec<Component>,
diff --git a/minecraft-chat/src/component.rs b/minecraft-chat/src/component.rs
index 3135c3ba..958440ba 100644
--- a/minecraft-chat/src/component.rs
+++ b/minecraft-chat/src/component.rs
@@ -9,7 +9,7 @@ use crate::{
translatable_component::{StringOrComponent, TranslatableComponent},
};
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub enum Component {
TextComponent(TextComponent),
TranslatableComponent(TranslatableComponent),
@@ -23,9 +23,9 @@ impl Component {
// if it's primitive, make it a text component
if !json.is_array() && !json.is_object() {
- component = Component::TextComponent(TextComponent::new(
+ return Ok(Component::TextComponent(TextComponent::new(
json.as_str().unwrap_or("").to_string(),
- ));
+ )));
}
// if it's an object, do things with { text } and stuff
else if json.is_object() {
@@ -41,11 +41,11 @@ impl Component {
// if it's a string component with no styling and no siblings, just add a string to with_array
// otherwise add the component to the array
let c = Component::new(&with[i])?;
- if let Component::TextComponent(textComponent) = c {
- if textComponent.base.siblings.len() == 0
- && textComponent.base.style.is_empty()
+ if let Component::TextComponent(text_component) = c {
+ if text_component.base.siblings.len() == 0
+ && text_component.base.style.is_empty()
{
- with_array.push(StringOrComponent::String(textComponent.text));
+ with_array.push(StringOrComponent::String(text_component.text));
break;
}
}
@@ -141,7 +141,7 @@ impl Component {
return Ok(component);
}
// ok so it's not an object, if it's an array deserialize every item
- if !json.is_array() {
+ else if !json.is_array() {
return Err(format!("Don't know how to turn {} into a Component", json));
}
let json_array = json.as_array().unwrap();
@@ -211,7 +211,7 @@ impl Component {
styled_component.push_str(&sibling.to_ansi(Some(current_style)));
}
- if is_base_style {
+ if is_base_style && ansi_text.len() > 0 {
styled_component.push_str("\x1b[m");
}
diff --git a/minecraft-chat/src/lib.rs b/minecraft-chat/src/lib.rs
index b7035e13..5e9f1e3a 100644
--- a/minecraft-chat/src/lib.rs
+++ b/minecraft-chat/src/lib.rs
@@ -6,6 +6,7 @@ extern crate lazy_static;
pub mod base_component;
pub mod component;
+pub mod splitter;
pub mod style;
pub mod text_component;
pub mod translatable_component;
diff --git a/minecraft-chat/src/splitter.rs b/minecraft-chat/src/splitter.rs
new file mode 100644
index 00000000..812c3365
--- /dev/null
+++ b/minecraft-chat/src/splitter.rs
@@ -0,0 +1,7 @@
+//! Used for splitting text
+//! This includes wrapping long lines and applying legacy color formats.
+//! I'm not sure why applying legacy color formats is done here but that's the way Minecraft does it.
+
+use crate::component::Component;
+
+fn split_lines(component: Component) {}
diff --git a/minecraft-chat/src/text_component.rs b/minecraft-chat/src/text_component.rs
index e950ee00..bd47d671 100644
--- a/minecraft-chat/src/text_component.rs
+++ b/minecraft-chat/src/text_component.rs
@@ -1,6 +1,6 @@
use crate::{base_component::BaseComponent, component::Component};
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub struct TextComponent {
pub base: BaseComponent,
pub text: String,
diff --git a/minecraft-chat/src/translatable_component.rs b/minecraft-chat/src/translatable_component.rs
index 327c5e07..0709f7bf 100644
--- a/minecraft-chat/src/translatable_component.rs
+++ b/minecraft-chat/src/translatable_component.rs
@@ -1,12 +1,12 @@
use crate::{base_component::BaseComponent, component::Component};
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub enum StringOrComponent {
String(String),
Component(Component),
}
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub struct TranslatableComponent {
pub base: BaseComponent,
pub key: String,