-
-
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
12 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
71 changes: 71 additions & 0 deletions
71
crates/beet_ecs/src/lifecycle/actions/insert_on_trigger.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::prelude::*; | ||
use bevy::ecs::schedule::SystemConfigs; | ||
use bevy::prelude::*; | ||
use std::marker::PhantomData; | ||
use std::ops::Deref; | ||
use std::ops::DerefMut; | ||
|
||
/// Triggers the given event when this behavior starts Insertning. | ||
#[derive(Debug, Clone, PartialEq, Component, Reflect)] | ||
#[reflect(Component, ActionMeta)] | ||
pub struct InsertOnTrigger<E: GenericActionEvent, T: GenericActionComponent> { | ||
pub value: T, | ||
phantom: PhantomData<E>, | ||
} | ||
impl<E: GenericActionEvent, T: GenericActionComponent> Deref | ||
for InsertOnTrigger<E, T> | ||
{ | ||
type Target = T; | ||
fn deref(&self) -> &Self::Target { &self.value } | ||
} | ||
impl<E: GenericActionEvent, T: GenericActionComponent> DerefMut | ||
for InsertOnTrigger<E, T> | ||
{ | ||
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.value } | ||
} | ||
|
||
impl<E: GenericActionEvent, T: Default + GenericActionComponent> Default | ||
for InsertOnTrigger<E, T> | ||
{ | ||
fn default() -> Self { | ||
Self { | ||
value: T::default(), | ||
phantom: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl<E: GenericActionEvent, T: GenericActionComponent> InsertOnTrigger<E, T> { | ||
pub fn new(value: impl Into<T>) -> Self { | ||
Self { | ||
value: value.into(), | ||
phantom: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl<E: GenericActionEvent, T: GenericActionComponent> ActionMeta | ||
for InsertOnTrigger<E, T> | ||
{ | ||
fn category(&self) -> ActionCategory { ActionCategory::World } | ||
} | ||
|
||
impl<E: GenericActionEvent, T: GenericActionComponent> ActionSystems | ||
for InsertOnTrigger<E, T> | ||
{ | ||
fn systems() -> SystemConfigs { inset_on_trigger::<E, T>.in_set(TickSet) } | ||
} | ||
|
||
fn inset_on_trigger<E: GenericActionEvent, T: GenericActionComponent>( | ||
mut commands: Commands, | ||
mut reader: EventReader<E>, | ||
query: Query<(Entity, &InsertOnTrigger<E, T>)>, | ||
) { | ||
for _ev in reader.read() { | ||
log::info!("EVENT"); | ||
for (entity, trigger) in query.iter() { | ||
log::info!("RECEIVED"); | ||
commands.entity(entity).insert(trigger.value.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use beet::prelude::*; | ||
use beet_examples::prelude::*; | ||
use bevy::prelude::*; | ||
mod scenes; | ||
|
||
fn main() { | ||
let mut app = App::new(); | ||
|
||
app.add_plugins(( | ||
ExamplePluginText::default(), | ||
DefaultBeetPlugins::default(), | ||
)) | ||
// .add_systems(Startup, scenes::hello_world) | ||
.add_systems(Startup, scenes::hello_net) | ||
// .add_systems(PostStartup, save_scene("target/scenes/hello_world.ron")) | ||
.run(); | ||
} |
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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
use beet_examples::prelude::*; | ||
use beet::prelude::*; | ||
use beet_examples::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
pub fn hello_net(mut commands: Commands) { | ||
commands | ||
.spawn((SequenceSelector::default(), Running)) | ||
.with_children(|parent| { | ||
parent.spawn(( | ||
LogOnRun("Message Sent: AppLoaded".into()), | ||
LogOnRun::new("Send: AppLoaded"), | ||
TriggerOnRun(AppLoaded), | ||
)); | ||
}); | ||
commands.spawn(( | ||
InsertOnTrigger::<OnUserMessage, Running>::new(Running), | ||
LogOnRun::new("Recv: Player Message"), | ||
)); | ||
} |
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
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