Skip to content

Commit 81e17d8

Browse files
committed
Merge pull request godotengine#102109 from bruvzg/export_res
[Export] Respect icon/splash screen import settings.
2 parents b1adcba + b3f7c8f commit 81e17d8

File tree

8 files changed

+69
-44
lines changed

8 files changed

+69
-44
lines changed

editor/export/editor_export_platform.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "core/extension/gdextension.h"
3636
#include "core/io/file_access_encrypted.h"
3737
#include "core/io/file_access_pack.h" // PACK_HEADER_MAGIC, PACK_FORMAT_VERSION
38+
#include "core/io/image_loader.h"
3839
#include "core/io/resource_uid.h"
3940
#include "core/io/zip_io.h"
4041
#include "core/version.h"
@@ -82,6 +83,28 @@ static int _get_pad(int p_alignment, int p_n) {
8283

8384
#define PCK_PADDING 16
8485

86+
Ref<Image> EditorExportPlatform::_load_icon_or_splash_image(const String &p_path, Error *r_error) const {
87+
Ref<Image> image;
88+
89+
if (!p_path.is_empty() && ResourceLoader::exists(p_path) && !ResourceLoader::get_resource_type(p_path).is_empty()) {
90+
Ref<Texture2D> texture = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, r_error);
91+
if (texture.is_valid()) {
92+
image = texture->get_image();
93+
if (image.is_valid() && image->is_compressed()) {
94+
image->decompress();
95+
}
96+
}
97+
}
98+
if (image.is_null()) {
99+
image.instantiate();
100+
Error err = ImageLoader::load_image(p_path, image);
101+
if (r_error) {
102+
*r_error = err;
103+
}
104+
}
105+
return image;
106+
}
107+
85108
bool EditorExportPlatform::fill_log_messages(RichTextLabel *p_log, Error p_err) {
86109
bool has_messages = false;
87110

editor/export/editor_export_platform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ class EditorExportPlatform : public RefCounted {
202202
Error _load_patches(const Vector<String> &p_patches);
203203
void _unload_patches();
204204

205+
Ref<Image> _load_icon_or_splash_image(const String &p_path, Error *r_error) const;
206+
205207
public:
206208
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const = 0;
207209

platform/android/export/export_plugin.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,18 +1723,18 @@ void EditorExportPlatformAndroid::_process_launcher_icons(const String &p_file_n
17231723
void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background, Ref<Image> &monochrome) {
17241724
String project_icon_path = GLOBAL_GET("application/config/icon");
17251725

1726-
icon.instantiate();
1727-
foreground.instantiate();
1728-
background.instantiate();
1729-
monochrome.instantiate();
1726+
Error err = OK;
17301727

17311728
// Regular icon: user selection -> project icon -> default.
17321729
String path = static_cast<String>(p_preset->get(LAUNCHER_ICON_OPTION)).strip_edges();
17331730
print_verbose("Loading regular icon from " + path);
1734-
if (path.is_empty() || ImageLoader::load_image(path, icon) != OK) {
1731+
if (!path.is_empty()) {
1732+
icon = _load_icon_or_splash_image(path, &err);
1733+
}
1734+
if (path.is_empty() || err != OK || icon.is_null() || icon->is_empty()) {
17351735
print_verbose("- falling back to project icon: " + project_icon_path);
17361736
if (!project_icon_path.is_empty()) {
1737-
ImageLoader::load_image(project_icon_path, icon);
1737+
icon = _load_icon_or_splash_image(project_icon_path, &err);
17381738
} else {
17391739
ERR_PRINT("No project icon specified. Please specify one in the Project Settings under Application -> Config -> Icon");
17401740
}
@@ -1743,7 +1743,10 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &
17431743
// Adaptive foreground: user selection -> regular icon (user selection -> project icon -> default).
17441744
path = static_cast<String>(p_preset->get(LAUNCHER_ADAPTIVE_ICON_FOREGROUND_OPTION)).strip_edges();
17451745
print_verbose("Loading adaptive foreground icon from " + path);
1746-
if (path.is_empty() || ImageLoader::load_image(path, foreground) != OK) {
1746+
if (!path.is_empty()) {
1747+
foreground = _load_icon_or_splash_image(path, &err);
1748+
}
1749+
if (path.is_empty() || err != OK || foreground.is_null() || foreground->is_empty()) {
17471750
print_verbose("- falling back to using the regular icon");
17481751
foreground = icon;
17491752
}
@@ -1752,14 +1755,14 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &
17521755
path = static_cast<String>(p_preset->get(LAUNCHER_ADAPTIVE_ICON_BACKGROUND_OPTION)).strip_edges();
17531756
if (!path.is_empty()) {
17541757
print_verbose("Loading adaptive background icon from " + path);
1755-
ImageLoader::load_image(path, background);
1758+
background = _load_icon_or_splash_image(path, &err);
17561759
}
17571760

17581761
// Adaptive monochrome: user selection -> default.
17591762
path = static_cast<String>(p_preset->get(LAUNCHER_ADAPTIVE_ICON_MONOCHROME_OPTION)).strip_edges();
17601763
if (!path.is_empty()) {
17611764
print_verbose("Loading adaptive monochrome icon from " + path);
1762-
ImageLoader::load_image(path, monochrome);
1765+
monochrome = _load_icon_or_splash_image(path, &err);
17631766
}
17641767
}
17651768

platform/ios/export/export_plugin.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -982,9 +982,9 @@ Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_pr
982982
}
983983
// Resize main app icon.
984984
icon_path = GLOBAL_GET("application/config/icon");
985-
Ref<Image> img = memnew(Image);
986-
Error err = ImageLoader::load_image(icon_path, img);
987-
if (err != OK) {
985+
Error err = OK;
986+
Ref<Image> img = _load_icon_or_splash_image(icon_path, &err);
987+
if (err != OK || img.is_null() || img->is_empty()) {
988988
add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
989989
return ERR_UNCONFIGURED;
990990
} else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
@@ -1003,9 +1003,9 @@ Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_pr
10031003
}
10041004
} else {
10051005
// Load custom icon and resize if required.
1006-
Ref<Image> img = memnew(Image);
1007-
Error err = ImageLoader::load_image(icon_path, img);
1008-
if (err != OK) {
1006+
Error err = OK;
1007+
Ref<Image> img = _load_icon_or_splash_image(icon_path, &err);
1008+
if (err != OK || img.is_null() || img->is_empty()) {
10091009
add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
10101010
return ERR_UNCONFIGURED;
10111011
} else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
@@ -1089,47 +1089,39 @@ Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExpor
10891089
const String custom_launch_image_3x = p_preset->get("storyboard/custom_image@3x");
10901090

10911091
if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) {
1092-
Ref<Image> image;
10931092
String image_path = p_dest_dir.path_join("[email protected]");
1094-
image.instantiate();
1095-
Error err = ImageLoader::load_image(custom_launch_image_2x, image);
1093+
Error err = OK;
1094+
Ref<Image> image = _load_icon_or_splash_image(custom_launch_image_2x, &err);
10961095

1097-
if (err) {
1098-
image.unref();
1096+
if (err != OK || image.is_null() || image->is_empty()) {
10991097
return err;
11001098
}
11011099

11021100
if (image->save_png(image_path) != OK) {
11031101
return ERR_FILE_CANT_WRITE;
11041102
}
11051103

1106-
image.unref();
11071104
image_path = p_dest_dir.path_join("[email protected]");
1108-
image.instantiate();
1109-
err = ImageLoader::load_image(custom_launch_image_3x, image);
1105+
image = _load_icon_or_splash_image(custom_launch_image_3x, &err);
11101106

1111-
if (err) {
1112-
image.unref();
1107+
if (err != OK || image.is_null() || image->is_empty()) {
11131108
return err;
11141109
}
11151110

11161111
if (image->save_png(image_path) != OK) {
11171112
return ERR_FILE_CANT_WRITE;
11181113
}
11191114
} else {
1115+
Error err = OK;
11201116
Ref<Image> splash;
11211117

11221118
const String splash_path = GLOBAL_GET("application/boot_splash/image");
11231119

11241120
if (!splash_path.is_empty()) {
1125-
splash.instantiate();
1126-
const Error err = ImageLoader::load_image(splash_path, splash);
1127-
if (err) {
1128-
splash.unref();
1129-
}
1121+
splash = _load_icon_or_splash_image(splash_path, &err);
11301122
}
11311123

1132-
if (splash.is_null()) {
1124+
if (err != OK || splash.is_null() || splash->is_empty()) {
11331125
splash.instantiate(boot_splash_png);
11341126
}
11351127

platform/macos/export/export_plugin.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,10 +1883,8 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
18831883
icon->get_buffer(&data.write[0], icon->get_length());
18841884
}
18851885
} else {
1886-
Ref<Image> icon;
1887-
icon.instantiate();
1888-
err = ImageLoader::load_image(icon_path, icon);
1889-
if (err == OK && !icon->is_empty()) {
1886+
Ref<Image> icon = _load_icon_or_splash_image(icon_path, &err);
1887+
if (err == OK && icon.is_valid() && !icon->is_empty()) {
18901888
_make_icon(p_preset, icon, data);
18911889
}
18921890
}

platform/web/export/export_plugin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ Error EditorExportPlatformWeb::_add_manifest_icon(const String &p_path, const St
192192

193193
Ref<Image> icon;
194194
if (!p_icon.is_empty()) {
195-
icon.instantiate();
196-
const Error err = ImageLoader::load_image(p_icon, icon);
197-
if (err != OK) {
195+
Error err = OK;
196+
icon = _load_icon_or_splash_image(p_icon, &err);
197+
if (err != OK || icon.is_null() || icon->is_empty()) {
198198
add_message(EXPORT_MESSAGE_ERROR, TTR("Icon Creation"), vformat(TTR("Could not read file: \"%s\"."), p_icon));
199199
return err;
200200
}

platform/web/export/export_plugin.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,28 @@ class EditorExportPlatformWeb : public EditorExportPlatform {
7777
}
7878

7979
Ref<Image> _get_project_icon() const {
80+
Error err = OK;
8081
Ref<Image> icon;
8182
icon.instantiate();
8283
const String icon_path = String(GLOBAL_GET("application/config/icon")).strip_edges();
83-
if (icon_path.is_empty() || ImageLoader::load_image(icon_path, icon) != OK) {
84+
if (!icon_path.is_empty()) {
85+
icon = _load_icon_or_splash_image(icon_path, &err);
86+
}
87+
if (icon_path.is_empty() || err != OK || icon.is_null() || icon->is_empty()) {
8488
return EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("DefaultProjectIcon"), EditorStringName(EditorIcons))->get_image();
8589
}
8690
return icon;
8791
}
8892

8993
Ref<Image> _get_project_splash() const {
94+
Error err = OK;
9095
Ref<Image> splash;
9196
splash.instantiate();
9297
const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges();
93-
if (splash_path.is_empty() || ImageLoader::load_image(splash_path, splash) != OK) {
98+
if (!splash_path.is_empty()) {
99+
splash = _load_icon_or_splash_image(splash_path, &err);
100+
}
101+
if (splash_path.is_empty() || err != OK || splash.is_null() || splash->is_empty()) {
94102
return Ref<Image>(memnew(Image(boot_splash_png)));
95103
}
96104
return splash;

platform/windows/export/export_plugin.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ Error EditorExportPlatformWindows::_process_icon(const Ref<EditorExportPreset> &
9393
f->seek(prev_offset);
9494
}
9595
} else {
96-
Ref<Image> src_image;
97-
src_image.instantiate();
98-
err = ImageLoader::load_image(p_src_path, src_image);
99-
ERR_FAIL_COND_V(err != OK || src_image->is_empty(), ERR_CANT_OPEN);
96+
Ref<Image> src_image = _load_icon_or_splash_image(p_src_path, &err);
97+
ERR_FAIL_COND_V(err != OK || src_image.is_null() || src_image->is_empty(), ERR_CANT_OPEN);
98+
10099
for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) {
101100
int size = (icon_size[i] == 0) ? 256 : icon_size[i];
102101

0 commit comments

Comments
 (0)