diff options
| author | mat <github@matdoes.dev> | 2021-12-08 00:41:42 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-08 00:41:42 -0600 |
| commit | c16d55ccddd741057bf532bd946b2854dc208c65 (patch) | |
| tree | e6ae8af47e1931ef98ea55913831197b8e65a7ee /minecraft-chat/src/component.rs | |
| parent | 4a44c58444c901d939a8594669c819ab2bfbac13 (diff) | |
| download | azalea-drasl-c16d55ccddd741057bf532bd946b2854dc208c65.tar.xz | |
start adding minecraft-chat
Diffstat (limited to 'minecraft-chat/src/component.rs')
| -rw-r--r-- | minecraft-chat/src/component.rs | 38 |
1 files changed, 38 insertions, 0 deletions
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 {} + } +} |
