Skip to content

Commit ba49259

Browse files
committed
[tvOS] extend tvOS plugins to support linker flags and plist types
1 parent 115634c commit ba49259

File tree

2 files changed

+155
-8
lines changed

2 files changed

+155
-8
lines changed

platform/tvos/export/export.cpp

+72-3
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,30 @@ void EditorExportPlatformTVOS::get_export_options(List<ExportOption> *r_options)
312312
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "plugins/" + found_plugins[i].name), false));
313313
}
314314

315+
Set<String> plist_keys;
316+
317+
for (int i = 0; i < found_plugins.size(); i++) {
318+
// Editable plugin plist values
319+
PluginConfigTVOS plugin = found_plugins[i];
320+
const String *K = nullptr;
321+
322+
while ((K = plugin.plist.next(K))) {
323+
String key = *K;
324+
PluginConfigTVOS::PlistItem item = plugin.plist[key];
325+
switch (item.type) {
326+
case PluginConfigTVOS::PlistItemType::STRING_INPUT: {
327+
String preset_name = "plugins_plist/" + key;
328+
if (!plist_keys.has(preset_name)) {
329+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), item.value));
330+
plist_keys.insert(preset_name);
331+
}
332+
} break;
333+
default:
334+
continue;
335+
}
336+
}
337+
}
338+
315339
plugins_changed.clear();
316340
plugins = found_plugins;
317341
}
@@ -787,6 +811,8 @@ Error EditorExportPlatformTVOS::_export_tvos_plugins(const Ref<EditorExportPrese
787811
Vector<String> added_embedded_dependenciy_names;
788812
HashMap<String, String> plist_values;
789813

814+
Set<String> plugin_linker_flags;
815+
790816
Error err;
791817

792818
for (int i = 0; i < enabled_plugins.size(); i++) {
@@ -853,19 +879,41 @@ Error EditorExportPlatformTVOS::_export_tvos_plugins(const Ref<EditorExportPrese
853879
p_config_data.capabilities.push_back(capability);
854880
}
855881

882+
// Linker flags
883+
// Checking duplicates
884+
for (int j = 0; j < plugin.linker_flags.size(); j++) {
885+
String linker_flag = plugin.linker_flags[j];
886+
plugin_linker_flags.insert(linker_flag);
887+
}
888+
856889
// Plist
857890
// Using hash map container to remove duplicates
858891
const String *K = nullptr;
859892

860893
while ((K = plugin.plist.next(K))) {
861894
String key = *K;
862-
String value = plugin.plist[key];
895+
PluginConfigTVOS::PlistItem item = plugin.plist[key];
896+
897+
String value;
898+
899+
switch (item.type) {
900+
case PluginConfigTVOS::PlistItemType::STRING_INPUT: {
901+
String preset_name = "plugins_plist/" + key;
902+
String input_value = p_preset->get(preset_name);
903+
value = "<string>" + input_value + "</string>";
904+
} break;
905+
default:
906+
value = item.value;
907+
break;
908+
}
863909

864910
if (key.empty() || value.empty()) {
865911
continue;
866912
}
867913

868-
plist_values[key] = value;
914+
String plist_key = "<key>" + key + "</key>";
915+
916+
plist_values[plist_key] = value;
869917
}
870918

871919
// CPP Code
@@ -892,7 +940,7 @@ Error EditorExportPlatformTVOS::_export_tvos_plugins(const Ref<EditorExportPrese
892940
continue;
893941
}
894942

895-
p_config_data.plist_content += "<key>" + key + "</key><string>" + value + "</string>\n";
943+
p_config_data.plist_content += key + value + "\n";
896944
}
897945
}
898946

@@ -933,6 +981,27 @@ Error EditorExportPlatformTVOS::_export_tvos_plugins(const Ref<EditorExportPrese
933981

934982
p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_");
935983
}
984+
985+
// Update Linker Flag Values
986+
{
987+
String result_linker_flags = " ";
988+
for (Set<String>::Element *E = plugin_linker_flags.front(); E; E = E->next()) {
989+
const String &flag = E->get();
990+
991+
if (flag.length() == 0) {
992+
continue;
993+
}
994+
995+
if (result_linker_flags.length() > 0) {
996+
result_linker_flags += ' ';
997+
}
998+
999+
result_linker_flags += flag;
1000+
}
1001+
result_linker_flags = result_linker_flags.replace("\"", "\\\"");
1002+
p_config_data.linker_flags += result_linker_flags;
1003+
}
1004+
9361005
return OK;
9371006
}
9381007

platform/tvos/export/godot_plugin_config.h

+83-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,24 @@ struct PluginConfigTVOS {
6464
static const char *DEPENDENCIES_SYSTEM_KEY;
6565
static const char *DEPENDENCIES_CAPABILITIES_KEY;
6666
static const char *DEPENDENCIES_FILES_KEY;
67+
static const char *DEPENDENCIES_LINKER_FLAGS;
6768

6869
static const char *PLIST_SECTION;
6970

71+
enum PlistItemType {
72+
UNKNOWN,
73+
STRING,
74+
INTEGER,
75+
BOOLEAN,
76+
RAW,
77+
STRING_INPUT,
78+
};
79+
80+
struct PlistItem {
81+
PlistItemType type;
82+
String value;
83+
};
84+
7085
// Set to true when the config file is properly loaded.
7186
bool valid_config = false;
7287
bool supports_targets = false;
@@ -86,10 +101,13 @@ struct PluginConfigTVOS {
86101

87102
Vector<String> files_to_copy;
88103
Vector<String> capabilities;
104+
Vector<String> linker_flags;
89105

90106
// Optional plist section
91-
// Supports only string types for now
92-
HashMap<String, String> plist;
107+
// String value is default value.
108+
// Currently supports `string`, `boolean`, `integer`, `raw`, `string_input` types
109+
// <name>:<type> = <value>
110+
HashMap<String, PlistItem> plist;
93111
};
94112

95113
const char *PluginConfigTVOS::PLUGIN_CONFIG_EXT = ".gdatvp";
@@ -106,6 +124,7 @@ const char *PluginConfigTVOS::DEPENDENCIES_EMBEDDED_KEY = "embedded";
106124
const char *PluginConfigTVOS::DEPENDENCIES_SYSTEM_KEY = "system";
107125
const char *PluginConfigTVOS::DEPENDENCIES_CAPABILITIES_KEY = "capabilities";
108126
const char *PluginConfigTVOS::DEPENDENCIES_FILES_KEY = "files";
127+
const char *PluginConfigTVOS::DEPENDENCIES_LINKER_FLAGS = "linker_flags";
109128

110129
const char *PluginConfigTVOS::PLIST_SECTION = "plist";
111130

@@ -247,6 +266,8 @@ static inline PluginConfigTVOS load_plugin_config(Ref<ConfigFile> config_file, c
247266
return plugin_config;
248267
}
249268

269+
config_file->clear();
270+
250271
Error err = config_file->load(path);
251272

252273
if (err != OK) {
@@ -275,20 +296,77 @@ static inline PluginConfigTVOS load_plugin_config(Ref<ConfigFile> config_file, c
275296
plugin_config.files_to_copy = resolve_local_dependencies(config_base_dir, files);
276297

277298
plugin_config.capabilities = config_file->get_value(PluginConfigTVOS::DEPENDENCIES_SECTION, PluginConfigTVOS::DEPENDENCIES_CAPABILITIES_KEY, Vector<String>());
299+
300+
plugin_config.linker_flags = config_file->get_value(PluginConfigTVOS::DEPENDENCIES_SECTION, PluginConfigTVOS::DEPENDENCIES_LINKER_FLAGS, Vector<String>());
278301
}
279302

280303
if (config_file->has_section(PluginConfigTVOS::PLIST_SECTION)) {
281304
List<String> keys;
282305
config_file->get_section_keys(PluginConfigTVOS::PLIST_SECTION, &keys);
283306

284307
for (int i = 0; i < keys.size(); i++) {
285-
String value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], String());
308+
Vector<String> key_components = keys[i].split(":");
309+
310+
String key_value = "";
311+
PluginConfigTVOS::PlistItemType key_type = PluginConfigTVOS::PlistItemType::UNKNOWN;
312+
313+
if (key_components.size() == 1) {
314+
key_value = key_components[0];
315+
key_type = PluginConfigTVOS::PlistItemType::STRING;
316+
} else if (key_components.size() == 2) {
317+
key_value = key_components[0];
318+
319+
if (key_components[1].to_lower() == "string") {
320+
key_type = PluginConfigTVOS::PlistItemType::STRING;
321+
} else if (key_components[1].to_lower() == "integer") {
322+
key_type = PluginConfigTVOS::PlistItemType::INTEGER;
323+
} else if (key_components[1].to_lower() == "boolean") {
324+
key_type = PluginConfigTVOS::PlistItemType::BOOLEAN;
325+
} else if (key_components[1].to_lower() == "raw") {
326+
key_type = PluginConfigTVOS::PlistItemType::RAW;
327+
} else if (key_components[1].to_lower() == "string_input") {
328+
key_type = PluginConfigTVOS::PlistItemType::STRING_INPUT;
329+
}
330+
}
286331

287-
if (value.empty()) {
332+
if (key_value.empty() || key_type == PluginConfigTVOS::PlistItemType::UNKNOWN) {
288333
continue;
289334
}
290335

291-
plugin_config.plist[keys[i]] = value;
336+
String value;
337+
338+
switch (key_type) {
339+
case PluginConfigTVOS::PlistItemType::STRING: {
340+
String raw_value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], String());
341+
value = "<string>" + raw_value + "</string>";
342+
} break;
343+
case PluginConfigTVOS::PlistItemType::INTEGER: {
344+
int raw_value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], 0);
345+
Dictionary value_dictionary;
346+
String value_format = "<integer>$value</integer>";
347+
value_dictionary["value"] = raw_value;
348+
value = value_format.format(value_dictionary, "$_");
349+
} break;
350+
case PluginConfigTVOS::PlistItemType::BOOLEAN:
351+
if (config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], false)) {
352+
value = "<true/>";
353+
} else {
354+
value = "<false/>";
355+
}
356+
break;
357+
case PluginConfigTVOS::PlistItemType::RAW: {
358+
String raw_value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], String());
359+
value = raw_value;
360+
} break;
361+
case PluginConfigTVOS::PlistItemType::STRING_INPUT: {
362+
String raw_value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], String());
363+
value = raw_value;
364+
} break;
365+
default:
366+
continue;
367+
}
368+
369+
plugin_config.plist[key_value] = PluginConfigTVOS::PlistItem{ key_type, value };
292370
}
293371
}
294372

0 commit comments

Comments
 (0)