Fix export options of scripted EditorExportPlugins

This commit is contained in:
RedworkDE 2023-07-04 15:39:23 +02:00
parent cdd2313ba2
commit fa84d09542
6 changed files with 38 additions and 29 deletions

View File

@ -90,11 +90,12 @@ void EditorExport::_save() {
String option_section = "preset." + itos(i) + ".options"; String option_section = "preset." + itos(i) + ".options";
for (const PropertyInfo &E : preset->get_properties()) { for (const KeyValue<StringName, Variant> &E : preset->values) {
if (E.usage & PROPERTY_USAGE_SECRET) { PropertyInfo *prop = preset->properties.getptr(E.key);
credentials->set_value(option_section, E.name, preset->get(E.name)); if (prop && prop->usage & PROPERTY_USAGE_SECRET) {
credentials->set_value(option_section, E.key, E.value);
} else { } 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<EditorExportPlatform> &p_platform) { void EditorExport::add_export_platform(const Ref<EditorExportPlatform> &p_platform) {
export_platforms.push_back(p_platform); export_platforms.push_back(p_platform);
should_update_presets = true;
} }
int EditorExport::get_export_platform_count() { 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<EditorExportPlugin> &p_plugin) { void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
if (!export_plugins.has(p_plugin)) { if (!export_plugins.has(p_plugin)) {
export_plugins.push_back(p_plugin); export_plugins.push_back(p_plugin);
should_update_presets = true;
} }
} }
void EditorExport::remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin) { void EditorExport::remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
export_plugins.erase(p_plugin); export_plugins.erase(p_plugin);
should_update_presets = true;
} }
Vector<Ref<EditorExportPlugin>> EditorExport::get_export_plugins() { Vector<Ref<EditorExportPlugin>> EditorExport::get_export_plugins() {
@ -314,8 +318,11 @@ void EditorExport::load_config() {
credentials->get_section_keys(option_section, &options); credentials->get_section_keys(option_section, &options);
for (const String &E : options) { for (const String &E : options) {
Variant value = credentials->get_value(option_section, E); // Drop values for secret properties that no longer exist, or during the next save they would end up in the regular config file.
preset->set(E, value); 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++) { for (int i = 0; i < export_platforms.size(); i++) {
Ref<EditorExportPlatform> platform = export_platforms[i]; Ref<EditorExportPlatform> 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++) { for (int j = 0; j < export_plugins.size(); j++) {
should_update |= export_plugins.write[j]->_should_update_export_options(platform); 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); platform->get_export_options(&options);
for (int j = 0; j < export_plugins.size(); j++) { 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; platform_options[platform->get_name()] = options;
} }
} }
should_update_presets = false;
bool export_presets_updated = false; bool export_presets_updated = false;
for (int i = 0; i < export_presets.size(); i++) { for (int i = 0; i < export_presets.size(); i++) {
@ -357,19 +366,16 @@ void EditorExport::update_export_presets() {
List<EditorExportPlatform::ExportOption> options = platform_options[preset->get_platform()->get_name()]; List<EditorExportPlatform::ExportOption> options = platform_options[preset->get_platform()->get_name()];
// Copy the previous preset values // Clear the preset properties prior to reloading, keep the values to preserve options from plugins that may be currently disabled.
HashMap<StringName, Variant> previous_values = preset->values;
// Clear the preset properties and values prior to reloading
preset->properties.clear(); preset->properties.clear();
preset->values.clear();
preset->update_visibility.clear(); preset->update_visibility.clear();
for (const EditorExportPlatform::ExportOption &E : options) { for (const EditorExportPlatform::ExportOption &E : options) {
preset->properties.push_back(E.option);
StringName option_name = E.option.name; 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; preset->update_visibility[option_name] = E.update_visibility;
} }
} }

View File

@ -45,6 +45,7 @@ class EditorExport : public Node {
Timer *save_timer = nullptr; Timer *save_timer = nullptr;
bool block_save = false; bool block_save = false;
bool should_update_presets = false;
static EditorExport *singleton; static EditorExport *singleton;

View File

@ -329,9 +329,10 @@ Ref<EditorExportPreset> EditorExportPlatform::create_preset() {
} }
for (const ExportOption &E : options) { for (const ExportOption &E : options) {
preset->properties.push_back(E.option); StringName option_name = E.option.name;
preset->values[E.option.name] = E.default_value; preset->properties[option_name] = E.option;
preset->update_visibility[E.option.name] = E.update_visibility; preset->values[option_name] = E.default_value;
preset->update_visibility[option_name] = E.update_visibility;
} }
return preset; return preset;

View File

@ -31,9 +31,9 @@
#include "editor_export.h" #include "editor_export.h"
bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) { bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) {
if (values.has(p_name)) { values[p_name] = p_value;
values[p_name] = p_value; EditorExport::singleton->save_presets();
EditorExport::singleton->save_presets(); if (update_visibility.has(p_name)) {
if (update_visibility[p_name]) { if (update_visibility[p_name]) {
notify_property_list_changed(); notify_property_list_changed();
} }
@ -61,9 +61,9 @@ String EditorExportPreset::_get_property_warning(const StringName &p_name) const
} }
void EditorExportPreset::_get_property_list(List<PropertyInfo> *p_list) const { void EditorExportPreset::_get_property_list(List<PropertyInfo> *p_list) const {
for (const PropertyInfo &E : properties) { for (const KeyValue<StringName, PropertyInfo> &E : properties) {
if (platform->get_export_option_visibility(this, E.name)) { if (platform->get_export_option_visibility(this, E.key)) {
p_list->push_back(E); p_list->push_back(E.value);
} }
} }
} }

View File

@ -70,7 +70,7 @@ private:
friend class EditorExport; friend class EditorExport;
friend class EditorExportPlatform; friend class EditorExportPlatform;
List<PropertyInfo> properties; HashMap<StringName, PropertyInfo> properties;
HashMap<StringName, Variant> values; HashMap<StringName, Variant> values;
HashMap<StringName, bool> update_visibility; HashMap<StringName, bool> 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; Variant get_or_env(const StringName &p_name, const String &p_env_var, bool *r_valid = nullptr) const;
const List<PropertyInfo> &get_properties() const { return properties; } const HashMap<StringName, PropertyInfo> &get_properties() const { return properties; }
const HashMap<StringName, Variant> &get_values() const { return values; }
EditorExportPreset(); EditorExportPreset();
}; };

View File

@ -577,8 +577,8 @@ void ProjectExportDialog::_duplicate_preset() {
preset->set_exclude_filter(current->get_exclude_filter()); preset->set_exclude_filter(current->get_exclude_filter());
preset->set_custom_features(current->get_custom_features()); preset->set_custom_features(current->get_custom_features());
for (const PropertyInfo &E : current->get_properties()) { for (const KeyValue<StringName, Variant> &E : current->get_values()) {
preset->set(E.name, current->get(E.name)); preset->set(E.key, E.value);
} }
EditorExport::get_singleton()->add_export_preset(preset); EditorExport::get_singleton()->add_export_preset(preset);