From d5088a9f20ebcf233b276d9a6a08f4adfe0aca60 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 17 Dec 2022 21:18:11 +0100 Subject: [PATCH] Implement pascal case auto naming for tasks without _generate_name() --- bt/bt_task.cpp | 2 +- editor/limbo_ai_editor_plugin.cpp | 58 ++++++++++++++++--------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/bt/bt_task.cpp b/bt/bt_task.cpp index 8d8a369..0714d7f 100644 --- a/bt/bt_task.cpp +++ b/bt/bt_task.cpp @@ -24,7 +24,7 @@ String BTTask::_generate_name() const { String name = get_script_instance()->get_script()->get_path(); if (!name.is_empty()) { // Generate name based on script file - name = name.get_basename().get_file().trim_prefix("BT"); + name = name.get_basename().get_file().trim_prefix("BT").to_pascal_case(); return name; } } diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index d64db6d..b48cf97 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -397,52 +397,54 @@ void TaskPanel::refresh() { } } - HashMap> categories; + HashMap> categorized_tasks; - categories["Composites"] = List(); - _populate_core_tasks_from_class("BTComposite", &categories["Composites"]); + categorized_tasks["Composites"] = List(); + _populate_core_tasks_from_class("BTComposite", &categorized_tasks["Composites"]); - categories["Actions"] = List(); - _populate_core_tasks_from_class("BTAction", &categories["Actions"]); + categorized_tasks["Actions"] = List(); + _populate_core_tasks_from_class("BTAction", &categorized_tasks["Actions"]); - categories["Decorators"] = List(); - _populate_core_tasks_from_class("BTDecorator", &categories["Decorators"]); + categorized_tasks["Decorators"] = List(); + _populate_core_tasks_from_class("BTDecorator", &categorized_tasks["Decorators"]); - categories["Conditions"] = List(); - _populate_core_tasks_from_class("BTCondition", &categories["Conditions"]); + categorized_tasks["Conditions"] = List(); + _populate_core_tasks_from_class("BTCondition", &categorized_tasks["Conditions"]); - categories["User"] = List(); + categorized_tasks["User"] = List(); String dir1 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_1"); - _populate_from_user_dir(dir1, &categories); + _populate_from_user_dir(dir1, &categorized_tasks); String dir2 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_2"); - _populate_from_user_dir(dir2, &categories); + _populate_from_user_dir(dir2, &categorized_tasks); String dir3 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_3"); - _populate_from_user_dir(dir3, &categories); + _populate_from_user_dir(dir3, &categorized_tasks); - List keys; - for (const KeyValue> &K : categories) { - keys.push_back(K.key); + List categories; + for (const KeyValue> &K : categorized_tasks) { + categories.push_back(K.key); } - keys.sort(); - for (List::Element *E = keys.front(); E; E = E->next()) { - String cat = E->get(); - List task_list = categories.get(cat); + categories.sort(); + for (String cat : categories) { + List tasks = categorized_tasks.get(cat); - if (task_list.size() == 0) { + if (tasks.size() == 0) { continue; } TaskSection *sec = memnew(TaskSection(cat)); - for (List::Element *E = task_list.front(); E; E = E->next()) { - String meta = E->get(); + for (String task_meta : tasks) { String tname; Ref icon; - icon = LimboAIEditor::get_task_icon(meta); - tname = meta.begins_with("res:") ? meta.get_file().get_basename().trim_prefix("BT") : meta.trim_prefix("BT"); - sec->add_task_button(tname, icon, meta); + icon = LimboAIEditor::get_task_icon(task_meta); + if (task_meta.begins_with("res:")) { + tname = task_meta.get_file().get_basename().trim_prefix("BT").to_pascal_case(); + } else { + tname = task_meta.trim_prefix("BT"); + } + sec->add_task_button(tname, icon, task_meta); } sec->set_filter(""); sec->connect("task_button_pressed", callable_mp(this, &TaskPanel::_on_task_button_pressed)); @@ -455,8 +457,8 @@ void TaskPanel::_populate_core_tasks_from_class(const StringName &p_base_class, List inheriters; ClassDB::get_inheriters_from_class(p_base_class, &inheriters); - for (List::Element *E = inheriters.front(); E; E = E->next()) { - p_task_classes->push_back(E->get()); + for (StringName cl : inheriters) { + p_task_classes->push_back(cl); } }