mod facts;
pub(crate) mod runner;
mod session;
mod stored;
pub(crate) use facts::turn_fields;
pub(crate) use runner::GraphState;
pub(crate) use stored::{DialogueCache, Pending};
use lingara_dialogue_ir::{DialogueIr, Document, Warning};
use crate::shared::Shared;
use crate::types::{CrossedVia, DialogueId, EmbedEvent, LogLevel};
pub(crate) const TARGET: &str = "lingara_embed::dialogue";
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum Step {
Reached { checkpoint: String, edge: Option<String>, via: CrossedVia },
Ended { outcome: String, checkpoint: String, edge: Option<String> },
Log { level: LogLevel, message: String },
}
pub(crate) fn log(level: LogLevel, message: String) -> Step {
Step::Log { level, message }
}
pub(crate) fn emit(shared: &Shared, dialogue: DialogueId, steps: Vec<Step>) {
for step in steps {
match step {
Step::Reached { checkpoint, edge, via } => shared.outbox.push_later(EmbedEvent::CheckpointReached { dialogue, checkpoint, edge, via }),
Step::Ended { outcome, checkpoint, edge } => shared.outbox.push_later(EmbedEvent::DialogueEnded { dialogue, outcome, checkpoint, edge }),
Step::Log { level, message } => shared.diag.emit(level, TARGET, message),
}
}
}
pub(crate) const PROCEDURAL_NOT_YET: &str = "this kit cannot run procedural dialogues yet: upgrade lingara-embed";
pub(crate) fn load_ir(ir_json: &str) -> Result<(DialogueIr, Vec<Warning>), String> {
match lingara_dialogue_ir::load_document(ir_json).map_err(|e| e.to_string())? {
(Document::Static(ir), warnings) => Ok((ir, warnings)),
(Document::Procedural(_), _) => Err(PROCEDURAL_NOT_YET.into()),
}
}
pub(crate) fn stance_notice(ir: &DialogueIr) -> Option<Step> {
let stance = ir.npcs.iter().any(|n| n.disposition.is_some()) || ir.checkpoints.iter().any(|c| c.steer_to.is_some());
stance.then(|| log(LogLevel::Info, "this dialogue's steering stance (`disposition`, `steer_to`) loads but is not sent yet".into()))
}