diff --git a/crates/bevy_remote/src/builtin_methods.rs b/crates/bevy_remote/src/builtin_methods.rs index 08458da1c02cf..e61a668ed7f2d 100644 --- a/crates/bevy_remote/src/builtin_methods.rs +++ b/crates/bevy_remote/src/builtin_methods.rs @@ -48,6 +48,9 @@ pub const BRP_REPARENT_METHOD: &str = "bevy/reparent"; /// The method path for a `bevy/list` request. pub const BRP_LIST_METHOD: &str = "bevy/list"; +/// The method path for a `bevy/components` request. +pub const BRP_COMPONENTS_METHOD: &str = "bevy/components"; + /// The method path for a `bevy/get+watch` request. pub const BRP_GET_AND_WATCH_METHOD: &str = "bevy/get+watch"; @@ -793,6 +796,19 @@ pub fn process_remote_list_watching_request( } } +/// Handles a `bevy/components` request (list all world components) coming from a client. +pub fn process_remote_components_request(In(_): In>, world: &World) -> BrpResult { + let components = world.components(); + let mut response = BrpListResponse::default(); + + for component in components.iter() { + response.push(component.name().to_owned()); + } + + response.sort(); + serde_json::to_value(response).map_err(BrpError::internal) +} + /// Immutably retrieves an entity from the [`World`], returning an error if the /// entity isn't present. fn get_entity(world: &World, entity: Entity) -> Result, BrpError> { diff --git a/crates/bevy_remote/src/lib.rs b/crates/bevy_remote/src/lib.rs index 576ee7dbf18bc..ecdcfc1b72266 100644 --- a/crates/bevy_remote/src/lib.rs +++ b/crates/bevy_remote/src/lib.rs @@ -257,6 +257,14 @@ //! in the last tick. //! //! +//! ### bevy/components +//! +//! list all components present on the world. +//! +//! `params`: None +//! +//! `result`: An array of fully-qualified type names of all world components +//! //! ## Custom methods //! //! In addition to the provided methods, the Bevy Remote Protocol can be extended to include custom @@ -404,6 +412,10 @@ impl Default for RemotePlugin { builtin_methods::BRP_LIST_METHOD, builtin_methods::process_remote_list_request, ) + .with_method( + builtin_methods::BRP_COMPONENTS_METHOD, + builtin_methods::process_remote_components_request, + ) .with_watching_method( builtin_methods::BRP_GET_AND_WATCH_METHOD, builtin_methods::process_remote_get_watching_request,