Gimme a scream Corey
This commit is contained in:
parent
ea0c1357cf
commit
33eb6187a0
7 changed files with 66 additions and 18 deletions
|
|
@ -2,6 +2,7 @@ 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)]
|
||||
|
|
@ -10,6 +11,7 @@ pub enum PlantType {
|
|||
None,
|
||||
Peashooter,
|
||||
Sunflower,
|
||||
CherryBomb,
|
||||
}
|
||||
|
||||
#[derive(GodotClass)]
|
||||
|
|
@ -17,7 +19,7 @@ pub enum PlantType {
|
|||
pub struct GodotGenome {
|
||||
#[export]
|
||||
from_plant: PlantType,
|
||||
genome: Genome,
|
||||
genome: Option<Genome>,
|
||||
base: Base<Node>
|
||||
}
|
||||
|
||||
|
|
@ -26,9 +28,23 @@ impl INode for GodotGenome {
|
|||
fn init(base: Base<Node>) -> Self {
|
||||
Self {
|
||||
from_plant: PlantType::None,
|
||||
genome: Genome::new(),
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use godot::prelude::*;
|
||||
use godot::classes::{Node2D,INode2D};
|
||||
use godot::classes::{Sprite2D,Node2D,INode2D};
|
||||
|
||||
use crate::wrapper::godot_genome::GodotGenome;
|
||||
|
||||
|
|
@ -7,11 +7,32 @@ use crate::wrapper::godot_genome::GodotGenome;
|
|||
#[class(init,base=Node2D)]
|
||||
pub struct Plant {
|
||||
#[export]
|
||||
genome_path: NodePath,
|
||||
genome: Option<Gd<GodotGenome>>,
|
||||
base: Base<Node2D>,
|
||||
}
|
||||
|
||||
#[godot_api]
|
||||
impl INode2D for Plant {
|
||||
fn ready(&mut self) {
|
||||
let Some(genome) = self.genome.clone() else { return; };
|
||||
|
||||
let Some(graph )= genome.bind().get_genome() else { return; };
|
||||
|
||||
let mut children = {
|
||||
let mut result = Vec::new();
|
||||
for _ in 0..graph.graph.len() {
|
||||
result.push(Sprite2D::new_alloc());
|
||||
}
|
||||
result
|
||||
};
|
||||
for i in 0..graph.graph.len() {
|
||||
children[i].set_name(&graph.graph[i].0.place.to_string());
|
||||
for edge in &graph.graph[i].1 {
|
||||
let edge_handle = children[*edge].clone();
|
||||
children[i].add_child(&edge_handle);
|
||||
}
|
||||
}
|
||||
|
||||
self.base_mut().add_child(&children[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue