summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/color_palette.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/util/color_palette.c b/src/util/color_palette.c
index 73dfc83..9cfdf32 100644
--- a/src/util/color_palette.c
+++ b/src/util/color_palette.c
@@ -40,31 +40,40 @@ bool camu_color_palette_init(str *path)
if (!nn_file_open(&file, path, NNWT_FILE_READONLY)) {
return false;
}
+
str s;
nn_file_read_as_str(&file, &s);
nn_file_close(&file);
json_error_t error;
json_t *root = json_loadb(s.data, s.length, 0, &error);
+ al_str_free(&s);
if (!root) {
- al_log_error("color_palette", "Failed to load %.*s as a json (%s).",
- al_str_fmt(path), error.text);
+ al_log_error("color_palette", "Failed to load %.*s as a json (%s).", al_str_fmt(path), error.text);
return false;
}
+
+ bool parsed = true;
+
json_t *special = json_object_get(root, "special");
if (!special) {
al_log_error("color_palette", "\"special\" field missing from the color palette.");
- return false;
+ parsed = false;
+ goto out;
}
+
json_t *colors = json_object_get(root, "colors");
if (!colors) {
al_log_error("color_palette", "\"colors\" field missing from the color palette.");
- return false;
+ parsed = false;
+ goto out;
}
+
json_t *object;
const char *color;
u32 value;
u32 index;
bool to_long_error;
+
for (u32 i = 0; i < ARRAY_SIZE(special_colors); i++) {
object = json_object_get(special, special_colors[i]);
if (!object) {
@@ -80,6 +89,7 @@ bool camu_color_palette_init(str *path)
al_log_warn("color_palette", "%s is not a valid hex color.", normal_colors[i]);
}
}
+
for (u32 i = 0; i < ARRAY_SIZE(normal_colors); i++) {
object = json_object_get(colors, normal_colors[i]);
if (!object) {
@@ -95,8 +105,13 @@ bool camu_color_palette_init(str *path)
al_log_warn("color_palette", "%s is not a valid hex color.", normal_colors[i]);
}
}
+
+out:
+ json_decref(root);
+
+ return parsed;
#else
(void)path;
+ return false;
#endif
- return true;
}