Seldom-SE / seldom_state

Component-based state machine plugin for Bevy. Useful for AI, player state, and other entities that occupy different states.
Apache License 2.0
172 stars 18 forks source link

add Clone on triggers if available #8

Closed hyranno closed 8 months ago

hyranno commented 8 months ago

This PR add Clone and some common traits onto triggers and some values for convenience. It is good for reusing triggers.

Implementing Clone on StateMachine will be convenient too, but it will conflict with pending PR (#7 ), so I won't implement until it is closed (weather merged or not).

Seldom-SE commented 8 months ago

StateMachine used to implement Clone, but I removed it so that triggers don't have to implement Clone. I recommend this pattern:

let state_machine_builder = || {
    StateMachine::default()
        .trans<MyState>(MyTrigger, MyOtherState)
};

commands.spawn((
    MyState,
    state_machine_builder(),
));

commands.spawn((
    MyOtherState,
    state_machine_builder(),
));

Or break it out into a separate function. I'd accept the impls that are here, though. But I'll wait to see what you think first.

hyranno commented 8 months ago

Sounds reasonable. It is good to allowing things to be not Clone, and it looks hard to implement Clone for StateMachine without forcing its member to be Clone. I expected these merits to implement Clone for StateMachine:

But I think these merits are less important.

Seldom-SE commented 8 months ago

Thanks!