From d878e2f8bdc2abe10679b027eed4ae07ed874702 Mon Sep 17 00:00:00 2001 From: poopy Date: Sun, 15 Sep 2024 17:30:53 +0200 Subject: [PATCH] add `allow_all` and `deny_all` methods to `DynamicSceneBuilder` (#15222) # Objective It would be convenient to be able to quickly deny or allow all components and resources on a `DynamicSceneBuilder` with a single method call. Context: #15210 renamed `{allow/deny}_all` to `{allow/deny}_all_components`. ## Solution Added two new methods to `DynamicSceneBuilder`, `allow_all` and `deny_all`, which affect both the component and resource filters. ## Showcase ### Before ```rust let builder = DynamicSceneBuilder::from_world(world) .deny_all_components() .deny_all_resources(); ``` ### After ```rust let builder = DynamicSceneBuilder::from_world(world).deny_all(); ``` --- .../bevy_scene/src/dynamic_scene_builder.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/bevy_scene/src/dynamic_scene_builder.rs b/crates/bevy_scene/src/dynamic_scene_builder.rs index 00d066d42f..e7d4519687 100644 --- a/crates/bevy_scene/src/dynamic_scene_builder.rs +++ b/crates/bevy_scene/src/dynamic_scene_builder.rs @@ -88,6 +88,26 @@ impl<'w> DynamicSceneBuilder<'w> { self } + /// Updates the filter to allow all component and resource types. + /// + /// This is useful for resetting the filter so that types may be selectively denied + /// with [`deny_component`](`Self::deny_component`) and [`deny_resource`](`Self::deny_resource`). + pub fn allow_all(mut self) -> Self { + self.component_filter = SceneFilter::allow_all(); + self.resource_filter = SceneFilter::allow_all(); + self + } + + /// Updates the filter to deny all component and resource types. + /// + /// This is useful for resetting the filter so that types may be selectively allowed + /// with [`allow_component`](`Self::allow_component`) and [`allow_resource`](`Self::allow_resource`). + pub fn deny_all(mut self) -> Self { + self.component_filter = SceneFilter::deny_all(); + self.resource_filter = SceneFilter::deny_all(); + self + } + /// Allows the given component type, `T`, to be included in the generated scene. /// /// This method may be called multiple times for any number of components.