use super::types::{WeirollCommand, WeirollScript};
#[derive(Debug, Default)]
pub struct WeirollPlanner {
commands: Vec<WeirollCommand>,
state: Vec<Vec<u8>>,
}
impl WeirollPlanner {
#[must_use]
pub const fn new() -> Self {
Self { commands: vec![], state: vec![] }
}
pub fn add_command(&mut self, cmd: WeirollCommand) -> &mut Self {
self.commands.push(cmd);
self
}
pub fn add_state_slot(&mut self, data: Vec<u8>) -> usize {
let idx = self.state.len();
self.state.push(data);
idx
}
#[must_use]
pub const fn command_count(&self) -> usize {
self.commands.len()
}
#[must_use]
pub const fn state_slot_count(&self) -> usize {
self.state.len()
}
#[must_use]
pub fn plan(self) -> WeirollScript {
WeirollScript {
commands: self.commands.iter().map(WeirollCommand::pack).collect(),
state: self.state,
}
}
}