Gene source and serde

This commit is contained in:
rendo 2026-04-01 09:06:25 +05:00
commit 264a8d9723
5 changed files with 55 additions and 31 deletions

View file

@ -4,7 +4,7 @@ use crate::genetics::flow::Flow;
#[derive(PartialEq,Eq,Clone)]
pub struct Gene {
pub plant_name: String,
pub plant_source: GeneSource,
pub place: String,
pub kind: GeneType
}
@ -13,6 +13,14 @@ pub struct GeneContext {
pub flow: Flow
}
#[derive(PartialEq,Eq,Clone,Copy)]
pub enum GeneSource {
Peashooter,
Sunflower,
CherryBomb,
PotatoMine,
}
/// GeneType is an enum that defines behaviour of gene.
#[derive(PartialEq,Eq,Clone)]
pub enum GeneType {
@ -67,18 +75,30 @@ pub enum ProduceDecision {
}
impl Gene {
pub fn new(plant_str: impl Into<String>, place_str: impl Into<String>, kind: GeneType) -> Self {
pub fn new(plant_source: GeneSource, place_str: impl Into<String>, kind: GeneType) -> Self {
Self {
plant_name: plant_str.into(),
plant_source,
place: place_str.into(),
kind,
}
}
}
impl Display for GeneSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f,"{}",match self {
GeneSource::Peashooter => "Peashooter",
GeneSource::Sunflower => "Sunflower",
GeneSource::CherryBomb => "CherryBomb",
GeneSource::PotatoMine => "PotatoMine",
});
Ok(())
}
}
impl Display for Gene {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f,"({}) {}",self.plant_name,self.place);
write!(f,"({}) {}",self.plant_source,self.place);
Ok(())
}
}
@ -121,3 +141,4 @@ impl GeneType {
ChildDistribution::All
}
}