From f3d3bd2cd1f11fdbc25058f426927cf59b2998bb Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Thu, 23 Dec 2021 17:20:05 -0600 Subject: [PATCH] Handle END and GOTO footers --- example/simple.story | 2 +- src/storybook.cpp | 19 +++++++++++++++---- src/storybook.h | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/example/simple.story b/example/simple.story index f236047..79efc9d 100644 --- a/example/simple.story +++ b/example/simple.story @@ -3,7 +3,7 @@ START One day Dane took a really big shit. Dane: "Wow, that was a really big shit" -1) Don't die [NEXT] +GOTO NEXT NEXT diff --git a/src/storybook.cpp b/src/storybook.cpp index 5dbe449..98f8277 100644 --- a/src/storybook.cpp +++ b/src/storybook.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "storybook.h" @@ -24,7 +25,7 @@ int main(int argc, const char *argv[]) { sb.Find("START"); sb.Play(); - while (!sb.IsEnded()) { + while (!sb.IsEnded) { sb.Play(); } @@ -50,8 +51,18 @@ void Storybook::Find(const char* id) { void Storybook::Play() { printf(current->body); -} -bool Storybook::IsEnded() { - return true; // TODO + switch (current->footer.type) { + case FooterType::End: + printf("The End."); + IsEnded = true; + break; + case FooterType::Goto: + Find(current->footer.link); + printf("Press ENTER to continue..."); + std::cin.get(); + break; + default: + IsEnded = true; // TODO + } } diff --git a/src/storybook.h b/src/storybook.h index 04862a4..80bf5bc 100644 --- a/src/storybook.h +++ b/src/storybook.h @@ -13,7 +13,7 @@ public: Storybook(FILE* fin); void Find(const char*); void Play(); - bool IsEnded(); + bool IsEnded = false; }; #endif /* STORYBOOK_H */