-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
command based entry api with EntityCommands::entry
#15274
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
Conversation
Can you say more about why this isn't an enum? I quite liked that design from the standard library and would prefer it here too. |
I don't think we can know if the component is present is all (not before actually executing the commands), so we can't know if it should be the |
Right, the deferred nature of it complicates things. We'd want to change which commands get queued or executed based on a branch that's taken later, which is way harder. |
Altough, this would work commands
.entity(entity)
.entry::<MyComponent>(|entry| {
// use entry as you would `EntityWorldMut::entry`
}); |
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.
I really like this. I think we should also add an or_from_world
variant, and I have another tiny suggestion.
wait, it says the "expect" thingy is experimental, I'll just revert that I think |
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.
We can bump the MSRV and use expect
, but I won't block on that being done in this PR. See #15118 for more info.
I'll merge this by next Monday at the latest.
If |
Even with access to that, it's still not correct. That would give you data about the state at the time the command is sent. But what we need is information at the time the command is evaluated, which may not match. |
Aah yea, good point |
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.
Lovely bit of API! Could we remove the _if_new
family of methods in the same PR, @alice-i-cecile? I would like to not have two ways of doing the same thing. _if_new
has not landed in a release yet, so no need to deprecate it.
Edit: nvm, this API does not work with bundles. In that case, could you add some breadcrumbs to _if_new
about using this API for Component
and some breadcrumbs here pointing to _if_new
for Bundle
s?
Yep, I'll do that once I get home |
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.
Thanks! Left some grammar corrections, then this is good to go :)
Co-authored-by: Jan Hohenheim <[email protected]>
Co-authored-by: Jan Hohenheim <[email protected]>
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.
Thanks for addressing my comments :)
Co-authored-by: Jan Hohenheim <[email protected]>
Should I add |
Ah heck, |
That'd be nice, yes :) |
This reverts commit d3eb64e.
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.
Maybe for completeness we should also have or_try_insert_with
?
Objective
It's convenient to be able to modify a component if it exist, and insert a default value if it doesn't. You can already do most of this with
EntityCommands::insert_if_new
, and all of this using a custom command. However, that does not spark joy in my opinion.Closes #10669
Solution
Introduce a new commands type
EntityEntryCommands
, along with a method to access it,EntityCommands::entry
.EntityEntryCommands
exposes a subset of the entry API (and_modify
,or_insert
, etc), however it's not an enum so it doesn't allow pattern matching. Also,or_insert
won't return the component because it's all based on commands.Testing
Added a new test
entity_commands_entry
.Showcase