/** * limbo_task_db.h * ============================================================================= * Copyright 2021-2024 Serhii Snitsaruk * * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. * ============================================================================= */ #ifndef LIMBO_TASK_DB_H #define LIMBO_TASK_DB_H #ifdef LIMBOAI_MODULE #include "core/object/class_db.h" #include "core/templates/hash_map.h" #include "core/templates/list.h" #endif // LIMBOAI_MODULE #ifdef LIMBOAI_GDEXTENSION #include #include #include #include using namespace godot; #endif // LIMBOAI_GDEXTENSION class LimboTaskDB { private: static HashMap> core_tasks; static HashMap> tasks_cache; struct ComparatorByTaskName { bool operator()(const String &p_left, const String &p_right) const { return get_task_name(p_left) < get_task_name(p_right); } }; public: template static void register_task() { GDREGISTER_CLASS(T); HashMap>::Iterator E = core_tasks.find(T::get_task_category()); if (E) { E->value.push_back(T::get_class_static()); } else { List tasks; tasks.push_back(T::get_class_static()); core_tasks.insert(T::get_task_category(), tasks); } } static void scan_user_tasks(); static _FORCE_INLINE_ String get_misc_category() { return "Misc"; } static List get_categories(); static List get_tasks_in_category(const String &p_category); static _FORCE_INLINE_ String get_task_name(String p_class_or_script_path) { if (p_class_or_script_path.begins_with("res:")) { return p_class_or_script_path.get_file().get_basename().trim_prefix("BT").to_pascal_case(); } else { return p_class_or_script_path.trim_prefix("BT"); } } }; #ifdef LIMBOAI_MODULE #define LIMBO_REGISTER_TASK(m_class) \ if (m_class::_class_is_enabled) { \ ::LimboTaskDB::register_task(); \ } #elif LIMBOAI_GDEXTENSION #define LIMBO_REGISTER_TASK(m_class) LimboTaskDB::register_task(); #endif #define TASK_CATEGORY(m_cat) \ public: \ static _FORCE_INLINE_ String get_task_category() { \ return String(#m_cat); \ } \ \ private: #endif // LIMBO_TASK_DB_H