Skip to content

Commit

Permalink
feat: Added lastline before choice (#2822)
Browse files Browse the repository at this point in the history
According to the YarnSpinner Documentation the tag "#lastline" should be
added on each line bevore a choice.

https://docs.yarnspinner.dev/getting-started/writing-in-yarn/tags-metadata#special-tags

This PR does this.
  • Loading branch information
synchronisator authored Oct 17, 2023
1 parent 28bc371 commit 3ef5252
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/flame_jenny/jenny/lib/src/parse/parse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -967,6 +980,7 @@ class _Parser {

class _NodeHeader {
_NodeHeader(this.title, this.tags);

String? title;
Map<String, String>? tags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion packages/flame_jenny/jenny/test/dialogue_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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))',
Expand All @@ -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))',
Expand Down Expand Up @@ -373,7 +378,7 @@ class _RecordingDialogueView extends DialogueView {

@override
FutureOr<bool> onLineStart(DialogueLine line) =>
_record('onLineStart($line)');
_record('onLineStart($line${line.tags.isNotEmpty ? line.tags : ""})');

@override
void onLineFinish(DialogueLine line) => _record('onLineFinish($line)');
Expand Down

0 comments on commit 3ef5252

Please sign in to comment.