From 81fbf91e208e84c300f78236e78044ed4b36b44c Mon Sep 17 00:00:00 2001 From: Tanasart Date: Tue, 23 Jul 2024 16:08:38 +0700 Subject: [PATCH] - Fix theme color overriding not being loaded. --- objects/o_dialog_preference/Create_0.gml | 12 ++++++++---- scripts/color_loader/color_loader.gml | 15 ++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/objects/o_dialog_preference/Create_0.gml b/objects/o_dialog_preference/Create_0.gml index 1a3a940fd..2984ba088 100644 --- a/objects/o_dialog_preference/Create_0.gml +++ b/objects/o_dialog_preference/Create_0.gml @@ -584,9 +584,10 @@ event_inherited(); dialog.setDefault(val); self.key = key; dialog.onApply = function(color) { - variable_struct_set(COLORS, key, color); - overrideColor(); + COLORS[$ key] = color; + overrideColor(key); }; + dialog.selector.onApply = dialog.onApply; addChildren(dialog); @@ -602,9 +603,12 @@ event_inherited(); return hh; }); - function overrideColor() { + function overrideColor(key) { var path = $"{DIRECTORY}Themes/{PREFERENCES.theme}/override.json"; - json_save_struct(path, COLORS, true); + var json = file_exists_empty(path)? json_load_struct(path) : {}; + + json[$ key] = COLORS[$ key]; + json_save_struct(path, json, true); } #endregion diff --git a/scripts/color_loader/color_loader.gml b/scripts/color_loader/color_loader.gml index ae323844f..e228fbee3 100644 --- a/scripts/color_loader/color_loader.gml +++ b/scripts/color_loader/color_loader.gml @@ -21,21 +21,13 @@ function _loadColor(theme = "default", replace = false) { var path = dirr + "/values.json"; var pathO = dirr + "/override.json"; - if(theme == "default" && !file_exists_empty(pathO)) { - COLOR_KEYS = variable_struct_get_names(COLORS); - array_sort(COLOR_KEYS, true); - return; - } + COLOR_KEYS = variable_struct_get_names(COLORS); + array_sort(COLOR_KEYS, true); + if(theme == "default" && !file_exists_empty(pathO)) return; if(!file_exists_empty(path)) { noti_status($"Colors not defined at {path}, rollback to default color."); return; } var clrs = json_load_struct(path); - - if(file_exists_empty(pathO)) { - var oclr = json_load_struct(pathO); - struct_override(clrs, oclr); - } - if(!struct_has(clrs, "values")) { print("Load color error"); return; } var valkeys = variable_struct_get_names(clrs.values); @@ -78,4 +70,5 @@ function _loadColor(theme = "default", replace = false) { COLORS[$ key] = c; } + if(file_exists_empty(pathO)) struct_override(COLORS, json_load_struct(pathO)); } \ No newline at end of file