2e7eebf603fef84bbbc4ddd45226cca217d75f71
2 #include "../ui/menu.h"
4 #include <drivers/fatfs/ff.h>
8 LEVELDESCRIPTION_MAX
= 14,
9 MENU_BUFLEN
= LEVELDESCRIPTION_MAX
+ 1 + LEVELFILE_MAX
+ 1
12 #define PROGRESS_FNAME "progress.dat"
14 static uint8_t jumpnrun_load_progress(void) {
18 if(FR_OK
== f_open(&fd
, PROGRESS_FNAME
, FA_OPEN_EXISTING
| FA_READ
)) {
20 f_read(&fd
, &progress
, sizeof(progress
), &bytes
);
27 static void jumpnrun_save_progress(uint8_t progress
) {
30 if(FR_OK
== f_open(&fd
, PROGRESS_FNAME
, FA_CREATE_ALWAYS
| FA_WRITE
)) {
32 f_write(&fd
, &progress
, sizeof(progress
), &bytes
);
37 static uint8_t jumpnrun_pick_level_from_fd(char *buf
, size_t *first_visible
, size_t *selected
, uint8_t progress
, FIL
*fd
) {
38 unsigned levelcount
= 0;
41 char buf
[MENU_BUFLEN
];
42 while(f_gets(buf
, MENU_BUFLEN
, fd
) && levelcount
<= progress
) {
47 if(FR_OK
!= f_lseek(fd
, 0)) {
48 return JUMPNRUN_ERROR
;
51 char menu_buf
[levelcount
][MENU_BUFLEN
];
52 char const *menu_index
[levelcount
];
53 char const *fnames
[levelcount
];
56 for(i
= 0; i
< levelcount
&& f_gets(menu_buf
[i
], MENU_BUFLEN
, fd
); ++i
) {
57 menu_index
[i
] = menu_buf
[i
];
59 for(p
= menu_buf
[i
]; *p
&& *p
!= '|'; ++p
)
67 *selected
= badge_menu(menu_index
, i
, first_visible
, *selected
);
69 strcpy(buf
, fnames
[*selected
]);
73 static uint8_t jumpnrun_pick_level(char *buf
, size_t *first_visible
, size_t *selected
, uint8_t progress
) {
76 if(FR_OK
!= f_open(&fd
, "levels.lst", FA_OPEN_EXISTING
| FA_READ
)) {
77 return JUMPNRUN_ERROR
;
80 uint8_t err
= jumpnrun_pick_level_from_fd(buf
, first_visible
, selected
, progress
, &fd
);
87 void jumpnrun_play(void) {
88 char buf
[LEVELFILE_MAX
+ 1];
89 size_t first_visible
= 0;
91 uint8_t progress
= jumpnrun_load_progress();
93 while(0 == jumpnrun_pick_level(buf
, &first_visible
, &selected
, progress
)) {
94 if(JUMPNRUN_WON
== jumpnrun_play_level(buf
) && selected
== progress
) {
95 selected
= ++progress
;
96 jumpnrun_save_progress(progress
);
This page took 0.04814 seconds and 3 git commands to generate.