diff --git a/src/cyoa.h b/src/cyoa.h index c9cdff9..c7f3397 100644 --- a/src/cyoa.h +++ b/src/cyoa.h @@ -2,7 +2,7 @@ #define CYOA_H #include -#include +#include #define STATCHECK_GT 1 #define STATCHECK_LT 2 @@ -28,14 +28,7 @@ struct Choice { Choice(char*, statcheck_t *statcheck, statchange_t *statchange); }; -struct ChoiceComparator { - bool operator()(const Choice* a, const Choice* b) const { - return a->option < b->option; - } -}; - -typedef std::set ChoiceList; - +typedef std::map ChoiceList; enum class FooterType { End, diff --git a/src/cyoa.leg b/src/cyoa.leg index b934fc7..bb6a4bf 100644 --- a/src/cyoa.leg +++ b/src/cyoa.leg @@ -57,8 +57,8 @@ Goto = 'GOTO' - < i:Identifier > Newline Ending = 'THE END' Newline -ChoiceList = c:Choice l:ChoiceList { $$ = l; $$.choices->insert(c.choice); } - | c:Choice { $$.choices = new ChoiceList(); $$.choices->insert(c.choice); } +ChoiceList = c:Choice l:ChoiceList { $$ = l; (*$$.choices)[c.choice->option] = c.choice; } + | c:Choice { $$.choices = new ChoiceList(); (*$$.choices)[c.choice->option] = c.choice; } Choice = b:Bullet f:Freetext r:Redirect { @@ -166,9 +166,8 @@ void print_page(Page *page) { break; case FooterType::Choices: printf("CHOICES:\n"); - for (Choice *c : *page->footer.choices) { - printf("%d) %s\n", c->option, c->flavor); - } + // TODO + break; } } diff --git a/src/storybook.cpp b/src/storybook.cpp index 87ca76f..cb57a5b 100644 --- a/src/storybook.cpp +++ b/src/storybook.cpp @@ -49,6 +49,14 @@ void Storybook::Find(const char* id) { current = NULL; } +void print_choice(Choice* c) { + printf("%d) %s", c->option, c->flavor); + if (c->statcheck) { + //TODO + } + printf("\n"); +} + void Storybook::Play() { printf(current->body); @@ -63,8 +71,8 @@ void Storybook::Play() { std::cin.get(); break; case FooterType::Choices: - for (Choice *c : *current->footer.choices) { - printf("%d) %s\n", c->option, c->flavor); + for (auto c : *current->footer.choices) { + print_choice(c.second); } default: IsEnded = true; // TODO