Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bevy/components method to BRP, which lists all world components #16626

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/bevy_remote/src/builtin_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<Option<Value>>, 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<EntityRef<'_>, BrpError> {
Expand Down
12 changes: 12 additions & 0 deletions crates/bevy_remote/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading