Skip to content

Commit

Permalink
fix: add reflect to SceneInstanceReady and other observers/events (b…
Browse files Browse the repository at this point in the history
…evyengine#16018)

# Objective

Built-in observers & events should be `Reflect` so that components that
interact with them can be serialized in scenes. This is a similar pr to
bevyengine#14259.
  • Loading branch information
mrchantey authored Oct 20, 2024
1 parent 26a5f7f commit 75096fb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{Asset, AssetId, AssetLoadError, AssetPath, UntypedAssetId};
use bevy_ecs::event::Event;
use bevy_reflect::Reflect;
use core::fmt::Debug;

/// An event emitted when a specific [`Asset`] fails to load.
Expand Down Expand Up @@ -42,7 +43,7 @@ impl<A: Asset> From<&AssetLoadFailedEvent<A>> for UntypedAssetLoadFailedEvent {
}

/// Events that occur for a specific loaded [`Asset`], such as "value changed" events and "dependency" events.
#[derive(Event)]
#[derive(Event, Reflect)]
pub enum AssetEvent<A: Asset> {
/// Emitted whenever an [`Asset`] is added.
Added { id: AssetId<A> },
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/removal_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::{

use derive_more::derive::Into;

#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
use core::{
fmt::Debug,
iter,
Expand All @@ -24,6 +26,8 @@ use core::{
/// Wrapper around [`Entity`] for [`RemovedComponents`].
/// Internally, `RemovedComponents` uses these as an `Events<RemovedComponentEntity>`.
#[derive(Event, Debug, Clone, Into)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
pub struct RemovedComponentEntity(Entity);

/// Wrapper around a [`EventCursor<RemovedComponentEntity>`] so that we
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_hierarchy/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use bevy_ecs::{event::Event, prelude::Entity};
use bevy_reflect::Reflect;

/// An [`Event`] that is fired whenever there is a change in the world's hierarchy.
///
/// [`Event`]: bevy_ecs::event::Event
#[derive(Event, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "reflect", derive(Reflect), reflect(Debug, PartialEq))]
pub enum HierarchyEvent {
/// Fired whenever an [`Entity`] is added as a child to a parent.
ChildAdded {
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_input/src/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,7 @@ pub fn gamepad_event_processing_system(

/// The intensity at which a gamepad's force-feedback motors may rumble.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
pub struct GamepadRumbleIntensity {
/// The rumble intensity of the strong gamepad motor.
///
Expand Down Expand Up @@ -1581,6 +1582,7 @@ impl GamepadRumbleIntensity {
#[doc(alias = "vibration")]
#[doc(alias = "vibrate")]
#[derive(Event, Clone)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
pub enum GamepadRumbleRequest {
/// Add a rumble to the given gamepad.
///
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_picking/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ pub mod prelude {
/// Note that systems reading these events in [`PreUpdate`](bevy_app) will not report ordering
/// ambiguities with picking backends. Take care to ensure such systems are explicitly ordered
/// against [`PickSet::Backends`](crate), or better, avoid reading `PointerHits` in `PreUpdate`.
#[derive(Event, Debug, Clone)]
#[derive(Event, Debug, Clone, Reflect)]
#[reflect(Debug)]
pub struct PointerHits {
/// The pointer associated with this hit test.
pub pointer: prelude::PointerId,
Expand Down
7 changes: 5 additions & 2 deletions crates/bevy_scene/src/scene_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bevy_ecs::{
world::{Command, Mut, World},
};
use bevy_hierarchy::{AddChild, BuildChildren, DespawnRecursiveExt, Parent};
use bevy_reflect::Reflect;
use bevy_utils::{HashMap, HashSet};
use derive_more::derive::{Display, Error};
use uuid::Uuid;
Expand All @@ -17,7 +18,8 @@ use uuid::Uuid;
/// See also [`Trigger`], [`SceneSpawner::instance_is_ready`].
///
/// [`Trigger`]: bevy_ecs::observer::Trigger
#[derive(Clone, Copy, Debug, Eq, PartialEq, Event)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Event, Reflect)]
#[reflect(Debug, PartialEq)]
pub struct SceneInstanceReady {
/// Instance which has been spawned.
pub instance_id: InstanceId,
Expand All @@ -31,7 +33,8 @@ pub struct InstanceInfo {
}

/// Unique id identifying a scene instance.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Reflect)]
#[reflect(Debug, PartialEq, Hash)]
pub struct InstanceId(Uuid);

impl InstanceId {
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
extern crate alloc;

use bevy_derive::Deref;
use bevy_reflect::prelude::ReflectDefault;
use bevy_reflect::Reflect;
use bevy_window::{RawHandleWrapperHolder, WindowEvent};
use core::marker::PhantomData;
use winit::event_loop::EventLoop;
Expand Down Expand Up @@ -149,7 +151,8 @@ impl<T: Event> Plugin for WinitPlugin<T> {

/// The default event that can be used to wake the window loop
/// Wakes up the loop if in wait state
#[derive(Debug, Default, Clone, Copy, Event)]
#[derive(Debug, Default, Clone, Copy, Event, Reflect)]
#[reflect(Debug, Default)]
pub struct WakeUp;

/// A wrapper type around [`winit::event_loop::EventLoopProxy`] with the specific
Expand Down

0 comments on commit 75096fb

Please sign in to comment.