godot-cpp-utils/util_functions.hpp

33 lines
876 B
C++
Raw Permalink Normal View History

2024-05-31 19:15:16 +00:00
#ifndef UTILS_FUNCTIONS_HPP
#define UTILS_FUNCTIONS_HPP
#include <godot_cpp/variant/dictionary.hpp>
2024-06-11 07:10:40 +00:00
#include <godot_cpp/classes/time.hpp>
2024-05-31 19:15:16 +00:00
#include <godot_cpp/templates/hash_map.hpp>
namespace utils {
2024-05-31 19:15:16 +00:00
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)
2024-05-31 19:15:16 +00:00
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()};
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;
}
2024-06-11 07:10:40 +00:00
static inline
double time_seconds() {
return double(godot::Time::get_singleton()->get_ticks_msec()) * 0.001;
}
}
2024-05-31 19:15:16 +00:00
#endif // !UTILS_FUNCTIONS_HPP