A little bit more progress on the progress save feature.
This commit is contained in:
70
main.c
70
main.c
@@ -129,15 +129,25 @@ char activity_button(int x, int y, int width, int height, char *title, char *sub
|
|||||||
// entertainment, reading, socializing,
|
// entertainment, reading, socializing,
|
||||||
// housework, journaling, programmming (or projects?),
|
// housework, journaling, programmming (or projects?),
|
||||||
// break, other
|
// break, other
|
||||||
enum activity_type {
|
typedef enum activity_type {
|
||||||
other,
|
other,
|
||||||
work,
|
work,
|
||||||
projects,
|
projects,
|
||||||
gaming,
|
gaming,
|
||||||
exercise,
|
exercise,
|
||||||
activity_type_COUNT
|
activity_type_COUNT
|
||||||
|
} activity_type;
|
||||||
|
|
||||||
|
char *activity_type_string_representation[activity_type_COUNT] = {
|
||||||
|
"Other", "Work", "Projects", "Gaming", "Exercise"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Color activity_type_color_representation[activity_type_COUNT] = {
|
||||||
|
RED, BLUE, YELLOW, GREEN, PURPLE
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: String representation.
|
||||||
|
|
||||||
typedef struct Activity {
|
typedef struct Activity {
|
||||||
enum activity_type activity; // TODO: Rename to kind or type.
|
enum activity_type activity; // TODO: Rename to kind or type.
|
||||||
Color color;
|
Color color;
|
||||||
@@ -170,6 +180,12 @@ int main(int argc, char *argv[])
|
|||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
|
Activity activities[100];
|
||||||
|
U32 current_activity = 0;
|
||||||
|
|
||||||
|
Activity_Stat activities_stats[activity_type_COUNT];
|
||||||
|
memset(activities_stats, 0, sizeof(activities_stats));
|
||||||
|
|
||||||
U64 secs = now();
|
U64 secs = now();
|
||||||
struct tm *t = localtime((time_t *)(&secs));
|
struct tm *t = localtime((time_t *)(&secs));
|
||||||
t->tm_hour = 0;
|
t->tm_hour = 0;
|
||||||
@@ -182,6 +198,8 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Clean up.
|
||||||
|
|
||||||
// Check if 2025-02-10 available
|
// Check if 2025-02-10 available
|
||||||
// build array
|
// build array
|
||||||
// then, save the file periodically (every ~5 seconds)
|
// then, save the file periodically (every ~5 seconds)
|
||||||
@@ -199,6 +217,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fix error handling.
|
// TODO: Fix error handling.
|
||||||
|
// WARNING: Not bullet proof, yet.
|
||||||
FILE *f;
|
FILE *f;
|
||||||
if(path_exists(file_buffer)) {
|
if(path_exists(file_buffer)) {
|
||||||
f = fopen(file_buffer, "r+");
|
f = fopen(file_buffer, "r+");
|
||||||
@@ -218,15 +237,38 @@ int main(int argc, char *argv[])
|
|||||||
size_t n = strcspn(line, "\r\n");
|
size_t n = strcspn(line, "\r\n");
|
||||||
line[n] = '\0';
|
line[n] = '\0';
|
||||||
|
|
||||||
printf("%s\n", line);
|
char activity_name[64];
|
||||||
|
U64 lower;
|
||||||
|
U64 upper;
|
||||||
|
int l = sscanf(line, "%s %llu %llu", activity_name, &lower, &upper);
|
||||||
|
if(l != 3)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* if(current_activity >= 0) */
|
if(lower > upper)
|
||||||
/* current_activity++; */
|
continue;
|
||||||
|
|
||||||
char test[64];
|
activity_type type = other;
|
||||||
U64 var1;
|
if(strcmp(activity_name, activity_type_string_representation[other]) == 0)
|
||||||
U64 var2;
|
type = other;
|
||||||
int l = sscanf(line, "%s %llu %llu", test, &var1, &var2);
|
else if(strcmp(activity_name, activity_type_string_representation[work]) == 0)
|
||||||
|
type = work;
|
||||||
|
else if(strcmp(activity_name, activity_type_string_representation[projects]) == 0)
|
||||||
|
type = projects;
|
||||||
|
else if(strcmp(activity_name, activity_type_string_representation[gaming]) == 0)
|
||||||
|
type = gaming;
|
||||||
|
else if(strcmp(activity_name, activity_type_string_representation[exercise]) == 0)
|
||||||
|
type = exercise;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
activities[current_activity].activity = type;
|
||||||
|
activities[current_activity].color = activity_type_color_representation[type];
|
||||||
|
activities[current_activity].began = lower;
|
||||||
|
activities[current_activity].ended = upper;
|
||||||
|
|
||||||
|
current_activity++;
|
||||||
|
|
||||||
|
printf("Added: %s\n", activity_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,20 +278,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
return 0;
|
/* return 0; */
|
||||||
|
|
||||||
U64 lower_bound_s = (U64)ts;
|
U64 lower_bound_s = (U64)ts;
|
||||||
U64 upper_bound_s = lower_bound_s + 86400;
|
U64 upper_bound_s = lower_bound_s + 86400;
|
||||||
// U64 upper_bound_s = lower_bound_s + 3600;
|
// U64 upper_bound_s = lower_bound_s + 3600;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Activity activities[100];
|
|
||||||
U32 current_activity = 0;
|
|
||||||
|
|
||||||
Activity_Stat activities_stats[activity_type_COUNT];
|
|
||||||
memset(activities_stats, 0, sizeof(activities_stats));
|
|
||||||
|
|
||||||
S32 window_w = 800;
|
S32 window_w = 800;
|
||||||
S32 window_h = 450;
|
S32 window_h = 450;
|
||||||
|
|
||||||
@@ -278,8 +312,6 @@ int main(int argc, char *argv[])
|
|||||||
while(!WindowShouldClose()) {
|
while(!WindowShouldClose()) {
|
||||||
U64 now_s = now();
|
U64 now_s = now();
|
||||||
|
|
||||||
// fprintf(stderr, "%lu ... %lu: %lu\n", lower_bound_s, upper_bound_s, now_s);
|
|
||||||
|
|
||||||
window_w = GetScreenWidth();
|
window_w = GetScreenWidth();
|
||||||
window_h = GetScreenHeight();
|
window_h = GetScreenHeight();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user