Skip to content

Commit

Permalink
shadow_color (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandcracker authored Dec 5, 2024
1 parent ff5e938 commit 51b142d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pumpkin-core/src/text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Here we build Mojang's Textcomponent, Which is used across many places, Often wh
- [x] Strikethrough
- [x] Obfuscated
- [x] Insertion
- [x] Shadow Color
- Click Event
- [x] Open URL
- [x] Run Command
Expand All @@ -42,4 +43,3 @@ Here we build Mojang's Textcomponent, Which is used across many places, Often wh
- [x] Uniform (Unicode)
- [x] Alt
- [x] Illageralt

28 changes: 28 additions & 0 deletions pumpkin-core/src/text/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,34 @@ impl Serialize for RGBColor {
}
}

#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq, Deserialize)]
pub struct ARGBColor {
alpha: u8,
red: u8,
green: u8,
blue: u8,
}

impl ARGBColor {
pub fn new(alpha: u8, red: u8, green: u8, blue: u8) -> Self {
ARGBColor {
alpha,
red,
green,
blue,
}
}
}

impl Serialize for ARGBColor {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_bytes([self.alpha, self.red, self.green, self.blue].as_ref())
}
}

/// Named Minecraft color
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
Expand Down
7 changes: 7 additions & 0 deletions pumpkin-core/src/text/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::str;
use std::borrow::Cow;

use crate::text::color::ARGBColor;
use click::ClickEvent;
use color::Color;
use colored::Colorize;
Expand Down Expand Up @@ -174,6 +175,12 @@ impl<'a> TextComponent<'a> {
self
}

/// Overrides the shadow properties of text.
pub fn shadow_color(mut self, color: ARGBColor) -> Self {
self.style.shadow_color = Some(color);
self
}

pub fn encode(&self) -> Vec<u8> {
// TODO: Somehow fix this ugly mess
#[derive(serde::Serialize)]
Expand Down
16 changes: 14 additions & 2 deletions pumpkin-core/src/text/style.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use serde::{Deserialize, Serialize};

use super::{
click::ClickEvent,
color::{self, Color},
hover::HoverEvent,
};
use crate::text::color::ARGBColor;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -38,6 +38,12 @@ pub struct Style<'a> {
/// Allows you to change the font of the text.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub font: Option<String>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "shadow_color"
)]
pub shadow_color: Option<ARGBColor>,
}

impl<'a> Style<'a> {
Expand Down Expand Up @@ -105,4 +111,10 @@ impl<'a> Style<'a> {
self.font = Some(identifier);
self
}

/// Overrides the shadow properties of text.
pub fn shadow_color(mut self, color: ARGBColor) -> Self {
self.shadow_color = Some(color);
self
}
}

0 comments on commit 51b142d

Please sign in to comment.