feat: added util_functions
This commit is contained in:
		
							parent
							
								
									46366f2e6f
								
							
						
					
					
						commit
						c48a3056e4
					
				
							
								
								
									
										1
									
								
								util_functions.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								util_functions.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| #include "util_functions.hpp" | ||||
							
								
								
									
										24
									
								
								util_functions.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								util_functions.hpp
									
									
									
									
									
										Normal 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
 | ||||
		Loading…
	
		Reference in a new issue
	
	 Sara
						Sara