Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added lastline before choice #2822

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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