From 65aea2815f1d77d429f9df1c1b4c9dc77ac1b16f Mon Sep 17 00:00:00 2001 From: Micky Date: Wed, 3 Jan 2024 13:48:47 +0100 Subject: [PATCH] Add autocompletion for `OS.has_feature()` --- core/core_bind.cpp | 16 ++++++++++ core/core_bind.h | 4 +++ editor/export/editor_export.cpp | 47 ++++++++++++++++++++++++++++++ editor/export/editor_export.h | 2 ++ editor/project_settings_editor.cpp | 45 +--------------------------- 5 files changed, 70 insertions(+), 44 deletions(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index d91c659d1e67..56b116ef482b 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -41,6 +41,9 @@ #include "core/os/keyboard.h" #include "core/os/thread_safe.h" #include "core/variant/typed_array.h" +#ifdef TOOLS_ENABLED +#include "editor/export/editor_export.h" +#endif // TOOLS_ENABLED namespace core_bind { @@ -557,6 +560,19 @@ String OS::get_unique_id() const { return ::OS::get_singleton()->get_unique_id(); } +#ifdef TOOLS_ENABLED +void OS::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { + String pf = p_function; + if (p_idx == 0 && pf == "has_feature") { + HashSet presets = EditorExport::get_singleton()->get_available_features(); + + for (const String &E : presets) { + r_options->push_back(E.quote()); + } + } +} +#endif // TOOLS_ENABLED + OS *OS::singleton = nullptr; void OS::_bind_methods() { diff --git a/core/core_bind.h b/core/core_bind.h index 715e26cf2302..870935117477 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -242,6 +242,10 @@ class OS : public Object { Vector get_granted_permissions() const; void revoke_granted_permissions(); +#ifdef TOOLS_ENABLED + virtual void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const override; +#endif // TOOLS_ENABLED + static OS *get_singleton() { return singleton; } OS() { singleton = this; } diff --git a/editor/export/editor_export.cpp b/editor/export/editor_export.cpp index 670fd0a06d94..2b70059f3f71 100644 --- a/editor/export/editor_export.cpp +++ b/editor/export/editor_export.cpp @@ -167,6 +167,53 @@ Vector> EditorExport::get_export_plugins() { return export_plugins; } +HashSet EditorExport::get_available_features() { + HashSet presets; + + presets.insert("bptc"); + presets.insert("s3tc"); + presets.insert("etc"); + presets.insert("etc2"); + presets.insert("editor"); + presets.insert("template_debug"); + presets.insert("template_release"); + presets.insert("debug"); + presets.insert("release"); + presets.insert("template"); + presets.insert("double"); + presets.insert("single"); + presets.insert("32"); + presets.insert("64"); + presets.insert("movie"); + + for (int i = 0; i < get_export_platform_count(); i++) { + List p; + get_export_platform(i)->get_platform_features(&p); + for (const String &E : p) { + presets.insert(E); + } + } + + for (int i = 0; i < get_export_preset_count(); i++) { + List p; + get_export_preset(i)->get_platform()->get_preset_features(get_export_preset(i), &p); + for (const String &E : p) { + presets.insert(E); + } + + String custom = get_export_preset(i)->get_custom_features(); + Vector custom_list = custom.split(","); + for (int j = 0; j < custom_list.size(); j++) { + String f = custom_list[j].strip_edges(); + if (!f.is_empty()) { + presets.insert(f); + } + } + } + + return presets; +} + void EditorExport::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { diff --git a/editor/export/editor_export.h b/editor/export/editor_export.h index 55dee0c468cc..2dca4297b03b 100644 --- a/editor/export/editor_export.h +++ b/editor/export/editor_export.h @@ -74,6 +74,8 @@ class EditorExport : public Node { void remove_export_plugin(const Ref &p_plugin); Vector> get_export_plugins(); + HashSet get_available_features(); + void load_config(); void update_export_presets(); bool poll_export_platforms(); diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index d587737ed406..c1041a03edc2 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -275,50 +275,7 @@ String ProjectSettingsEditor::_get_setting_name() const { } void ProjectSettingsEditor::_add_feature_overrides() { - HashSet presets; - - presets.insert("bptc"); - presets.insert("s3tc"); - presets.insert("etc"); - presets.insert("etc2"); - presets.insert("editor"); - presets.insert("template_debug"); - presets.insert("template_release"); - presets.insert("debug"); - presets.insert("release"); - presets.insert("template"); - presets.insert("double"); - presets.insert("single"); - presets.insert("32"); - presets.insert("64"); - presets.insert("movie"); - - EditorExport *ee = EditorExport::get_singleton(); - - for (int i = 0; i < ee->get_export_platform_count(); i++) { - List p; - ee->get_export_platform(i)->get_platform_features(&p); - for (const String &E : p) { - presets.insert(E); - } - } - - for (int i = 0; i < ee->get_export_preset_count(); i++) { - List p; - ee->get_export_preset(i)->get_platform()->get_preset_features(ee->get_export_preset(i), &p); - for (const String &E : p) { - presets.insert(E); - } - - String custom = ee->get_export_preset(i)->get_custom_features(); - Vector custom_list = custom.split(","); - for (int j = 0; j < custom_list.size(); j++) { - String f = custom_list[j].strip_edges(); - if (!f.is_empty()) { - presets.insert(f); - } - } - } + HashSet presets = EditorExport::get_singleton()->get_available_features(); feature_box->clear(); feature_box->add_item(TTR("(All)"), 0); // So it is always on top.