diff --git a/src/world/de.rs b/src/world/de.rs index 7ab8ba7..0a4b4b6 100644 --- a/src/world/de.rs +++ b/src/world/de.rs @@ -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, + pub messages: Vec, /// Default text color pub color: Option, } @@ -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, }, diff --git a/src/world/mod.rs b/src/world/mod.rs index 6426c92..8a2e9be 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -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; diff --git a/src/world/sign.rs b/src/world/sign.rs index 579f5b3..c913b6f 100644 --- a/src/world/sign.rs +++ b/src/world/sign.rs @@ -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". diff --git a/src/world/json_text.rs b/src/world/text_value.rs similarity index 93% rename from src/world/json_text.rs rename to src/world/text_value.rs index 7d3ff3a..336b1b1 100644 --- a/src/world/json_text.rs +++ b/src/world/text_value.rs @@ -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, /// 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]),