Use bundle wrappers to select the insert mode #19768
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Allow bundles to define their insert mode in a flexible but explicit way. More specifically this is a potential solution to #19715 and an alternative to #19726 as presented here.
This is a first step in that direction an doesn't provide a merging solution, it focuses on aligning existing
InsertMode
APIs to the proposed direction.Solution
The current insert APIs use a separate parameter to control the insert mode for the whole bundle:
The proposal changes this to allow each bundle to define its own insert mode. To keep things sane and flexible most bundles wouldn't actually use that capacity and instead would simply inherit the insert mode from their outer bundle (if one exists). To support that, we update the dynamic bundle trait:
The idea is that as
get_components
gets recursively called, the insert mode flows from outer bundles to inner bundles:Then, we can define new bundle types that wrap an inner bundle and override the insert mode:
Testing
WIP. For now my main concern are component hooks, the current structure is not designed to support multiple insert modes in a single insert call. For now I've left the hooks always enabled as if all components used
InsertMode::Replace
but that obviously is not acceptable as a final solution.Showcase
These changes in action would look like this:
We could deprecate
insert_if_new(bundle)
or keep it as a shorthand forinsert(IgnoreIfCollides(bundle))
.Future work
These changes would pave the way for a future
MergeIfCollides
, which we would use inSpawnRelated
: