diff --git a/README.md b/README.md index c48872d..64c13fc 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ Since the original watchface is **NOT** open source, this "port" could be more a - The original [Maan On My Wrist](https://apps.rebble.io/en_US/application/557724772d93bc0eae00004c?native=false&query=maan§ion=watchfaces) is still perfectly silly on b&w screens! # Considerations For The Future -- Restore last combo after using an app - Add more Maan art (see [this gallery](https://www.flickr.com/photos/53297919@N04/albums/72157624708812279) for potential candidates) - Potential light mode (don't hold your breath - I'm still not sure this would look good and I don't like the idea of having settings) - Black&white support if I get bored or Pebble releases a modern b&w watch (Flint doesn't count) diff --git a/src/c/main.c b/src/c/main.c index 24472d9..a7f1aeb 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -119,6 +119,10 @@ static const GColor8 s_dark_bg_colors[] = { GColorBrilliantRose, GColorMelon, GColorShockingPink, // Brown GColorRoseVale}; +#define storage_key_head 0 +#define storage_key_butt 1 +#define storage_key_color 2 +static uint8_t s_head_index, s_butt_index; static void destroy_animation_handler(Animation *animation, bool finished, void *context) { animation_destroy(animation); @@ -207,7 +211,8 @@ static void schedule_guy_animation(Animation *raise_tmpl, Animation *out_tmpl, A static void update_minute_30_out_handler(Animation *animation, bool finished, void *context) { // destroy and reassign gbitmap_destroy(s_butt); - s_butt = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]); + s_butt_index = rand() % s_butt_count; + s_butt = gbitmap_create_with_resource(s_random_butts[s_butt_index]); // swap colors replace_gbitmap_color(GColorGreen, s_random_color_next, s_butt, NULL); @@ -228,7 +233,8 @@ static void update_minute_30() { static void update_minute_60_out_handler(Animation *animation, bool finished, void *context) { // destroy and reassign gbitmap_destroy(s_head); - s_head = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]); + s_head_index = rand() % s_head_count; + s_head = gbitmap_create_with_resource(s_random_heads[s_head_index]); // swap colors replace_gbitmap_color(GColorGreen, s_random_color_next, s_head, NULL); @@ -379,15 +385,22 @@ static void init() { window_set_background_color(s_main_window, GColorBlack); // load initial batch of silly guy parts into memory - s_head = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]); - s_butt = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]); + if (persist_exists(storage_key_color)) { + s_head_index = persist_read_int(storage_key_head); + s_butt_index = persist_read_int(storage_key_butt); + s_random_color_current = (GColor8){.argb = persist_read_int(storage_key_color)}; + } else { + s_head_index = rand() % s_head_count; + s_butt_index = rand() % s_butt_count; + s_random_color_current = s_dark_bg_colors[rand() % s_color_count]; + } + s_head = gbitmap_create_with_resource(s_random_heads[s_head_index]); + s_butt = gbitmap_create_with_resource(s_random_butts[s_butt_index]); - // pick starting colors - s_random_color_current = s_dark_bg_colors[rand() % s_color_count]; + // set starting colors + s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; replace_gbitmap_color(GColorGreen, s_random_color_current, s_head, NULL); replace_gbitmap_color(GColorGreen, s_random_color_current, s_butt, NULL); - // don't overwrite current color, as it will need to be replaced - s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; // load custom font #if PBL_DISPLAY_WIDTH <= 180 @@ -489,6 +502,11 @@ static void deinit() { gbitmap_destroy(s_bt0_icon); gbitmap_destroy(s_bt1_icon); + // write to persistent storage + persist_write_int(storage_key_head, s_head_index); + persist_write_int(storage_key_butt, s_butt_index); + persist_write_int(storage_key_color, s_random_color_current.argb); + // destroy window window_destroy(s_main_window); }