feat: added util_functions

main
Sara 2024-05-31 21:15:16 +02:00
parent 46366f2e6f
commit c48a3056e4
2 changed files with 25 additions and 0 deletions

1
util_functions.cpp Normal file
View File

@ -0,0 +1 @@
#include "util_functions.hpp"

24
util_functions.hpp Normal file
View File

@ -0,0 +1,24 @@
#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>
gd::Dictionary hashmap_to_dictionary(gd::HashMap<T, U> const &map) {
gd::Dictionary dict{};
for(gd::KeyValue<T, U> const &kvp : map)
dict[kvp.key] = kvp.value;
return dict;
}
template<typename T, typename U>
gd::HashMap<T, U> dictionary_to_hashmap(gd::Dictionary const &dict) {
gd::HashMap<T, U> map{};
gd::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