Skip to content

Commit

Permalink
feat: update leagues for 3.22
Browse files Browse the repository at this point in the history
  • Loading branch information
shonya3 committed Aug 17, 2023
1 parent 341f682 commit e00ace3
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 61 deletions.
2 changes: 1 addition & 1 deletion divi/p.json

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions divi/src/league.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,63 @@ use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub enum League {
Crucible,
Standard,
#[serde(alias = "Crucible-HC")]
HardcoreCrucible,
Hardcore,
#[serde(alias = "SSF Standard")]
SSFStandard,
#[serde(alias = "SSF Hardcore")]
SSFHardcore,
#[serde(alias = "SSF Crucible")]
SSFCrucible,
#[serde(alias = "HC SSF Crucible")]
SSFHCCrucible,
Ancestor,
#[serde(alias = "Hardcore Ancestor")]
HardcoreAncestor,
#[serde(alias = "SSF Ancestor")]
SSFAncestor,
#[serde(alias = "HC SSF Ancestor")]
SSFHCAncestor,
}

impl Default for League {
fn default() -> Self {
League::Crucible
League::Ancestor
}
}

impl Display for League {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
League::Crucible => write!(f, "Crucible"),
League::Standard => write!(f, "Standard"),
League::HardcoreCrucible => write!(f, "Hardcore Crucible"),
League::Hardcore => write!(f, "Hardcore"),
League::SSFStandard => write!(f, "Solo Self-Found"),
League::SSFHardcore => write!(f, "Hardcore SSF"),
League::SSFCrucible => write!(f, "SSF Crucible"),
League::SSFHCCrucible => write!(f, "HC SSF Crucible"),
League::Ancestor => write!(f, "Ancestor"),
League::HardcoreAncestor => write!(f, "Hardcore Ancestor"),
League::SSFAncestor => write!(f, "SSF Ancestor"),
League::SSFHCAncestor => write!(f, "HC SSF Ancestor"),
}
}
}

#[derive(Debug, Serialize, Deserialize, Clone, Hash, Eq, PartialEq)]
pub enum TradeLeague {
Crucible,
Standard,
#[serde(alias = "Crucible-HC")]
HardcoreCrucible,
Hardcore,
Ancestor,
#[serde(alias = "Hardcore Ancestor", rename = "Hardcore Ancestor")]
HardcoreAncestor,
}

impl Display for TradeLeague {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TradeLeague::Crucible => write!(f, "Crucible"),
TradeLeague::Standard => write!(f, "Standard"),
TradeLeague::HardcoreCrucible => write!(f, "Hardcore Crucible"),
TradeLeague::Hardcore => write!(f, "Hardcore"),
TradeLeague::Ancestor => write!(f, "Ancestor"),
TradeLeague::HardcoreAncestor => write!(f, "Hardcore Ancestor"),
}
}
}
impl Default for TradeLeague {
fn default() -> Self {
TradeLeague::Crucible
TradeLeague::Ancestor
}
}
38 changes: 19 additions & 19 deletions divi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ pub trait IsCard {
fn is_legacy_card(&self) -> bool;
}

#[cfg(test)]
mod tests {
use std::fs;

use crate::{
prices::Prices,
sample::{DivinationCardsSample, SampleData},
};

#[test]
fn fix_typos() {
let prices: Prices =
serde_json::from_str(&fs::read_to_string(&"Crucible-prices.json").unwrap()).unwrap();

let sample_data = SampleData::Csv(fs::read_to_string("example-3.csv").unwrap());
let sample = DivinationCardsSample::create(sample_data, Some(prices)).unwrap();
assert_eq!(sample.fixed_names.len(), 26);
}
}
// #[cfg(test)]
// mod tests {
// use std::fs;

// use crate::{
// prices::Prices,
// sample::{DivinationCardsSample, SampleData},
// };

// #[test]
// fn fix_typos() {
// let prices: Prices =
// serde_json::from_str(&fs::read_to_string(&"Crucible-prices.json").unwrap()).unwrap();

// let sample_data = SampleData::Csv(fs::read_to_string("example-3.csv").unwrap());
// let sample = DivinationCardsSample::create(sample_data, Some(prices)).unwrap();
// assert_eq!(sample.fixed_names.len(), 26);
// }
// }
3 changes: 2 additions & 1 deletion divi/src/prices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl Prices {
let json = client.get(url).send().await?.text().await?;
// std::fs::write("ninja.json", &json).unwrap();
let data = serde_json::from_str::<PriceData>(&json).unwrap();
dbg!(&data);
Ok(Prices::from(data.lines))
}
}
Expand Down Expand Up @@ -77,6 +78,6 @@ impl From<Vec<DivinationCardPrice>> for Prices {

#[tokio::test]
async fn testfetch() {
let p = Prices::fetch(&TradeLeague::Crucible).await.unwrap();
let p = Prices::fetch(&TradeLeague::Ancestor).await.unwrap();
std::fs::write("p.json", serde_json::to_string(&p).unwrap()).unwrap();
}
2 changes: 1 addition & 1 deletion divi/src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ mod tests {
assert_eq!(cards_total_amount, 181);
let sample = DivinationCardsSample::create(
SampleData::CardNameAmountList(vec),
Some(Prices::fetch(&TradeLeague::HardcoreCrucible).await.unwrap()),
Some(Prices::fetch(&TradeLeague::HardcoreAncestor).await.unwrap()),
)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const ACTIVE_LEAGUE = 'Crucible';
export const ACTIVE_LEAGUE = 'Ancestor';
export const downloadText = (filename: string, text: string = 'empty') => {
const file = new File([text], filename);
const a = document.createElement('a');
Expand Down
31 changes: 11 additions & 20 deletions packages/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
export type Order = 'asc' | 'desc' | 'unordered';
export type League =
| 'Crucible'
| 'Standard'
| 'Crucible-HC'
| 'Hardcore'
| 'SSF Standard'
| 'SSF Hardcore'
| 'SSF Crucible'
| 'HC SSF Crucible';
export const leagues = Object.freeze([
'Crucible',

export const leagues = [
'Ancestor',
'Standard',
'Crucible-HC',
'Hardcore Ancestor',
'Hardcore',
'SSF Standard',
'SSF Hardcore',
'SSF Crucible',
'HC SSF Crucible',
]) satisfies Readonly<League[]>;
export type TradeLeague = 'Crucible' | 'Standard' | 'Crucible-HC' | 'Hardcore';
export const tradeLeagues = Object.freeze(['Crucible', 'Standard', 'Crucible-HC', 'Hardcore']) satisfies Readonly<
TradeLeague[]
>;
'SSF Ancestor',
'HC SSF Ancestor',
] as const;
export const tradeLeagues = ['Ancestor', 'Standard', 'Hardcore Ancestor', 'Hardcore'] as const;
export const permanentLeagues: Readonly<League[]> = ['Standard', 'Hardcore', 'SSF Standard'] as const;

export const permanentLeagues: Readonly<League[]> = Object.freeze(['Standard', 'Hardcore', 'SSF Standard']);
export type League = (typeof leagues)[number];
export type TradeLeague = (typeof tradeLeagues)[number];

export const isTradeLeague = (s: string): s is TradeLeague => {
return tradeLeagues.includes(s as TradeLeague);
Expand Down

0 comments on commit e00ace3

Please sign in to comment.