mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-04-12 00:05:07 +02:00
world: rename JSONText to TextValue
New Minecraft version do not store text as JSON anymore.
This commit is contained in:
parent
442009eb08
commit
ba6e4bae7f
4 changed files with 20 additions and 20 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::json_text::JSONText;
|
||||
use super::text_value::TextValue;
|
||||
|
||||
/// Element of the `palette` list of 1.18+ [block states](BlockStatesV1_18)
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -110,7 +110,7 @@ pub enum BiomesV0 {
|
|||
#[derive(Debug, Deserialize)]
|
||||
pub struct BlockEntitySignV1_20Text {
|
||||
/// Lines of sign text
|
||||
pub messages: Vec<JSONText>,
|
||||
pub messages: Vec<TextValue>,
|
||||
/// Default text color
|
||||
pub color: Option<String>,
|
||||
}
|
||||
|
@ -125,13 +125,13 @@ pub enum BlockEntitySign {
|
|||
#[serde(rename_all = "PascalCase")]
|
||||
V0 {
|
||||
/// Line 1 of the sign text
|
||||
text1: JSONText,
|
||||
text1: TextValue,
|
||||
/// Line 2 of the sign text
|
||||
text2: JSONText,
|
||||
text2: TextValue,
|
||||
/// Line 3 of the sign text
|
||||
text3: JSONText,
|
||||
text3: TextValue,
|
||||
/// Line 4 of the sign text
|
||||
text4: JSONText,
|
||||
text4: TextValue,
|
||||
/// Default text color
|
||||
color: Option<String>,
|
||||
},
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
pub mod block_entity;
|
||||
pub mod chunk;
|
||||
pub mod de;
|
||||
pub mod json_text;
|
||||
pub mod layer;
|
||||
pub mod section;
|
||||
pub mod sign;
|
||||
pub mod text_value;
|
||||
|
|
|
@ -8,7 +8,7 @@ use serde::Serialize;
|
|||
|
||||
use super::{
|
||||
de,
|
||||
json_text::{FormattedText, FormattedTextList, JSONText},
|
||||
text_value::{FormattedText, FormattedTextList, TextValue},
|
||||
};
|
||||
|
||||
/// Version-independent reference to (front or back) sign text
|
||||
|
@ -18,7 +18,7 @@ pub struct RawSignText<'a> {
|
|||
///
|
||||
/// A regular sign always has 4 lines of text. The back of pre-1.20
|
||||
/// signs is represented as a [SignText] without any `messages`.
|
||||
pub messages: Vec<&'a JSONText>,
|
||||
pub messages: Vec<&'a TextValue>,
|
||||
/// Sign color
|
||||
///
|
||||
/// Defaults to "black".
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! Newtype and helper methods for handling Minecraft Raw JSON Text
|
||||
//! Newtype and helper methods for handling Minecraft text values
|
||||
|
||||
use std::{collections::VecDeque, fmt::Display};
|
||||
|
||||
|
@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
/// A span of formatted text
|
||||
///
|
||||
/// A [JSONText] consists of a tree of [FormattedText] nodes (canonically
|
||||
/// A [TextValue] consists of a tree of [FormattedText] nodes (canonically
|
||||
/// represented as a [FormattedTextTree], but other kinds are possible with
|
||||
/// is handled by [DeserializedText].
|
||||
///
|
||||
|
@ -21,7 +21,7 @@ pub struct FormattedText {
|
|||
/// Text content
|
||||
pub text: String,
|
||||
/// Text color
|
||||
#[serde(skip_serializing_if = "Option::is_none", with = "json_color")]
|
||||
#[serde(skip_serializing_if = "Option::is_none", with = "text_color")]
|
||||
pub color: Option<Color>,
|
||||
/// Bold formatting
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
@ -107,9 +107,9 @@ impl Display for FormattedTextList {
|
|||
}
|
||||
}
|
||||
|
||||
/// Raw deserialized [JSONText]
|
||||
/// Raw deserialized [TextValue]
|
||||
///
|
||||
/// A [JSONText] can contain various different JSON types.
|
||||
/// A [TextValue] can contain various different types serialized as JSON or NBT.
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum DeserializedText {
|
||||
|
@ -169,18 +169,18 @@ impl Default for DeserializedText {
|
|||
}
|
||||
}
|
||||
|
||||
/// Minecraft Raw JSON Text
|
||||
/// Minecraft raw text value
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct JSONText(pub String);
|
||||
pub struct TextValue(pub String);
|
||||
|
||||
impl JSONText {
|
||||
/// Deserializes a [JSONText] into a [DeserializedText]
|
||||
impl TextValue {
|
||||
/// Deserializes a [TextValue] into a [DeserializedText]
|
||||
pub fn deserialize(&self) -> DeserializedText {
|
||||
serde_json::from_str(&self.0).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
mod json_color {
|
||||
mod text_color {
|
||||
//! Helpers for serializing and deserializing [FormattedText](super::FormattedText) colors
|
||||
|
||||
use minedmap_resource::Color;
|
||||
|
@ -190,7 +190,7 @@ mod json_color {
|
|||
ser::Error as _,
|
||||
};
|
||||
|
||||
/// Named JSON text colors
|
||||
/// Named text colors
|
||||
static COLORS: phf::Map<&'static str, Color> = phf::phf_map! {
|
||||
"black" => Color([0x00, 0x00, 0x00]),
|
||||
"dark_blue" => Color([0x00, 0x00, 0xAA]),
|
Loading…
Add table
Reference in a new issue