Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- src/encoder.rs +4 -4
- src/http.rs +1 -1
- src/nbt.rs +8 -2
src/encoder.rs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
//! Кодирование в текст из ячеек по 28 символов, раскладка по частям, словари.
|
| 2 |
//!
|
| 3 |
-
//! Ячейка позиции: `{
|
| 4 |
//! Ячейка-заголовок: `KKKKKKKKNNNNNNNNLLLLLLLL0000` — три поля по 8 цифр и 4 нуля добивки:
|
| 5 |
//! K — индекс блока в списке блоков,
|
| 6 |
//! N — номер NBT (элемент списка NBT с индексом N-1, 0 — нет NBT),
|
|
@@ -474,14 +474,14 @@ mod tests {
|
|
| 474 |
let mut b = Vec::new();
|
| 475 |
push_position(&mut b, 1, -1, 9999).unwrap();
|
| 476 |
assert_eq!(b.len(), CELL_LEN);
|
| 477 |
-
assert_eq!(String::from_utf8(b).unwrap(), r#"{
|
| 478 |
}
|
| 479 |
|
| 480 |
#[test]
|
| 481 |
fn position_cell_zero_and_min() {
|
| 482 |
let mut b = Vec::new();
|
| 483 |
push_position(&mut b, 0, -999, 0).unwrap();
|
| 484 |
-
assert_eq!(String::from_utf8(b).unwrap(), r#"{
|
| 485 |
}
|
| 486 |
|
| 487 |
#[test]
|
|
@@ -538,7 +538,7 @@ mod tests {
|
|
| 538 |
"00000000",
|
| 539 |
"00000001",
|
| 540 |
"0000",
|
| 541 |
-
r#"{
|
| 542 |
]
|
| 543 |
.concat()
|
| 544 |
);
|
|
|
|
| 1 |
//! Кодирование в текст из ячеек по 28 символов, раскладка по частям, словари.
|
| 2 |
//!
|
| 3 |
+
//! Ячейка позиции: `{'x':0000,'y':0000,'z':0000}`
|
| 4 |
//! Ячейка-заголовок: `KKKKKKKKNNNNNNNNLLLLLLLL0000` — три поля по 8 цифр и 4 нуля добивки:
|
| 5 |
//! K — индекс блока в списке блоков,
|
| 6 |
//! N — номер NBT (элемент списка NBT с индексом N-1, 0 — нет NBT),
|
|
|
|
| 474 |
let mut b = Vec::new();
|
| 475 |
push_position(&mut b, 1, -1, 9999).unwrap();
|
| 476 |
assert_eq!(b.len(), CELL_LEN);
|
| 477 |
+
assert_eq!(String::from_utf8(b).unwrap(), r#"{'x':0001,'y':-001,'z':9999}"#);
|
| 478 |
}
|
| 479 |
|
| 480 |
#[test]
|
| 481 |
fn position_cell_zero_and_min() {
|
| 482 |
let mut b = Vec::new();
|
| 483 |
push_position(&mut b, 0, -999, 0).unwrap();
|
| 484 |
+
assert_eq!(String::from_utf8(b).unwrap(), r#"{'x':0000,'y':-999,'z':0000}"#);
|
| 485 |
}
|
| 486 |
|
| 487 |
#[test]
|
|
|
|
| 538 |
"00000000",
|
| 539 |
"00000001",
|
| 540 |
"0000",
|
| 541 |
+
r#"{'x':0000,'y':0000,'z':0000}"#,
|
| 542 |
]
|
| 543 |
.concat()
|
| 544 |
);
|
src/http.rs
CHANGED
|
@@ -328,7 +328,7 @@ mod tests {
|
|
| 328 |
}
|
| 329 |
|
| 330 |
fn pos(x: &str, y: &str, z: &str) -> String {
|
| 331 |
-
format!(r#"{{
|
| 332 |
}
|
| 333 |
|
| 334 |
/// chest с NBT в (1,1,1); dirt в (5,5,5); stone в (0,0,0) и (-1,2,3).
|
|
|
|
| 328 |
}
|
| 329 |
|
| 330 |
fn pos(x: &str, y: &str, z: &str) -> String {
|
| 331 |
+
format!(r#"{{'x':{x},'y':{y},'z':{z}}}"#)
|
| 332 |
}
|
| 333 |
|
| 334 |
/// chest с NBT в (1,1,1); dirt в (5,5,5); stone в (0,0,0) и (-1,2,3).
|
src/nbt.rs
CHANGED
|
@@ -379,7 +379,7 @@ pub fn compound_snbt(map: &BTreeMap<String, Tag<'_>>, skip: &[&str]) -> String {
|
|
| 379 |
}
|
| 380 |
|
| 381 |
/// NBT compound как JSON-словарь `{ключ: текст}`: значение — обычный текст для строк, SNBT-текст для остального
|
| 382 |
-
/// (числа, списки, вложенные compound; экранирует serde_json). Ключи из `skip` пропускаются, порядок — по алфавиту.
|
| 383 |
pub fn compound_dict_json(map: &BTreeMap<String, Tag<'_>>, skip: &[&str]) -> String {
|
| 384 |
let mut obj = serde_json::Map::new();
|
| 385 |
for (k, v) in map {
|
|
@@ -391,6 +391,10 @@ pub fn compound_dict_json(map: &BTreeMap<String, Tag<'_>>, skip: &[&str]) -> Str
|
|
| 391 |
_ => {
|
| 392 |
let mut t = String::new();
|
| 393 |
write_snbt(v, &mut t);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
t
|
| 395 |
}
|
| 396 |
};
|
|
@@ -821,7 +825,7 @@ mod tests {
|
|
| 821 |
let data = litematic(|o| region(o, "r", [-5, 10, -1], [1, 1, 1], &air_stone(), &pack(&[1], 2)));
|
| 822 |
let g = parse(&data, 10).unwrap();
|
| 823 |
let cell = String::from_utf8(g[&key("stone")].clone()).unwrap();
|
| 824 |
-
assert_eq!(cell, r#"{
|
| 825 |
}
|
| 826 |
|
| 827 |
#[test]
|
|
@@ -1060,6 +1064,8 @@ mod tests {
|
|
| 1060 |
m.insert("id".into(), Tag::String("minecraft:chest".into()));
|
| 1061 |
m.insert("x".into(), Tag::Int(1));
|
| 1062 |
m.insert("Lock".into(), Tag::String("a \"b\"".into()));
|
|
|
|
|
|
|
| 1063 |
m.insert("Items".into(), Tag::List(vec![Tag::Compound(inner)]));
|
| 1064 |
let v: serde_json::Value =
|
| 1065 |
serde_json::from_str(&compound_dict_json(&m, &["x", "id"])).unwrap();
|
|
|
|
| 379 |
}
|
| 380 |
|
| 381 |
/// NBT compound как JSON-словарь `{ключ: текст}`: значение — обычный текст для строк, SNBT-текст для остального
|
| 382 |
+
/// (числа, списки, вложенные compound; экранирует serde_json). Ключи из `skip` и пустые теги (`{}`, `[]`) пропускаются, порядок — по алфавиту.
|
| 383 |
pub fn compound_dict_json(map: &BTreeMap<String, Tag<'_>>, skip: &[&str]) -> String {
|
| 384 |
let mut obj = serde_json::Map::new();
|
| 385 |
for (k, v) in map {
|
|
|
|
| 391 |
_ => {
|
| 392 |
let mut t = String::new();
|
| 393 |
write_snbt(v, &mut t);
|
| 394 |
+
// пустые теги (`{}`, `[]`) не храним
|
| 395 |
+
if t == "{}" || t == "[]" {
|
| 396 |
+
continue;
|
| 397 |
+
}
|
| 398 |
t
|
| 399 |
}
|
| 400 |
};
|
|
|
|
| 825 |
let data = litematic(|o| region(o, "r", [-5, 10, -1], [1, 1, 1], &air_stone(), &pack(&[1], 2)));
|
| 826 |
let g = parse(&data, 10).unwrap();
|
| 827 |
let cell = String::from_utf8(g[&key("stone")].clone()).unwrap();
|
| 828 |
+
assert_eq!(cell, r#"{'x':-005,'y':0010,'z':-001}"#);
|
| 829 |
}
|
| 830 |
|
| 831 |
#[test]
|
|
|
|
| 1064 |
m.insert("id".into(), Tag::String("minecraft:chest".into()));
|
| 1065 |
m.insert("x".into(), Tag::Int(1));
|
| 1066 |
m.insert("Lock".into(), Tag::String("a \"b\"".into()));
|
| 1067 |
+
m.insert("components".into(), Tag::Compound(BTreeMap::new()));
|
| 1068 |
+
m.insert("Empty".into(), Tag::List(vec![]));
|
| 1069 |
m.insert("Items".into(), Tag::List(vec![Tag::Compound(inner)]));
|
| 1070 |
let v: serde_json::Value =
|
| 1071 |
serde_json::from_str(&compound_dict_json(&m, &["x", "id"])).unwrap();
|