1
Fork 0
mirror of https://github.com/Steffo99/patched-porobot.git synced 2024-12-25 19:14:20 +00:00
patched-porobot/src/schema/setbundle/art.rs

83 lines
2.7 KiB
Rust
Raw Normal View History

//! Module defining [CardArt].
2022-08-04 16:53:49 +00:00
/// An art asset associated with a [super::Card].
2022-08-04 16:49:59 +00:00
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct CardArt {
/// URL to the `.png` image of the rendered card.
///
/// # Example
///
/// `https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png`
///
#[serde(rename = "gameAbsolutePath")]
pub card_png: String,
/// URL to the `.png` image of the full card art.
///
/// # Example
///
/// `https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png`
///
#[serde(rename = "fullAbsolutePath")]
pub full_png: String,
}
impl CardArt {
/// URL to the `.jpg` image of the `en_us` locale of the rendered card, via `poro.steffo.eu`.
///
/// Please do not overload this endpoint, as it currently does not use a CDN!
///
/// # Example
///
/// `https://poro.steffo.eu/set1-en_us/en_us/img/cards/01DE001.jpg`
///
pub fn card_jpg(&self) -> String {
self.card_png
.replace("https://dd.b.pvp.net/latest/set1", "https://poro.steffo.eu/set1-en_us")
.replace(".png", ".jpg")
}
/// URL to the `.jpg` image of the `en_us` locale of the full card art, via `poro.steffo.eu`.
///
/// Please do not overload this endpoint, as it currently does not use a CDN!
///
/// # Example
///
/// `https://poro.steffo.eu/set1-en_us/en_us/img/cards/01DE001-full.jpg`
///
pub fn full_jpg(&self) -> String {
self.full_png
.replace("https://dd.b.pvp.net/latest/set1", "https://poro.steffo.eu/set1-en_us")
.replace(".png", ".jpg")
}
}
#[cfg(test)]
mod tests {
use super::CardArt;
#[test]
fn deserialize() {
assert_eq!(
2022-08-03 15:41:50 +00:00
serde_json::de::from_str::<'static, CardArt>(r#"{"gameAbsolutePath": "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png", "fullAbsolutePath": "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png"}"#).unwrap(),
CardArt {
2022-08-03 00:56:59 +00:00
card_png: String::from("https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png"),
full_png: String::from("https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png"),
}
);
}
#[test]
fn png_to_jpg() {
let art = CardArt {
2022-08-03 00:56:59 +00:00
card_png: String::from("https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png"),
full_png: String::from("https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png"),
};
assert_eq!(art.card_jpg(), "https://poro.steffo.eu/set1-en_us/en_us/img/cards/01DE001.jpg");
assert_eq!(art.full_jpg(), "https://poro.steffo.eu/set1-en_us/en_us/img/cards/01DE001-full.jpg");
}
}