2023-02-14 05:32:32 +01:00
|
|
|
function json_encode_minify(map) {
|
2023-11-13 07:11:52 +01:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
return json_minify(json_encode(map));
|
|
|
|
}
|
|
|
|
|
|
|
|
function json_stringify_minify(map) {
|
2023-11-13 07:11:52 +01:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
return json_minify(json_stringify(map));
|
|
|
|
}
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
function json_load(path) {
|
2023-11-13 07:11:52 +01:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-12-08 03:50:09 +01:00
|
|
|
if(!file_exists_empty(path)) return noone;
|
2022-12-10 05:06:01 +01:00
|
|
|
|
2023-11-13 07:11:52 +01:00
|
|
|
var s = file_read_all(path);
|
2022-12-10 05:06:01 +01:00
|
|
|
var js = json_decode(s);
|
|
|
|
return js;
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
function json_save(path, map) {
|
2023-11-13 07:11:52 +01:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
var s = json_encode_minify(map);
|
2022-12-10 05:06:01 +01:00
|
|
|
|
2023-01-04 02:30:04 +01:00
|
|
|
var f = file_text_open_write(path);
|
|
|
|
file_text_write_string(f, s);
|
|
|
|
file_text_close(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
function json_load_struct(path) {
|
2023-11-13 07:11:52 +01:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-12-08 03:50:09 +01:00
|
|
|
if(!file_exists_empty(path)) return noone;
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-11-13 12:11:54 +01:00
|
|
|
var s = file_read_all(path);
|
2023-03-05 07:16:44 +01:00
|
|
|
var js = json_try_parse(s);
|
2023-01-04 02:30:04 +01:00
|
|
|
return js;
|
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
function json_save_struct(path, struct, pretty = false) {
|
2023-11-13 07:11:52 +01:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
var s;
|
2023-11-13 12:11:54 +01:00
|
|
|
if(pretty) s = json_stringify(struct, true);
|
|
|
|
else s = json_stringify_minify(struct);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
var f = file_text_open_write(path);
|
|
|
|
file_text_write_string(f, s);
|
|
|
|
file_text_close(f);
|
|
|
|
}
|