Skip to content

Commit

Permalink
Save NYT final attempt, fixes #15 once and for all
Browse files Browse the repository at this point in the history
  • Loading branch information
mupfdev committed Apr 18, 2022
1 parent 049227f commit 11312b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
25 changes: 9 additions & 16 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ int game_update(game_t *core)
{
if (SDL_TRUE == core->nyt_mode)
{
core->nyt_final_attempt = core->attempt;
core->nyt_final_attempt = core->attempt + 1;
core->nyt_has_ended = SDL_TRUE;
game_save(core);
}
Expand Down Expand Up @@ -495,7 +495,7 @@ int game_update(game_t *core)
stats_pos_x = 57;
}

stbsp_snprintf(stats, 16, "Wordle %u %1u/6", get_nyt_daily_index(), core->nyt_attempt_count);
stbsp_snprintf(stats, 16, "Wordle %u %1u/6", get_nyt_daily_index(), core->nyt_final_attempt);
osd_print(stats, stats_pos_x, 12, core);
}
}
Expand Down Expand Up @@ -576,13 +576,13 @@ void game_save(game_t* core)
state.tile[index].state = core->tile[index].state;
}

state.version = SAVE_VERSION;
state.version = SAVE_VERSION;
state.current_index = core->current_index;
state.previous_letter = core->previous_letter;
state.valid_answer_index = core->valid_answer_index;
state.attempt = core->attempt;
state.seed = core->seed;
state.language = core->wordlist.language;
state.seed = core->seed;
state.language = core->wordlist.language;

save_file = fopen(SAVE_FILE, "wb");
if (NULL == save_file)
Expand All @@ -608,15 +608,8 @@ void game_save(game_t* core)
state.previous_letter = core->previous_letter;
state.valid_answer_index = core->valid_answer_index;
state.has_ended = core->nyt_has_ended;

if (SDL_TRUE == state.has_ended)
{
state.attempt = core->nyt_final_attempt;
}
else
{
state.attempt = core->attempt;
}
state.attempt = core->attempt;
state.final_attempt = core->nyt_final_attempt;

save_file = fopen(DAILY_SAVE_FILE, "wb");
if (NULL == save_file)
Expand Down Expand Up @@ -715,6 +708,7 @@ void game_load(SDL_bool load_daily, game_t* core)
core->valid_answer_index = state.valid_answer_index;
core->attempt = state.attempt;
core->nyt_has_ended = state.has_ended;
core->nyt_final_attempt = state.final_attempt;

set_language(LANG_ENGLISH, SDL_FALSE, core);
}
Expand Down Expand Up @@ -1135,8 +1129,7 @@ static void show_results(game_t* core)

if (SDL_TRUE == core->nyt_mode)
{
core->nyt_attempt_count = core->attempt + 1;
core->show_stats = SDL_TRUE;
core->show_stats = SDL_TRUE;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct nyt_save_state
int valid_answer_index;
Uint8 attempt;
SDL_bool has_ended;
Uint8 final_attempt;

} nyt_save_state_t;

Expand All @@ -99,7 +100,6 @@ typedef struct game
SDL_bool show_stats;
SDL_bool language_set_once;
SDL_bool nyt_has_ended;
unsigned int nyt_attempt_count;
tile_t tile[30];
int current_index;
char previous_letter;
Expand Down

0 comments on commit 11312b7

Please sign in to comment.