wrapper pt1

This commit is contained in:
Rendo 2026-04-02 00:32:52 +05:00
commit 219fc97519
6 changed files with 58 additions and 4 deletions

View file

@ -6,6 +6,8 @@ pub enum GenePlace {
Stem,
Head,
Face,
Mouth,
Eyes,
Leaf,
}
@ -17,6 +19,8 @@ impl Display for GenePlace {
GenePlace::Head => "Head",
GenePlace::Face => "Face",
GenePlace::Leaf => "Leaf",
GenePlace::Eyes => "Eyes",
GenePlace::Mouth => "Mouth",
})
}
}
@ -29,6 +33,8 @@ impl GenePlace {
GenePlace::Head => GenePlace::Head,
GenePlace::Face => GenePlace::Face,
GenePlace::Leaf => GenePlace::Leaf,
GenePlace::Mouth => GenePlace::Face,
GenePlace::Eyes => GenePlace::Face,
}
}
}

View file

@ -2,7 +2,7 @@ use std::fmt::Display;
use crate::genetics::gene::Gene;
#[derive(Clone,PartialEq,Eq)]
#[derive(Default,Clone,PartialEq,Eq)]
pub struct Genome {
pub(crate) graph: Vec<(Gene,Vec<usize>)>,
}

View file

@ -6,12 +6,14 @@ pub fn peashooter_template() -> Genome {
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::Face,GeneType::consumer(|_|{}))
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,4),
(2,5),
]).unwrap()
}
@ -20,11 +22,13 @@ pub fn sunflower_template() -> Genome {
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::Face, GeneType::consumer(|_|{})),
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()
}

View file

@ -1,2 +1,11 @@
use godot::prelude::*;
pub mod genetics;
pub mod wrapper;
struct PVZGenetics;
#[gdextension]
unsafe impl ExtensionLibrary for PVZGenetics {
}

View file

@ -0,0 +1,34 @@
use godot::prelude::*;
use godot::classes::{Node,INode};
use crate::genetics::genome::Genome;
#[derive(GodotConvert, Var, Export, Default, Clone)]
#[godot(via = GString)]
pub enum PlantType {
#[default] // Rust standard attribute, not godot-rust.
None,
Peashooter,
Sunflower,
}
#[derive(GodotClass)]
#[class(base=Node)]
struct GodotGenome {
#[export]
from_plant: PlantType,
genome: Genome,
base: Base<Node>
}
#[godot_api]
impl INode for GodotGenome {
fn init(base: Base<Node>) -> Self {
Self {
from_plant: PlantType::None,
genome: Genome::new(),
base
}
}
}

View file

@ -0,0 +1 @@
pub mod godot_genome;