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
|
#define CYOA_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <map>
|
||||||
|
|
||||||
#define STATCHECK_GT 1
|
#define STATCHECK_GT 1
|
||||||
#define STATCHECK_LT 2
|
#define STATCHECK_LT 2
|
||||||
@ -28,14 +28,7 @@ struct Choice {
|
|||||||
Choice(char*, statcheck_t *statcheck, statchange_t *statchange);
|
Choice(char*, statcheck_t *statcheck, statchange_t *statchange);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ChoiceComparator {
|
typedef std::map<int, Choice*> ChoiceList;
|
||||||
bool operator()(const Choice* a, const Choice* b) const {
|
|
||||||
return a->option < b->option;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::set<Choice*, ChoiceComparator> ChoiceList;
|
|
||||||
|
|
||||||
|
|
||||||
enum class FooterType {
|
enum class FooterType {
|
||||||
End,
|
End,
|
||||||
|
@ -57,8 +57,8 @@ Goto = 'GOTO' - < i:Identifier > Newline
|
|||||||
|
|
||||||
Ending = 'THE END' Newline
|
Ending = 'THE END' Newline
|
||||||
|
|
||||||
ChoiceList = c:Choice l:ChoiceList { $$ = l; $$.choices->insert(c.choice); }
|
ChoiceList = c:Choice l:ChoiceList { $$ = l; (*$$.choices)[c.choice->option] = c.choice; }
|
||||||
| c:Choice { $$.choices = new ChoiceList(); $$.choices->insert(c.choice); }
|
| c:Choice { $$.choices = new ChoiceList(); (*$$.choices)[c.choice->option] = c.choice; }
|
||||||
|
|
||||||
Choice = b:Bullet f:Freetext r:Redirect
|
Choice = b:Bullet f:Freetext r:Redirect
|
||||||
{
|
{
|
||||||
@ -166,9 +166,8 @@ void print_page(Page *page) {
|
|||||||
break;
|
break;
|
||||||
case FooterType::Choices:
|
case FooterType::Choices:
|
||||||
printf("CHOICES:\n");
|
printf("CHOICES:\n");
|
||||||
for (Choice *c : *page->footer.choices) {
|
// TODO
|
||||||
printf("%d) %s\n", c->option, c->flavor);
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,14 @@ void Storybook::Find(const char* id) {
|
|||||||
current = NULL;
|
current = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_choice(Choice* c) {
|
||||||
|
printf("%d) %s", c->option, c->flavor);
|
||||||
|
if (c->statcheck) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
void Storybook::Play() {
|
void Storybook::Play() {
|
||||||
printf(current->body);
|
printf(current->body);
|
||||||
|
|
||||||
@ -63,8 +71,8 @@ void Storybook::Play() {
|
|||||||
std::cin.get();
|
std::cin.get();
|
||||||
break;
|
break;
|
||||||
case FooterType::Choices:
|
case FooterType::Choices:
|
||||||
for (Choice *c : *current->footer.choices) {
|
for (auto c : *current->footer.choices) {
|
||||||
printf("%d) %s\n", c->option, c->flavor);
|
print_choice(c.second);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
IsEnded = true; // TODO
|
IsEnded = true; // TODO
|
||||||
|
Loading…
Reference in New Issue
Block a user