Big rework
This commit is contained in:
parent
bfce0362b9
commit
ba78ce8502
8 changed files with 67 additions and 53 deletions
|
|
@ -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<String>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub mod plant_templates;
|
||||
pub mod plants;
|
||||
pub mod gene;
|
||||
pub mod genome;
|
||||
pub mod arguments;
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
||||
0
rust-pvz-genetics/src/genetics/plants/cherry_bomb.rs
Normal file
0
rust-pvz-genetics/src/genetics/plants/cherry_bomb.rs
Normal file
3
rust-pvz-genetics/src/genetics/plants/mod.rs
Normal file
3
rust-pvz-genetics/src/genetics/plants/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod peashooter;
|
||||
pub mod sunflower;
|
||||
pub mod cherry_bomb;
|
||||
27
rust-pvz-genetics/src/genetics/plants/peashooter.rs
Normal file
27
rust-pvz-genetics/src/genetics/plants/peashooter.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
|
||||
0
rust-pvz-genetics/src/genetics/plants/sunflower.rs
Normal file
0
rust-pvz-genetics/src/genetics/plants/sunflower.rs
Normal file
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue