]> git.earman.xyz Git - sensor-watch.git/commitdiff
Wordle game resets after 24hrs of not playing when not using daily streak
authorDavid Volovskiy <devolov@gmail.com>
Tue, 27 Aug 2024 16:08:24 +0000 (12:08 -0400)
committerDavid Volovskiy <devolov@gmail.com>
Tue, 3 Sep 2024 20:11:54 +0000 (16:11 -0400)
movement/watch_faces/complication/wordle_face.c
movement/watch_faces/complication/wordle_face.h

index 09b5dc2f6c6ef6dba4f6268f279346a73e04df28..1cf931b41c122a5b4e8ba96e5e15ef18615485b8 100644 (file)
@@ -25,9 +25,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "wordle_face.h"
-#if WORDLE_USE_DAILY_STREAK
 #include "watch_utility.h"
-#endif
 
 static uint32_t get_random(uint32_t max) {
     #if __EMSCRIPTEN__
@@ -298,6 +296,11 @@ static uint32_t get_day_unix_time(void) {
     now.unit.hour = now.unit.minute = now.unit.second = 0;
     return watch_utility_date_time_to_unix_time(now, 0);
 }
+#else
+static uint32_t get_day_unix_time(void) {
+    watch_date_time now = watch_rtc_get_date_time();
+    return watch_utility_date_time_to_unix_time(now, 0);
+}
 #endif
 
 static void display_lose(wordle_state_t *state, uint8_t subsecond) {
@@ -373,9 +376,7 @@ static bool act_on_btn(wordle_state_t *state, const uint8_t pin) {
 #endif
         return true;
     case SCREEN_STREAK:
-#if WORDLE_USE_DAILY_STREAK
         state->curr_day = get_day_unix_time();
-#endif
         reset_board(state);
         return true;
     case SCREEN_WIN:
@@ -495,10 +496,15 @@ void wordle_face_setup(movement_settings_t *settings, uint8_t watch_face_index,
 void wordle_face_activate(movement_settings_t *settings, void *context) {
     (void) settings;
     wordle_state_t *state = (wordle_state_t *)context;
+    uint32_t now = get_day_unix_time();
 #if WORDLE_USE_DAILY_STREAK
-    uint32_t now = get_day_unix_time() ;
-    if (now >= (state->prev_day + (60 *60 * 24))) state->streak = 0;
     if (state->curr_day != now) reset_all_elements(state);
+    if (now >= (state->prev_day + (60 *60 * 24))) state->streak = 0;
+#else
+    if (is_playing(state) && now >= (state->curr_day + (60 *60 * 24))) {
+        state->streak = 0;
+        reset_board(state);
+    }
 #endif
     state->using_random_guess = false;
     if (is_playing(state) && state->curr_screen >= SCREEN_RESULT) {
index 2a3cc1dc48e56595e2f42dc9ef3a2b63cebfbd97..ffb3782da585179b4cf44ffe7a9b72d35eb53e50 100644 (file)
@@ -66,7 +66,8 @@
 
 #define WORDLE_LENGTH 5
 #define WORDLE_MAX_ATTEMPTS 6
-#define WORDLE_USE_DAILY_STREAK false
+#define WORDLE_USE_DAILY_STREAK false  // If true, the board will reset daily and the streak will go to zero if the game isn't played for a day
+                                       // If false, then the streak will still reset if the game is not completed within 24 hours
 #define WORDLE_ALLOW_NON_WORD_AND_REPEAT_GUESSES false  // This allows non-words to be entered and repeat guesses to be made. It saves ~11.5KB of ROM.
 /*  WORDLE_USE_RANDOM_GUESS
  *  0 = Don't allow quickly choosing a random quess
@@ -119,9 +120,9 @@ typedef struct {
     uint8_t streak;
     WordleScreen curr_screen;
     bool known_wrong_letters[WORDLE_NUM_VALID_LETTERS];
+    uint32_t curr_day;
 #if WORDLE_USE_DAILY_STREAK
     uint32_t prev_day;
-    uint32_t curr_day;
 #endif
 } wordle_state_t;