From 04cb2b15608e558c25b1c6057990c148ad8079df Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 25 Aug 2023 18:08:18 +0200 Subject: [PATCH] Sort tasks within task categories --- util/limbo_task_db.cpp | 4 ++++ util/limbo_task_db.h | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/util/limbo_task_db.cpp b/util/limbo_task_db.cpp index 94a2899..6fc4c08 100644 --- a/util/limbo_task_db.cpp +++ b/util/limbo_task_db.cpp @@ -83,6 +83,10 @@ void LimboTaskDB::scan_user_tasks() { String dir1 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_" + itos(i)); _populate_from_user_dir(dir1, &tasks_cache); } + + for (KeyValue> &E : tasks_cache) { + E.value.sort_custom(); + } } List LimboTaskDB::get_categories() { diff --git a/util/limbo_task_db.h b/util/limbo_task_db.h index 2849475..6ac587a 100644 --- a/util/limbo_task_db.h +++ b/util/limbo_task_db.h @@ -21,6 +21,12 @@ 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() { @@ -39,6 +45,13 @@ public: 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"); + } + } }; #define LIMBO_REGISTER_TASK(m_class) \