Support an Open Source Developer! :hearts:
Read the documentation.
State
trait that is simple to implement.Add the following to you Cargo.toml file:
game_state_machine = "*"
Use it like so: ```rust use gamestatemachine::*;
type StateData = (isize, isize);
pub struct Test;
impl State
fn on_resume(&mut self, data: &mut StateData) {
self.on_start(data);
}
fn update(&mut self, _data: &mut StateData) -> StateTransition<StateData> {
StateTransition::Push(Box::new(Test))
}
}
fn main() {
let mut sm = StateMachine::
let mut state_data = (0, 10);
sm.push(Box::new(Test), &mut state_data);
assert!(state_data.0 == 10);
sm.update(&mut state_data);
assert!(state_data.0 == 20);
sm.stop(&mut state_data);
assert!(state_data.0 == 20);
assert!(!sm.is_running())
} ```