interpret method
Interprets a single BaseNarrativeModel and executes the defined handlers
Parses the instruction and determines which actions to run.
Multiple handlers can be triggered for a single sentence (e.g. both read and write).
Implementation
Future<void> interpret(BaseNarrativeModel sentence) async {
final instruction = sentence.instruction.toLowerCase();
final shouldAsk = sentence.choices.isNotEmpty;
final shouldWait = sentence.waitForUserInput;
final shouldNavigate =
sentence.phase != null && sentence.phase != currentPhase;
if (shouldNavigate) currentPhase = sentence.phase!;
if (instruction.contains('write')) {
await _handleWrite(sentence);
}
if (instruction.contains('read')) {
await _handleRead(sentence);
}
if (shouldNavigate && shouldWait) {
await engine.pauseUntilUserContinues();
} else if (shouldWait) {
await _handleWait(sentence);
}
if (shouldAsk) {
await _handleAsk(sentence);
}
if (shouldNavigate) {
await _handleNavigate(sentence);
}
if (!_isHandled(instruction)) {
onUnhandled?.call(sentence);
}
}