-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Refactor EntityEvent
to support ContainsEntity
#21408
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
base: main
Are you sure you want to change the base?
Conversation
It looks like your PR is a breaking change, but you didn't provide a migration guide. Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes. |
I'm reluctant to do this as it will break object safety. That will be a pretty widespread problem when trying to fix this though. |
It won't be needed with @cart 's suggestion. I'll revise the CL. How do we feel about immutable entity events though? |
Generally open to it, but haven't thought about this hard enough to be convinced that they're the only solution :) |
This reverts commit 1cee14f.
I've updated the PR with the simplified implementation. Great idea! :)
I'm open to suggestions! From my usage of the engine so far, I have yet to find a use case for propagating events, which as I understand, is the only reason entity events are mutable. So from my perspective, I could easily envision all entity events being immutable by default, and only mutable if If we do that, we could then implement |
This is related to #21384
Objective
The goal of this change is to enable
EntityEvent
to work with any Entity-like type which implementsContainsEntity
.Solution
EntityEvent::event_target
fromEntity
to&impl ContainsEntity
event_target().entity()
instead ofevent_target()
EntityEvent::event_target_mut
intoEntityEvent::set_event_target
I'm not fully happy with this solution yet, but I'm opening the PR to discuss the options from here.
Mainly the issue revolves around
set_event_target
. To make this work, we need the underlying type to be constructible from an entity. This may not always be safe from user's perspective (it wouldn't be withInstance<T>
for example).Based on my understanding of the system, an event's target is only mutated in the case of event propagation, which makes sense.
To work around this, I propose that we flag
EntityEvents
as immutable or not; or "not propagatable" or not (I'm open to other terminology! :P).This would allow us to implement
set_event_target
asunreachable()!
and throw an error instead if the user tries to propagate such an event. We could even maybe enforce this compile time but it'll require additional complexity (mostly in form of different permutations oftrigger_*
method family).Testing
test_derive_entity_event
to cover all permutations