import glob
import re

files = glob.glob('editor/widgets/**/*.cpp', recursive=True)
for file in files:
    with open(file, 'r') as f:
        content = f.read()

    bool_parse = r'if (json_object_is_type(val_obj, json_type_string)) {\n                        const char *s = json_object_get_string(val_obj);\n                        \1 = (s && (strcmp(s, "true") == 0 || strcmp(s, "1") == 0));\n                    } else {\n                        \1 = json_object_get_boolean(val_obj);\n                    }'
    
    content = re.sub(r'([a-zA-Z0-9_]+)\s*=\s*json_object_get_boolean\(val_obj\);', bool_parse, content)

    with open(file, 'w') as f:
        f.write(content)
        
    print(f"Patched {file}")
