mirror of
https://github.com/pepaskopec-blip/Graduately.git
synced 2026-10-27 15:14:35 +00:00
Refactor networks quizzes, progress tracking, and page wiring.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
1e84a1f663
commit
02c994fb5e
7 changed files with 406 additions and 945 deletions
93
progress.c
93
progress.c
|
|
@ -52,6 +52,7 @@ void unit_load_progress(UnitCtx *u) {
|
|||
void load_progress(void) {
|
||||
for (int i = 0; i < NUM_UNLOCKED; i++)
|
||||
unit_load_progress(&units[i]);
|
||||
net_load_progress();
|
||||
}
|
||||
|
||||
/* Redraw the exercise rails of every unit that already has a page. */
|
||||
|
|
@ -122,6 +123,7 @@ void refresh_completion_ui(void) {
|
|||
}
|
||||
|
||||
all_rails_redraw();
|
||||
refresh_net_completion_ui();
|
||||
refresh_stats_ui();
|
||||
}
|
||||
|
||||
|
|
@ -132,3 +134,94 @@ void mark_done(UnitCtx *u, int n) {
|
|||
refresh_completion_ui();
|
||||
unit_save_progress(u);
|
||||
}
|
||||
|
||||
void net_load_progress(void) {
|
||||
GKeyFile *kf = g_key_file_new();
|
||||
GError *err = NULL;
|
||||
|
||||
if (!g_key_file_load_from_file(kf, PROGRESS_NET, G_KEY_FILE_NONE, &err)) {
|
||||
if (err)
|
||||
g_error_free(err);
|
||||
g_key_file_free(kf);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NET_LESSONS; i++) {
|
||||
gchar key[8];
|
||||
|
||||
g_snprintf(key, sizeof(key), "%d", i + 1);
|
||||
net_lessons[i].done = g_key_file_get_boolean(kf, "done", key, NULL);
|
||||
}
|
||||
|
||||
g_key_file_free(kf);
|
||||
}
|
||||
|
||||
void net_save_progress(void) {
|
||||
GKeyFile *kf = g_key_file_new();
|
||||
|
||||
for (int i = 0; i < NET_LESSONS; i++) {
|
||||
gchar key[8];
|
||||
|
||||
g_snprintf(key, sizeof(key), "%d", i + 1);
|
||||
g_key_file_set_boolean(kf, "done", key, net_lessons[i].done);
|
||||
}
|
||||
|
||||
if (g_mkdir_with_parents(PROGRESS_DIR, 0755) != 0) {
|
||||
g_key_file_free(kf);
|
||||
return;
|
||||
}
|
||||
|
||||
gchar *data = g_key_file_to_data(kf, NULL, NULL);
|
||||
g_key_file_free(kf);
|
||||
|
||||
if (data) {
|
||||
GError *err = NULL;
|
||||
g_file_set_contents(PROGRESS_NET, data, -1, &err);
|
||||
if (err)
|
||||
g_error_free(err);
|
||||
g_free(data);
|
||||
}
|
||||
}
|
||||
|
||||
void refresh_net_completion_ui(void) {
|
||||
for (int i = 0; i < NET_LESSONS; i++) {
|
||||
GtkWidget *node = net_nodes[i];
|
||||
GtkWidget *icon = net_lessons[i].done_icon;
|
||||
|
||||
if (!node)
|
||||
continue;
|
||||
if (net_lessons[i].done) {
|
||||
gtk_widget_remove_css_class(node, "current");
|
||||
gtk_widget_add_css_class(node, "done");
|
||||
if (icon)
|
||||
gtk_widget_set_visible(icon, TRUE);
|
||||
} else {
|
||||
gtk_widget_remove_css_class(node, "done");
|
||||
gtk_widget_add_css_class(node, "current");
|
||||
if (icon)
|
||||
gtk_widget_set_visible(icon, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mark_net_done(int lesson_id) {
|
||||
if (lesson_id < 0 || lesson_id >= NET_LESSONS)
|
||||
return;
|
||||
if (net_lessons[lesson_id].done)
|
||||
return;
|
||||
net_lessons[lesson_id].done = TRUE;
|
||||
net_save_progress();
|
||||
refresh_net_completion_ui();
|
||||
refresh_stats_ui();
|
||||
}
|
||||
|
||||
void progress_for_net(ProgressSum *out) {
|
||||
out->total_ex += NET_LESSONS;
|
||||
out->open_units += NET_LESSONS;
|
||||
for (int i = 0; i < NET_LESSONS; i++) {
|
||||
if (net_lessons[i].done) {
|
||||
out->done_ex++;
|
||||
out->done_units++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue