blob: 7955eeda95f14b162be76703ded2dcc8eff3ba3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 {}
}
}
|