updated models

This commit is contained in:
TotallyNot 2023-05-10 12:04:44 +02:00
parent 171f9f2936
commit 7752933abd
3 changed files with 23 additions and 2 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "torn-api" name = "torn-api"
version = "0.5.15" version = "0.5.16"
edition = "2021" edition = "2021"
authors = ["Pyrit [2111649]"] authors = ["Pyrit [2111649]"]
license = "MIT" license = "MIT"

View file

@ -122,6 +122,8 @@ pub enum FactionSelection {
Upgrades, Upgrades,
Weapons, Weapons,
Lookup, Lookup,
Caches,
CrimeExp,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
@ -171,6 +173,8 @@ pub enum TornSelection {
Timestamp, Timestamp,
Lookup, Lookup,
CityShops, CityShops,
ItemDetails,
TerritoryNames,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]

View file

@ -168,10 +168,14 @@ pub enum EliminationTeam {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Competition { pub enum Competition {
Elimination { Elimination {
score: i16, score: i32,
attacks: i16, attacks: i16,
team: EliminationTeam, team: EliminationTeam,
}, },
DogTags {
score: i32,
position: Option<i32>,
},
} }
fn deserialize_comp<'de, D>(deserializer: D) -> Result<Option<Competition>, D::Error> fn deserialize_comp<'de, D>(deserializer: D) -> Result<Option<Competition>, D::Error>
@ -186,11 +190,14 @@ where
Team, Team,
Attacks, Attacks,
TeamName, TeamName,
Position,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
enum CompetitionName { enum CompetitionName {
Elimination, Elimination,
#[serde(rename = "Dog Tags")]
DogTags,
} }
struct CompetitionVisitor; struct CompetitionVisitor;
@ -224,6 +231,7 @@ where
let mut score = None; let mut score = None;
let mut attacks = None; let mut attacks = None;
let mut name = None; let mut name = None;
let mut position = None;
while let Some(key) = map.next_key()? { while let Some(key) = map.next_key()? {
match key { match key {
@ -236,6 +244,9 @@ where
Field::Attacks => { Field::Attacks => {
attacks = Some(map.next_value()?); attacks = Some(map.next_value()?);
} }
Field::Position => {
position = Some(map.next_value()?);
}
Field::Team => { Field::Team => {
let team_raw: &str = map.next_value()?; let team_raw: &str = map.next_value()?;
team = if team_raw.is_empty() { team = if team_raw.is_empty() {
@ -294,6 +305,12 @@ where
Ok(None) Ok(None)
} }
} }
CompetitionName::DogTags => {
let score = score.ok_or_else(|| de::Error::missing_field("score"))?;
let position = position.ok_or_else(|| de::Error::missing_field("position"))?;
Ok(Some(Competition::DogTags { score, position }))
}
} }
} }
} }