godot-cpp-utils/util_functions.hpp

27 lines
722 B
C++

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