use std::fmt;
#[derive(Clone, Debug, Default, PartialEq)]
pub struct EsfFit {
pub hull: Option<u32>,
pub name: Option<String>,
pub mode: Option<u32>,
pub entries: Vec<Entry>,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Entry {
pub type_id: Option<u32>,
pub count: Option<u32>,
pub fit_name: Option<String>,
pub charge: Option<u32>,
pub charge_count: Option<u32>,
pub mutaplasmid: Option<u32>,
pub overrides: Vec<(u32, f64)>,
pub state: Option<State>,
pub location: Option<Location>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum State {
Off = 1,
On = 2,
Heat = 3,
}
impl State {
pub(crate) const ALL: [State; 3] = [State::Off, State::On, State::Heat];
pub fn as_str(self) -> &'static str {
match self {
State::Off => "off",
State::On => "on",
State::Heat => "heat",
}
}
}
impl fmt::Display for State {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Location {
High = 1,
Mid,
Low,
Rig,
Sub,
Svc,
Cargo,
Bay,
Ammo,
Booster,
Command,
Corpse,
Depot,
Expedition,
Fleet,
Frigate,
Fuel,
Gas,
Ice,
Infrastructure,
Maintenance,
Mineral,
Mining,
Moon,
Planetary,
Quafe,
Subsystem,
}
impl Location {
pub(crate) const ALL: [Location; 27] = [
Location::High,
Location::Mid,
Location::Low,
Location::Rig,
Location::Sub,
Location::Svc,
Location::Cargo,
Location::Bay,
Location::Ammo,
Location::Booster,
Location::Command,
Location::Corpse,
Location::Depot,
Location::Expedition,
Location::Fleet,
Location::Frigate,
Location::Fuel,
Location::Gas,
Location::Ice,
Location::Infrastructure,
Location::Maintenance,
Location::Mineral,
Location::Mining,
Location::Moon,
Location::Planetary,
Location::Quafe,
Location::Subsystem,
];
pub(crate) const RACKS: [Location; 6] = [
Location::Sub,
Location::High,
Location::Mid,
Location::Low,
Location::Rig,
Location::Svc,
];
pub fn as_str(self) -> &'static str {
match self {
Location::High => "high",
Location::Mid => "mid",
Location::Low => "low",
Location::Rig => "rig",
Location::Sub => "sub",
Location::Svc => "svc",
Location::Cargo => "cargo",
Location::Bay => "bay",
Location::Ammo => "ammo",
Location::Booster => "booster",
Location::Command => "command",
Location::Corpse => "corpse",
Location::Depot => "depot",
Location::Expedition => "expedition",
Location::Fleet => "fleet",
Location::Frigate => "frigate",
Location::Fuel => "fuel",
Location::Gas => "gas",
Location::Ice => "ice",
Location::Infrastructure => "infrastructure",
Location::Maintenance => "maintenance",
Location::Mineral => "mineral",
Location::Mining => "mining",
Location::Moon => "moon",
Location::Planetary => "planetary",
Location::Quafe => "quafe",
Location::Subsystem => "subsystem",
}
}
pub(crate) fn from_name(name: &str) -> Option<Location> {
Location::ALL.into_iter().find(|l| l.as_str() == name)
}
pub fn is_rack(self) -> bool {
self <= Location::Svc
}
pub fn is_stored(self) -> bool {
!self.is_rack()
}
}
impl fmt::Display for Location {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}