Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix export options of scripted EditorExportPlugins #79025

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions editor/export/editor_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StringName, Variant> &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);
}
}
}
Expand All @@ -116,6 +117,7 @@ void EditorExport::_bind_methods() {

void EditorExport::add_export_platform(const Ref<EditorExportPlatform> &p_platform) {
export_platforms.push_back(p_platform);
should_update_presets = true;
}

int EditorExport::get_export_platform_count() {
Expand Down Expand Up @@ -169,11 +171,13 @@ void EditorExport::remove_export_preset(int p_idx) {
void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &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<EditorExportPlugin> &p_plugin) {
export_plugins.erase(p_plugin);
should_update_presets = true;
}

Vector<Ref<EditorExportPlugin>> EditorExport::get_export_plugins() {
Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -332,7 +339,8 @@ void EditorExport::update_export_presets() {
for (int i = 0; i < export_platforms.size(); 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++) {
should_update |= export_plugins.write[j]->_should_update_export_options(platform);
}
Expand All @@ -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++) {
Expand All @@ -357,19 +366,16 @@ void EditorExport::update_export_presets() {

List<EditorExportPlatform::ExportOption> options = platform_options[preset->get_platform()->get_name()];

// Copy the previous preset values
HashMap<StringName, Variant> 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;
}
}
Expand Down
1 change: 1 addition & 0 deletions editor/export/editor_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class EditorExport : public Node {

Timer *save_timer = nullptr;
bool block_save = false;
bool should_update_presets = false;

static EditorExport *singleton;

Expand Down
7 changes: 4 additions & 3 deletions editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ Ref<EditorExportPreset> 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;
Expand Down
12 changes: 6 additions & 6 deletions editor/export/editor_export_preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -61,9 +61,9 @@ String EditorExportPreset::_get_property_warning(const StringName &p_name) const
}

void EditorExportPreset::_get_property_list(List<PropertyInfo> *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<StringName, PropertyInfo> &E : properties) {
if (platform->get_export_option_visibility(this, E.key)) {
p_list->push_back(E.value);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions editor/export/editor_export_preset.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class EditorExportPreset : public RefCounted {
friend class EditorExport;
friend class EditorExportPlatform;

List<PropertyInfo> properties;
HashMap<StringName, PropertyInfo> properties;
HashMap<StringName, Variant> values;
HashMap<StringName, bool> update_visibility;

Expand Down Expand Up @@ -154,7 +154,8 @@ class EditorExportPreset : public RefCounted {

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();
};
Expand Down
4 changes: 2 additions & 2 deletions editor/export/project_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StringName, Variant> &E : current->get_values()) {
preset->set(E.key, E.value);
}

EditorExport::get_singleton()->add_export_preset(preset);
Expand Down