updated models

This commit is contained in:
TotallyNot 2023-05-10 12:04:44 +02:00
parent 6b4189ab2d
commit fee450f04b
3 changed files with 23 additions and 2 deletions

View file

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

View file

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

View file

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