bubbles/lib.rs
1//! Lightweight, engine-agnostic dialogue runtime for Rust games.
2//!
3//! On [crates.io](https://crates.io/crates/bubbles-dialogue) the package is **bubbles-dialogue**
4//! because the crate name **bubbles** was already taken there. This library is still named
5//! **bubbles**: depend on `bubbles-dialogue` in `Cargo.toml` and `use bubbles::…` in code.
6//!
7//! Write branching dialogue in `.bub` scripts, compile them once, then drive
8//! the dialogue from any game loop via a pull-based event API.
9//!
10//! # Quick start
11//!
12//! ```rust
13//! use bubbles::{compile, DialogueEvent, HashMapStorage, Runner};
14//!
15//! let source = "title: Greet\n---\nHello!\n===\n";
16//! let prog = compile(source).unwrap();
17//! let mut runner = Runner::new(prog, HashMapStorage::new());
18//! runner.start("Greet").unwrap();
19//!
20//! assert!(matches!(
21//! runner.next_event().unwrap(),
22//! Some(DialogueEvent::NodeStarted(_))
23//! ));
24//! assert!(matches!(
25//! runner.next_event().unwrap(),
26//! Some(DialogueEvent::Line { .. })
27//! ));
28//! assert!(matches!(
29//! runner.next_event().unwrap(),
30//! Some(DialogueEvent::NodeComplete(_))
31//! ));
32//! assert!(matches!(
33//! runner.next_event().unwrap(),
34//! Some(DialogueEvent::DialogueComplete)
35//! ));
36//! ```
37//!
38//! # Modules
39//!
40//! | Module | Contents |
41//! |--------|----------|
42//! | [`value`] | [`Value`], [`VariableStorage`], [`HashMapStorage`] |
43//! | [`compiler`] | [`compile`], [`compile_many`], [`validate`], [`Program`], [`VariableDecl`] |
44//! | [`runtime`] | [`Runner`], [`RunnerPhase`], [`DialogueEvent`], [`LineMode`], [`LineProvider`], [`line_id_from_tags`], [`line_mode_from_tags`], [`RunnerSnapshot`] |
45//! | [`library`] | [`FunctionLibrary`] and built-in functions |
46//! | [`saliency`] | [`SaliencyStrategy`], [`FirstAvailable`], [`BestLeastRecentlyViewed`], `RandomAvailable` (`rand` feature) |
47//!
48//! Lint policy is defined once in `Cargo.toml` under `[lints.rust]` /
49//! `[lints.clippy]`; we deliberately do not duplicate it here.
50
51pub mod compiler;
52pub mod error;
53pub mod library;
54pub mod runtime;
55pub mod saliency;
56pub mod value;
57
58pub use compiler::{Program, VariableDecl, compile, compile_many, validate};
59pub use error::{DialogueError, Result};
60pub use library::FunctionLibrary;
61pub use runtime::RunnerSnapshot;
62pub use runtime::{
63 DialogueEvent, DialogueOption, HashMapProvider, LineMode, LineProvider, MarkupSpan,
64 PassthroughProvider, Runner, RunnerBuilder, RunnerPhase, line_id_from_tags,
65 line_mode_from_tags, option_group_from_tags,
66};
67#[cfg(feature = "rand")]
68pub use saliency::RandomAvailable;
69pub use saliency::{BestLeastRecentlyViewed, Candidate, FirstAvailable, SaliencyStrategy};
70pub use value::{HashMapStorage, Value, VariableStorage};