use crate::prelude::Scene;
pub mod pawn;
pub mod scene;
#[doc = include_str!("../../docs/engine.md")]
#[derive(Clone)]
pub struct Engine {
pub timeline: Vec<Scene>,
pub timenow: usize,
}
impl Engine {
pub fn new(scene: Scene) -> Self {
Self {
timeline: vec![scene],
timenow: 0,
}
}
pub fn get_active_scene(&self) -> Option<&Scene> {
self.timeline.get(self.timenow)
}
pub fn get_active_scene_mut(&mut self) -> Option<&mut Scene> {
self.timeline.get_mut(self.timenow)
}
pub fn push_scene(&mut self, scene: Scene) {
self.timeline.push(scene);
self.timenow = self.timeline.len() - 1;
}
pub fn pop_scene(&mut self) {
if self.timeline.len() > 1 {
self.timeline.pop();
self.timenow = self.timeline.len() - 1;
}
}
pub fn rollback_to(&mut self, index: usize) {
if index < self.timeline.len() {
self.timeline.truncate(index + 1);
self.timenow = self.timeline.len() - 1;
}
}
pub fn rewind_to(&mut self, index: usize) -> Result<(), &'static str> {
if index < self.timeline.len() {
self.timenow = index;
Ok(())
} else {
Err("Index out of bounds")
}
}
pub fn get_scene_at(&self, index: usize) -> Option<&Scene> {
self.timeline.get(index)
}
}