diff --git a/Cargo.toml b/Cargo.toml index 455aed5..b136d5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,14 +14,13 @@ repository = "https://github.com/Seldom-SE/seldom_state" leafwing_input = ["dep:leafwing-input-manager"] [dependencies] -bevy = { version = "0.13.0", default-features = false } +leafwing-input-manager = { git = "https://github.com/Leafwing-Studios/leafwing-input-manager", rev = "a603533", default-features = false, optional = true } +bevy = { version = "0.14.0-rc.2", default-features = false } either = "1.9" -leafwing-input-manager = { version = "0.13.0", default-features = false, optional = true } -seldom_fn_plugin = "0.6.0" [dev-dependencies] -bevy = "0.13.0" -leafwing-input-manager = "0.13.0" +bevy = "0.14.0-rc.2" +leafwing-input-manager = { git = "https://github.com/Leafwing-Studios/leafwing-input-manager", rev = "a603533" } [[example]] name = "input" diff --git a/src/lib.rs b/src/lib.rs index 943ca6a..22e3af6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,9 +8,7 @@ pub mod set; mod state; pub mod trigger; -use machine::machine_plugin; use prelude::*; -use trigger::trigger_plugin; /// Add to your app to use this crate #[derive(Debug, Default)] @@ -18,22 +16,15 @@ pub struct StateMachinePlugin; impl Plugin for StateMachinePlugin { fn build(&self, app: &mut App) { - app.fn_plugin(state_machine_plugin); + app.add_plugins((machine::plug, trigger::plug)); } } -/// Function called by [`StateMachinePlugin`]. You may instead call it directly or use -/// `seldom_fn_plugin`, which is another crate I maintain. -pub fn state_machine_plugin(app: &mut App) { - app.fn_plugin(machine_plugin).fn_plugin(trigger_plugin); -} - /// Module for convenient imports. Use with `use seldom_state::prelude::*;`. pub mod prelude { pub(crate) use bevy::prelude::*; #[cfg(feature = "leafwing_input")] pub(crate) use leafwing_input_manager::prelude::*; - pub(crate) use seldom_fn_plugin::FnPluginExt; #[cfg(feature = "leafwing_input")] pub use crate::trigger::{ @@ -48,7 +39,6 @@ pub mod prelude { pub use crate::{ machine::StateMachine, state::{AnyState, EntityState}, - state_machine_plugin, trigger::{always, done, on_event, Done, IntoTrigger, Never, Trigger}, StateMachinePlugin, }; diff --git a/src/machine.rs b/src/machine.rs index cb4457b..31e5a1d 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -5,7 +5,10 @@ use std::{ }; use bevy::{ - ecs::system::{Command, EntityCommands, SystemState}, + ecs::{ + system::{EntityCommands, SystemState}, + world::Command, + }, tasks::{ComputeTaskPool, ParallelSliceMut}, utils::HashMap, }; @@ -17,7 +20,7 @@ use crate::{ trigger::{IntoTrigger, TriggerOut}, }; -pub(crate) fn machine_plugin(app: &mut App) { +pub(crate) fn plug(app: &mut App) { app.add_systems(PostUpdate, transition.in_set(StateSet::Transition)); } @@ -363,7 +366,7 @@ pub(crate) fn transition( let par_commands = system_state.get(world); let task_pool = ComputeTaskPool::get(); // chunk size of None means to automatically pick - borrowed_machines.par_splat_map_mut(task_pool, None, |chunk| { + borrowed_machines.par_splat_map_mut(task_pool, None, |_, chunk| { for (entity, machine) in chunk { par_commands.command_scope(|mut commands| machine.run(world, *entity, &mut commands)); } @@ -403,11 +406,11 @@ mod tests { let mut app = App::new(); app.add_systems(Update, transition); let machine = StateMachine::default().with_state::(); - let entity = app.world.spawn((machine, StateOne)).id(); + let entity = app.world_mut().spawn((machine, StateOne)).id(); app.update(); // should have moved to state two assert!( - app.world.get::(entity).is_some(), + app.world().get::(entity).is_some(), "StateMachine should have the initial component" ); } @@ -420,25 +423,25 @@ mod tests { let machine = StateMachine::default() .trans::(always, StateTwo) .trans::(resource_present, StateThree); - let entity = app.world.spawn((machine, StateOne)).id(); + let entity = app.world_mut().spawn((machine, StateOne)).id(); - assert!(app.world.get::(entity).is_some()); + assert!(app.world().get::(entity).is_some()); app.update(); // should have moved to state two - assert!(app.world.get::(entity).is_none()); - assert!(app.world.get::(entity).is_some()); + assert!(app.world().get::(entity).is_none()); + assert!(app.world().get::(entity).is_some()); app.update(); // not yet... - assert!(app.world.get::(entity).is_some()); - assert!(app.world.get::(entity).is_none()); + assert!(app.world().get::(entity).is_some()); + assert!(app.world().get::(entity).is_none()); - app.world.insert_resource(SomeResource); + app.world_mut().insert_resource(SomeResource); app.update(); // okay, *now* - assert!(app.world.get::(entity).is_none()); - assert!(app.world.get::(entity).is_some()); + assert!(app.world().get::(entity).is_none()); + assert!(app.world().get::(entity).is_some()); } #[test] @@ -447,7 +450,7 @@ mod tests { app.add_systems(Update, transition); let entity = app - .world + .world_mut() .spawn(( StateMachine::default().trans::(always, StateOne), StateOne, @@ -457,7 +460,7 @@ mod tests { // the sort of bug this is trying to catch: if you insert the new state and then remove the // old state, self-transitions will leave you without the state assert!( - app.world.get::(entity).is_some(), + app.world().get::(entity).is_some(), "transitioning from a state to itself should work" ); } diff --git a/src/state.rs b/src/state.rs index 321011c..9b1ffba 100644 --- a/src/state.rs +++ b/src/state.rs @@ -3,7 +3,7 @@ use std::{ fmt::{self, Debug, Formatter}, }; -use bevy::ecs::system::{Command, EntityCommands}; +use bevy::ecs::{system::EntityCommands, world::Command}; use crate::prelude::*; @@ -137,17 +137,17 @@ mod tests { .on_exit::(|commands| commands.commands().insert_resource(SomeResource)) .on_enter::(|commands| commands.commands().insert_resource(AnotherResource)); - let entity = app.world.spawn((machine, StateOne)).id(); - assert!(app.world.get::(entity).is_some()); + let entity = app.world_mut().spawn((machine, StateOne)).id(); + assert!(app.world().get::(entity).is_some()); app.update(); - assert!(app.world.get::(entity).is_some()); + assert!(app.world().get::(entity).is_some()); assert!( - app.world.contains_resource::(), + app.world().contains_resource::(), "exit state triggers should run" ); assert!( - app.world.contains_resource::(), + app.world().contains_resource::(), "exit state triggers should run" ); } diff --git a/src/trigger.rs b/src/trigger.rs index 37214c0..05d424e 100644 --- a/src/trigger.rs +++ b/src/trigger.rs @@ -19,7 +19,7 @@ use std::{convert::Infallible, fmt::Debug}; use crate::{prelude::*, set::StateSet}; -pub(crate) fn trigger_plugin(app: &mut App) { +pub(crate) fn plug(app: &mut App) { app.configure_sets( PostUpdate, StateSet::RemoveDoneMarkers.after(StateSet::Transition),