Add banlist status to filters

This commit is contained in:
kageru 2023-02-03 16:19:26 +01:00
parent 0e1e55c185
commit 56cf06e7d5
4 changed files with 38 additions and 13 deletions

@ -31,6 +31,23 @@ pub struct Card {
pub link_arrows: Option<Vec<String>>, pub link_arrows: Option<Vec<String>>,
#[serde(default)] #[serde(default)]
pub card_sets: Vec<CardSet>, pub card_sets: Vec<CardSet>,
pub banlist_info: Option<BanlistInfo>,
}
#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Copy, Default)]
pub struct BanlistInfo {
#[serde(default)]
pub ban_tcg: BanlistStatus,
}
#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Copy, Default)]
pub enum BanlistStatus {
Banned = 0,
Limited = 1,
#[serde(rename = "Semi-Limited")]
SemiLimited = 2,
#[default]
Unlimited = 3,
} }
#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Default)] #[derive(Debug, Deserialize, PartialEq, Eq, Clone, Default)]

@ -1,7 +1,7 @@
use time::Date; use time::Date;
use crate::{ use crate::{
data::Card, data::{BanlistStatus, Card},
parser::{Field, Operator, RawCardFilter, Value, OPERATOR_CHARS}, parser::{Field, Operator, RawCardFilter, Value, OPERATOR_CHARS},
SETS_BY_NAME, SETS_BY_NAME,
}; };
@ -23,6 +23,7 @@ pub struct SearchCard {
link_arrows: Option<Vec<String>>, link_arrows: Option<Vec<String>>,
sets: Vec<String>, sets: Vec<String>,
original_year: Option<i32>, original_year: Option<i32>,
legal_copies: i32,
} }
impl From<&Card> for SearchCard { impl From<&Card> for SearchCard {
@ -48,6 +49,7 @@ impl From<&Card> for SearchCard {
}) })
.map(Date::year) .map(Date::year)
.min(), .min(),
legal_copies: card.banlist_info.map(|bi| bi.ban_tcg).unwrap_or(BanlistStatus::Unlimited) as i32,
} }
} }
} }
@ -77,6 +79,7 @@ pub fn build_filter(query: RawCardFilter) -> Result<CardFilter, String> {
RawCardFilter(Field::Level, op, Value::Numerical(n)) => Box::new(move |card| op.filter_number(card.level, n)), RawCardFilter(Field::Level, op, Value::Numerical(n)) => Box::new(move |card| op.filter_number(card.level, n)),
RawCardFilter(Field::LinkRating, op, Value::Numerical(n)) => Box::new(move |card| op.filter_number(card.link_rating, n)), RawCardFilter(Field::LinkRating, op, Value::Numerical(n)) => Box::new(move |card| op.filter_number(card.link_rating, n)),
RawCardFilter(Field::Year, op, Value::Numerical(n)) => Box::new(move |card| op.filter_number(card.original_year, n)), RawCardFilter(Field::Year, op, Value::Numerical(n)) => Box::new(move |card| op.filter_number(card.original_year, n)),
RawCardFilter(Field::Legal, op, Value::Numerical(n)) => Box::new(move |card| op.filter_number(Some(card.legal_copies), n)),
RawCardFilter(Field::Type, Operator::Equal, Value::String(s)) => Box::new(move |card| card.r#type == s), RawCardFilter(Field::Type, Operator::Equal, Value::String(s)) => Box::new(move |card| card.r#type == s),
RawCardFilter(Field::Type, Operator::NotEqual, Value::String(s)) => Box::new(move |card| card.r#type != s), RawCardFilter(Field::Type, Operator::NotEqual, Value::String(s)) => Box::new(move |card| card.r#type != s),
RawCardFilter(Field::Attribute, Operator::Equal, Value::String(s)) => Box::new(move |card| card.attribute.contains(&s)), RawCardFilter(Field::Attribute, Operator::Equal, Value::String(s)) => Box::new(move |card| card.attribute.contains(&s)),

@ -64,6 +64,7 @@ fn value(input: &str) -> IResult<&str, Value> {
pub enum Field { pub enum Field {
Atk = 1, Atk = 1,
Def = 2, Def = 2,
Legal = 3,
Level = 4, Level = 4,
LinkRating = 6, LinkRating = 6,
Year = 8, Year = 8,
@ -89,6 +90,7 @@ impl Display for Field {
Self::LinkRating => "link rating", Self::LinkRating => "link rating",
Self::Set => "set", Self::Set => "set",
Self::Year => "year", Self::Year => "year",
Self::Legal => "allowed copies",
}) })
} }
} }
@ -108,6 +110,7 @@ impl FromStr for Field {
"name" => Self::Name, "name" => Self::Name,
"set" | "s" => Self::Set, "set" | "s" => Self::Set,
"year" | "y" => Self::Year, "year" | "y" => Self::Year,
"legal" | "copies" => Self::Legal,
_ => Err(s.to_string())?, _ => Err(s.to_string())?,
}) })
} }

@ -13,6 +13,7 @@ Currently supported search fields are:
<li>The <code>attribute</code> (or <code>attr</code> or <code>a</code>) of a card. This is “Light”, “Dark”, “Earth”, etc.</li> <li>The <code>attribute</code> (or <code>attr</code> or <code>a</code>) of a card. This is “Light”, “Dark”, “Earth”, etc.</li>
<li>The <code>text</code> (or <code>effect</code>, <code>eff</code>, <code>e</code>, or <code>o</code>) of a card. This is either the effect or flavor text (for normal monsters). For pendulum cards, this searches in both pendulum and monster effects. The <code>o</code> alias is to help my muscle memory coming from Scryfall.</li> <li>The <code>text</code> (or <code>effect</code>, <code>eff</code>, <code>e</code>, or <code>o</code>) of a card. This is either the effect or flavor text (for normal monsters). For pendulum cards, this searches in both pendulum and monster effects. The <code>o</code> alias is to help my muscle memory coming from Scryfall.</li>
<li>The <code>set</code> (or <code>s</code>) a card was printed in. This considers all printings, not just the original.</li> <li>The <code>set</code> (or <code>s</code>) a card was printed in. This considers all printings, not just the original.</li>
<li>The <code>copies</code> (or <code>legal</code>) you’re allowed to play according to the current banlist.</li>
</ul> </ul>
Anything not associated with a search field is interpreted as a search in the card name, so <a href="/?q=l%3A4+utopia"><code>l:4 utopia</code></a> will show all level/rank 4 monsters with “Utopia” in their name.<br/> Anything not associated with a search field is interpreted as a search in the card name, so <a href="/?q=l%3A4+utopia"><code>l:4 utopia</code></a> will show all level/rank 4 monsters with “Utopia” in their name.<br/>
If your search contains spaces (e.g. searching for an effect that says “destroy that target”), the text must be quoted like <code>effect:"destroy that target"</code>. If your search contains spaces (e.g. searching for an effect that says “destroy that target”), the text must be quoted like <code>effect:"destroy that target"</code>.
@ -34,4 +35,5 @@ The following search operators are supported:
<li>All Synchro monsters that are Dark attribute, level 5 or higher, and have exactly 2200 ATK: <a href="/?q=c%3Asynchro+a%3Adark+l%3E%3D5+atk%3A2200"><code>c:synchro a:dark l>=5 atk:2200</code></a></li> <li>All Synchro monsters that are Dark attribute, level 5 or higher, and have exactly 2200 ATK: <a href="/?q=c%3Asynchro+a%3Adark+l%3E%3D5+atk%3A2200"><code>c:synchro a:dark l>=5 atk:2200</code></a></li>
<li>All counter traps that can negate summons: <a href="/?q=c%3Atrap+t%3Acounter+e%3A%22negate+the+summon%22"><code>c:trap t:counter e:"negate the summon"</code></a></li> <li>All counter traps that can negate summons: <a href="/?q=c%3Atrap+t%3Acounter+e%3A%22negate+the+summon%22"><code>c:trap t:counter e:"negate the summon"</code></a></li>
<li>All effect monsters printed in Legend of Blue-Eyes: <a href="/?q=set%3Alob+c%3Aeffect"><code>set:lob c:effect</code></a></li> <li>All effect monsters printed in Legend of Blue-Eyes: <a href="/?q=set%3Alob+c%3Aeffect"><code>set:lob c:effect</code></a></li>
<li>All Zoodiac cards that are currently banned: <a href="/?q=legal%3A0+zoodiac"><code>legal:0 zoodiac</code></a></li>
</ul> </ul>