2024-05-31 19:15:16 +00:00
|
|
|
#ifndef UTILS_FUNCTIONS_HPP
|
|
|
|
#define UTILS_FUNCTIONS_HPP
|
|
|
|
|
|
|
|
#include <godot_cpp/variant/dictionary.hpp>
|
|
|
|
#include <godot_cpp/templates/hash_map.hpp>
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
2024-05-31 19:18:42 +00:00
|
|
|
godot::Dictionary hashmap_to_dictionary(godot::HashMap<T, U> const &map) {
|
|
|
|
godot::Dictionary dict{};
|
|
|
|
for(godot::KeyValue<T, U> const &kvp : map)
|
2024-05-31 19:15:16 +00:00
|
|
|
dict[kvp.key] = kvp.value;
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
2024-05-31 19:18:42 +00:00
|
|
|
godot::HashMap<T, U> dictionary_to_hashmap(godot::Dictionary const &dict) {
|
|
|
|
godot::HashMap<T, U> map{};
|
|
|
|
godot::Array keys{dict.keys()};
|
2024-05-31 19:15:16 +00:00
|
|
|
for(size_t i = 0; i < keys.size(); ++i)
|
|
|
|
map.insert(keys[i], dict[keys[i]]);
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !UTILS_FUNCTIONS_HPP
|