bevy/crates
Bob Gardner ec1aa48fc6
Created an EventMutator for when you want to mutate an event before reading (#13818)
# Objective

- Often in games you will want to create chains of systems that modify
some event. For example, a chain of damage systems that handle a
DamageEvent and modify the underlying value before the health system
finally consumes the event. Right now this requires either:

* Using a component added to the entity
* Consuming and refiring events

Neither is ideal when really all we want to do is read the events value,
modify it, and write it back.

## Solution

- Create an EventMutator class similar to EventReader but with ResMut<T>
and iterators that return &mut so that events can be mutated.

## Testing

- I replicated all the existing tests for EventReader to make sure
behavior was the same (I believe) and added a number of tests specific
to testing that 1) events can actually be mutated, and that 2)
EventReader sees changes from EventMutator for events it hasn't already
seen.

## Migration Guide

Users currently using `ManualEventReader` should use `EventCursor`
instead. `ManualEventReader` will be removed in Bevy 0.16. Additionally,
`Events::get_reader` has been replaced by `Events::get_cursor`.

Users currently directly accessing the `Events` resource for mutation
should move to `EventMutator` if possible.

---------

Co-authored-by: poopy <gonesbird@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2024-07-08 14:53:06 +00:00
..
bevy_a11y Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_animation Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_app Created an EventMutator for when you want to mutate an event before reading (#13818) 2024-07-08 14:53:06 +00:00
bevy_asset Created an EventMutator for when you want to mutate an event before reading (#13818) 2024-07-08 14:53:06 +00:00
bevy_audio Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_color Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_core Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_core_pipeline Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_derive Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_dev_tools Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_diagnostic Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_dylib Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_dynamic_plugin Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_ecs Created an EventMutator for when you want to mutate an event before reading (#13818) 2024-07-08 14:53:06 +00:00
bevy_encase_derive Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_gilrs Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_gizmos Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_gltf Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_hierarchy Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_input Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_internal Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_log Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_macro_utils Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_math Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_mikktspace Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_pbr Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_picking Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_ptr Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_reflect Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_render Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_scene Created an EventMutator for when you want to mutate an event before reading (#13818) 2024-07-08 14:53:06 +00:00
bevy_sprite Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_state Created an EventMutator for when you want to mutate an event before reading (#13818) 2024-07-08 14:53:06 +00:00
bevy_tasks Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_text Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_time Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_transform Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_ui Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_utils Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_window Bump Version after Release (#14219) 2024-07-08 12:54:08 +00:00
bevy_winit Created an EventMutator for when you want to mutate an event before reading (#13818) 2024-07-08 14:53:06 +00:00