diff --git a/packages/flame_jenny/jenny/lib/src/parse/parse.dart b/packages/flame_jenny/jenny/lib/src/parse/parse.dart index ec499639282..8830525b569 100644 --- a/packages/flame_jenny/jenny/lib/src/parse/parse.dart +++ b/packages/flame_jenny/jenny/lib/src/parse/parse.dart @@ -134,6 +134,16 @@ class _Parser { if (lines.isNotEmpty && lines.last is DialogueChoice) { (lines.last as DialogueChoice).options.add(option); } else { + if (lines.isNotEmpty && lines.last is DialogueLine) { + final lastLine = lines.removeLast() as DialogueLine; + lines.add( + DialogueLine( + content: lastLine.content!, + character: lastLine.character, + tags: [...lastLine.tags, '#lastline'], + ), + ); + } lines.add(DialogueChoice([option])); } } else if (nextToken == Token.startCommand) { @@ -912,8 +922,11 @@ class _Parser { } bool takeId() => takeTokenType(TokenType.id); + bool takeText() => takeTokenType(TokenType.text); + bool takePerson() => takeTokenType(TokenType.person); + bool takeNewline() { if (position >= tokens.length) { return true; @@ -967,6 +980,7 @@ class _Parser { class _NodeHeader { _NodeHeader(this.title, this.tags); + String? title; Map? tags; } diff --git a/packages/flame_jenny/jenny/lib/src/structure/dialogue_line.dart b/packages/flame_jenny/jenny/lib/src/structure/dialogue_line.dart index 145d5996c2a..f7ba148599e 100644 --- a/packages/flame_jenny/jenny/lib/src/structure/dialogue_line.dart +++ b/packages/flame_jenny/jenny/lib/src/structure/dialogue_line.dart @@ -56,6 +56,9 @@ class DialogueLine extends DialogueEntry { final LineContent _content; String? _value; + /// The content of this Line. + LineContent? get content => _content; + /// The character who is speaking the line. This can be null if the line does /// not contain a speaker. Character? get character => _character; diff --git a/packages/flame_jenny/jenny/test/dialogue_runner_test.dart b/packages/flame_jenny/jenny/test/dialogue_runner_test.dart index 8228321f1a4..45de437dfdb 100644 --- a/packages/flame_jenny/jenny/test/dialogue_runner_test.dart +++ b/packages/flame_jenny/jenny/test/dialogue_runner_test.dart @@ -124,6 +124,7 @@ void main() { test('dialogue with choices', () async { final yarn = YarnProject() ..parse('title: X\n---\n' + 'Question?\n' '-> Hi there\n' '-> Howdy\n' ' Greetings to you too\n' @@ -138,6 +139,8 @@ void main() { [ '[*] onDialogueStart()', '[*] onNodeStart(Node(X))', + '[*] onLineStart(DialogueLine(Question?)[#lastline])', + '[*] onLineFinish(DialogueLine(Question?))', '[*] onChoiceStart(DialogueChoice([Option(Hi there), ' + 'Option(Howdy), Option(Yo! #disabled)])) -> 1', '[*] onChoiceFinish(Option(Howdy))', @@ -157,6 +160,8 @@ void main() { [ '[*] onDialogueStart()', '[*] onNodeStart(Node(X))', + '[*] onLineStart(DialogueLine(Question?)[#lastline])', + '[*] onLineFinish(DialogueLine(Question?))', '[*] onChoiceStart(DialogueChoice([Option(Hi there), ' + 'Option(Howdy), Option(Yo! #disabled)])) -> 0', '[*] onChoiceFinish(Option(Hi there))', @@ -373,7 +378,7 @@ class _RecordingDialogueView extends DialogueView { @override FutureOr onLineStart(DialogueLine line) => - _record('onLineStart($line)'); + _record('onLineStart($line${line.tags.isNotEmpty ? line.tags : ""})'); @override void onLineFinish(DialogueLine line) => _record('onLineFinish($line)');