dedicated_server_export_plugin.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #include "dedicated_server_export_plugin.h"
  31. EditorExportPreset::FileExportMode DedicatedServerExportPlugin::_get_export_mode_for_path(const String &p_path) {
  32. Ref<EditorExportPreset> preset = get_export_preset();
  33. ERR_FAIL_COND_V(preset.is_null(), EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED);
  34. EditorExportPreset::FileExportMode mode = preset->get_file_export_mode(p_path);
  35. if (mode != EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) {
  36. return mode;
  37. }
  38. String path = p_path;
  39. if (path.begins_with("res://")) {
  40. path = path.substr(6);
  41. }
  42. Vector<String> parts = path.split("/");
  43. while (parts.size() > 0) {
  44. parts.resize(parts.size() - 1);
  45. String test_path = "res://";
  46. if (parts.size() > 0) {
  47. test_path += String("/").join(parts) + "/";
  48. }
  49. mode = preset->get_file_export_mode(test_path);
  50. if (mode != EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) {
  51. break;
  52. }
  53. }
  54. return mode;
  55. }
  56. PackedStringArray DedicatedServerExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const {
  57. PackedStringArray ret;
  58. Ref<EditorExportPreset> preset = get_export_preset();
  59. ERR_FAIL_COND_V(preset.is_null(), ret);
  60. if (preset->is_dedicated_server()) {
  61. ret.append("dedicated_server");
  62. }
  63. return ret;
  64. }
  65. uint64_t DedicatedServerExportPlugin::_get_customization_configuration_hash() const {
  66. Ref<EditorExportPreset> preset = get_export_preset();
  67. ERR_FAIL_COND_V(preset.is_null(), 0);
  68. if (preset->get_export_filter() != EditorExportPreset::EXPORT_CUSTOMIZED) {
  69. return 0;
  70. }
  71. return preset->get_customized_files().hash();
  72. }
  73. bool DedicatedServerExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
  74. Ref<EditorExportPreset> preset = get_export_preset();
  75. ERR_FAIL_COND_V(preset.is_null(), false);
  76. current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;
  77. return preset->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED;
  78. }
  79. bool DedicatedServerExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
  80. Ref<EditorExportPreset> preset = get_export_preset();
  81. ERR_FAIL_COND_V(preset.is_null(), false);
  82. current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;
  83. return preset->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED;
  84. }
  85. Node *DedicatedServerExportPlugin::_customize_scene(Node *p_root, const String &p_path) {
  86. // Simply set the export mode based on the scene path. All the real
  87. // customization happens in _customize_resource().
  88. current_export_mode = _get_export_mode_for_path(p_path);
  89. return nullptr;
  90. }
  91. Ref<Resource> DedicatedServerExportPlugin::_customize_resource(const Ref<Resource> &p_resource, const String &p_path) {
  92. // If the resource has a path, we use that to get our export mode. But if it
  93. // doesn't, we assume that this resource is embedded in the last resource with
  94. // a path.
  95. if (p_path != "") {
  96. current_export_mode = _get_export_mode_for_path(p_path);
  97. }
  98. if (p_resource.is_valid() && current_export_mode == EditorExportPreset::MODE_FILE_STRIP && p_resource->has_method("create_placeholder")) {
  99. Callable::CallError err;
  100. Ref<Resource> result = const_cast<Resource *>(p_resource.ptr())->callp("create_placeholder", nullptr, 0, err);
  101. if (err.error == Callable::CallError::CALL_OK) {
  102. return result;
  103. }
  104. }
  105. return Ref<Resource>();
  106. }
  107. void DedicatedServerExportPlugin::_end_customize_scenes() {
  108. current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;
  109. }
  110. void DedicatedServerExportPlugin::_end_customize_resources() {
  111. current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;
  112. }