-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
64 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 12 additions & 2 deletions
14
crates/beet_ecs/src/lifecycle/actions/lifecycle_actions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
use bevy::prelude::*; | ||
use bevy::reflect::GetTypeRegistration; | ||
|
||
/// Minimal traits generally required for an action component. | ||
pub trait GenericActionComponent: | ||
Clone + Component + FromReflect + GetTypeRegistration | ||
Clone + Component + FromReflect + GetTypeRegistration | ||
{ | ||
} | ||
impl<T: Clone + Component + FromReflect + GetTypeRegistration> | ||
GenericActionComponent for T | ||
GenericActionComponent for T | ||
{ | ||
} | ||
/// Minimal traits generally required for an action event. | ||
pub trait GenericActionEvent: | ||
Clone + Event + FromReflect + GetTypeRegistration | ||
{ | ||
} | ||
impl<T: Clone + Event + FromReflect + GetTypeRegistration> | ||
GenericActionEvent for T | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::prelude::*; | ||
use bevy::ecs::schedule::SystemConfigs; | ||
use bevy::prelude::*; | ||
|
||
/// Triggers the given event when this behavior starts running. | ||
#[derive(Debug, Clone, PartialEq, Deref, DerefMut, Component, Reflect)] | ||
#[reflect(Component, ActionMeta)] | ||
pub struct TriggerOnRun<T: GenericActionEvent>(pub T); | ||
|
||
impl<T: Default + GenericActionEvent> Default for TriggerOnRun<T> { | ||
fn default() -> Self { Self(T::default()) } | ||
} | ||
|
||
impl<T: GenericActionEvent> TriggerOnRun<T> { | ||
pub fn new(value: impl Into<T>) -> Self { Self(value.into()) } | ||
} | ||
|
||
impl<T: GenericActionEvent> ActionMeta for TriggerOnRun<T> { | ||
fn category(&self) -> ActionCategory { ActionCategory::World } | ||
} | ||
|
||
impl<T: GenericActionEvent> ActionSystems for TriggerOnRun<T> { | ||
fn systems() -> SystemConfigs { trigger_on_run::<T>.in_set(TickSet) } | ||
} | ||
|
||
fn trigger_on_run<T: GenericActionEvent>( | ||
mut writer: EventWriter<T>, | ||
query: Query<&TriggerOnRun<T>, Added<Running>>, | ||
) { | ||
for trigger in query.iter() { | ||
writer.send(trigger.0.clone()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters