use crate::interactive_fiction::data::condition::Condition;
use crate::interactive_fiction::data::effect::Effect;
use crate::interactive_fiction::data::ids::NodeId;
use crate::interactive_fiction::data::text::Text;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Dialogue {
pub start: NodeId,
pub nodes: BTreeMap<NodeId, DialogueNode>,
}
impl Dialogue {
pub fn new(start: NodeId) -> Self {
Self {
start,
nodes: BTreeMap::new(),
}
}
pub fn with_node(mut self, id: NodeId, node: DialogueNode) -> Self {
self.nodes.insert(id, node);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DialogueNode {
pub text: Text,
pub on_enter: Vec<Effect>,
pub options: Vec<DialogueOption>,
}
impl DialogueNode {
pub fn new(text: Text) -> Self {
Self {
text,
on_enter: Vec::new(),
options: Vec::new(),
}
}
pub fn with_on_enter(mut self, effects: Vec<Effect>) -> Self {
self.on_enter = effects;
self
}
pub fn with_option(mut self, option: DialogueOption) -> Self {
self.options.push(option);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DialogueOption {
pub label: Text,
pub condition: Option<Condition>,
pub visible_when_locked: bool,
pub locked_reason: Option<Text>,
pub effects: Vec<Effect>,
pub goto: Option<NodeId>,
}
impl DialogueOption {
pub fn new(label: Text) -> Self {
Self {
label,
condition: None,
visible_when_locked: false,
locked_reason: None,
effects: Vec::new(),
goto: None,
}
}
pub fn with_condition(mut self, condition: Condition) -> Self {
self.condition = Some(condition);
self
}
pub fn visible_when_locked(mut self, reason: Text) -> Self {
self.visible_when_locked = true;
self.locked_reason = Some(reason);
self
}
pub fn with_effects(mut self, effects: Vec<Effect>) -> Self {
self.effects = effects;
self
}
pub fn goto(mut self, node: NodeId) -> Self {
self.goto = Some(node);
self
}
}