pub trait ScheduledAction: Send + Sync + Reflect {
fn execute(&mut self, world: &mut World);
}
#[derive(Reflect, Clone)]
enum ScheduleItem {
PlayerAction,
// We cant use function traits here because they can't be serialized.
OneshotEvent(Box<dyn ScheduledAction>),
TurnBasedEvent(Box<dyn ScheduledAction>),
}
#[derive(Reflect, Default, Clone)]
struct ScheduleEntry {
time: u64,
item: ScheduledAction,
}
#[derive(Resource, Reflect)]
#[reflect(Resource)]
pub struct RPGSchedule {
heap: BinaryHeap<ScheduleEntry>,
}
I have two problems implementing Reflect for my turn based schedule.
- For BinaryHeap to implement Reflect ScheduleEntry needs to implement Copy but it can't otherwise it would not be object-safe
- I can't implement Reflect for Box<dyn ScheduledAction>
All I want from the scheudled action is to emit one event. My first try was to store events. But they are also not object-safe ...
I would love some input. Either on how to fix this system or on ideas for an alternative.
One obvious thing is I could just use a super fat enum and dispatch on that ... workable but I'd be interested in a "proper" solution.
Thank you for your time!
Cheers
Felix