tangled
alpha
login
or
join now
kokirigla.de
/
nara
0
fork
atom
online Minecraft written book viewer
0
fork
atom
overview
issues
pulls
pipelines
feat(text): finish component subtypes
kokirigla.de
3 weeks ago
abfac3f1
02ff7447
verified
This commit was signed with the committer's
known signature
.
kokirigla.de
SSH Key Fingerprint:
SHA256:BlSEtD3ZoKT3iKveofI8gba+lZ9CEolKRM1Pzy3pAwg=
+118
-3
3 changed files
expand all
collapse all
unified
split
justfile
nara_text
src
lib.rs
profile.rs
+3
-2
justfile
reviewed
···
14
14
15
15
lint:
16
16
@cargo clippy
17
17
-
17
17
+
18
18
alias b := build
19
19
20
20
build:
···
23
23
test:
24
24
@cargo test
25
25
26
26
-
ok: lint test
26
26
+
ok: lint test
27
27
+
@cargo check --workspace
+84
-1
nara_text/src/lib.rs
reviewed
···
1
1
use serde::{Deserialize, Serialize};
2
2
3
3
pub mod color;
4
4
+
pub mod profile;
4
5
5
6
#[derive(Debug, Serialize, Deserialize)]
6
7
#[serde(untagged)]
···
17
18
text: Option<TextComponent>,
18
19
#[serde(flatten)]
19
20
translation: Option<TranslationComponent>,
21
21
+
// DO NOT FLATTEN THE SCORE COMPONENT
22
22
+
score: Option<ScoreComponent>,
23
23
+
#[serde(flatten)]
24
24
+
selector: Option<SelectorComponent>,
25
25
+
#[serde(flatten)]
26
26
+
keybind: Option<KeybindComponent>,
27
27
+
#[serde(flatten)]
28
28
+
nbt: Option<NbtComponent>,
29
29
+
#[serde(flatten)]
30
30
+
object: Option<ObjectComponent>,
20
31
#[serde(flatten)]
21
32
formatting: ComponentFormatting,
22
33
#[serde(default, rename = "extra", skip_serializing_if = "Vec::is_empty")]
23
34
children: Vec<Component>,
24
35
}
25
36
37
37
+
// TODO(kokiriglade): make this a struct later
38
38
+
pub type Identifier = String;
39
39
+
26
40
#[serde_with::skip_serializing_none]
27
41
#[derive(Debug, Serialize, Deserialize)]
28
42
pub struct ComponentFormatting {
29
43
color: Option<color::Color>,
30
30
-
font: Option<String>, // todo(kokiriglade): an Identifier struct? or is that too over-enginereed?
44
44
+
font: Option<Identifier>,
31
45
bold: Option<bool>,
32
46
italic: Option<bool>,
33
47
underlined: Option<bool>,
···
48
62
#[serde(default, skip_serializing_if = "Vec::is_empty")]
49
63
with: Vec<Component>,
50
64
}
65
65
+
66
66
+
#[serde_with::skip_serializing_none]
67
67
+
#[derive(Debug, Serialize, Deserialize)]
68
68
+
pub struct ScoreComponent {
69
69
+
name: String,
70
70
+
objective: String,
71
71
+
}
72
72
+
73
73
+
#[serde_with::skip_serializing_none]
74
74
+
#[derive(Debug, Serialize, Deserialize)]
75
75
+
pub struct SelectorComponent {
76
76
+
selector: String,
77
77
+
separator: Option<Box<Component>>,
78
78
+
}
79
79
+
80
80
+
#[serde_with::skip_serializing_none]
81
81
+
#[derive(Debug, Serialize, Deserialize)]
82
82
+
pub struct KeybindComponent {
83
83
+
keybind: String,
84
84
+
}
85
85
+
86
86
+
#[derive(Debug, Serialize, Deserialize)]
87
87
+
#[serde(rename_all = "snake_case")]
88
88
+
pub enum NbtComponentSource {
89
89
+
Block,
90
90
+
Entity,
91
91
+
Storage,
92
92
+
}
93
93
+
94
94
+
#[serde_with::skip_serializing_none]
95
95
+
#[derive(Debug, Serialize, Deserialize)]
96
96
+
pub struct NbtComponent {
97
97
+
source: Option<NbtComponentSource>,
98
98
+
#[serde(rename = "nbt")]
99
99
+
path: String,
100
100
+
interpret: Option<bool>,
101
101
+
separator: Option<Box<Component>>,
102
102
+
entity: Option<String>,
103
103
+
block: Option<String>,
104
104
+
storage: Option<Identifier>,
105
105
+
}
106
106
+
107
107
+
#[derive(Debug, Serialize, Deserialize)]
108
108
+
#[serde(tag = "object", rename_all = "snake_case")]
109
109
+
pub enum ObjectComponent {
110
110
+
Atlas(AtlasObject),
111
111
+
Player(PlayerObject),
112
112
+
}
113
113
+
114
114
+
#[serde_with::skip_serializing_none]
115
115
+
#[derive(Debug, Serialize, Deserialize)]
116
116
+
pub struct AtlasObject {
117
117
+
atlas: Option<Identifier>,
118
118
+
sprite: Identifier,
119
119
+
}
120
120
+
121
121
+
#[derive(Debug, Serialize, Deserialize)]
122
122
+
#[serde(untagged)]
123
123
+
pub enum PlayerProfileOrName {
124
124
+
Profile(profile::PlayerProfile),
125
125
+
Name(String),
126
126
+
}
127
127
+
128
128
+
#[serde_with::skip_serializing_none]
129
129
+
#[derive(Debug, Serialize, Deserialize)]
130
130
+
pub struct PlayerObject {
131
131
+
player: PlayerProfileOrName,
132
132
+
hat: Option<bool>,
133
133
+
}
+31
nara_text/src/profile.rs
reviewed
···
1
1
+
use serde::{Deserialize, Serialize};
2
2
+
3
3
+
use crate::Identifier;
4
4
+
5
5
+
#[serde_with::skip_serializing_none]
6
6
+
#[derive(Debug, Serialize, Deserialize)]
7
7
+
pub struct PlayerProfile {
8
8
+
name: Option<String>,
9
9
+
id: Option<[i32; 4]>, // TODO(kokiriglade): use an actual UUID type
10
10
+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
11
11
+
properties: Vec<PlayerProfileProperty>,
12
12
+
texture: Option<Identifier>,
13
13
+
cape: Option<Identifier>,
14
14
+
elytra: Option<Identifier>,
15
15
+
model: Option<PlayerModel>,
16
16
+
}
17
17
+
18
18
+
#[serde_with::skip_serializing_none]
19
19
+
#[derive(Debug, Serialize, Deserialize)]
20
20
+
pub struct PlayerProfileProperty {
21
21
+
name: String,
22
22
+
value: String,
23
23
+
signature: Option<String>,
24
24
+
}
25
25
+
26
26
+
#[derive(Debug, Serialize, Deserialize)]
27
27
+
#[serde(rename_all = "snake_case")]
28
28
+
pub enum PlayerModel {
29
29
+
Slim,
30
30
+
Wide,
31
31
+
}