Use a set for story options
This commit is contained in:
parent
b30463dfd2
commit
e94e43f547
12
src/cyoa.h
12
src/cyoa.h
@ -2,6 +2,7 @@
|
|||||||
#define CYOA_H
|
#define CYOA_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#define STATCHECK_GT 1
|
#define STATCHECK_GT 1
|
||||||
#define STATCHECK_LT 2
|
#define STATCHECK_LT 2
|
||||||
@ -27,6 +28,15 @@ struct Choice {
|
|||||||
Choice(char*, statcheck_t *statcheck, statchange_t *statchange);
|
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;
|
||||||
|
|
||||||
|
|
||||||
enum class FooterType {
|
enum class FooterType {
|
||||||
End,
|
End,
|
||||||
Goto,
|
Goto,
|
||||||
@ -36,7 +46,7 @@ enum class FooterType {
|
|||||||
struct Footer {
|
struct Footer {
|
||||||
FooterType type;
|
FooterType type;
|
||||||
union {
|
union {
|
||||||
std::vector<Choice*> *choices;
|
ChoiceList *choices;
|
||||||
char *link;
|
char *link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
10
src/cyoa.leg
10
src/cyoa.leg
@ -16,7 +16,7 @@ std::vector<Page*> pages;
|
|||||||
|
|
||||||
Page *emit_ending();
|
Page *emit_ending();
|
||||||
Page *emit_goto(char*);
|
Page *emit_goto(char*);
|
||||||
Page *emit_choices(std::vector<Choice*>*);
|
Page *emit_choices(ChoiceList*);
|
||||||
|
|
||||||
void append_body(Page *page, char *str);
|
void append_body(Page *page, char *str);
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ union value {
|
|||||||
Page *page;
|
Page *page;
|
||||||
char *string;
|
char *string;
|
||||||
Choice *choice;
|
Choice *choice;
|
||||||
std::vector<Choice*> *choices;
|
ChoiceList *choices;
|
||||||
int num;
|
int num;
|
||||||
statcheck_t *statcheck;
|
statcheck_t *statcheck;
|
||||||
statchange_t *statchange;
|
statchange_t *statchange;
|
||||||
@ -57,8 +57,8 @@ Goto = 'GOTO' - < i:Identifier > Newline
|
|||||||
|
|
||||||
Ending = 'THE END' Newline
|
Ending = 'THE END' Newline
|
||||||
|
|
||||||
ChoiceList = c:Choice l:ChoiceList { $$ = l; $$.choices->push_back(c.choice); }
|
ChoiceList = c:Choice l:ChoiceList { $$ = l; $$.choices->insert(c.choice); }
|
||||||
| c:Choice { $$.choices = new std::vector<Choice*>(); $$.choices->push_back(c.choice); }
|
| c:Choice { $$.choices = new ChoiceList(); $$.choices->insert(c.choice); }
|
||||||
|
|
||||||
Choice = b:Bullet f:Freetext r:Redirect
|
Choice = b:Bullet f:Freetext r:Redirect
|
||||||
{
|
{
|
||||||
@ -135,7 +135,7 @@ Page *emit_ending() {
|
|||||||
return mypage;
|
return mypage;
|
||||||
}
|
}
|
||||||
|
|
||||||
Page *emit_choices(std::vector<Choice*> *choices) {
|
Page *emit_choices(ChoiceList *choices) {
|
||||||
Page *mypage = new Page;
|
Page *mypage = new Page;
|
||||||
mypage->footer.type = FooterType::Choices;
|
mypage->footer.type = FooterType::Choices;
|
||||||
mypage->footer.choices = choices;
|
mypage->footer.choices = choices;
|
||||||
|
@ -62,6 +62,10 @@ void Storybook::Play() {
|
|||||||
printf("Press ENTER to continue...");
|
printf("Press ENTER to continue...");
|
||||||
std::cin.get();
|
std::cin.get();
|
||||||
break;
|
break;
|
||||||
|
case FooterType::Choices:
|
||||||
|
for (Choice *c : *current->footer.choices) {
|
||||||
|
printf("%d) %s\n", c->option, c->flavor);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
IsEnded = true; // TODO
|
IsEnded = true; // TODO
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user