Actually choices should be a map<int,Choice*>

This commit is contained in:
Dane Johnson 2021-12-26 17:22:24 -06:00
parent e94e43f547
commit 9006913174
3 changed files with 16 additions and 16 deletions

View File

@ -2,7 +2,7 @@
#define CYOA_H
#include <vector>
#include <set>
#include <map>
#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<Choice*, ChoiceComparator> ChoiceList;
typedef std::map<int, Choice*> ChoiceList;
enum class FooterType {
End,

View File

@ -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;
}
}

View File

@ -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