33 lines
		
	
	
		
			876 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			876 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #ifndef UTILS_FUNCTIONS_HPP
 | |
| #define UTILS_FUNCTIONS_HPP
 | |
| 
 | |
| #include <godot_cpp/variant/dictionary.hpp>
 | |
| #include <godot_cpp/classes/time.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;
 | |
| }
 | |
| 
 | |
| static inline
 | |
| double time_seconds() {
 | |
|     return double(godot::Time::get_singleton()->get_ticks_msec()) * 0.001;
 | |
| }
 | |
| }
 | |
| 
 | |
| #endif // !UTILS_FUNCTIONS_HPP
 | 
