Pixel-Composer/scripts/ds_map/ds_map.gml

77 lines
1.5 KiB
Text
Raw Normal View History

2022-09-23 13:28:42 +02:00
function ds_map_clone(map) {
var m = ds_map_create();
var k = ds_map_find_first(map);
repeat(ds_map_size(map)) {
m[? k] = map[? k];
k = ds_map_find_next(map, k);
}
return m;
}
function ds_map_try_get(map, key, def = 0) {
2022-01-13 05:24:03 +01:00
if(ds_map_exists(map, key)) return map[? key];
return def;
}
function ds_map_override(original, newmap) {
2022-01-29 14:25:18 +01:00
if(is_undefined(original)) return;
if(!ds_exists(original, ds_type_map)) return;
if(is_undefined(newmap)) return;
if(!ds_exists(newmap, ds_type_map)) return;
2022-01-13 05:24:03 +01:00
var k = ds_map_find_first(newmap);
repeat(ds_map_size(newmap)) {
2022-11-01 03:06:03 +01:00
original[? k] = newmap[? k] ?? 1;
2022-01-13 05:24:03 +01:00
k = ds_map_find_next(newmap, k);
}
}
2022-12-10 05:06:01 +01:00
2023-01-25 06:49:00 +01:00
function ds_map_arr_to_list(map) {
var k = ds_map_find_first(map);
repeat(ds_map_size(map)) {
if(is_array(map[? k])) {
var l = ds_list_create_from_array(map[? k]);
ds_map_replace_list(map, k, l);
}
k = ds_map_find_next(map, k);
}
}
function ds_map_list_to_arr(map) {
var k = ds_map_find_first(map);
repeat(ds_map_size(map)) {
if(ds_map_is_list(map, k))
map[? k] = array_create_from_list(map[? k]);
k = ds_map_find_next(map, k);
}
}
2022-12-10 05:06:01 +01:00
function ds_map_print(map) {
var txt = "{";
var k = ds_map_find_first(map);
repeat(ds_map_size(map)) {
2024-11-20 09:05:51 +01:00
txt += $"{k} : {map[? k]}, ";
2022-12-10 05:06:01 +01:00
k = ds_map_find_next(map, k);
}
txt += "}";
return txt;
2024-11-20 09:05:51 +01:00
}
function ds_map_to_struct(map) {
var _s = {};
var k = ds_map_find_first(map);
repeat(ds_map_size(map)) {
_s[$ k] = map[? k];
k = ds_map_find_next(map, k);
}
return _s;
2022-12-10 05:06:01 +01:00
}