51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
use godot::prelude::*;
|
|
use godot::classes::{Node,INode};
|
|
|
|
use crate::genetics::genome::Genome;
|
|
use crate::genetics::plants::peashooter::peashooter_template;
|
|
use crate::genetics::plants::sunflower::sunflower_template;
|
|
|
|
#[derive(GodotConvert, Var, Export, Default, Clone)]
|
|
#[godot(via = GString)]
|
|
pub enum PlantType {
|
|
#[default] // Rust standard attribute, not godot-rust.
|
|
None,
|
|
Peashooter,
|
|
Sunflower,
|
|
CherryBomb,
|
|
}
|
|
|
|
#[derive(GodotClass)]
|
|
#[class(base=Node)]
|
|
pub struct GodotGenome {
|
|
#[export]
|
|
from_plant: PlantType,
|
|
genome: Option<Genome>,
|
|
base: Base<Node>
|
|
}
|
|
|
|
#[godot_api]
|
|
impl INode for GodotGenome {
|
|
fn init(base: Base<Node>) -> Self {
|
|
Self {
|
|
from_plant: PlantType::None,
|
|
genome: None,
|
|
base
|
|
}
|
|
}
|
|
fn ready(&mut self) {
|
|
self.genome = match self.from_plant {
|
|
PlantType::Peashooter => Some(peashooter_template()),
|
|
PlantType::Sunflower => Some(sunflower_template()),
|
|
PlantType::CherryBomb => Some(peashooter_template()),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
impl GodotGenome {
|
|
pub fn get_genome(&self) -> Option<Genome> {
|
|
self.genome.clone()
|
|
}
|
|
}
|