genetics-vs-zombies/rust-pvz-genetics/src/genetics/gene/mod.rs
2026-04-05 22:02:45 +05:00

67 lines
1.7 KiB
Rust

use std::fmt::Display;
pub mod gene_types;
pub mod gene_place;
pub mod gene_source;
pub use gene_types::GeneType;
pub use gene_source::GeneSource;
pub use gene_place::GenePlace;
use godot::builtin::Vector2;
#[derive(PartialEq,Eq,Clone)]
pub struct Gene {
pub plant_source: GeneSource,
pub place: GenePlace,
pub kind: GeneType,
pub sprite: Option<String>,
pub get_child_position: fn(GenePlace) -> Vector2
}
impl Gene {
pub fn invisible(plant_source: GeneSource,place: GenePlace,kind: GeneType) -> Self {
Self {
plant_source,
place,
kind,
sprite: None,
get_child_position: |_| Vector2::ZERO,
}
}
pub fn structural(plant_source: GeneSource, place: GenePlace, kind: GeneType, get_child_position: fn(GenePlace) -> Vector2) -> Self {
Self {
plant_source,
place,
kind,
sprite: None,
get_child_position,
}
}
pub fn visible(plant_source: GeneSource, place: GenePlace, kind: GeneType, sprite: String) -> Self {
Self {
plant_source,
place,
kind,
sprite: Some(sprite),
get_child_position: |_| Vector2::ZERO,
}
}
pub fn new(plant_source: GeneSource, place: GenePlace, kind: GeneType, sprite: String, get_child_position: fn(GenePlace) -> Vector2) -> Self {
Self {
plant_source,
place,
kind,
sprite: Some(sprite),
get_child_position,
}
}
}
impl Display for Gene {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f,"({}) {}",self.plant_source,self.place)
}
}