Skip to content

Commit

Permalink
refactor!: use a single feature flag for bevy integration (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornaz authored Jul 14, 2022
1 parent 878af47 commit a77893b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ jobs:
- "unstable-load-from-file, yaml"
- "unstable-load-from-file, ron"
- "bevy-07"
- "bevy-app-07"
- "bevy-sprite-07"

steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ yaml = { package = "serde_yaml", version = "0.8.25", default-features = false, o
ron = { version = "0.7.1", default-features = false, optional = true }

# Public dependencies (Present in the public API)
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
anyhow = { version = "1.0", default-features = false, optional = true }

## Bevy 0.7
bevy_core = { version = "0.7.0", default-features = false }
bevy_ecs = { version = "0.7.0", default-features = false }
bevy_reflect = { version = "0.7.0", default-features = false }
bevy_asset = { version = "0.7.0", default-features = false }
bevy-app-07 = { package = "bevy_app",version = "0.7.0", default-features = false, optional = true }
bevy-sprite-07 = { package = "bevy_sprite", version = "0.7.0", default-features = false, optional = true }
bevy_utils = { version = "0.7.0", default-features = false, optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
anyhow = { version = "1.0", default-features = false, optional = true }

[dev-dependencies]
bevy = { version = "0.7.0", default-features = false, features = ["render", "x11", "png"] }
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ cargo add benimator
* `yaml` deserialization from yaml asset files (also requires `unstable-load-from-file`)
* `ron` deserialization from ron asset files (also requires `unstable-load-from-file`)
* `bevy-07` all integrations with bevy 0.7
* `bevy-app-07` integration with `bevy_app` 0.7
* `bevy-sprite-07` integration with `bevy_sprite` 0.7

### Unstable features

Expand Down
14 changes: 4 additions & 10 deletions src/integration/bevy_07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,31 @@ use std::ops::DerefMut;
use crate::{
state::SpriteState, Play, PlaySpeedMultiplier, SpriteSheetAnimation, SpriteSheetAnimationState,
};
#[cfg(feature = "bevy-app-07")]
use bevy_app_07::prelude::*;
use bevy_asset::prelude::*;
use bevy_core::prelude::*;
use bevy_ecs::prelude::*;
#[cfg(feature = "bevy-sprite-07")]
use bevy_sprite_07::prelude::*;

#[cfg(feature = "bevy-app-07")]
impl Plugin for crate::AnimationPlugin {
fn build(&self, app: &mut App) {
app.add_asset::<crate::SpriteSheetAnimation>()
.add_system_set_to_stage(CoreStage::PreUpdate, auto_insert_state());

#[cfg(feature = "bevy-sprite-07")]
app.add_system_set_to_stage(CoreStage::Update, animation_systems::<TextureAtlasSprite>());
.add_system_set_to_stage(CoreStage::PreUpdate, auto_insert_state())
.add_system_set_to_stage(CoreStage::Update, animation_systems::<TextureAtlasSprite>());

#[cfg(feature = "unstable-load-from-file")]
app.init_asset_loader::<crate::animation::load::SpriteSheetAnimationLoader>();
}
}

#[cfg(feature = "bevy-sprite-07")]
impl SpriteState for TextureAtlasSprite {
fn set_current_index(&mut self, index: usize) {
self.index = index;
}
}

/// Systems to automatically insert (and remove) the state component
pub fn auto_insert_state() -> SystemSet {
fn auto_insert_state() -> SystemSet {
SystemSet::new()
.with_system(insert_state)
.with_system(remove_state)
Expand All @@ -47,7 +41,7 @@ pub fn auto_insert_state() -> SystemSet {
///
/// * `bevy_asset::assets::Assets<benimator::SpriteSheetAnimation>`
/// * `bevy_core::time::Time`
pub fn animation_systems<T: SpriteState + Component>() -> SystemSet {
fn animation_systems<T: SpriteState + Component>() -> SystemSet {
SystemSet::new().with_system(animate::<T>)
}

Expand Down
2 changes: 1 addition & 1 deletion src/integration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Integration with third party crates
/// Integration with bevy 0.7
#[cfg(any(feature = "bevy-app-07", feature = "bevy-sprite-07"))]
#[cfg(feature = "bevy-07")]
pub mod bevy_07;

0 comments on commit a77893b

Please sign in to comment.