Skip to content

Commit c188683

Browse files
committed
[tvOS] extend tvOS plugins to support linker flags and plist types
1 parent 22b6f1a commit c188683

File tree

2 files changed

+150
-8
lines changed

2 files changed

+150
-8
lines changed

platform/tvos/export/export.cpp

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,30 @@ void EditorExportPlatformTVOS::get_export_options(List<ExportOption> *r_options)
314314
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "plugins/" + found_plugins[i].name), false));
315315
}
316316

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

819+
Set<String> plugin_linker_flags;
820+
795821
Error err;
796822

797823
for (int i = 0; i < enabled_plugins.size(); i++) {
@@ -858,19 +884,41 @@ Error EditorExportPlatformTVOS::_export_tvos_plugins(const Ref<EditorExportPrese
858884
p_config_data.capabilities.push_back(capability);
859885
}
860886

887+
// Linker flags
888+
// Checking duplicates
889+
for (int j = 0; j < plugin.linker_flags.size(); j++) {
890+
String linker_flag = plugin.linker_flags[j];
891+
plugin_linker_flags.insert(linker_flag);
892+
}
893+
861894
// Plist
862895
// Using hash map container to remove duplicates
863896
const String *K = nullptr;
864897

865898
while ((K = plugin.plist.next(K))) {
866899
String key = *K;
867-
String value = plugin.plist[key];
900+
PluginConfigTVOS::PlistItem item = plugin.plist[key];
901+
902+
String value;
903+
904+
switch (item.type) {
905+
case PluginConfigTVOS::PlistItemType::STRING_INPUT: {
906+
String preset_name = "plugins_plist/" + key;
907+
String input_value = p_preset->get(preset_name);
908+
value = "<string>" + input_value + "</string>";
909+
} break;
910+
default:
911+
value = item.value;
912+
break;
913+
}
868914

869915
if (key.is_empty() || value.is_empty()) {
870916
continue;
871917
}
872918

873-
plist_values[key] = value;
919+
String plist_key = "<key>" + key + "</key>";
920+
921+
plist_values[plist_key] = value;
874922
}
875923

876924
// CPP Code
@@ -897,7 +945,7 @@ Error EditorExportPlatformTVOS::_export_tvos_plugins(const Ref<EditorExportPrese
897945
continue;
898946
}
899947

900-
p_config_data.plist_content += "<key>" + key + "</key><string>" + value + "</string>\n";
948+
p_config_data.plist_content += key + value + "\n";
901949
}
902950
}
903951

@@ -938,6 +986,27 @@ Error EditorExportPlatformTVOS::_export_tvos_plugins(const Ref<EditorExportPrese
938986

939987
p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_");
940988
}
989+
990+
// Update Linker Flag Values
991+
{
992+
String result_linker_flags = " ";
993+
for (Set<String>::Element *E = plugin_linker_flags.front(); E; E = E->next()) {
994+
const String &flag = E->get();
995+
996+
if (flag.length() == 0) {
997+
continue;
998+
}
999+
1000+
if (result_linker_flags.length() > 0) {
1001+
result_linker_flags += ' ';
1002+
}
1003+
1004+
result_linker_flags += flag;
1005+
}
1006+
result_linker_flags = result_linker_flags.replace("\"", "\\\"");
1007+
p_config_data.linker_flags += result_linker_flags;
1008+
}
1009+
9411010
return OK;
9421011
}
9431012

platform/tvos/export/godot_plugin_config.h

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ struct PluginConfigTVOS {
6868

6969
inline static const char *PLIST_SECTION = "plist";
7070

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+
7185
// Set to true when the config file is properly loaded.
7286
bool valid_config = false;
7387
bool supports_targets = false;
@@ -91,8 +105,10 @@ struct PluginConfigTVOS {
91105
Vector<String> linker_flags;
92106

93107
// Optional plist section
94-
// Supports only string types for now
95-
HashMap<String, String> plist;
108+
// String value is default value.
109+
// Currently supports `string`, `boolean`, `integer`, `raw`, `string_input` types
110+
// <name>:<type> = <value>
111+
HashMap<String, PlistItem> plist;
96112
};
97113

98114
static inline String resolve_local_dependency_path(String plugin_config_dir, String dependency_path) {
@@ -233,6 +249,8 @@ static inline PluginConfigTVOS load_plugin_config(Ref<ConfigFile> config_file, c
233249
return plugin_config;
234250
}
235251

252+
config_file->clear();
253+
236254
Error err = config_file->load(path);
237255

238256
if (err != OK) {
@@ -270,13 +288,68 @@ static inline PluginConfigTVOS load_plugin_config(Ref<ConfigFile> config_file, c
270288
config_file->get_section_keys(PluginConfigTVOS::PLIST_SECTION, &keys);
271289

272290
for (int i = 0; i < keys.size(); i++) {
273-
String value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], String());
291+
Vector<String> key_components = keys[i].split(":");
292+
293+
String key_value = "";
294+
PluginConfigTVOS::PlistItemType key_type = PluginConfigTVOS::PlistItemType::UNKNOWN;
295+
296+
if (key_components.size() == 1) {
297+
key_value = key_components[0];
298+
key_type = PluginConfigTVOS::PlistItemType::STRING;
299+
} else if (key_components.size() == 2) {
300+
key_value = key_components[0];
301+
302+
if (key_components[1].to_lower() == "string") {
303+
key_type = PluginConfigTVOS::PlistItemType::STRING;
304+
} else if (key_components[1].to_lower() == "integer") {
305+
key_type = PluginConfigTVOS::PlistItemType::INTEGER;
306+
} else if (key_components[1].to_lower() == "boolean") {
307+
key_type = PluginConfigTVOS::PlistItemType::BOOLEAN;
308+
} else if (key_components[1].to_lower() == "raw") {
309+
key_type = PluginConfigTVOS::PlistItemType::RAW;
310+
} else if (key_components[1].to_lower() == "string_input") {
311+
key_type = PluginConfigTVOS::PlistItemType::STRING_INPUT;
312+
}
313+
}
274314

275-
if (value.is_empty()) {
315+
if (key_value.is_empty() || key_type == PluginConfigTVOS::PlistItemType::UNKNOWN) {
276316
continue;
277317
}
278318

279-
plugin_config.plist[keys[i]] = value;
319+
String value;
320+
321+
switch (key_type) {
322+
case PluginConfigTVOS::PlistItemType::STRING: {
323+
String raw_value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], String());
324+
value = "<string>" + raw_value + "</string>";
325+
} break;
326+
case PluginConfigTVOS::PlistItemType::INTEGER: {
327+
int raw_value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], 0);
328+
Dictionary value_dictionary;
329+
String value_format = "<integer>$value</integer>";
330+
value_dictionary["value"] = raw_value;
331+
value = value_format.format(value_dictionary, "$_");
332+
} break;
333+
case PluginConfigTVOS::PlistItemType::BOOLEAN:
334+
if (config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], false)) {
335+
value = "<true/>";
336+
} else {
337+
value = "<false/>";
338+
}
339+
break;
340+
case PluginConfigTVOS::PlistItemType::RAW: {
341+
String raw_value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], String());
342+
value = raw_value;
343+
} break;
344+
case PluginConfigTVOS::PlistItemType::STRING_INPUT: {
345+
String raw_value = config_file->get_value(PluginConfigTVOS::PLIST_SECTION, keys[i], String());
346+
value = raw_value;
347+
} break;
348+
default:
349+
continue;
350+
}
351+
352+
plugin_config.plist[key_value] = PluginConfigTVOS::PlistItem{ key_type, value };
280353
}
281354
}
282355

0 commit comments

Comments
 (0)