use crate::components::CellState;
#[cfg(feature = "auto-coloring")]
use bevy::color::{
palettes::css::{AQUA, GOLD, WHITE},
Color,
};
use bevy::prelude::Component;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Component, Default)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub enum WireWorldCellState {
#[default]
Conductor,
ElectronHead,
ElectronTail,
}
impl CellState for WireWorldCellState {
fn new_cell_state<'a>(&self, neighbor_cells: impl Iterator<Item = &'a Self>) -> Self {
match self {
Self::Conductor => {
let electron_head_count =
neighbor_cells.filter(|&c| *c == Self::ElectronHead).count();
match electron_head_count {
1 | 2 => Self::ElectronHead,
_ => Self::Conductor,
}
}
Self::ElectronHead => Self::ElectronTail,
Self::ElectronTail => Self::Conductor,
}
}
#[cfg(feature = "auto-coloring")]
fn color(&self) -> Option<Color> {
Some(match self {
Self::Conductor => Color::Srgba(GOLD),
Self::ElectronHead => Color::Srgba(AQUA),
Self::ElectronTail => Color::Srgba(WHITE),
})
}
}