Skip to content

Commit

Permalink
Merge pull request #72895 from RedworkDE/editor-export-plugin-settings
Browse files Browse the repository at this point in the history
Allow EditorExportPlugins to provide export options
  • Loading branch information
akien-mga committed Apr 17, 2023
2 parents de416c5 + 6963e84 commit 96cc100
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
25 changes: 25 additions & 0 deletions doc/classes/EditorExportPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,31 @@
Return a [PackedStringArray] of additional features this preset, for the given [param platform], should have.
</description>
</method>
<method name="_get_export_options" qualifiers="virtual const">
<return type="Dictionary[]" />
<param index="0" name="platform" type="EditorExportPlatform" />
<description>
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.
</description>
</method>
<method name="_get_name" qualifiers="virtual const">
<return type="String" />
<description>
Return the name identifier of this plugin (for future identification by the exporter). The plugins are sorted by name before exporting.
Implementing this method is required.
</description>
</method>
<method name="_should_update_export_options" qualifiers="virtual const">
<return type="bool" />
<param index="0" name="platform" type="EditorExportPlatform" />
<description>
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.
</description>
</method>
<method name="add_file">
<return type="void" />
<param index="0" name="path" type="String" />
Expand Down Expand Up @@ -185,6 +203,13 @@
In case of a directory code-sign will error if you place non code object in directory.
</description>
</method>
<method name="get_option" qualifiers="const">
<return type="Variant" />
<param index="0" name="name" type="StringName" />
<description>
Returns the current value of an export option supplied by [method _get_export_options].
</description>
</method>
<method name="skip">
<return type="void" />
<description>
Expand Down
11 changes: 10 additions & 1 deletion editor/export/editor_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,19 @@ void EditorExport::update_export_presets() {
for (int i = 0; i < export_platforms.size(); i++) {
Ref<EditorExportPlatform> 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<EditorExportPlatform::ExportOption> 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;
}
}
Expand Down
11 changes: 8 additions & 3 deletions editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ Ref<EditorExportPreset> EditorExportPlatform::create_preset() {
List<ExportOption> options;
get_export_options(&options);

Vector<Ref<EditorExportPlugin>> 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<EditorExportPlatform>(this), &options);
}

for (const ExportOption &E : options) {
preset->properties.push_back(E.option);
preset->values[E.option.name] = E.default_value;
Expand Down Expand Up @@ -489,6 +494,7 @@ EditorExportPlatform::ExportNotifier::ExportNotifier(EditorExportPlatform &p_pla
Vector<Ref<EditorExportPlugin>> 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) {
Expand All @@ -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<EditorExportPlugin>());
}
}

Expand Down Expand Up @@ -932,12 +939,10 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
}
};

// 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<SortByName>();

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]);
Expand Down
29 changes: 29 additions & 0 deletions editor/export/editor_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ Vector<String> 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<String> &p_features) {
GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features);
}
Expand Down Expand Up @@ -191,6 +196,26 @@ PackedStringArray EditorExportPlugin::_get_export_features(const Ref<EditorExpor
return ret;
}

void EditorExportPlugin::_get_export_options(const Ref<EditorExportPlatform> &p_platform, List<EditorExportPlatform::ExportOption> *r_options) const {
TypedArray<Dictionary> 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<EditorExportPlatform> &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<String> &p_features) {
}

Expand All @@ -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");
Expand All @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions editor/export/editor_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
#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"

class EditorExportPlugin : public RefCounted {
GDCLASS(EditorExportPlugin, RefCounted);

friend class EditorExport;
friend class EditorExportPlatform;

Ref<EditorExportPreset> export_preset;
Expand Down Expand Up @@ -121,6 +123,8 @@ class EditorExportPlugin : public RefCounted {
GDVIRTUAL0(_end_customize_resources)

GDVIRTUAL2RC(PackedStringArray, _get_export_features, const Ref<EditorExportPlatform> &, bool);
GDVIRTUAL1RC(TypedArray<Dictionary>, _get_export_options, const Ref<EditorExportPlatform> &);
GDVIRTUAL1RC(bool, _should_update_export_options, const Ref<EditorExportPlatform> &);

GDVIRTUAL0RC(String, _get_name)

Expand All @@ -136,6 +140,8 @@ class EditorExportPlugin : public RefCounted {
virtual void _end_customize_resources();

virtual PackedStringArray _get_export_features(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const;
virtual void _get_export_options(const Ref<EditorExportPlatform> &p_export_platform, List<EditorExportPlatform::ExportOption> *r_options) const;
virtual bool _should_update_export_options(const Ref<EditorExportPlatform> &p_export_platform) const;

virtual String _get_name() const;

Expand All @@ -148,6 +154,7 @@ class EditorExportPlugin : public RefCounted {
Vector<String> get_ios_bundle_files() const;
String get_ios_cpp_code() const;
const Vector<String> &get_macos_plugin_files() const;
Variant get_option(const StringName &p_name) const;

EditorExportPlugin();
};
Expand Down

0 comments on commit 96cc100

Please sign in to comment.