Fix #7
This commit is contained in:
parent
55c86b22ef
commit
f14cd281b7
1 changed files with 18 additions and 0 deletions
|
@ -11,6 +11,7 @@ struct Manager {
|
|||
beat_count: i32,
|
||||
#[var]
|
||||
scenes: Array<Gd<PackedScene>>,
|
||||
current_scene: Option<i32>,
|
||||
instanced_scenes: Vec<Gd<Node>>,
|
||||
base: Base<Node>
|
||||
}
|
||||
|
@ -22,6 +23,7 @@ impl INode for Manager {
|
|||
bgm: GString::from(""),
|
||||
beat_count: 0,
|
||||
scenes: Array::new(),
|
||||
current_scene: None,
|
||||
instanced_scenes: Vec::new(),
|
||||
base,
|
||||
}
|
||||
|
@ -43,7 +45,23 @@ impl INode for Manager {
|
|||
impl Manager {
|
||||
#[func]
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue