2022-08-02 12:13:31 +00:00
|
|
|
//! Module defining [CardArt].
|
|
|
|
|
2022-08-03 16:30:15 +00:00
|
|
|
/// An art asset associated with a [super::Card].
|
2022-08-02 13:45:09 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
2022-08-02 12:13:31 +00:00
|
|
|
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 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 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")
|
|
|
|
}
|
2022-08-02 13:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[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(),
|
2022-08-02 13:45:09 +00:00
|
|
|
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"),
|
2022-08-02 13:45:09 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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"),
|
2022-08-02 13:45:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
2022-08-02 12:13:31 +00:00
|
|
|
}
|