use crate::components::CellState;
#[cfg(feature = "auto-coloring")]
use bevy::prelude::Color;
use bevy::prelude::Component;
use std::ops::{Deref, DerefMut};
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Component)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub struct ConwayCell4555State(pub bool);
impl CellState for ConwayCell4555State {
fn new_cell_state<'a>(&self, neighbor_cells: impl Iterator<Item = &'a Self>) -> Self {
let alive_cells_count = neighbor_cells.filter(|&c| c.0).count();
let alive = matches!((self.0, alive_cells_count), (true, 4 | 5) | (false, 5));
Self(alive)
}
#[cfg(feature = "auto-coloring")]
fn color(&self) -> Option<Color> {
if self.0 {
Some(Color::WHITE)
} else {
None
}
}
}
impl Deref for ConwayCell4555State {
type Target = bool;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for ConwayCell4555State {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl From<bool> for ConwayCell4555State {
fn from(val: bool) -> Self {
Self(val)
}
}