Path: blob/master/editor/export/dedicated_server_export_plugin.cpp
9896 views
/**************************************************************************/1/* dedicated_server_export_plugin.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "dedicated_server_export_plugin.h"3132EditorExportPreset::FileExportMode DedicatedServerExportPlugin::_get_export_mode_for_path(const String &p_path) {33Ref<EditorExportPreset> preset = get_export_preset();34ERR_FAIL_COND_V(preset.is_null(), EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED);3536EditorExportPreset::FileExportMode mode = preset->get_file_export_mode(p_path);37if (mode != EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) {38return mode;39}4041String path = p_path;42if (path.begins_with("res://")) {43path = path.substr(6);44}4546Vector<String> parts = path.split("/");4748while (parts.size() > 0) {49parts.resize(parts.size() - 1);5051String test_path = "res://";52if (parts.size() > 0) {53test_path += String("/").join(parts) + "/";54}5556mode = preset->get_file_export_mode(test_path);57if (mode != EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) {58break;59}60}6162return mode;63}6465PackedStringArray DedicatedServerExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const {66PackedStringArray ret;6768Ref<EditorExportPreset> preset = get_export_preset();69ERR_FAIL_COND_V(preset.is_null(), ret);7071if (preset->is_dedicated_server()) {72ret.append("dedicated_server");73}74return ret;75}7677uint64_t DedicatedServerExportPlugin::_get_customization_configuration_hash() const {78Ref<EditorExportPreset> preset = get_export_preset();79ERR_FAIL_COND_V(preset.is_null(), 0);8081if (preset->get_export_filter() != EditorExportPreset::EXPORT_CUSTOMIZED) {82return 0;83}8485return preset->get_customized_files().hash();86}8788bool DedicatedServerExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {89Ref<EditorExportPreset> preset = get_export_preset();90ERR_FAIL_COND_V(preset.is_null(), false);9192current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;9394return preset->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED;95}9697bool DedicatedServerExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {98Ref<EditorExportPreset> preset = get_export_preset();99ERR_FAIL_COND_V(preset.is_null(), false);100101current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;102103return preset->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED;104}105106Node *DedicatedServerExportPlugin::_customize_scene(Node *p_root, const String &p_path) {107// Simply set the export mode based on the scene path. All the real108// customization happens in _customize_resource().109current_export_mode = _get_export_mode_for_path(p_path);110return nullptr;111}112113Ref<Resource> DedicatedServerExportPlugin::_customize_resource(const Ref<Resource> &p_resource, const String &p_path) {114// If the resource has a path, we use that to get our export mode. But if it115// doesn't, we assume that this resource is embedded in the last resource with116// a path.117if (p_path != "") {118current_export_mode = _get_export_mode_for_path(p_path);119}120121if (p_resource.is_valid() && current_export_mode == EditorExportPreset::MODE_FILE_STRIP && p_resource->has_method("create_placeholder")) {122Callable::CallError err;123Ref<Resource> result = p_resource->callp("create_placeholder", nullptr, 0, err);124if (err.error == Callable::CallError::CALL_OK) {125return result;126}127}128129return Ref<Resource>();130}131132void DedicatedServerExportPlugin::_end_customize_scenes() {133current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;134}135136void DedicatedServerExportPlugin::_end_customize_resources() {137current_export_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;138}139140141