added faction peace treaties and territory wars
This commit is contained in:
parent
e589b7b438
commit
f28c390394
4 changed files with 104 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#![allow(unused)]
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use serde::de::{Deserialize, Deserializer, Error, Unexpected, Visitor};
|
||||
|
||||
|
|
@ -92,6 +94,47 @@ where
|
|||
deserializer.deserialize_any(DumbVisitor)
|
||||
}
|
||||
|
||||
pub(crate) fn datetime_map<'de, D>(
|
||||
deserializer: D,
|
||||
) -> Result<BTreeMap<i32, chrono::DateTime<chrono::Utc>>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
#[derive(serde::Deserialize)]
|
||||
struct UnixTimestamp(
|
||||
#[serde(with = "chrono::serde::ts_seconds")] chrono::DateTime<chrono::Utc>,
|
||||
);
|
||||
|
||||
struct MapVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for MapVisitor {
|
||||
type Value = BTreeMap<i32, chrono::DateTime<chrono::Utc>>;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(formatter, "map of unix timestamps")
|
||||
}
|
||||
|
||||
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut result = BTreeMap::new();
|
||||
while let Some(key) = map.next_key::<&'de str>()? {
|
||||
let id = key
|
||||
.parse()
|
||||
.map_err(|_e| A::Error::invalid_value(Unexpected::Str(key), &"integer"))?;
|
||||
|
||||
let ts: UnixTimestamp = map.next_value()?;
|
||||
result.insert(id, ts.0);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_map(MapVisitor)
|
||||
}
|
||||
|
||||
#[cfg(feature = "decimal")]
|
||||
pub(crate) fn string_or_decimal<'de, D>(deserializer: D) -> Result<rust_decimal::Decimal, D::Error>
|
||||
where
|
||||
|
|
|
|||
|
|
@ -35,6 +35,21 @@ pub struct Member<'a> {
|
|||
pub last_action: LastAction,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct FactionTerritoryWar<'a> {
|
||||
pub territory: &'a str,
|
||||
pub assaulting_faction: i32,
|
||||
pub defending_faction: i32,
|
||||
pub score: i32,
|
||||
pub required_score: i32,
|
||||
|
||||
#[serde(with = "chrono::serde::ts_seconds")]
|
||||
pub start_time: DateTime<Utc>,
|
||||
|
||||
#[serde(with = "chrono::serde::ts_seconds")]
|
||||
pub end_time: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Basic<'a> {
|
||||
#[serde(rename = "ID")]
|
||||
|
|
@ -49,6 +64,12 @@ pub struct Basic<'a> {
|
|||
|
||||
#[serde(borrow)]
|
||||
pub members: BTreeMap<i32, Member<'a>>,
|
||||
|
||||
#[serde(deserialize_with = "de_util::datetime_map")]
|
||||
pub peace: BTreeMap<i32, DateTime<Utc>>,
|
||||
|
||||
#[serde(borrow)]
|
||||
pub territory_wars: Vec<FactionTerritoryWar<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue