Skip to content

Commit

Permalink
chore: reduce API surface (#27)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: All struct fields are now private

BREAKING CHANGE: All enums are marked with `#[non_exhaustive]`

BREAKING CHANGE: The struct constructor of `AnimationPlugin` is now private. Use `AnimationPlugin::default()` to install it.
  • Loading branch information
jcornaz committed Jan 19, 2022
1 parent 8acb6d2 commit 540341a
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ A sprite sheet animation plugin for [bevy](https://bevyengine.org)
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AnimationPlugin) // <-- Add the plugin
.add_plugin(AnimationPlugin::default()) // <-- Add the plugin
.add_startup_system(spawn)
.run();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/change_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
App::new()
.init_resource::<Animations>()
.add_plugins(DefaultPlugins)
.add_plugin(AnimationPlugin)
.add_plugin(AnimationPlugin::default())
.add_startup_system_to_stage(StartupStage::PreStartup, create_animations.system())
.add_startup_system(spawn_animated_coin.system())
.add_startup_system(spawn_camera.system())
Expand Down
2 changes: 1 addition & 1 deletion examples/end_of_animation_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use benimator::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AnimationPlugin)
.add_plugin(AnimationPlugin::default())
.add_startup_system(spawn_animated_coin.system())
.add_startup_system(spawn_camera.system())
.add_system_to_stage(CoreStage::PostUpdate, removal_detection.system())
Expand Down
2 changes: 1 addition & 1 deletion examples/ping_pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use benimator::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AnimationPlugin)
.add_plugin(AnimationPlugin::default())
.add_startup_system(spawn.system())
.run();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use benimator::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AnimationPlugin) // <-- Add the plugin
.add_plugin(AnimationPlugin::default()) // <-- Add the plugin
.add_startup_system(spawn.system())
.run();
}
Expand Down
12 changes: 5 additions & 7 deletions src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use bevy_reflect::TypeUuid;
#[uuid = "6378e9c2-ecd1-4029-9cd5-801caf68517c"]
pub struct SpriteSheetAnimation {
/// Frames
pub frames: Vec<Frame>,
pub(crate) frames: Vec<Frame>,
/// Animation mode
pub(crate) mode: AnimationMode,
}

/// Animation mode (run once, repeat or ping-pong)
#[non_exhaustive]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum AnimationMode {
/// Runs the animation once and then stop playing
Expand All @@ -33,9 +34,9 @@ pub enum AnimationMode {
#[derive(Debug, Copy, Clone, Default)]
pub struct Frame {
/// Index in the sprite atlas
pub index: usize,
pub(crate) index: usize,
/// How long should the frame be displayed
pub duration: Duration,
pub(crate) duration: Duration,
}

impl SpriteSheetAnimation {
Expand All @@ -60,14 +61,11 @@ impl SpriteSheetAnimation {
///
/// # Example
///
/// You may use this to create a reversed animation:
/// ```
/// # use benimator::SpriteSheetAnimation;
/// # use std::time::Duration;
/// // Easily create a reversed animation
/// let animation = SpriteSheetAnimation::from_iter((0..5).rev(), Duration::from_millis(100));
///
/// assert_eq!(animation.frames.iter().map(|frame| frame.index).collect::<Vec<_>>(), vec![4, 3, 2, 1, 0]);
/// assert!(animation.frames.iter().all(|frame| frame.duration.as_millis() == 100));
/// ```
///
/// For more granular configuration, see [`from_frames`](SpriteSheetAnimation::from_frames)
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! fn main() {
//! App::new()
//! .add_plugins(DefaultPlugins)
//! .add_plugin(AnimationPlugin) // <-- Enable sprite-sheet animations
//! .add_plugin(AnimationPlugin::default()) // <-- Enable sprite-sheet animations
//! .add_startup_system(spawn.system())
//! // ...
//! .run()
Expand Down Expand Up @@ -125,10 +125,12 @@ mod state;
/// Plugin to enable sprite-sheet animation
///
/// See crate level documentation for usage
#[non_exhaustive]
#[derive(Default)]
pub struct AnimationPlugin;

/// Labels of systems that run during the post-update stage
#[non_exhaustive]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, SystemLabel)]
pub enum AnimationPostUpdateSystem {
/// System that update the sprite atlas textures
Expand Down
2 changes: 1 addition & 1 deletion tests/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn app() -> App {

app.add_plugin(CorePlugin)
.add_plugin(AssetPlugin)
.add_plugin(AnimationPlugin);
.add_plugin(AnimationPlugin::default());

app
}

0 comments on commit 540341a

Please sign in to comment.