Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- src/nbt.rs +3 -1
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 {
|
|
@@ -387,6 +387,7 @@ pub fn compound_dict_json(map: &BTreeMap<String, Tag<'_>>, skip: &[&str]) -> Str
|
|
| 387 |
continue;
|
| 388 |
}
|
| 389 |
let t = match v {
|
|
|
|
| 390 |
Tag::String(s) => s.clone(),
|
| 391 |
_ => {
|
| 392 |
let mut t = String::new();
|
|
@@ -1066,6 +1067,7 @@ mod tests {
|
|
| 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();
|
|
|
|
| 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 {
|
|
|
|
| 387 |
continue;
|
| 388 |
}
|
| 389 |
let t = match v {
|
| 390 |
+
Tag::String(s) if s.is_empty() => continue,
|
| 391 |
Tag::String(s) => s.clone(),
|
| 392 |
_ => {
|
| 393 |
let mut t = String::new();
|
|
|
|
| 1067 |
m.insert("Lock".into(), Tag::String("a \"b\"".into()));
|
| 1068 |
m.insert("components".into(), Tag::Compound(BTreeMap::new()));
|
| 1069 |
m.insert("Empty".into(), Tag::List(vec![]));
|
| 1070 |
+
m.insert("custom_name".into(), Tag::String(String::new()));
|
| 1071 |
m.insert("Items".into(), Tag::List(vec![Tag::Compound(inner)]));
|
| 1072 |
let v: serde_json::Value =
|
| 1073 |
serde_json::from_str(&compound_dict_json(&m, &["x", "id"])).unwrap();
|