diff --git a/rust-pvz-genetics/src/genetics/gene/mod.rs b/rust-pvz-genetics/src/genetics/gene/mod.rs index 5c10536..a2f79c1 100644 --- a/rust-pvz-genetics/src/genetics/gene/mod.rs +++ b/rust-pvz-genetics/src/genetics/gene/mod.rs @@ -7,22 +7,55 @@ 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 kind: GeneType, + pub sprite: Option, + pub get_child_position: fn(GeneType) -> Vector2 } impl Gene { - pub fn new(plant_source: GeneSource, place: GenePlace, kind: GeneType) -> Self { + 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(GeneType) -> 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(GeneType) -> Vector2) -> Self { + Self { + plant_source, + place, + kind, + sprite: Some(sprite), + get_child_position, + } + } + } diff --git a/rust-pvz-genetics/src/genetics/mod.rs b/rust-pvz-genetics/src/genetics/mod.rs index babea0a..fa7a2a1 100644 --- a/rust-pvz-genetics/src/genetics/mod.rs +++ b/rust-pvz-genetics/src/genetics/mod.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod tests; -pub mod plant_templates; +pub mod plants; pub mod gene; pub mod genome; pub mod arguments; diff --git a/rust-pvz-genetics/src/genetics/plant_templates.rs b/rust-pvz-genetics/src/genetics/plant_templates.rs deleted file mode 100644 index a3ac5ba..0000000 --- a/rust-pvz-genetics/src/genetics/plant_templates.rs +++ /dev/null @@ -1,49 +0,0 @@ -use crate::genetics::{flow::Flow, gene::{GenePlace,GeneSource, GeneType,Gene}, genome::Genome}; - -pub fn peashooter_template() -> Genome { - Genome::from_edges(vec![ - Gene::new(GeneSource::Peashooter,GenePlace::Root, GeneType::pure_producer(|_|{Flow::empty()})), - Gene::new(GeneSource::Peashooter,GenePlace::Stem, GeneType::fill_all()), - Gene::new(GeneSource::Peashooter,GenePlace::Head,GeneType::random_distribution()), - Gene::new(GeneSource::Peashooter,GenePlace::Leaf,GeneType::modifier(|_|{Flow::empty()})), - Gene::new(GeneSource::Peashooter,GenePlace::Eyes,GeneType::Structural), - Gene::new(GeneSource::Peashooter,GenePlace::Mouth,GeneType::consumer(|_|{})) - ],vec![ - (0,1), - (1,2), - (2,3), - (2,4), - (2,5), - ]).unwrap() -} - -pub fn sunflower_template() -> Genome { - Genome::from_edges(vec![ - Gene::new(GeneSource::Sunflower,GenePlace::Root, GeneType::Structural), - Gene::new(GeneSource::Sunflower,GenePlace::Stem, GeneType::Structural), - Gene::new(GeneSource::Sunflower,GenePlace::Head, GeneType::modifier(|_|{Flow::empty()})), - Gene::new(GeneSource::Sunflower,GenePlace::Eyes, GeneType::Structural), - Gene::new(GeneSource::Sunflower,GenePlace::Mouth, GeneType::consumer(|_|{})), - ], vec![ - (0,1), - (1,2), - (2,3), - (2,4), - ]).unwrap() -} - -pub fn cherry_bomb_template() -> Genome { - Genome::from_edges(vec![ - Gene::new(GeneSource::CherryBomb,GenePlace::Root, GeneType::modifier(|_|{Flow::empty()})), - Gene::new(GeneSource::CherryBomb,GenePlace::Head, GeneType::consumer(|_|{})), - Gene::new(GeneSource::CherryBomb,GenePlace::Head, GeneType::consumer(|_|{})), - Gene::new(GeneSource::CherryBomb,GenePlace::Face, GeneType::Structural), - Gene::new(GeneSource::CherryBomb,GenePlace::Face, GeneType::Structural), - ], vec![ - (0,1), - (0,2), - (1,3), - (2,4), - ]).unwrap() -} - diff --git a/rust-pvz-genetics/src/genetics/plants/cherry_bomb.rs b/rust-pvz-genetics/src/genetics/plants/cherry_bomb.rs new file mode 100644 index 0000000..e69de29 diff --git a/rust-pvz-genetics/src/genetics/plants/mod.rs b/rust-pvz-genetics/src/genetics/plants/mod.rs new file mode 100644 index 0000000..3605cfb --- /dev/null +++ b/rust-pvz-genetics/src/genetics/plants/mod.rs @@ -0,0 +1,3 @@ +pub mod peashooter; +pub mod sunflower; +pub mod cherry_bomb; diff --git a/rust-pvz-genetics/src/genetics/plants/peashooter.rs b/rust-pvz-genetics/src/genetics/plants/peashooter.rs new file mode 100644 index 0000000..336818b --- /dev/null +++ b/rust-pvz-genetics/src/genetics/plants/peashooter.rs @@ -0,0 +1,27 @@ +use crate::genetics::{gene::{Gene, GenePlace}, genome::Genome}; +use godot::builtin::Vector2; + +pub fn peashooter_template() -> Genome { + Genome::from_edges(vec![ + Gene::new() + ], vec![ + + ]) +} + +fn get_place_base(place: GenePlace) -> Vector2 { + Vector2::ZERO +} + +fn get_place_stem(place: GenePlace) -> Vector2 { + Vector2::ZERO +} + +fn get_place_head(place: GenePlace) -> Vector2 { + Vector2::ZERO +} + +fn get_place_leaf(place: GenePlace) -> Vector2 { + Vector2::ZERO +} + diff --git a/rust-pvz-genetics/src/genetics/plants/sunflower.rs b/rust-pvz-genetics/src/genetics/plants/sunflower.rs new file mode 100644 index 0000000..e69de29 diff --git a/rust-pvz-genetics/src/godot_wrapper/plant.rs b/rust-pvz-genetics/src/godot_wrapper/plant.rs index 0b63022..16517ce 100644 --- a/rust-pvz-genetics/src/godot_wrapper/plant.rs +++ b/rust-pvz-genetics/src/godot_wrapper/plant.rs @@ -1,7 +1,7 @@ use godot::prelude::*; use godot::classes::{Sprite2D,Node2D,INode2D}; -use crate::wrapper::godot_genome::GodotGenome; +use crate::godot_wrapper::godot_genome::GodotGenome; #[derive(GodotClass)] #[class(init,base=Node2D)]