From 6963e84b58b72d6103c4ddb38c80173a62df7bf4 Mon Sep 17 00:00:00 2001 From: RedworkDE <10944644+RedworkDE@users.noreply.github.com> Date: Wed, 8 Feb 2023 13:36:02 +0100 Subject: [PATCH] Allow EditorExportPlugins to provide export options --- doc/classes/EditorExportPlugin.xml | 25 ++++++++++++++++++++ editor/export/editor_export.cpp | 11 ++++++++- editor/export/editor_export_platform.cpp | 11 ++++++--- editor/export/editor_export_plugin.cpp | 29 ++++++++++++++++++++++++ editor/export/editor_export_plugin.h | 7 ++++++ 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/doc/classes/EditorExportPlugin.xml b/doc/classes/EditorExportPlugin.xml index e5740f806d20..a5b42bb89232 100644 --- a/doc/classes/EditorExportPlugin.xml +++ b/doc/classes/EditorExportPlugin.xml @@ -99,6 +99,17 @@ Return a [PackedStringArray] of additional features this preset, for the given [param platform], should have. + + + + + Return a list of export options that can be configured for this export plugin. + Each element in the return value is a [Dictionary] with the following keys: + - [code]option[/code]: A dictionary with the structure documented by [method Object.get_property_list], but all keys are optional. + - [code]default_value[/code]: The default value for this option. + - [code]update_visibility[/code]: An optional boolean value. If set to [code]true[/code], the preset will emit [signal Object.property_list_changed] when the option is changed. + + @@ -106,6 +117,13 @@ Implementing this method is required. + + + + + Return [code]true[/code], if the result of [method _get_export_options] has changed and the export options of preset corresponding to [param platform] should be updated. + + @@ -185,6 +203,13 @@ In case of a directory code-sign will error if you place non code object in directory. + + + + + Returns the current value of an export option supplied by [method _get_export_options]. + + diff --git a/editor/export/editor_export.cpp b/editor/export/editor_export.cpp index 299523b36854..3f192342a184 100644 --- a/editor/export/editor_export.cpp +++ b/editor/export/editor_export.cpp @@ -313,10 +313,19 @@ void EditorExport::update_export_presets() { for (int i = 0; i < export_platforms.size(); i++) { Ref platform = export_platforms[i]; - if (platform->should_update_export_options()) { + bool 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); + } + + if (should_update) { List options; platform->get_export_options(&options); + for (int j = 0; j < export_plugins.size(); j++) { + export_plugins.write[j]->_get_export_options(platform, &options); + } + platform_options[platform->get_name()] = options; } } diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index fa6b0a77163c..4e173799115f 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -322,6 +322,11 @@ Ref EditorExportPlatform::create_preset() { List options; get_export_options(&options); + Vector> export_plugins = EditorExport::get_singleton()->get_export_plugins(); + for (int i = 0; i < export_plugins.size(); i++) { + export_plugins.write[i]->_get_export_options(Ref(this), &options); + } + for (const ExportOption &E : options) { preset->properties.push_back(E.option); preset->values[E.option.name] = E.default_value; @@ -489,6 +494,7 @@ EditorExportPlatform::ExportNotifier::ExportNotifier(EditorExportPlatform &p_pla Vector> export_plugins = EditorExport::get_singleton()->get_export_plugins(); //initial export plugin callback for (int i = 0; i < export_plugins.size(); i++) { + export_plugins.write[i]->set_export_preset(p_preset); if (export_plugins[i]->get_script_instance()) { //script based PackedStringArray features_psa; for (const String &feature : features) { @@ -508,6 +514,7 @@ EditorExportPlatform::ExportNotifier::~ExportNotifier() { export_plugins.write[i]->_export_end_script(); } export_plugins.write[i]->_export_end(); + export_plugins.write[i]->set_export_preset(Ref()); } } @@ -932,12 +939,10 @@ Error EditorExportPlatform::export_project_files(const Ref & } }; - // Always sort by name, to so if for some reason theya are re-arranged, it still works. + // Always sort by name, to so if for some reason they are re-arranged, it still works. export_plugins.sort_custom(); for (int i = 0; i < export_plugins.size(); i++) { - export_plugins.write[i]->set_export_preset(p_preset); - if (p_so_func) { for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) { err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]); diff --git a/editor/export/editor_export_plugin.cpp b/editor/export/editor_export_plugin.cpp index 5887befcd846..4e2c1a9af72a 100644 --- a/editor/export/editor_export_plugin.cpp +++ b/editor/export/editor_export_plugin.cpp @@ -127,6 +127,11 @@ Vector EditorExportPlugin::get_ios_project_static_libs() const { return ios_project_static_libs; } +Variant EditorExportPlugin::get_option(const StringName &p_name) const { + ERR_FAIL_NULL_V(export_preset, Variant()); + return export_preset->get(p_name); +} + void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector &p_features) { GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features); } @@ -191,6 +196,26 @@ PackedStringArray EditorExportPlugin::_get_export_features(const Ref &p_platform, List *r_options) const { + TypedArray ret; + GDVIRTUAL_CALL(_get_export_options, p_platform, ret); + for (int i = 0; i < ret.size(); i++) { + Dictionary option = ret[i]; + ERR_CONTINUE_MSG(!option.has("option"), "Missing required element 'option'"); + ERR_CONTINUE_MSG(!option.has("default_value"), "Missing required element 'default_value'"); + PropertyInfo property_info = PropertyInfo::from_dict(option["option"]); + Variant default_value = option["default_value"]; + bool update_visibility = option.has("update_visibility") && option["update_visibility"]; + r_options->push_back(EditorExportPlatform::ExportOption(property_info, default_value, update_visibility)); + } +} + +bool EditorExportPlugin::_should_update_export_options(const Ref &p_platform) const { + bool ret = false; + GDVIRTUAL_CALL(_should_update_export_options, p_platform, ret); + return ret; +} + void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const HashSet &p_features) { } @@ -213,6 +238,7 @@ void EditorExportPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_ios_cpp_code); ClassDB::bind_method(D_METHOD("add_macos_plugin_file", "path"), &EditorExportPlugin::add_macos_plugin_file); ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip); + ClassDB::bind_method(D_METHOD("get_option", "name"), &EditorExportPlugin::get_option); GDVIRTUAL_BIND(_export_file, "path", "type", "features"); GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags"); @@ -229,6 +255,9 @@ void EditorExportPlugin::_bind_methods() { GDVIRTUAL_BIND(_end_customize_scenes); GDVIRTUAL_BIND(_end_customize_resources); + GDVIRTUAL_BIND(_get_export_options, "platform"); + GDVIRTUAL_BIND(_should_update_export_options, "platform"); + GDVIRTUAL_BIND(_get_export_features, "platform", "debug"); GDVIRTUAL_BIND(_get_name); } diff --git a/editor/export/editor_export_plugin.h b/editor/export/editor_export_plugin.h index fad647a67bc6..120141b34797 100644 --- a/editor/export/editor_export_plugin.h +++ b/editor/export/editor_export_plugin.h @@ -32,6 +32,7 @@ #define EDITOR_EXPORT_PLUGIN_H #include "core/extension/gdextension.h" +#include "editor_export_platform.h" #include "editor_export_preset.h" #include "editor_export_shared_object.h" #include "scene/main/node.h" @@ -39,6 +40,7 @@ class EditorExportPlugin : public RefCounted { GDCLASS(EditorExportPlugin, RefCounted); + friend class EditorExport; friend class EditorExportPlatform; Ref export_preset; @@ -121,6 +123,8 @@ class EditorExportPlugin : public RefCounted { GDVIRTUAL0(_end_customize_resources) GDVIRTUAL2RC(PackedStringArray, _get_export_features, const Ref &, bool); + GDVIRTUAL1RC(TypedArray, _get_export_options, const Ref &); + GDVIRTUAL1RC(bool, _should_update_export_options, const Ref &); GDVIRTUAL0RC(String, _get_name) @@ -136,6 +140,8 @@ class EditorExportPlugin : public RefCounted { virtual void _end_customize_resources(); virtual PackedStringArray _get_export_features(const Ref &p_export_platform, bool p_debug) const; + virtual void _get_export_options(const Ref &p_export_platform, List *r_options) const; + virtual bool _should_update_export_options(const Ref &p_export_platform) const; virtual String _get_name() const; @@ -148,6 +154,7 @@ class EditorExportPlugin : public RefCounted { Vector get_ios_bundle_files() const; String get_ios_cpp_code() const; const Vector &get_macos_plugin_files() const; + Variant get_option(const StringName &p_name) const; EditorExportPlugin(); };