diff --git a/examples/states_ui/credits.rs b/examples/states_ui/credits.rs index 01362ad993..4dd05846d4 100644 --- a/examples/states_ui/credits.rs +++ b/examples/states_ui/credits.rs @@ -6,7 +6,11 @@ use amethyst::{ winit::{MouseButton, VirtualKeyCode}, }; +<<<<<<< Updated upstream use crate::{menu::MainMenu, util::delete_hierarchy}; +======= +use crate::menu::MainMenu; +>>>>>>> Stashed changes // A simple 'Screen' State, only capable of loading/showing the prefab ui and registering simple // UI interactions (pressing escape or clicking anywhere). @@ -48,9 +52,12 @@ impl SimpleState for CreditsScreen { } fn on_stop(&mut self, data: StateData) { - if let Some(handler) = self.ui_handle { - delete_hierarchy(handler, data.world).expect("Failed to remove CreditScreen"); + if let Some(root_entity) = self.ui_handle { + data.world + .delete_entity(root_entity) + .expect("Failed to remove CreditScreen"); } + self.ui_handle = None; } } diff --git a/examples/states_ui/game.rs b/examples/states_ui/game.rs index 7b91fc1f2d..634f1b8c3f 100644 --- a/examples/states_ui/game.rs +++ b/examples/states_ui/game.rs @@ -1,4 +1,8 @@ +<<<<<<< Updated upstream use crate::{pause::PauseMenuState, util::delete_hierarchy}; +======= +use crate::pause::PauseMenuState; +>>>>>>> Stashed changes use amethyst::{ audio::output::init_output, core::Time, @@ -46,9 +50,12 @@ impl SimpleState for Game { } fn on_stop(&mut self, data: StateData<'_, GameData<'_, '_>>) { - if let Some(entity) = self.ui_root { - delete_hierarchy(entity, data.world).expect("Failed to remove Game Screen"); + if let Some(root_entity) = self.ui_root { + data.world + .delete_entity(root_entity) + .expect("Failed to remove Game Screen"); } + self.ui_root = None; self.fps_display = None; self.random_text = None; diff --git a/examples/states_ui/main.rs b/examples/states_ui/main.rs index 1d7c7e1723..14e053515b 100644 --- a/examples/states_ui/main.rs +++ b/examples/states_ui/main.rs @@ -14,7 +14,6 @@ mod events; mod game; mod menu; mod pause; -mod util; mod welcome; /// Quick overview what you can do when running this example: diff --git a/examples/states_ui/menu.rs b/examples/states_ui/menu.rs index 008ebadde6..62041266c9 100644 --- a/examples/states_ui/menu.rs +++ b/examples/states_ui/menu.rs @@ -92,9 +92,12 @@ impl SimpleState for MainMenu { fn on_stop(&mut self, data: StateData) { // after destroying the current UI, invalidate references as well (makes things cleaner) - if let Some(entity) = self.ui_root { - delete_hierarchy(entity, data.world).expect("Failed to remove MainMenu"); + if let Some(root_entity) = self.ui_root { + data.world + .delete_entity(root_entity) + .expect("Failed to remove MainMenu"); } + self.ui_root = None; self.button_start = None; self.button_load = None; diff --git a/examples/states_ui/util.rs b/examples/states_ui/util.rs deleted file mode 100644 index ff10407ed8..0000000000 --- a/examples/states_ui/util.rs +++ /dev/null @@ -1,25 +0,0 @@ -use amethyst::{ - core::transform::ParentHierarchy, - ecs::{ - error::WrongGeneration, - prelude::{Entity, World, WorldExt}, - }, -}; - -use std::iter; - -/// delete the specified root entity and all of its descendents as specified -/// by the Parent component and maintained by the ParentHierarchy resource -// from https://github.com/amethyst/evoli src/utils/hierarchy_util.rs -pub fn delete_hierarchy(root: Entity, world: &mut World) -> Result<(), WrongGeneration> { - let entities = { - iter::once(root) - .chain( - world - .read_resource::() - .all_children_iter(root), - ) - .collect::>() - }; - world.delete_entities(&entities) -} diff --git a/examples/states_ui/welcome.rs b/examples/states_ui/welcome.rs index 8801412152..6353d68223 100644 --- a/examples/states_ui/welcome.rs +++ b/examples/states_ui/welcome.rs @@ -6,7 +6,6 @@ use amethyst::{ winit::{MouseButton, VirtualKeyCode}, }; -use crate::util::delete_hierarchy; #[derive(Default, Debug)] pub struct WelcomeScreen { @@ -43,9 +42,12 @@ impl SimpleState for WelcomeScreen { } fn on_stop(&mut self, data: StateData) { - if let Some(handler) = self.ui_handle { - delete_hierarchy(handler, data.world).expect("Failed to remove WelcomeScreen"); + if let Some(root_entity) = self.ui_handle { + data.world + .delete_entity(root_entity) + .expect("Failed to remove WelcomeScreen"); } + self.ui_handle = None; } }