| 1 | /**************************************************************************/ |
| 2 | /* dedicated_server_export_plugin.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "dedicated_server_export_plugin.h" |
| 32 | |
| 33 | EditorExportPreset::FileExportMode DedicatedServerExportPlugin::_get_export_mode_for_path(const String &p_path) { |
| 34 | Ref<EditorExportPreset> preset = get_export_preset(); |
| 35 | ERR_FAIL_COND_V(preset.is_null(), EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED); |
| 36 | |
| 37 | EditorExportPreset::FileExportMode mode = preset->get_file_export_mode(p_path); |
| 38 | if (mode != EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) { |
| 39 | return mode; |
| 40 | } |
| 41 | |
| 42 | String path = p_path; |
| 43 | if (path.begins_with("res://" )) { |
| 44 | path = path.substr(6); |
| 45 | } |
| 46 | |
| 47 | Vector<String> parts = path.split("/" ); |
| 48 | |
| 49 | while (parts.size() > 0) { |
| 50 | parts.resize(parts.size() - 1); |
| 51 | |
| 52 | String test_path = "res://" ; |
| 53 | if (parts.size() > 0) { |
| 54 | test_path += String("/" ).join(parts) + "/" ; |
| 55 | } |
| 56 | |
| 57 | mode = preset->get_file_export_mode(test_path); |
| 58 | if (mode != EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) { |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return mode; |
| 64 | } |
| 65 | |
| 66 | PackedStringArray DedicatedServerExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const { |
| 67 | PackedStringArray ret; |
| 68 | |
| 69 | Ref<EditorExportPreset> preset = get_export_preset(); |
| 70 | ERR_FAIL_COND_V(preset.is_null(), ret); |
| 71 | |
| 72 | if (preset->is_dedicated_server()) { |
| 73 | ret.append("dedicated_server" ); |
| 74 | } |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | uint64_t DedicatedServerExportPlugin::_get_customization_configuration_hash() const { |
| 79 | Ref<EditorExportPreset> preset = get_export_preset(); |
| 80 | ERR_FAIL_COND_V(preset.is_null(), 0); |
| 81 | |
| 82 | if (preset->get_export_filter() != EditorExportPreset::EXPORT_CUSTOMIZED) { |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | return preset->get_customized_files().hash(); |
| 87 | } |
| 88 | |
| 89 | bool DedicatedServerExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) { |
| 90 | Ref<EditorExportPreset> preset = get_export_preset(); |
| 91 | ERR_FAIL_COND_V(preset.is_null(), false); |
| 92 | |
| 93 | current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED; |
| 94 | |
| 95 | return preset->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED; |
| 96 | } |
| 97 | |
| 98 | bool DedicatedServerExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) { |
| 99 | Ref<EditorExportPreset> preset = get_export_preset(); |
| 100 | ERR_FAIL_COND_V(preset.is_null(), false); |
| 101 | |
| 102 | current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED; |
| 103 | |
| 104 | return preset->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED; |
| 105 | } |
| 106 | |
| 107 | Node *DedicatedServerExportPlugin::_customize_scene(Node *p_root, const String &p_path) { |
| 108 | // Simply set the export mode based on the scene path. All the real |
| 109 | // customization happens in _customize_resource(). |
| 110 | current_export_mode = _get_export_mode_for_path(p_path); |
| 111 | return nullptr; |
| 112 | } |
| 113 | |
| 114 | Ref<Resource> DedicatedServerExportPlugin::_customize_resource(const Ref<Resource> &p_resource, const String &p_path) { |
| 115 | // If the resource has a path, we use that to get our export mode. But if it |
| 116 | // doesn't, we assume that this resource is embedded in the last resource with |
| 117 | // a path. |
| 118 | if (p_path != "" ) { |
| 119 | current_export_mode = _get_export_mode_for_path(p_path); |
| 120 | } |
| 121 | |
| 122 | if (p_resource.is_valid() && current_export_mode == EditorExportPreset::MODE_FILE_STRIP && p_resource->has_method("create_placeholder" )) { |
| 123 | Callable::CallError err; |
| 124 | Ref<Resource> result = const_cast<Resource *>(p_resource.ptr())->callp("create_placeholder" , nullptr, 0, err); |
| 125 | if (err.error == Callable::CallError::CALL_OK) { |
| 126 | return result; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | return Ref<Resource>(); |
| 131 | } |
| 132 | |
| 133 | void DedicatedServerExportPlugin::_end_customize_scenes() { |
| 134 | current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED; |
| 135 | } |
| 136 | |
| 137 | void DedicatedServerExportPlugin::_end_customize_resources() { |
| 138 | current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED; |
| 139 | } |
| 140 | |