use crate::{error::InklingError, knot::Address, line::InternalChoice, story::types::VariableSet};
#[cfg(feature = "serde_support")]
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub type FollowResult = Result<EncounteredEvent, InklingError>;
pub type LineDataBuffer = Vec<LineText>;
#[derive(Clone, Debug, PartialEq)]
pub enum EncounteredEvent {
BranchingChoice(Vec<ChoiceInfo>),
Divert(Address),
Done,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ChoiceInfo {
pub num_visited: u32,
pub choice_data: InternalChoice,
}
impl ChoiceInfo {
pub fn from_choice(choice: &InternalChoice, num_visited: u32) -> Self {
ChoiceInfo {
num_visited,
choice_data: choice.clone(),
}
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde_support", derive(Deserialize, Serialize))]
pub struct FollowData {
pub knot_visit_counts: HashMap<String, HashMap<String, u32>>,
pub variables: VariableSet,
}
#[derive(Clone, Debug, PartialEq)]
pub struct LineText {
pub text: String,
pub glue_begin: bool,
pub glue_end: bool,
pub tags: Vec<String>,
}
#[cfg(test)]
pub struct LineTextBuilder {
pub text: String,
pub glue_begin: bool,
pub glue_end: bool,
pub tags: Vec<String>,
}
#[cfg(test)]
impl LineTextBuilder {
pub fn from_string(content: &str) -> Self {
LineTextBuilder {
text: content.to_string(),
glue_begin: false,
glue_end: false,
tags: Vec::new(),
}
}
pub fn build(self) -> LineText {
LineText {
text: self.text,
glue_begin: self.glue_begin,
glue_end: self.glue_end,
tags: self.tags,
}
}
pub fn with_glue_begin(mut self) -> Self {
self.glue_begin = true;
self
}
pub fn with_glue_end(mut self) -> Self {
self.glue_end = true;
self
}
pub fn with_tags(mut self, tags: &[String]) -> Self {
self.tags = tags.to_vec();
self
}
}