-
-
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
13 changed files
with
45 additions
and
145 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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,27 @@ | ||
use crate::action::ActionCategory; | ||
use bevy::ecs::component::ComponentId; | ||
use bevy::ecs::world::DeferredWorld; | ||
use crate::prelude::*; | ||
use bevy::prelude::*; | ||
use std::marker::PhantomData; | ||
use bevy::utils::all_tuples; | ||
|
||
|
||
pub struct ActionBuilder<T: ActionBuilderTypes> { | ||
category: ActionCategory, | ||
on_add: Option<fn(DeferredWorld, Entity, ComponentId)>, | ||
on_remove: Option<fn(DeferredWorld, Entity, ComponentId)>, | ||
// observers: T::Observers, | ||
phantom: PhantomData<T>, | ||
} | ||
|
||
impl<T: ActionBuilderComponent> Default | ||
for ActionBuilder<DefaultActionTypes<T>> | ||
{ | ||
fn default() -> Self { | ||
Self { | ||
category: ActionCategory::default(), | ||
on_add: None, | ||
on_remove: None, | ||
phantom: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
// just use name as a placeholder | ||
impl ActionBuilder<DefaultActionTypes<Name>> { | ||
pub fn new<C: ActionBuilderComponent>( | ||
) -> ActionBuilder<DefaultActionTypes<C>> { | ||
default() | ||
} | ||
} | ||
|
||
|
||
impl<T: ActionBuilderTypes> ActionBuilder<T> { | ||
// pub fn add_observers( | ||
|
||
pub fn on_add( | ||
mut self, | ||
on_add: fn(DeferredWorld, Entity, ComponentId), | ||
) -> Self { | ||
self.on_add = Some(on_add); | ||
self | ||
} | ||
pub fn on_remove( | ||
mut self, | ||
on_remove: fn(DeferredWorld, Entity, ComponentId), | ||
) -> Self { | ||
self.on_remove = Some(on_remove); | ||
self | ||
} | ||
|
||
pub fn with_category(mut self, category: ActionCategory) -> Self { | ||
self.category = category; | ||
self | ||
} | ||
pub trait ActionBuilder: Sized { | ||
fn build(app: &mut App, config: &BeetConfig); | ||
} | ||
|
||
impl<T: ActionBuilderTypes> Plugin for ActionBuilder<T> { | ||
fn build(&self, app: &mut App) { | ||
#[cfg(feature = "reflect")] | ||
app.register_type::<T::Component>(); | ||
|
||
let world = app.world_mut(); | ||
let hooks = world.register_component_hooks::<T::Component>(); | ||
if let Some(on_add) = self.on_add { | ||
hooks.on_add(on_add); | ||
} | ||
if let Some(on_remove) = self.on_remove { | ||
hooks.on_remove(on_remove); | ||
} | ||
macro_rules! impl_plugins_tuples { | ||
($($param: ident),*) => { | ||
impl<$($param),*> ActionBuilder for ($($param,)*) | ||
where | ||
$($param: ActionBuilder),* | ||
{ | ||
#[allow(non_snake_case, unused_variables)] | ||
#[track_caller] | ||
fn build(app:&mut App, config: &BeetConfig){ | ||
$( | ||
$param::build(app, config); | ||
)* | ||
// ($($param::systems(),)*).into_configs() | ||
} | ||
} | ||
} | ||
} | ||
#[cfg(feature = "reflect")] | ||
pub trait ActionBuilderComponent: Component + bevy::reflect::GetTypeRegistration {} | ||
#[cfg(feature = "reflect")] | ||
impl<T: Component + bevy::reflect::GetTypeRegistration> ActionBuilderComponent for T {} | ||
#[cfg(not(feature = "reflect"))] | ||
pub trait ActionBuilderComponent: Component {} | ||
#[cfg(not(feature = "reflect"))] | ||
impl<T: Component> ActionBuilderComponent for T {} | ||
|
||
pub trait ActionBuilderTypes: 'static + Send + Sync { | ||
type Component: ActionBuilderComponent; | ||
} | ||
pub struct DefaultActionTypes<T: ActionBuilderComponent>(PhantomData<T>); | ||
impl<T: ActionBuilderComponent> ActionBuilderTypes for DefaultActionTypes<T> { | ||
type Component = T; | ||
} | ||
all_tuples!(impl_plugins_tuples, 1, 15, P); |
File renamed without changes.
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
File renamed without changes.
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,3 +1,12 @@ | ||
pub mod action_builder; | ||
#[allow(unused_imports)] | ||
pub use self::action_builder::*; | ||
pub mod action_meta; | ||
#[allow(unused_imports)] | ||
pub use self::action_meta::*; | ||
pub mod action_plugin; | ||
#[allow(unused_imports)] | ||
pub use self::action_plugin::*; | ||
pub mod beet_config; | ||
#[allow(unused_imports)] | ||
pub use self::beet_config::*; |
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
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