#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq)]
pub enum Color {
#[serde(rename = "R")]
Red,
#[serde(rename = "G")]
Green,
#[serde(rename = "B")]
Blue,
#[serde(rename = "W")]
White,
}
#[derive(Debug)]
pub struct ItemSockets {
pub(crate) abyssal_count: u64,
pub(crate) regular_groups: Vec<SocketGroup>,
}
impl Default for ItemSockets {
fn default() -> Self {
ItemSockets {
abyssal_count: 0,
regular_groups: vec![],
}
}
}
impl ItemSockets {
pub fn regular_count(&self) -> u64 {
self.regular_groups.iter().map(|g| g.size() as u64).sum()
}
#[inline]
pub fn abyssal_count(&self) -> u64 {
self.abyssal_count
}
#[inline]
pub fn colors<'s>(&'s self) -> Box<Iterator<Item=Color> + 's> {
Box::new(self.regular_groups.iter().flat_map(|g| g.colors.iter().cloned()))
}
pub fn links<'s>(&'s self) -> Box<Iterator<Item=Box<Iterator<Item=Color> + 's>> + 's> {
Box::new(
self.regular_groups.iter().map(|g| {
Box::new(g.colors.iter().cloned()) as Box<Iterator<Item=Color>>
})
)
}
#[inline]
pub fn max_links(&self) -> usize {
self.regular_groups.iter().map(|g| g.size()).max().unwrap_or(0)
}
}
#[derive(Debug)]
pub struct SocketGroup {
pub(crate) id: u8,
pub(crate) colors: Vec<Color>,
}
impl SocketGroup {
#[inline]
pub fn size(&self) -> usize {
self.colors.len()
}
#[inline]
pub fn count_of(&self, color: Color) -> usize {
self.colors.iter().filter(|&&c| c == color).count()
}
}