This commit is contained in:
Otto 2024-08-11 23:23:54 +03:00
parent 55c86b22ef
commit f14cd281b7

View file

@ -11,6 +11,7 @@ struct Manager {
beat_count: i32, beat_count: i32,
#[var] #[var]
scenes: Array<Gd<PackedScene>>, scenes: Array<Gd<PackedScene>>,
current_scene: Option<i32>,
instanced_scenes: Vec<Gd<Node>>, instanced_scenes: Vec<Gd<Node>>,
base: Base<Node> base: Base<Node>
} }
@ -22,6 +23,7 @@ impl INode for Manager {
bgm: GString::from(""), bgm: GString::from(""),
beat_count: 0, beat_count: 0,
scenes: Array::new(), scenes: Array::new(),
current_scene: None,
instanced_scenes: Vec::new(), instanced_scenes: Vec::new(),
base, base,
} }
@ -43,7 +45,23 @@ impl INode for Manager {
impl Manager { impl Manager {
#[func] #[func]
fn set_scene(&mut self, number: i32) { fn set_scene(&mut self, number: i32) {
let current_scene = self.current_scene;
let scene = self.instanced_scenes[number as usize].clone(); // Memory leak??? Idk let scene = self.instanced_scenes[number as usize].clone(); // Memory leak??? Idk
self.current_scene = Some(self.instanced_scenes[number as usize].get_index());
let node: Option<Gd<Node>>;
match current_scene {
Some(_) => {
node = self.base_mut().get_child(current_scene.unwrap());
match node {
Some(value) => {
value.upcast::<Node>().queue_free();
}
None => {}
};
}
None => {}
}
self.base_mut().add_child(scene); self.base_mut().add_child(scene);
} }