add rulings link and make pend effects more readable

This commit is contained in:
kageru 2023-02-17 15:37:03 +01:00
parent 51c3847aeb
commit 4178501a07
5 changed files with 23 additions and 8 deletions

1
Cargo.lock generated

@ -206,6 +206,7 @@ dependencies = [
"actix-web",
"itertools",
"nom",
"regex",
"serde",
"serde_json",
"test-case",

@ -10,6 +10,7 @@ nom = "7.1.3"
actix-web = { version = "4.3.0", default_features = false, features = ["macros"] }
itertools = "0.10.5"
time = { version = "0.3.17", features = ["serde", "serde-human-readable"] }
regex = { version = "1.7.1", default_features = false, features = ["std"] }
[dev-dependencies]
test-case = "2.2.2"

@ -66,6 +66,7 @@ pub struct Set {
impl Card {
pub fn extended_info(&self) -> Result<String, fmt::Error> {
let mut s = String::with_capacity(1000);
write!(s, "<p>Click <a href=\"https://db.ygorganization.com/search#card:{}\">here</a> for rulings.</p>", &self.name)?;
s.push_str("<h3>Printings:</h3>");
for printing in &self.card_sets {
write!(s, "{}: {} ({})", printing.set_name, printing.set_code, printing.set_rarity)?;
@ -129,7 +130,7 @@ impl Display for Card {
}
)?;
self.basic_info(f, "<br/>")?;
write!(f, "</em><p>{}</p>", &self.text)?;
write!(f, "</em><hr/><p>{}</p>", &self.text)?;
Ok(())
}
}

@ -3,6 +3,7 @@ use actix_web::{get, http::header, web, App, Either, HttpResponse, HttpServer};
use data::{Card, CardInfo, Set};
use filter::SearchCard;
use itertools::Itertools;
use regex::{Captures, Regex};
use serde::Deserialize;
use std::{collections::HashMap, fmt::Write, fs::File, io::BufReader, net::Ipv4Addr, sync::LazyLock, time::Instant};
use time::Date;
@ -26,8 +27,19 @@ static CARDS: LazyLock<Vec<Card>> = LazyLock::new(|| {
});
cards
});
static CARDS_BY_ID: LazyLock<HashMap<usize, Card>> =
LazyLock::new(|| CARDS.iter().map(|c| (c.id, Card { text: c.text.replace('\r', "").replace('\n', "<br/>"), ..c.clone() })).collect());
static CARDS_BY_ID: LazyLock<HashMap<usize, Card>> = LazyLock::new(|| {
CARDS
.iter()
.map(|c| {
let text = PENDULUM_SEPARATOR
.replacen(&c.text.replace('\r', ""), 1, |caps: &Captures| {
format!("</p><hr/>[ {} ]<p>", caps.iter().flatten().last().map_or_else(|| "Monster Effect", |g| g.as_str()))
})
.replace('\n', "<br/>");
(c.id, Card { text, ..c.clone() })
})
.collect()
});
static SEARCH_CARDS: LazyLock<Vec<SearchCard>> = LazyLock::new(|| CARDS.iter().map(SearchCard::from).collect());
static SETS_BY_NAME: LazyLock<HashMap<String, Set>> = LazyLock::new(|| {
serde_json::from_reader::<_, Vec<Set>>(BufReader::new(File::open("sets.json").expect("sets.json not found")))
@ -36,6 +48,8 @@ static SETS_BY_NAME: LazyLock<HashMap<String, Set>> = LazyLock::new(|| {
.map(|s| (s.set_name.to_lowercase(), s))
.collect()
});
static PENDULUM_SEPARATOR: LazyLock<Regex> =
LazyLock::new(|| Regex::new("(\\n-+)?\\n\\[\\s?(Monster Effect|Flavor Text)\\s?\\]\\n?").unwrap());
static IMG_HOST: LazyLock<String> = LazyLock::new(|| std::env::var("IMG_HOST").unwrap_or_else(|_| String::new()));
@ -105,7 +119,7 @@ async fn card_info(card_id: web::Path<usize>) -> AnyResult<HttpResponse> {
description: card.short_info()?,
query: None,
body: format!(
r#"<div> <img alt="Card Image: {}" class="fullimage" src="{}/static/full/{}.jpg"/>{card} {} </div>"#,
r#"<div> <img alt="Card Image: {}" class="fullimage" src="{}/static/full/{}.jpg"/>{card} <hr/> {} </div>"#,
card.name,
IMG_HOST.as_str(),
card.id,

@ -35,6 +35,8 @@ code {
p {
text-align: justify;
margin-block-start: 0.2em;
margin-block-end: 0.2em;
}
form > * {
@ -61,10 +63,6 @@ a {
color: var(--hl);
}
hr {
border-color: var(--hl);
}
h2 {
margin-block-end: 0;
margin-block-start: 0;