Gimme a scream Corey
This commit is contained in:
parent
ea0c1357cf
commit
33eb6187a0
7 changed files with 66 additions and 18 deletions
|
|
@ -1,14 +0,0 @@
|
|||
[configuration]
|
||||
entry_symbol = "gdext_rust_init"
|
||||
compatibility_minimum = 4.6
|
||||
reloadable = true
|
||||
|
||||
[libraries]
|
||||
linux.debug.x86_64 = "res://../rust/target/debug/librust-pvz-genetics.so"
|
||||
linux.release.x86_64 = "res://../rust/target/release/librust-pvz-genetics.so"
|
||||
windows.debug.x86_64 = "res://../rust/target/debug/rust-pvz-genetics.dll"
|
||||
windows.release.x86_64 = "res://../rust/target/release/rust-pvz-genetics.dll"
|
||||
macos.debug = "res://../rust/target/debug/librust-pvz-genetics.dylib"
|
||||
macos.release = "res://../rust/target/release/librust-pvz-genetics.dylib"
|
||||
macos.debug.arm64 = "res://../rust/target/debug/librust-pvz-genetics.dylib"
|
||||
macos.release.arm64 = "res://../rust/target/release/librust-pvz-genetics.dylib"
|
||||
14
godot-pvz-genetics/genetics.gdextension
Normal file
14
godot-pvz-genetics/genetics.gdextension
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[configuration]
|
||||
entry_symbol = "gdext_rust_init"
|
||||
compatibility_minimum = 4.2
|
||||
reloadable = true
|
||||
|
||||
[libraries]
|
||||
linux.debug.x86_64 = "res://../rust-pvz-genetics/target/debug/librust_pvz_genetics.so"
|
||||
linux.release.x86_64 = "res://../rust-pvz-genetics/target/release/librust_pvz_genetics.so"
|
||||
windows.debug.x86_64 = "res://../rust-pvz-genetics/target/debug/rust_pvz_genetics.dll"
|
||||
windows.release.x86_64 = "res://../rust-pvz-genetics/target/release/rust_pvz_genetics.dll"
|
||||
macos.debug = "res://../rust-pvz-genetics/target/debug/librust_pvz_genetics.dylib"
|
||||
macos.release = "res://../rust-pvz-genetics/target/release/librust_pvz_genetics.dylib"
|
||||
macos.debug.arm64 = "res://../rust-pvz-genetics/target/debug/librust_pvz_genetics.dylib"
|
||||
macos.release.arm64 = "res://../rust-pvz-genetics/target/release/librust_pvz_genetics.dylib"
|
||||
1
godot-pvz-genetics/genetics.gdextension.uid
Normal file
1
godot-pvz-genetics/genetics.gdextension.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bpmsf3vf4h188
|
||||
|
|
@ -11,6 +11,7 @@ config_version=5
|
|||
[application]
|
||||
|
||||
config/name="godot-pvz-genetics"
|
||||
run/main_scene="uid://bh0bpqalry5my"
|
||||
config/features=PackedStringArray("4.6", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
|
|
|
|||
9
godot-pvz-genetics/scenes/world.tscn
Normal file
9
godot-pvz-genetics/scenes/world.tscn
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[gd_scene format=3 uid="uid://bh0bpqalry5my"]
|
||||
|
||||
[node name="World" type="Node2D" unique_id=1672334032]
|
||||
|
||||
[node name="GodotGenome" type="GodotGenome" parent="." unique_id=1134546682]
|
||||
from_plant = "CherryBomb"
|
||||
|
||||
[node name="Plant" type="Plant" parent="." unique_id=1494298949 node_paths=PackedStringArray("genome")]
|
||||
genome = NodePath("../GodotGenome")
|
||||
|
|
@ -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