1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
use serde::{Deserialize, Deserializer, Serialize};
use std::str::FromStr;
use std::collections::HashMap;
#[derive(Deserialize, Serialize, Clone)]
pub struct Location {
pub solar_system_id: i32,
pub station_id: Option<i32>,
pub structure_id: Option<i32>,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct RawNode {
pub itemID: u64,
pub typeID: u64,
pub groupID: u64,
#[serde(deserialize_with = "deserialize_optional_u64")]
pub solarSystemID: Option<u64>,
#[serde(deserialize_with = "deserialize_optional_u64")]
pub constellationID: Option<u64>,
#[serde(deserialize_with = "deserialize_optional_u64")]
pub regionID: Option<u64>,
#[serde(deserialize_with = "deserialize_optional_u64")]
pub orbitID: Option<u64>,
pub x: Option<f64>,
pub y: Option<f64>,
pub z: Option<f64>,
#[serde(deserialize_with = "deserialize_optional_f64")]
pub radius: Option<f64>,
pub itemName: Option<String>,
#[serde(deserialize_with = "deserialize_optional_f64")]
pub security: Option<f64>,
}
fn deserialize_optional_u64<'de, D>(deserializer: D) -> Result<Option<u64>, D::Error>
where
D: Deserializer<'de>,
{
let s: Option<String> = Option::deserialize(deserializer)?;
match s.as_deref() {
Some("None") | Some("") => Ok(None), // Handle "None" and empty strings
Some(str_val) => u64::from_str(str_val)
.map(Some)
.map_err(serde::de::Error::custom),
None => Ok(None),
}
}
fn deserialize_optional_f64<'de, D>(deserializer: D) -> Result<Option<f64>, D::Error>
where
D: Deserializer<'de>,
{
let s: Option<String> = Option::deserialize(deserializer)?;
match s.as_deref() {
Some("None") | Some("") => Ok(None), // Handle "None" and empty strings
Some(str_val) => str_val.parse::<f64>()
.map(Some)
.map_err(serde::de::Error::custom),
None => Ok(None),
}
}
#[derive(Debug)]
pub struct MapNode {
pub item_id: u64,
pub is_station: bool,
pub solar_system_id: u64,
pub region_id: u64,
pub x: f64,
pub y: f64,
pub z: f64,
pub name: String,
pub security: f64,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct Connection {
stargate_id: u64,
destination_id: u64,
}
pub type Graph = HashMap<u64, Vec<u64>>;
|