Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New motiongfx_common crate separated out from motiongfx_core #52

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ license.workspace = true
repository.workspace = true

[dependencies]
bevy = { version = "0.13", default-features = false }
motiongfx_core = { version = "0.1.0", path = "crates/motiongfx_core" }
motiongfx_common = { version = "0.1.0", path = "crates/motiongfx_common", optional = true }
motiongfx_vello = { version = "0.1.0", path = "crates/motiongfx_vello", optional = true }

[features]
default = ["vello"]
vello = ["dep:motiongfx_vello"]
default = ["common", "vello_graphics"]
common = ["dep:motiongfx_common"]
vello_graphics = ["dep:motiongfx_vello"]

[dev-dependencies]
bevy = "0.13"
Expand Down
13 changes: 13 additions & 0 deletions crates/motiongfx_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "motiongfx_common"
version.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
bevy = { version = "0.13", default-features = false }
motiongfx_core = { version = "0.1.0", path = "../motiongfx_core" }

[lints]
workspace = true
66 changes: 66 additions & 0 deletions crates/motiongfx_common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use bevy::{
ecs::system::{EntityCommand, EntityCommands},
prelude::*,
};
use motiongfx_core::prelude::*;

pub mod motion;

pub mod prelude {
pub use crate::{
motion::{
standard_material_motion::StandardMaterialMotion, transform_motion::TransformMotion,
},
AddNewAssetCommandExt, MotionGfxCommonPlugin,
};
}

pub struct MotionGfxCommonPlugin;

impl Plugin for MotionGfxCommonPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(
update_component::<Transform, Vec3>,
update_component::<Transform, Quat>,
update_component::<Transform, f32>,
update_component::<Sprite, Color>,
update_component::<Sprite, f32>,
update_asset::<StandardMaterial, Color>,
update_asset::<StandardMaterial, f32>,
update_asset::<ColorMaterial, Color>,
update_asset::<ColorMaterial, f32>,
)
.in_set(UpdateSequenceSet),
);
}
}

pub trait AddNewAssetCommandExt<A: Asset> {
/// Adds a new asset and attach the handle to this entity.
fn add_new_asset(&mut self, asset: A) -> &mut Self;
}

impl<A: Asset> AddNewAssetCommandExt<A> for EntityCommands<'_> {
fn add_new_asset(&mut self, asset: A) -> &mut Self {
self.add(AddNewAssetCommand(asset))
}
}

pub struct AddNewAssetCommand<A: Asset>(A);

impl<A: Asset> EntityCommand for AddNewAssetCommand<A> {
fn apply(self, id: Entity, world: &mut World) {
let mut materials = world.get_resource_mut::<Assets<A>>().unwrap_or_else(|| {
panic!(
"Assets<{}> resource not initialized.",
A::type_ident().unwrap()
)
});

let material = materials.add(self.0);

world.entity_mut(id).insert(material);
}
}
2 changes: 2 additions & 0 deletions crates/motiongfx_common/src/motion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod standard_material_motion;
pub mod transform_motion;
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use bevy::prelude::*;

use crate::{act, prelude::Action};

use super::{GetId, GetMutValue};
use motiongfx_core::prelude::*;

pub trait StandardMaterialMotion<const N: usize> {
fn std_material(&mut self) -> StandardMaterialMotionBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use bevy::prelude::*;

use crate::{act, prelude::Action};

use super::{GetId, GetMutValue};
use motiongfx_core::prelude::*;

pub trait TransformMotion<const N: usize> {
fn transform(&mut self) -> TransformMotionBuilder;
Expand Down
11 changes: 4 additions & 7 deletions crates/motiongfx_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ license.workspace = true
repository.workspace = true

[dependencies]
motiongfx_core_macros = { path = "macros" }

bevy = "0.13"
bevy = { version = "0.13", default-features = false }
bevy_vello = { version = "0.4", optional = true }
bevy_vello_graphics = { version = "0.1.0", git = "https://github.com/voxell-tech/bevy_vello_graphics", optional = true }
smallvec = "1.11"
motiongfx_core_macros = { version = "0.1.0", path = "macros" }

[lints]
workspace = true

[features]
default = ["vello_graphics"]
vello_graphics = ["dep:bevy_vello_graphics", "vello"]
vello = ["dep:bevy_vello"]
default = []
vello_graphics = ["dep:bevy_vello_graphics", "dep:bevy_vello"]
2 changes: 1 addition & 1 deletion crates/motiongfx_core/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ repository.workspace = true
proc-macro = true

[dependencies]
proc-macro2 = "1.0"
syn = "2.0"
quote = "1.0"
bevy_macro_utils = "0.13"
proc-macro2 = "1.0"

[lints]
workspace = true
4 changes: 2 additions & 2 deletions crates/motiongfx_core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy::prelude::*;
use crate::{
ease::{cubic, EaseFn},
f32lerp::F32Lerp,
prelude::MultiSequenceOrdering,
prelude::MultiSeqOrd,
sequence::Sequence,
};

Expand Down Expand Up @@ -265,7 +265,7 @@ impl<'a> SequenceBuilder<'a, 'a> {
}
}

impl MultiSequenceOrdering for SequenceBuilder<'_, '_> {
impl MultiSeqOrd for SequenceBuilder<'_, '_> {
fn chain(self) -> Sequence {
self.sequences.chain()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/motiongfx_core/src/f32lerp.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bevy::prelude::*;

pub mod bevy_f32lerp;
pub mod glam_f32lerp;
#[cfg(feature = "vello")]
pub mod math_f32lerp;
#[cfg(feature = "vello_graphics")]
pub mod vello_f32lerp;
#[cfg(feature = "vello_graphics")]
pub mod vello_graphics_f32lerp;
Expand Down
2 changes: 1 addition & 1 deletion crates/motiongfx_core/src/f32lerp/vello_f32lerp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{prelude::*, utils::smallvec};
use bevy_vello::prelude::*;

use super::F32Lerp;
Expand Down
33 changes: 4 additions & 29 deletions crates/motiongfx_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
use bevy::prelude::*;
use prelude::{update_asset, update_component};
use sequence::{sequence_controller, sequence_player};
use slide::slide_controller;

#[cfg(feature = "vello")]
pub use bevy_vello;
#[cfg(feature = "vello_graphics")]
pub use bevy_vello_graphics;

pub mod action;
pub mod color_palette;
pub mod ease;
pub mod f32lerp;
pub mod motion;
pub mod sequence;
pub mod slide;
pub mod tuple_motion;

pub mod prelude {
pub use crate::{
action::{act, Action, SequenceBuilderExt},
color_palette::{ColorKey, ColorPalette},
ease,
f32lerp::F32Lerp,
motion::{
standard_material_motion::StandardMaterialMotion, transform_motion::TransformMotion,
AddNewAssetCommandExtension, GetId, GetMut, GetMutValue,
},
sequence::{
all, any, chain, delay, flow, update_asset, update_component, MultiSequenceOrdering,
Sequence, SequenceBundle, SequenceController, SequencePlayer, SequencePlayerBundle,
SingleSequenceOrdering,
all, any, chain, delay, flow, update_asset, update_component, MultiSeqOrd, Sequence,
SequenceBundle, SequenceController, SequencePlayer, SequencePlayerBundle, SingleSeqOrd,
},
slide::{create_slide, SlideBundle, SlideController, SlideCurrState, SlideTargetState},
tuple_motion::{GetId, GetMut, GetMutValue},
MotionGfxPlugin, UpdateSequenceSet,
};
}
Expand All @@ -44,21 +34,6 @@ impl Plugin for MotionGfxPlugin {
Update,
(sequence_player, slide_controller).before(UpdateSequenceSet),
)
.add_systems(
Update,
(
update_component::<Transform, Vec3>,
update_component::<Transform, Quat>,
update_component::<Transform, f32>,
update_component::<Sprite, Color>,
update_component::<Sprite, f32>,
update_asset::<StandardMaterial, Color>,
update_asset::<StandardMaterial, f32>,
update_asset::<ColorMaterial, Color>,
update_asset::<ColorMaterial, f32>,
)
.in_set(UpdateSequenceSet),
)
.add_systems(Update, sequence_controller.after(UpdateSequenceSet));
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/motiongfx_core/src/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub struct SequencePlayer {

// SEQUENCE ORDERING FUNCTIONS

pub trait MultiSequenceOrdering {
pub trait MultiSeqOrd {
/// Run one [`Sequence`] after another.
fn chain(self) -> Sequence;
/// Run all [`Sequence`]s concurrently and wait for all of them to finish.
Expand All @@ -100,7 +100,7 @@ pub trait MultiSequenceOrdering {
fn flow(self, delay: f32) -> Sequence;
}

impl MultiSequenceOrdering for &[Sequence] {
impl MultiSeqOrd for &[Sequence] {
fn chain(self) -> Sequence {
chain(self)
}
Expand All @@ -118,12 +118,12 @@ impl MultiSequenceOrdering for &[Sequence] {
}
}

pub trait SingleSequenceOrdering {
pub trait SingleSeqOrd {
/// Run a [`Sequence`] after a fixed delay time.
fn delay(self, t: f32) -> Sequence;
}

impl SingleSequenceOrdering for Sequence {
impl SingleSeqOrd for Sequence {
fn delay(self, t: f32) -> Sequence {
delay(t, self)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/motiongfx_core/src/slide.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::prelude::*;

use crate::prelude::{MultiSequenceOrdering, Sequence, SequenceController};
use crate::prelude::{MultiSeqOrd, Sequence, SequenceController};

#[derive(Bundle, Default)]
pub struct SlideBundle {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
use bevy::prelude::*;
use motiongfx_core_macros::tuple_combinations;

use bevy::{
ecs::system::{EntityCommand, EntityCommands},
prelude::*,
};

pub mod standard_material_motion;
pub mod transform_motion;

pub trait GetId {
fn id(&self) -> Entity;
}
Expand Down Expand Up @@ -54,31 +47,3 @@ macro_rules! impl_get_mut_value {
}

tuple_combinations!(impl_get_mut_value, 20);

pub trait AddNewAssetCommandExtension<A: Asset> {
/// Adds a new asset and attach the handle to this entity.
fn add_new_asset(&mut self, asset: A) -> &mut Self;
}

impl<A: Asset> AddNewAssetCommandExtension<A> for EntityCommands<'_> {
fn add_new_asset(&mut self, asset: A) -> &mut Self {
self.add(AddNewAssetCommand(asset))
}
}

pub struct AddNewAssetCommand<A: Asset>(A);

impl<A: Asset> EntityCommand for AddNewAssetCommand<A> {
fn apply(self, id: Entity, world: &mut World) {
let mut materials = world.get_resource_mut::<Assets<A>>().unwrap_or_else(|| {
panic!(
"Assets<{}> resource not initialized.",
A::type_ident().unwrap()
)
});

let material = materials.add(self.0);

world.entity_mut(id).insert(material);
}
}
4 changes: 2 additions & 2 deletions crates/motiongfx_vello/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ license.workspace = true
repository.workspace = true

[dependencies]
motiongfx_core = { version = "0.1.0", path = "../motiongfx_core" }
bevy = { version = "0.13", default-features = false }
bevy_vello_graphics = { version = "0.1.0", git = "https://github.com/voxell-tech/bevy_vello_graphics" }
bevy = "0.13"
motiongfx_core = { version = "0.1.0", path = "../motiongfx_core", features = ["vello_graphics"] }

[lints]
workspace = true
6 changes: 1 addition & 5 deletions crates/motiongfx_vello/src/motion/fill_motion.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use bevy::prelude::*;
use bevy_vello_graphics::prelude::*;
use motiongfx_core::{
act,
motion::{GetId, GetMutValue},
prelude::Action,
};
use motiongfx_core::prelude::*;

pub trait FillMotion<const N: usize> {
fn fill(&mut self) -> FillMotionBuilder;
Expand Down
Loading