DialogueManager class
Central service for the Narrative/Dialogue System.
Manages DialogueGraph registration, DialogueRunner lifecycle, global variables, localization, conditions, and commands.
Typical setup
final narrative = DialogueManager();
// Load localized strings
await narrative.localizer.loadLocale(const Locale('en'));
// Load dialogue assets
await narrative.loadGraph('assets/dialogue/innkeeper.yarn');
// Register custom conditions
narrative.conditions.register('playerHasKey', (vars) => player.hasKey);
// Register custom commands
narrative.commands.register('fade_out', (ctx) async => camera.fadeOut());
// Create a runner and start dialogue
final runner = narrative.createRunner('innkeeper');
runner.signals.currentLine.addListener(() { ... });
await runner.start('Start');
Constructors
- DialogueManager({DialogueLocalizer? localizer, DialogueVariableStore? globalVariables})
Properties
-
activeGraphId
→ Signal<
String?> -
Emits the DialogueGraph.id of the currently active graph, or
null.final - commands ↔ DialogueCommandRegistry
-
Registry for custom
<<commandName args>>handlers.latefinal - conditions ↔ DialogueConditionRegistry
-
Registry for named Dart condition predicates (
[conditionName]in Yarn).latefinal - globalVariables → DialogueVariableStore
-
Global variable store shared across all runners created by this
manager. Persists between individual dialogue sessions.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
isAnyDialogueActive
→ Signal<
bool> -
truewhen at least one runner created by this manager is active.final - localizer → DialogueLocalizer
-
Localizer used by all runners. Load locales early in your boot sequence.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createRunner(
String graphId, {NarrativeSignals? signals}) → DialogueRunner -
Creates a new DialogueRunner for the graph registered under
graphId. -
createRunnerForEntity(
int entityId, String graphId, {NarrativeSignals? signals}) → DialogueRunner -
Creates a runner bound to an ECS entity (keyed by
entityId). -
dispose(
) → Future< void> - Stops all active runners and clears all state.
-
disposeRunner(
DialogueRunner runner) → Future< void> -
Stops and removes
runnerfrom internal tracking. -
disposeRunnerForEntity(
int entityId) → Future< void> -
Removes and disposes the runner for
entityId. -
getGraph(
String id) → DialogueGraph? -
Returns the registered graph for
id, ornullif not found. -
getRunnerForEntity(
int entityId) → DialogueRunner? -
Returns the runner bound to
entityId, ornull. -
hasGraph(
String id) → bool -
trueif a graph withidhas been registered. -
loadGraph(
String assetPath, {String? id, AssetBundle? bundle}) → Future< DialogueGraph> -
Loads a
.yarnasset fromassetPathand registers it. -
mergeGraph(
DialogueGraph graph) → void -
Merges
graphinto an existing graph by the same id, or registers it. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parseAndRegister(
String yarnSource, {required String id}) → DialogueGraph - Parses a Yarn Spinner source string and registers the resulting graph.
-
registerGraph(
DialogueGraph graph) → void -
Manually registers a
graph(e.g. built programmatically or from tests). -
startDialogue(
{required String graphId, String startNode = 'Start'}) → Future< DialogueRunner> -
Convenience: creates a runner, starts dialogue from
startNode, and returns the runner. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited