Small fixes
This commit is contained in:
parent
33eb6187a0
commit
bfce0362b9
4 changed files with 2 additions and 1 deletions
50
rust-pvz-genetics/src/godot_wrapper/godot_genome.rs
Normal file
50
rust-pvz-genetics/src/godot_wrapper/godot_genome.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
use godot::prelude::*;
|
||||
use godot::classes::{Node,INode};
|
||||
|
||||
use crate::genetics::genome::Genome;
|
||||
use crate::genetics::plant_templates::{cherry_bomb_template, peashooter_template, 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(cherry_bomb_template()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl GodotGenome {
|
||||
pub fn get_genome(&self) -> Option<Genome> {
|
||||
self.genome.clone()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue