From fa84d09542cfd60f7a881c7d5655a2a74de39c9f Mon Sep 17 00:00:00 2001 From: RedworkDE <10944644+RedworkDE@users.noreply.github.com> Date: Tue, 4 Jul 2023 15:39:23 +0200 Subject: [PATCH] Fix export options of scripted EditorExportPlugins --- editor/export/editor_export.cpp | 38 ++++++++++++++---------- editor/export/editor_export.h | 1 + editor/export/editor_export_platform.cpp | 7 +++-- editor/export/editor_export_preset.cpp | 12 ++++---- editor/export/editor_export_preset.h | 5 ++-- editor/export/project_export.cpp | 4 +-- 6 files changed, 38 insertions(+), 29 deletions(-) diff --git a/editor/export/editor_export.cpp b/editor/export/editor_export.cpp index 106f7932102..6c4fb480d70 100644 --- a/editor/export/editor_export.cpp +++ b/editor/export/editor_export.cpp @@ -90,11 +90,12 @@ void EditorExport::_save() { String option_section = "preset." + itos(i) + ".options"; - for (const PropertyInfo &E : preset->get_properties()) { - if (E.usage & PROPERTY_USAGE_SECRET) { - credentials->set_value(option_section, E.name, preset->get(E.name)); + for (const KeyValue &E : preset->values) { + PropertyInfo *prop = preset->properties.getptr(E.key); + if (prop && prop->usage & PROPERTY_USAGE_SECRET) { + credentials->set_value(option_section, E.key, E.value); } else { - config->set_value(option_section, E.name, preset->get(E.name)); + config->set_value(option_section, E.key, E.value); } } } @@ -116,6 +117,7 @@ void EditorExport::_bind_methods() { void EditorExport::add_export_platform(const Ref &p_platform) { export_platforms.push_back(p_platform); + should_update_presets = true; } int EditorExport::get_export_platform_count() { @@ -169,11 +171,13 @@ void EditorExport::remove_export_preset(int p_idx) { void EditorExport::add_export_plugin(const Ref &p_plugin) { if (!export_plugins.has(p_plugin)) { export_plugins.push_back(p_plugin); + should_update_presets = true; } } void EditorExport::remove_export_plugin(const Ref &p_plugin) { export_plugins.erase(p_plugin); + should_update_presets = true; } Vector> EditorExport::get_export_plugins() { @@ -314,8 +318,11 @@ void EditorExport::load_config() { credentials->get_section_keys(option_section, &options); for (const String &E : options) { - Variant value = credentials->get_value(option_section, E); - preset->set(E, value); + // Drop values for secret properties that no longer exist, or during the next save they would end up in the regular config file. + if (preset->get_properties().has(E)) { + Variant value = credentials->get_value(option_section, E); + preset->set(E, value); + } } } @@ -332,7 +339,8 @@ void EditorExport::update_export_presets() { for (int i = 0; i < export_platforms.size(); i++) { Ref platform = export_platforms[i]; - bool should_update = platform->should_update_export_options(); + bool should_update = should_update_presets; + should_update |= platform->should_update_export_options(); for (int j = 0; j < export_plugins.size(); j++) { should_update |= export_plugins.write[j]->_should_update_export_options(platform); } @@ -342,12 +350,13 @@ void EditorExport::update_export_presets() { platform->get_export_options(&options); for (int j = 0; j < export_plugins.size(); j++) { - export_plugins.write[j]->_get_export_options(platform, &options); + export_plugins[j]->_get_export_options(platform, &options); } platform_options[platform->get_name()] = options; } } + should_update_presets = false; bool export_presets_updated = false; for (int i = 0; i < export_presets.size(); i++) { @@ -357,19 +366,16 @@ void EditorExport::update_export_presets() { List options = platform_options[preset->get_platform()->get_name()]; - // Copy the previous preset values - HashMap previous_values = preset->values; - - // Clear the preset properties and values prior to reloading + // Clear the preset properties prior to reloading, keep the values to preserve options from plugins that may be currently disabled. preset->properties.clear(); - preset->values.clear(); preset->update_visibility.clear(); for (const EditorExportPlatform::ExportOption &E : options) { - preset->properties.push_back(E.option); - StringName option_name = E.option.name; - preset->values[option_name] = previous_values.has(option_name) ? previous_values[option_name] : E.default_value; + preset->properties[option_name] = E.option; + if (!preset->has(option_name)) { + preset->values[option_name] = E.default_value; + } preset->update_visibility[option_name] = E.update_visibility; } } diff --git a/editor/export/editor_export.h b/editor/export/editor_export.h index 343686a4cf2..55dee0c468c 100644 --- a/editor/export/editor_export.h +++ b/editor/export/editor_export.h @@ -45,6 +45,7 @@ class EditorExport : public Node { Timer *save_timer = nullptr; bool block_save = false; + bool should_update_presets = false; static EditorExport *singleton; diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index 00fbd851660..d04eeafd079 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -329,9 +329,10 @@ Ref EditorExportPlatform::create_preset() { } for (const ExportOption &E : options) { - preset->properties.push_back(E.option); - preset->values[E.option.name] = E.default_value; - preset->update_visibility[E.option.name] = E.update_visibility; + StringName option_name = E.option.name; + preset->properties[option_name] = E.option; + preset->values[option_name] = E.default_value; + preset->update_visibility[option_name] = E.update_visibility; } return preset; diff --git a/editor/export/editor_export_preset.cpp b/editor/export/editor_export_preset.cpp index 2aca19a2ad5..a7dc44e3a81 100644 --- a/editor/export/editor_export_preset.cpp +++ b/editor/export/editor_export_preset.cpp @@ -31,9 +31,9 @@ #include "editor_export.h" bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) { - if (values.has(p_name)) { - values[p_name] = p_value; - EditorExport::singleton->save_presets(); + values[p_name] = p_value; + EditorExport::singleton->save_presets(); + if (update_visibility.has(p_name)) { if (update_visibility[p_name]) { notify_property_list_changed(); } @@ -61,9 +61,9 @@ String EditorExportPreset::_get_property_warning(const StringName &p_name) const } void EditorExportPreset::_get_property_list(List *p_list) const { - for (const PropertyInfo &E : properties) { - if (platform->get_export_option_visibility(this, E.name)) { - p_list->push_back(E); + for (const KeyValue &E : properties) { + if (platform->get_export_option_visibility(this, E.key)) { + p_list->push_back(E.value); } } } diff --git a/editor/export/editor_export_preset.h b/editor/export/editor_export_preset.h index 194858b4e87..8b59da06ddc 100644 --- a/editor/export/editor_export_preset.h +++ b/editor/export/editor_export_preset.h @@ -70,7 +70,7 @@ private: friend class EditorExport; friend class EditorExportPlatform; - List properties; + HashMap properties; HashMap values; HashMap update_visibility; @@ -154,7 +154,8 @@ public: Variant get_or_env(const StringName &p_name, const String &p_env_var, bool *r_valid = nullptr) const; - const List &get_properties() const { return properties; } + const HashMap &get_properties() const { return properties; } + const HashMap &get_values() const { return values; } EditorExportPreset(); }; diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index 8009b3038ce..7c7762e0fd7 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -577,8 +577,8 @@ void ProjectExportDialog::_duplicate_preset() { preset->set_exclude_filter(current->get_exclude_filter()); preset->set_custom_features(current->get_custom_features()); - for (const PropertyInfo &E : current->get_properties()) { - preset->set(E.name, current->get(E.name)); + for (const KeyValue &E : current->get_values()) { + preset->set(E.key, E.value); } EditorExport::get_singleton()->add_export_preset(preset);