#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::format::{Block, Child};
#[derive(Debug, Default, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[serde(default)]
pub struct ExecutionState {
pub story: String,
pub paragraph: String,
pub block: Block,
pub index: usize,
pub is_loop_body: bool,
}
impl ExecutionState {
pub fn new(story: String, paragraph: String, block: Block) -> Self {
Self {
story,
paragraph,
block,
index: 0,
is_loop_body: false,
}
}
pub fn new_loop_body(story: String, paragraph: String, block: Block) -> Self {
Self {
story,
paragraph,
block,
index: 0,
is_loop_body: true,
}
}
pub fn next_line(&mut self) -> Option<Child> {
let line = self.block.children.get(self.index).cloned();
self.index += 1;
line
}
}