Actually choices should be a map<int,Choice*>
This commit is contained in:
parent
e94e43f547
commit
9006913174
11
src/cyoa.h
11
src/cyoa.h
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user