From 78e4fcff29ea09440510d8ec5954ed486373ddd2 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 19 Feb 2026 13:34:37 -0800 Subject: [PATCH] Switching activities is now a separate function. --- main.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index 0151ae7..b47af80 100644 --- a/main.c +++ b/main.c @@ -162,6 +162,19 @@ Hours break_time(U64 seconds) return hours; } +void switch_activity(activity *activities, U32 *current_activity, activity_type type, U64 time) +{ + if((activities[*current_activity].type != type) && (0 <= type && type < activity_type_COUNT)) { + (*current_activity)++; + + activities[*current_activity].type = type; + activities[*current_activity].color = + activity_type_color_representation[type]; + activities[*current_activity].began = time; + activities[*current_activity].ended = time; + } +} + int main(int argc, char *argv[]) { (void)argc; @@ -317,15 +330,8 @@ int main(int argc, char *argv[]) for(U32 i = 0; i < activity_type_COUNT; i++) { if(IsKeyPressed(KEY_ONE + i)) { - current_activity++; - - activities[current_activity].type = i; - activities[current_activity].color = - activity_type_color_representation[i]; - activities[current_activity].began = now_s; - activities[current_activity].ended = now_s; + switch_activity(activities, ¤t_activity, i, now_s); } - } activities[current_activity].ended = now_s; @@ -375,13 +381,7 @@ int main(int argc, char *argv[]) activity_type_color_representation[i])) { if(activities[current_activity].type != i) { - current_activity++; - - activities[current_activity].type = i; - activities[current_activity].color = - activity_type_color_representation[i]; - activities[current_activity].began = now_s; - activities[current_activity].ended = now_s; + switch_activity(activities, ¤t_activity, i, now_s); } } if(activities[current_activity].type == i)