Tee

Struct Tee 

Source
pub struct Tee {
    pub body: WithShadow,
    pub feet: WithShadow,
    pub eye: [EyeTypeData; 6],
    pub hand: WithShadow,
    pub used_uv: UV,
}
Expand description

Represents a parsed Tee character, containing all its visual components.

The Tee struct holds all the necessary parts to render a character, including body parts, feet, hands, and various eye states. Each part is stored separately from its shadow to allow for independent manipulation.

Fields§

§body: WithShadow

The body part of the character, including both the main body and its shadow

§feet: WithShadow

The feet parts of the character, including both the main feet and their shadow

§eye: [EyeTypeData; 6]

An array of eye images, ordered as follows:

[Normal, Angry, Pain, Happy, Empty, Surprise]

§hand: WithShadow

The hand parts of the character, including both the main hand and its shadow

§used_uv: UV

The UV mapping used to extract parts from the source image

Implementations§

Source§

impl Tee

Source

pub fn new(data: Bytes, format: ImageFormat) -> Result<Self>

Parses a Tee struct from raw image data with default uv::TEE_UV_LAYOUT.

§Arguments
  • data - The raw bytes of an image containing the Tee parts.
  • format - The ImageFormat of the input data (e.g., PNG, JPEG).
§Returns

A Result which is Ok(Tee) on successful parsing, or Err(TeeError) on failure.

§Example
use tee_morphosis::tee::Tee;
use image::ImageFormat;

let image_data = std::fs::read("tee_parts.png")?;
let tee = Tee::new(image_data.into(), ImageFormat::Png)?;
Source

pub fn new_with_uv(data: Bytes, uv: UV, format: ImageFormat) -> Result<Self>

Parses a Tee struct from raw image data with a custom UV layout.

§Arguments
  • data - The raw bytes of an image containing the Tee parts.
  • uv - A UV struct containing the coordinates and dimensions for each part on the source image.
  • format - The ImageFormat of the input data (e.g., PNG, JPEG).
§Returns

A Result which is Ok(Tee) on successful parsing, or Err(TeeError) on failure.

§Example
use tee_morphosis::tee::{Tee, uv::UV};
use image::ImageFormat;

let image_data = std::fs::read("custom_tee_parts.png")?;
let custom_uv = UV { /* custom layout */ };
let tee = Tee::new_with_uv(image_data.into(), custom_uv, ImageFormat::Png)?;
Source

pub async fn new_from_url_with_uv(url: &str, uv: UV) -> Result<Self>

Available on crate feature net only.

Asynchronously fetches a Tee skin from a URL and parses it with a custom UV layout. The image format is determined from the Content-Type header of the response.

§Arguments
  • url - A string slice that holds the URL of the skin image.
  • uv - A UV struct containing the coordinates and dimensions for each part.
§Returns

A Result which is Ok(Tee) on successful fetching and parsing, or Err(TeeError) on failure.

§Example
use tee_morphosis::tee::{Tee, uv::UV};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let custom_uv = UV { /* custom layout */ };
    let tee = Tee::new_from_url_with_uv("https://example.com/tee.png", custom_uv).await?;
    Ok(())
}
Source

pub async fn new_from_url(url: &str) -> Result<Self>

Available on crate feature net only.

Asynchronously fetches a Tee skin from a URL and parses it with the default UV layout. The image format is determined from the Content-Type header of the response.

§Arguments
  • url - A string slice that holds the URL of the skin image.
§Returns

A Result which is Ok(Tee) on successful fetching and parsing, or Err(TeeError) on failure.

§Example
use tee_morphosis::tee::Tee;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let tee = Tee::new_from_url("https://example.com/tee.png").await?;
    Ok(())
}
Source

pub fn apply_hsl_to_parts(&mut self, hsl: (f32, f32, f32), parts: &[TeePart])

Applies HSL color transformation to specific parts of the Tee.

§Arguments
  • hls - A tuple of (hue, saturation, value) values, each in the range [0.0, 1.0].
  • parts - A slice of TeePart specifying which parts to apply the transformation to.
§Example
use tee_morphosis::tee::{Tee, parts::TeePart};
use tee_morphosis::tee:hsl::ddnet_color_to_hsl;

let mut tee = Tee::new(/* ... */)?;

let hsl = ddnet_color_to_hsl(1900500);
tee.apply_hsl_to_parts(hsl, &[TeePart::Body]);
Source

pub fn apply_hsl_to_all(&mut self, hls: HSL)

Applies HSL color transformation to all parts of the Tee.

§Arguments
  • hls - A tuple of (hue, saturation, value) values, each in the range [0.0, 1.0].
§Example
use tee_morphosis::tee::Tee;
use tee_morphosis::tee:hsl::ddnet_color_to_hsl;

let mut tee = Tee::new(/* ... */)?;

let hsl = ddnet_color_to_hsl(1900500);
tee.apply_hsl_to_all(hsl);
Source

pub fn compose( &self, skin: Skin, eye_type: EyeType, img_format: ImageFormat, ) -> Result<Bytes>

Composites the Tee parts onto a base skin image to create a final character portrait.

§Arguments
  • skin - The base Skin to draw the Tee parts onto.
  • eye_type - The EyeType to use for the eyes in the final image.
  • img_format - The desired ImageFormat for the output bytes (e.g., PNG, JPEG).
§Returns

A Result which is Ok(Bytes) containing the final image data on success, or Err(TeeError) on failure.

§Example
use tee_morphosis::tee::{Tee, parts::EyeType, skin::TEE_SKIN_LAYOUT};
use image::ImageFormat;

let tee = Tee::new(/* ... */)?;
let result = tee.compose(TEE_SKIN_LAYOUT, EyeType::Happy, ImageFormat::Png)?;
std::fs::write("output.png", result)?;
Source

pub fn compose_png(&self, skin: Skin, eye_type: EyeType) -> Result<Bytes>

Composites the Tee with PNG format.

§Arguments
  • skin - The base Skin to draw the Tee parts onto.
  • eye_type - The type of eyes to use.
§Returns

A Result which is Ok(Bytes) containing the final image data on success, or Err(TeeError) on failure.

§Example
use tee_morphosis::tee::{Tee, skin::TEE_SKIN_LAYOUT};

let tee = Tee::new(/* ... */)?;
let result = tee.compose_png(TEE_SKIN_LAYOUT, EyeType::Happy)?;
std::fs::write("output.png", result)?;
Source

pub fn get_eye(&self, type: EyeType) -> &RgbaImage

Retrieves the image for a specific eye type.

§Arguments
  • type - The EyeType to retrieve.
§Returns

A reference to the RgbaImage corresponding to the requested eye type. This function will panic if the internal state is inconsistent, which is prevented by the construction logic in Tee::new.

§Example
use tee_morphosis::tee::{Tee, parts::EyeType};

let tee = Tee::new(/* ... */)?;
let happy_eye = tee.get_eye(EyeType::Happy);
Source

pub fn get_all_parts(&self) -> HashMap<TeePart, &WithShadow>

Returns all parts of the Tee as a HashMap.

note: does not include eyes. Use Tee::get_all_eyes instead

§Returns

A HashMap<TeePart, &WithShadow> containing all parts of the Tee.

§Example
use tee_morphosis::tee::{Tee, parts::TeePart};

let tee = Tee::new(/* ... */)?;
let all_parts = tee.get_all_parts();
let body_image = all_parts.get(&TeePart::Body).unwrap();
Source

pub fn get_all_eyes(&self) -> HashMap<EyeType, &RgbaImage>

Returns all eye types of the Tee as a HashMap.

for specific one, use Tee::get_eye

§Returns

A HashMap<EyeType, &RgbaImage> containing all eye types of the Tee.

§Example
use tee_morphosis::tee::{Tee, parts::EyeType};

let tee = Tee::new(/* ... */)?;
let all_eyes = tee.get_all_eyes();
let happy_eye = all_eyes.get(&EyeType::Happy).unwrap();

Trait Implementations§

Source§

impl Clone for Tee

Source§

fn clone(&self) -> Tee

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tee

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Tee

Source§

fn eq(&self, other: &Tee) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Tee

Auto Trait Implementations§

§

impl Freeze for Tee

§

impl RefUnwindSafe for Tee

§

impl Send for Tee

§

impl Sync for Tee

§

impl Unpin for Tee

§

impl UnwindSafe for Tee

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more