Pixel-Composer/scripts/json_file/json_file.gml
2023-12-08 09:50:09 +07:00

53 lines
1.0 KiB
Plaintext

function json_encode_minify(map) {
gml_pragma("forceinline");
return json_minify(json_encode(map));
}
function json_stringify_minify(map) {
gml_pragma("forceinline");
return json_minify(json_stringify(map));
}
function json_load(path) {
gml_pragma("forceinline");
if(!file_exists_empty(path)) return noone;
var s = file_read_all(path);
var js = json_decode(s);
return js;
}
function json_save(path, map) {
gml_pragma("forceinline");
var s = json_encode_minify(map);
var f = file_text_open_write(path);
file_text_write_string(f, s);
file_text_close(f);
}
function json_load_struct(path) {
gml_pragma("forceinline");
if(!file_exists_empty(path)) return noone;
var s = file_read_all(path);
var js = json_try_parse(s);
return js;
}
function json_save_struct(path, struct, pretty = false) {
gml_pragma("forceinline");
var s;
if(pretty) s = json_stringify(struct, true);
else s = json_stringify_minify(struct);
var f = file_text_open_write(path);
file_text_write_string(f, s);
file_text_close(f);
}