-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
BRP resource methods #17423
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
BRP resource methods #17423
Conversation
|
This looks good to me. Excited to see these new methods implemented. Do we want to consider renaming the methods to be a little more hierarchical in the future or maybe some other scheme? For example:
I feel like they may get a little unwieldy over time as more and more methods are added. |
This is a very good idea. I'll change them when I have time :) (I guess there's also the question of which other methods, if any, should get moved to the |
alice-i-cecile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Straightforward, tested and uncontroversially useful. Thanks!
|
@Leinnan I actually need a second review over here. Can you do a pass on this? |
|
|
||
| /// Given a resource's type path, return the associated [`TypeRegistration`] from the given | ||
| /// `type_registry` if possible. | ||
| fn get_resource_type_registration<'r>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really minor: this could be imho named get_type_registration since it would work the same way for the non resource type. In case that is changed, change also the resource_path argument name.
Leinnan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1997 if you'd like to help out. |
Objective
So far, built-in BRP methods allow users to interact with entities' components, but global resources have remained beyond its reach. The goal of this PR is to take the first steps in rectifying this shortfall.
Solution
Added five new default methods to BRP:
bevy/get_resource: Extracts the value of a given resource from the world.bevy/insert_resource: Serializes an input value to a given resource type and inserts it into the world.bevy/remove_resource: Removes the given resource from the world.bevy/mutate_resource: Replaces the value of a field in a given resource with the result of serializing a given input value.bevy/list_resources: Lists all resources in the type registry with an availableReflectResource.Testing
Added a test resource to the
serverexample scene that you can use to mess around with the new BRP methods.Showcase
Resources can now be retrieved and manipulated remotely using a handful of new BRP methods. For example, a resource that looks like this:
can be manipulated remotely as follows.
Retrieving the value of the resource:
{ "jsonrpc": "2.0", "id": 1, "method": "bevy/get_resource", "params": { "resource": "path::to::my::module::PlayerSpawnSettings" } }Inserting a resource value into the world:
{ "jsonrpc": "2.0", "id": 2, "method": "bevy/insert_resource", "params": { "resource": "path::to::my::module::PlayerSpawnSettings", "value": { "location": [ 2.5, 2.5 ], "lives": 25 } } }Removing the resource from the world:
{ "jsonrpc": "2.0", "id": 3, "method": "bevy/remove_resource", "params": { "resource": "path::to::my::module::PlayerSpawnSettings" } }Mutating a field of the resource specified by a path:
{ "jsonrpc": "2.0", "id": 4, "method": "bevy/mutate_resource", "params": { "resource": "path::to::my::module::PlayerSpawnSettings", "path": ".location.x", "value": -3.0 } }Listing all manipulable resources in the type registry:
{ "jsonrpc": "2.0", "id": 5, "method": "bevy/list_resources" }