storybook/rust-ffi-demo/demo.c

54 lines
1.3 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdint.h>
#include "demo.h"
const char* story = "START\n"
"One day, Dane took a really big shit!\n"
"GOTO DIALOG\n"
"DIALOG\n"
"\"Wow, that was a really big shit!\"\n"
"1) Die [DIE]\n"
"2) Don't die <Strength 100+> [DONT_DIE] (-1 Honor)\n"
"DONT_DIE\n"
"But he died anyways.\n"
"GOTO DIE\n"
"DIE\n"
"Then he died. Fuck you, Dane!\n"
"THE END\n";
int main() {
Book *book = storybook_make_book(story);
while(!storybook_is_ended(book)) {
char* s = storybook_get_body(book);
printf("%s\n", s);
storybook_free_string(s);
enum footer footer = storybook_get_footer(book);
switch (footer) {
case (FOOTER_ENDING):
printf("The End\n");
storybook_advance_nooption(book);
break;
case (FOOTER_GOTO):
storybook_advance_nooption(book);
break;
case (FOOTER_CHOICES):
2022-01-19 09:57:20 -06:00
int n = storybook_get_num_choices(book);
for (int i = 1; i <= n; i++) {
Choice* choice = storybook_get_choice(book, i);
printf("%d) %s\n", choice->option, choice->flavor);
storybook_free_choice(choice);
}
uint32_t option;
printf("Make a choice: ");
scanf("%d", &option);
storybook_advance_option(book, option);
}
}
storybook_free_book(book);
return 0;
}