2017-04-09 00:37:31 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_import_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-04-09 00:37:31 +02:00
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-04-09 00:37:31 +02:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2017-04-09 00:37:31 +02:00
|
|
|
#include "editor_import_plugin.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/object/script_language.h"
|
2017-04-09 00:37:31 +02:00
|
|
|
|
|
|
|
EditorImportPlugin::EditorImportPlugin() {
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorImportPlugin::get_importer_name() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_importer_name, ret)) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ERR_FAIL_V_MSG(String(), "Unimplemented _get_importer_name in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorImportPlugin::get_visible_name() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_visible_name, ret)) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ERR_FAIL_V_MSG(String(), "Unimplemented _get_visible_name in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorImportPlugin::get_recognized_extensions(List<String> *p_extensions) const {
|
2021-08-22 03:52:44 +02:00
|
|
|
Vector<String> extensions;
|
|
|
|
|
|
|
|
if (GDVIRTUAL_CALL(_get_recognized_extensions, extensions)) {
|
|
|
|
for (int i = 0; i < extensions.size(); i++) {
|
|
|
|
p_extensions->push_back(extensions[i]);
|
|
|
|
}
|
2021-11-10 16:33:11 +01:00
|
|
|
return;
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
ERR_FAIL_MSG("Unimplemented _get_recognized_extensions in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorImportPlugin::get_preset_name(int p_idx) const {
|
2021-08-22 03:52:44 +02:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_preset_name, p_idx, ret)) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ERR_FAIL_V_MSG(String(), "Unimplemented _get_preset_name in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 21:24:26 +02:00
|
|
|
int EditorImportPlugin::get_preset_count() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
int ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_preset_count, ret)) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ERR_FAIL_V_MSG(-1, "Unimplemented _get_preset_count in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorImportPlugin::get_save_extension() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_save_extension, ret)) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ERR_FAIL_V_MSG(String(), "Unimplemented _get_save_extension in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorImportPlugin::get_resource_type() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_resource_type, ret)) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ERR_FAIL_V_MSG(String(), "Unimplemented _get_resource_type in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
2018-02-13 14:59:56 +01:00
|
|
|
float EditorImportPlugin::get_priority() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
float ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_priority, ret)) {
|
|
|
|
return ret;
|
2018-02-13 14:59:56 +01:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
ERR_FAIL_V_MSG(-1, "Unimplemented _get_priority in add-on.");
|
2018-02-13 14:59:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int EditorImportPlugin::get_import_order() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
int ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_import_order, ret)) {
|
|
|
|
return ret;
|
2018-02-13 14:59:56 +01:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
ERR_FAIL_V_MSG(-1, "Unimplemented _get_import_order in add-on.");
|
2018-02-13 14:59:56 +01:00
|
|
|
}
|
|
|
|
|
2021-11-14 18:02:38 +01:00
|
|
|
void EditorImportPlugin::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options, int p_preset) const {
|
2017-04-09 00:37:31 +02:00
|
|
|
Array needed;
|
|
|
|
needed.push_back("name");
|
|
|
|
needed.push_back("default_value");
|
2022-08-05 03:41:48 +02:00
|
|
|
TypedArray<Dictionary> options;
|
2021-11-14 18:02:38 +01:00
|
|
|
if (GDVIRTUAL_CALL(_get_import_options, p_path, p_preset, options)) {
|
2021-08-22 03:52:44 +02:00
|
|
|
for (int i = 0; i < options.size(); i++) {
|
|
|
|
Dictionary d = options[i];
|
|
|
|
ERR_FAIL_COND(!d.has_all(needed));
|
|
|
|
String name = d["name"];
|
|
|
|
Variant default_value = d["default_value"];
|
|
|
|
|
|
|
|
PropertyHint hint = PROPERTY_HINT_NONE;
|
|
|
|
if (d.has("property_hint")) {
|
|
|
|
hint = (PropertyHint)d["property_hint"].operator int64_t();
|
|
|
|
}
|
|
|
|
|
|
|
|
String hint_string;
|
|
|
|
if (d.has("hint_string")) {
|
|
|
|
hint_string = d["hint_string"];
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t usage = PROPERTY_USAGE_DEFAULT;
|
|
|
|
if (d.has("usage")) {
|
|
|
|
usage = d["usage"];
|
|
|
|
}
|
|
|
|
|
|
|
|
ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value);
|
|
|
|
r_options->push_back(option);
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
2021-11-10 16:33:11 +01:00
|
|
|
return;
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
|
|
|
|
ERR_FAIL_MSG("Unimplemented _get_import_options in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
2022-05-13 15:04:37 +02:00
|
|
|
bool EditorImportPlugin::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
|
2017-04-09 00:37:31 +02:00
|
|
|
Dictionary d;
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<StringName, Variant>::ConstIterator E = p_options.begin();
|
2017-04-09 00:37:31 +02:00
|
|
|
while (E) {
|
2022-05-13 15:04:37 +02:00
|
|
|
d[E->key] = E->value;
|
|
|
|
++E;
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
2022-09-29 11:53:28 +02:00
|
|
|
bool visible = false;
|
2021-11-14 18:02:38 +01:00
|
|
|
if (GDVIRTUAL_CALL(_get_option_visibility, p_path, p_option, d, visible)) {
|
2021-08-22 03:52:44 +02:00
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_V_MSG(false, "Unimplemented _get_option_visibility in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
2022-05-13 15:04:37 +02:00
|
|
|
Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
|
2017-04-09 00:37:31 +02:00
|
|
|
Dictionary options;
|
2022-08-31 19:24:04 +02:00
|
|
|
TypedArray<String> platform_variants, gen_files;
|
2017-04-09 00:37:31 +02:00
|
|
|
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<StringName, Variant>::ConstIterator E = p_options.begin();
|
2017-04-09 00:37:31 +02:00
|
|
|
while (E) {
|
2022-05-13 15:04:37 +02:00
|
|
|
options[E->key] = E->value;
|
|
|
|
++E;
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
int err = 0;
|
2021-08-22 03:52:44 +02:00
|
|
|
if (GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err)) {
|
|
|
|
Error ret_err = Error(err);
|
|
|
|
|
|
|
|
for (int i = 0; i < platform_variants.size(); i++) {
|
|
|
|
r_platform_variants->push_back(platform_variants[i]);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < gen_files.size(); i++) {
|
|
|
|
r_gen_files->push_back(gen_files[i]);
|
|
|
|
}
|
|
|
|
return ret_err;
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
ERR_FAIL_V_MSG(ERR_METHOD_NOT_FOUND, "Unimplemented _import in add-on.");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorImportPlugin::_bind_methods() {
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_get_importer_name)
|
|
|
|
GDVIRTUAL_BIND(_get_visible_name)
|
|
|
|
GDVIRTUAL_BIND(_get_preset_count)
|
|
|
|
GDVIRTUAL_BIND(_get_preset_name, "preset_index")
|
|
|
|
GDVIRTUAL_BIND(_get_recognized_extensions)
|
2021-11-14 18:02:38 +01:00
|
|
|
GDVIRTUAL_BIND(_get_import_options, "path", "preset_index")
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_get_save_extension)
|
|
|
|
GDVIRTUAL_BIND(_get_resource_type)
|
|
|
|
GDVIRTUAL_BIND(_get_priority)
|
|
|
|
GDVIRTUAL_BIND(_get_import_order)
|
2021-11-14 18:02:38 +01:00
|
|
|
GDVIRTUAL_BIND(_get_option_visibility, "path", "option_name", "options")
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_import, "source_file", "save_path", "options", "platform_variants", "gen_files");
|
2017-04-09 00:37:31 +02:00
|
|
|
}
|