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)