2023-02-14 02:48:33 +01:00
|
|
|
#macro struct_has variable_struct_exists
|
2024-01-20 05:06:56 +01:00
|
|
|
#macro struct_key variable_struct_get_names
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-09-21 09:34:49 +02:00
|
|
|
function struct_override(original, override) {
|
2024-04-09 05:32:00 +02:00
|
|
|
INLINE
|
|
|
|
|
2023-02-14 02:48:33 +01:00
|
|
|
var args = variable_struct_get_names(override);
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(args); i < n; i++ ) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _key = args[i];
|
|
|
|
|
2023-10-21 15:41:05 +02:00
|
|
|
if(!struct_has(original, _key)) continue;
|
2023-10-02 08:57:44 +02:00
|
|
|
original[$ _key] = override[$ _key];
|
2023-02-14 02:48:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return original;
|
2024-09-21 09:34:49 +02:00
|
|
|
}
|
2023-05-28 20:57:54 +02:00
|
|
|
|
2024-09-21 09:34:49 +02:00
|
|
|
function struct_override_nested(original, override) {
|
2024-04-13 07:32:04 +02:00
|
|
|
INLINE
|
|
|
|
|
|
|
|
var args = variable_struct_get_names(override);
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(args); i < n; i++ ) {
|
|
|
|
var _key = args[i];
|
|
|
|
|
|
|
|
if(!struct_has(original, _key)) continue;
|
|
|
|
if(is_struct(original[$ _key]))
|
|
|
|
struct_override_nested(original[$ _key], override[$ _key])
|
|
|
|
else
|
|
|
|
original[$ _key] = override[$ _key];
|
|
|
|
}
|
|
|
|
|
|
|
|
return original;
|
2024-09-21 09:34:49 +02:00
|
|
|
}
|
2024-04-13 07:32:04 +02:00
|
|
|
|
2024-09-21 09:34:49 +02:00
|
|
|
function struct_append(original, append) {
|
2024-04-09 05:32:00 +02:00
|
|
|
INLINE
|
|
|
|
|
2023-09-22 17:01:56 +02:00
|
|
|
var args = variable_struct_get_names(append);
|
|
|
|
|
2024-04-09 05:32:00 +02:00
|
|
|
for( var i = 0, n = array_length(args); i < n; i++ )
|
2023-09-22 17:01:56 +02:00
|
|
|
original[$ args[i]] = append[$ args[i]];
|
|
|
|
|
|
|
|
return original;
|
2024-09-21 09:34:49 +02:00
|
|
|
}
|
2023-09-22 17:01:56 +02:00
|
|
|
|
2024-09-21 09:34:49 +02:00
|
|
|
function struct_try_get(struct, key, def = 0) {
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-10-02 08:57:44 +02:00
|
|
|
|
2023-07-30 13:56:22 +02:00
|
|
|
if(struct[$ key] != undefined) return struct[$ key];
|
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
key = string_replace_all(key, "_", " ");
|
2023-07-30 13:56:22 +02:00
|
|
|
return struct[$ key] ?? def;
|
2024-09-21 09:34:49 +02:00
|
|
|
}
|
2023-10-02 08:57:44 +02:00
|
|
|
|
2024-09-21 09:34:49 +02:00
|
|
|
function struct_try_override(original, override, key) {
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-10-02 08:57:44 +02:00
|
|
|
|
2023-10-03 11:27:36 +02:00
|
|
|
if(!is_struct(original) || !is_struct(override)) return;
|
2023-10-02 08:57:44 +02:00
|
|
|
if(!struct_has(override, key)) return;
|
2023-10-03 11:27:36 +02:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
original[$ key] = override[$ key];
|
2024-11-20 09:05:51 +01:00
|
|
|
}
|