bevy/crates/bevy_ecs/src/system
JaySpruce 0f2b2de333
Move some structs that impl Command to methods on World and EntityWorldMut (#16999)
## Objective

Commands were previously limited to structs that implemented `Command`.
Now there are blanket implementations for closures, which (in my
opinion) are generally preferable.

Internal commands within `commands/mod.rs` have been switched from
structs to closures, but there are a number of internal commands in
other areas of the engine that still use structs. I'd like to tidy these
up by moving their implementations to methods on
`World`/`EntityWorldMut` and changing `Commands` to use those methods
through closures.

This PR handles the following:
- `TriggerEvent` and `EmitDynamicTrigger` double as commands and helper
structs, and can just be moved to `World` methods.
- Four structs that enabled insertion/removal of components via
reflection. This functionality shouldn't be exclusive to commands, and
can be added to `EntityWorldMut`.
- Five structs that mostly just wrapped `World` methods, and can be
replaced with closures that do the same thing.

## Solution

- __Observer Triggers__ (`observer/trigger_event.rs` and
`observer/mod.rs`)
- Moved the internals of `TriggerEvent` to the `World` methods that used
it.
  - Replaced `EmitDynamicTrigger` with two `World` methods:
    - `trigger_targets_dynamic`
    - `trigger_targets_dynamic_ref`
- `TriggerTargets` was now the only thing in
`observer/trigger_event.rs`, so it's been moved to `observer/mod.rs` and
`trigger_event.rs` was deleted.
- __Reflection Insert/Remove__ (`reflect/entity_commands.rs`)
- Replaced the following `Command` impls with equivalent methods on
`EntityWorldMut`:
    - `InsertReflect` -> `insert_reflect`
    - `InsertReflectWithRegistry` -> `insert_reflect_with_registry`
    - `RemoveReflect` -> `remove_reflect`
    - `RemoveReflectWithRegistry` -> `remove_reflect_with_registry`
- __System Registration__ (`system/system_registry.rs`)
- The following `Command` impls just wrapped a `World` method and have
been replaced with closures:
    - `RunSystemWith`
    - `UnregisterSystem`
    - `RunSystemCachedWith`
    - `UnregisterSystemCached`
- `RegisterSystem` called a helper function that basically worked as a
constructor for `RegisteredSystem` and made sure it came with a marker
component. That helper function has been replaced with
`RegisteredSystem::new` and a `#[require]`.

## Possible Addition

The extension trait that adds the reflection commands,
`ReflectCommandExt`, isn't strictly necessary; we could just `impl
EntityCommands`. We could even move them to the same files as the main
impls and put it behind a `#[cfg]`.

The PR that added it [had a similar
conversation](https://github.com/bevyengine/bevy/pull/8895#discussion_r1234713671)
and decided to stick with the trait, but we could revisit it here if so
desired.
2024-12-29 22:18:53 +00:00
..
commands Move some structs that impl Command to methods on World and EntityWorldMut (#16999) 2024-12-29 22:18:53 +00:00
adapter_system.rs Add no_std support to bevy_ecs (#16758) 2024-12-17 21:40:36 +00:00
builder.rs Add no_std support to bevy_ecs (#16758) 2024-12-17 21:40:36 +00:00
combinator.rs Set panic as default fallible system param behavior (#16638) 2024-12-24 02:36:03 +00:00
exclusive_function_system.rs Add no_std support to bevy_ecs (#16758) 2024-12-17 21:40:36 +00:00
exclusive_system_param.rs Move all_tuples to a new crate (#16161) 2024-12-03 17:41:09 +00:00
function_system.rs Set panic as default fallible system param behavior (#16638) 2024-12-24 02:36:03 +00:00
input.rs Support SystemInput tuples up to 8 elements (#16814) 2024-12-15 05:59:34 +00:00
mod.rs Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
observer_system.rs Rename App/World::observe to add_observer, EntityWorldMut::observe_entity to observe. (#15754) 2024-10-09 15:39:29 +00:00
query.rs Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
schedule_system.rs Add no_std support to bevy_ecs (#16758) 2024-12-17 21:40:36 +00:00
system_name.rs Remove thiserror from bevy_ecs (#15774) 2024-10-09 14:20:58 +00:00
system_param.rs Set panic as default fallible system param behavior (#16638) 2024-12-24 02:36:03 +00:00
system_registry.rs Move some structs that impl Command to methods on World and EntityWorldMut (#16999) 2024-12-29 22:18:53 +00:00
system.rs Set panic as default fallible system param behavior (#16638) 2024-12-24 02:36:03 +00:00