From ab03dcf44dfd2534dd69b1432db3b2b5653fc5e5 Mon Sep 17 00:00:00 2001 From: Sergey Minakov Date: Mon, 21 Jun 2021 17:46:27 +0300 Subject: [PATCH] [iOS] Support multiple plist types --- platform/iphone/export/export.cpp | 40 +++++++++- platform/iphone/plugin/godot_plugin_config.h | 81 ++++++++++++++++++-- 2 files changed, 113 insertions(+), 8 deletions(-) diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index 7cdfd6f16ded..1f96ea6576c0 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -367,6 +367,25 @@ void EditorExportPlatformIOS::get_export_options(List *r_options) r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "plugins/" + found_plugins[i].name), false)); } + for (int i = 0; i < found_plugins.size(); i++) { + // Editable plugin plist values + PluginConfigIOS plugin = found_plugins[i]; + const String *K = nullptr; + + while ((K = plugin.plist.next(K))) { + String key = *K; + PluginConfigIOS::PlistItem item = plugin.plist[key]; + switch (item.type) { + case PluginConfigIOS::PlistItemType::STRING_INPUT: { + String preset_name = "plugins_plist/" + key; + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), item.value)); + } break; + default: + continue; + } + } + } + plugins_changed.clear(); plugins = found_plugins; @@ -1336,13 +1355,28 @@ Error EditorExportPlatformIOS::_export_ios_plugins(const Ref while ((K = plugin.plist.next(K))) { String key = *K; - String value = plugin.plist[key]; + PluginConfigIOS::PlistItem item = plugin.plist[key]; + + String value; + + switch (item.type) { + case PluginConfigIOS::PlistItemType::STRING_INPUT: { + String preset_name = "plugins_plist/" + key; + String input_value = p_preset->get(preset_name); + value = "" + input_value + ""; + } break; + default: + value = item.value; + break; + } if (key.empty() || value.empty()) { continue; } - plist_values[key] = value; + String plist_key = "" + key + ""; + + plist_values[plist_key] = value; } // CPP Code @@ -1369,7 +1403,7 @@ Error EditorExportPlatformIOS::_export_ios_plugins(const Ref continue; } - p_config_data.plist_content += "" + key + "" + value + "\n"; + p_config_data.plist_content += key + value + "\n"; } } diff --git a/platform/iphone/plugin/godot_plugin_config.h b/platform/iphone/plugin/godot_plugin_config.h index 12c0fb46b198..66b4d3913108 100644 --- a/platform/iphone/plugin/godot_plugin_config.h +++ b/platform/iphone/plugin/godot_plugin_config.h @@ -70,6 +70,20 @@ struct PluginConfigIOS { static const char *PLIST_SECTION; + enum PlistItemType { + UNKNOWN, + STRING, + INTEGER, + BOOLEAN, + RAW, + STRING_INPUT, + }; + + struct PlistItem { + PlistItemType type; + String value; + }; + // Set to true when the config file is properly loaded. bool valid_config = false; bool supports_targets = false; @@ -93,8 +107,10 @@ struct PluginConfigIOS { Vector linker_flags; // Optional plist section - // Supports only string types for now - HashMap plist; + // String value is default value. + // Currently supports `string`, `boolean`, `integer`, `raw`, `string_input` types + // : = + HashMap plist; }; const char *PluginConfigIOS::PLUGIN_CONFIG_EXT = ".gdip"; @@ -291,13 +307,68 @@ static inline PluginConfigIOS load_plugin_config(Ref config_file, co config_file->get_section_keys(PluginConfigIOS::PLIST_SECTION, &keys); for (int i = 0; i < keys.size(); i++) { - String value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], String()); + Vector key_components = keys[i].split(":"); + + String key_value = ""; + PluginConfigIOS::PlistItemType key_type = PluginConfigIOS::PlistItemType::UNKNOWN; + + if (key_components.size() == 1) { + key_value = key_components[0]; + key_type = PluginConfigIOS::PlistItemType::STRING; + } else if (key_components.size() == 2) { + key_value = key_components[0]; + + if (key_components[1].to_lower() == "string") { + key_type = PluginConfigIOS::PlistItemType::STRING; + } else if (key_components[1].to_lower() == "integer") { + key_type = PluginConfigIOS::PlistItemType::INTEGER; + } else if (key_components[1].to_lower() == "boolean") { + key_type = PluginConfigIOS::PlistItemType::BOOLEAN; + } else if (key_components[1].to_lower() == "raw") { + key_type = PluginConfigIOS::PlistItemType::RAW; + } else if (key_components[1].to_lower() == "string_input") { + key_type = PluginConfigIOS::PlistItemType::STRING_INPUT; + } + } - if (value.empty()) { + if (key_value.empty() || key_type == PluginConfigIOS::PlistItemType::UNKNOWN) { continue; } - plugin_config.plist[keys[i]] = value; + String value; + + switch (key_type) { + case PluginConfigIOS::PlistItemType::STRING: { + String raw_value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], String()); + value = "" + raw_value + ""; + } break; + case PluginConfigIOS::PlistItemType::INTEGER: { + int raw_value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], 0); + Dictionary value_dictionary; + String value_format = "$value"; + value_dictionary["value"] = raw_value; + value = value_format.format(value_dictionary, "$_"); + } break; + case PluginConfigIOS::PlistItemType::BOOLEAN: + if (config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], false)) { + value = ""; + } else { + value = ""; + } + break; + case PluginConfigIOS::PlistItemType::RAW: { + String raw_value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], String()); + value = raw_value; + } break; + case PluginConfigIOS::PlistItemType::STRING_INPUT: { + String raw_value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], String()); + value = raw_value; + } break; + default: + continue; + } + + plugin_config.plist[key_value] = PluginConfigIOS::PlistItem{ key_type, value }; } }