Add a "version" project setting and use it in new export presets

This makes it easy to retrieve the project version at runtime
for display purposes, while simplifying the export preset configuration.
You can now leave the version empty unless you need to override it on a per-preset
basis.

Since export presets save the values of default values to the `export_presets.cfg`
file, this change only affects export presets created after this commit was merged.
This commit is contained in:
Hugo Locurcio
2023-07-17 09:53:45 +02:00
parent eb4301b941
commit ad4480bf2e
12 changed files with 65 additions and 21 deletions

View File

@ -30,6 +30,8 @@
#include "editor_export.h"
#include "core/config/project_settings.h"
bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) {
values[p_name] = p_value;
EditorExport::singleton->save_presets();
@ -332,4 +334,35 @@ Variant EditorExportPreset::get_or_env(const StringName &p_name, const String &p
return get(p_name, r_valid);
}
String EditorExportPreset::get_version(const StringName &p_preset_string, bool p_windows_version) const {
String result = get(p_preset_string);
if (result.is_empty()) {
result = GLOBAL_GET("application/config/version");
if (p_windows_version) {
// Modify version number to match Windows constraints (version numbers must have 4 components).
const PackedStringArray result_split = result.split(".");
String windows_version;
if (result_split.is_empty()) {
// Use a valid fallback if the version string is empty, as a version number must be specified.
result = "1.0.0.0";
} else if (result_split.size() == 1) {
result = result + ".0.0.0";
} else if (result_split.size() == 2) {
result = result + ".0.0";
} else if (result_split.size() == 3) {
result = result + ".0";
} else {
// 4 components or more in the version string. Trim to contain only the first 4 components.
result = vformat("%s.%s.%s.%s", result_split[0] + result_split[1] + result_split[2] + result_split[3]);
}
} else if (result.is_empty()) {
// Use a valid fallback if the version string is empty, as a version number must be specified.
result = "1.0.0";
}
}
return result;
}
EditorExportPreset::EditorExportPreset() {}