aboutsummaryrefslogtreecommitdiff
path: root/minecraft-chat/src
diff options
context:
space:
mode:
Diffstat (limited to 'minecraft-chat/src')
-rw-r--r--minecraft-chat/src/base_component.rs6
-rw-r--r--minecraft-chat/src/component.rs38
-rw-r--r--minecraft-chat/src/events.rs26
-rw-r--r--minecraft-chat/src/lib.rs8
-rw-r--r--minecraft-chat/src/mutable_component.rs1
-rw-r--r--minecraft-chat/src/style.rs98
-rw-r--r--minecraft-chat/src/text_component.rs17
-rw-r--r--minecraft-chat/src/translatable_component.rs10
8 files changed, 204 insertions, 0 deletions
diff --git a/minecraft-chat/src/base_component.rs b/minecraft-chat/src/base_component.rs
new file mode 100644
index 00000000..2ed5646d
--- /dev/null
+++ b/minecraft-chat/src/base_component.rs
@@ -0,0 +1,6 @@
+use crate::component::Component;
+
+pub trait BaseComponent {
+ const siblings: Vec<Component>;
+ // style:
+}
diff --git a/minecraft-chat/src/component.rs b/minecraft-chat/src/component.rs
new file mode 100644
index 00000000..7955eeda
--- /dev/null
+++ b/minecraft-chat/src/component.rs
@@ -0,0 +1,38 @@
+use serde_json;
+
+use crate::{
+ base_component::BaseComponent, text_component::TextComponent,
+ translatable_component::TranslatableComponent,
+};
+
+pub struct Component {}
+
+// public static class Serializer
+pub impl Component {
+ pub fn new(json: serde_json::Value) -> Self {
+ let component: BaseComponent;
+ // if it's primitive, make it a text component
+ if !json.is_array() && !json.is_object() {
+ return TextComponent::new(json.as_str().unwrap());
+ }
+
+ // if it's an object, do things with { text } and stuff
+ if json.is_object() {
+ // if it has text,
+ if json.get("text").is_some() {
+ let text = json.get("text").unwrap().to_string();
+ }
+ } else if json.get("translate").is_some() {
+ let translate = json.get("translate").unwrap().to_string();
+ } else if json.get("with").is_some() {
+ let with = json.get("with").unwrap().as_array().unwrap();
+ let mut with_array = Vec::with_capacity(with.len());
+ for i in 0..with.len() {
+ with_array.push(Component::new(with[i].clone()).deserialize(with[i].clone()));
+ }
+ let mut translatable_component = TranslatableComponent::new(translate, with_array);
+ }
+
+ Component {}
+ }
+}
diff --git a/minecraft-chat/src/events.rs b/minecraft-chat/src/events.rs
new file mode 100644
index 00000000..a547169e
--- /dev/null
+++ b/minecraft-chat/src/events.rs
@@ -0,0 +1,26 @@
+enum ClickAction {
+ OPEN_URL = Action::new("open_url", true),
+ OPEN_FILE = Action::new("open_file", false),
+ RUN_COMMAND = Action::new("run_command", true),
+ SUGGEST_COMMAND = Action::new("suggest_command", true),
+ CHANGE_PAGE = Action::new("change_page", true),
+ COPY_TO_CLIPBOARD = Action::new("copy_to_clipboard", true),
+}
+
+struct ClickAction {
+ pub name: String,
+ pub allow_from_server: bool,
+}
+
+impl ClickAction {
+ fn new(name: &str, allow_from_server: bool) -> Self {
+ Self {
+ name: name.to_string(),
+ allow_from_server,
+ }
+ }
+}
+
+struct ClickEvent {
+ action: ClickAction,
+}
diff --git a/minecraft-chat/src/lib.rs b/minecraft-chat/src/lib.rs
index 31e1bb20..cc887f66 100644
--- a/minecraft-chat/src/lib.rs
+++ b/minecraft-chat/src/lib.rs
@@ -1,3 +1,11 @@
+//! Things for working with Minecraft chat messages.
+
+pub mod base_component;
+pub mod component;
+pub mod mutable_component;
+pub mod text_component;
+pub mod translatable_component;
+
#[cfg(test)]
mod tests {
#[test]
diff --git a/minecraft-chat/src/mutable_component.rs b/minecraft-chat/src/mutable_component.rs
new file mode 100644
index 00000000..4fd3124d
--- /dev/null
+++ b/minecraft-chat/src/mutable_component.rs
@@ -0,0 +1 @@
+pub struct MutableComponent {}
diff --git a/minecraft-chat/src/style.rs b/minecraft-chat/src/style.rs
new file mode 100644
index 00000000..63422305
--- /dev/null
+++ b/minecraft-chat/src/style.rs
@@ -0,0 +1,98 @@
+struct TextColor {
+ value: u32,
+ name: Option<String>,
+}
+
+const PREFIX_CODE: char = '\u{00a7}';
+
+struct ChatFormatting {
+ name: String,
+ code: char,
+ is_format: bool,
+ id: i32,
+ color: Option<u32>,
+}
+
+impl ChatFormatting {
+ fn new(name: &str, code: char, is_format: bool, id: i32, color: Option<u32>) -> ChatFormatting {
+ ChatFormatting {
+ name: name.to_string(),
+ code,
+ is_format,
+ id,
+ color,
+ }
+ }
+}
+
+enum ChatFormatting {
+ BLACK = ChatFormatting::new("BLACK", '0', false, 0, Some(0)),
+ DARK_BLUE = ChatFormatting::new("DARK_BLUE", '1', false, 1, Some(170)),
+ DARK_GREEN = ChatFormatting::new("DARK_GREEN", '2', false, 2, Some(43520)),
+ DARK_AQUA = ChatFormatting::new("DARK_AQUA", '3', false, 3, Some(43690)),
+ DARK_RED = ChatFormatting::new("DARK_RED", '4', false, 4, Some(1114112)),
+ DARK_PURPLE = ChatFormatting::new("DARK_PURPLE", '5', false, 5, Some(11141290)),
+ GOLD = ChatFormatting::new("GOLD", '6', false, 6, Some(16755200)),
+ GRAY = ChatFormatting::new("GRAY", '7', false, 7, Some(11184810)),
+ DARK_GRAY = ChatFormatting::new("DARK_GRAY", '8', false, 8, Some(5592405)),
+ BLUE = ChatFormatting::new("BLUE", '9', false, 9, Some(5592575)),
+ GREEN = ChatFormatting::new("GREEN", 'a', false, 10, Some(5635925)),
+ AQUA = ChatFormatting::new("AQUA", 'b', false, 11, Some(5636095)),
+ RED = ChatFormatting::new("RED", 'c', false, 12, Some(16733525)),
+ LIGHT_PURPLE = ChatFormatting::new("LIGHT_PURPLE", 'd', false, 13, Some(16733695)),
+ YELLOW = ChatFormatting::new("YELLOW", 'e', false, 14, Some(16777045)),
+ WHITE = ChatFormatting::new("WHITE", 'f', false, 15, Some(16777215)),
+ OBFUSCATED = ChatFormatting::new("OBFUSCATED", 'k', true, -1, None),
+ BOLD = ChatFormatting::new("BOLD", 'l', true, -1, None),
+ STRIKETHROUGH = ChatFormatting::new("STRIKETHROUGH", 'm', true, -1, None),
+ UNDERLINE = ChatFormatting::new("UNDERLINE", 'n', true, -1, None),
+ ITALIC = ChatFormatting::new("ITALIC", 'o', true, -1, None),
+ RESET = ChatFormatting::new("RESET", 'r', -1, -1, None),
+}
+
+impl TextColor {
+ fn new(value: u32, name: Option<String>) -> Self {
+ Self { value, name }
+ }
+
+ fn format(&self) -> String {
+ format!("#{:06X}", self.value)
+ }
+
+ fn to_string(&self) -> String {
+ if let Some(name) = &self.name {
+ name.clone()
+ } else {
+ self.format()
+ }
+ }
+}
+
+struct Style {
+ // @Nullable
+ // final TextColor color;
+ // @Nullable
+ // final Boolean bold;
+ // @Nullable
+ // final Boolean italic;
+ // @Nullable
+ // final Boolean underlined;
+ // @Nullable
+ // final Boolean strikethrough;
+ // @Nullable
+ // final Boolean obfuscated;
+ // @Nullable
+ // final ClickEvent clickEvent;
+ // @Nullable
+ // final HoverEvent hoverEvent;
+ // @Nullable
+ // final String insertion;
+ // @Nullable
+ // final ResourceLocation font;
+ color: TextColor,
+ bold: bool,
+ italic: bool,
+ underlined: bool,
+ strikethrough: bool,
+ obfuscated: bool,
+}
diff --git a/minecraft-chat/src/text_component.rs b/minecraft-chat/src/text_component.rs
new file mode 100644
index 00000000..381befbb
--- /dev/null
+++ b/minecraft-chat/src/text_component.rs
@@ -0,0 +1,17 @@
+use crate::base_component::BaseComponent;
+
+pub struct TextComponent {
+ pub text: String,
+}
+
+impl TextComponent {
+ pub fn new(text: &str) -> TextComponent {
+ TextComponent {
+ text: text.to_string(),
+ }
+ }
+
+ pub fn to_string(&self) -> String {
+ self.text.clone()
+ }
+}
diff --git a/minecraft-chat/src/translatable_component.rs b/minecraft-chat/src/translatable_component.rs
new file mode 100644
index 00000000..e9099e55
--- /dev/null
+++ b/minecraft-chat/src/translatable_component.rs
@@ -0,0 +1,10 @@
+pub struct TranslatableComponent {
+ pub key: String,
+ pub args: Vec<String>,
+}
+
+impl TranslatableComponent {
+ pub fn new(key: String, args: Vec<String>) -> Self {
+ Self { key, args }
+ }
+}