summaryrefslogtreecommitdiff
path: root/editor/import
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import')
-rw-r--r--editor/import/editor_import_plugin.cpp170
-rw-r--r--editor/import/editor_import_plugin.h13
-rw-r--r--editor/import/resource_importer_scene.cpp39
-rw-r--r--editor/import/resource_importer_scene.h7
4 files changed, 141 insertions, 88 deletions
diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp
index 8660289c40..d219f6e325 100644
--- a/editor/import/editor_import_plugin.cpp
+++ b/editor/import/editor_import_plugin.cpp
@@ -35,102 +35,131 @@ EditorImportPlugin::EditorImportPlugin() {
}
String EditorImportPlugin::get_importer_name() const {
- ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_importer_name")), "");
- return get_script_instance()->call("_get_importer_name");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_importer_name, ret)) {
+ return ret;
+ }
+ ERR_FAIL_V_MSG(String(), "Unimplemented _get_importer_name in add-on.");
}
String EditorImportPlugin::get_visible_name() const {
- ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_visible_name")), "");
- return get_script_instance()->call("_get_visible_name");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_visible_name, ret)) {
+ return ret;
+ }
+ ERR_FAIL_V_MSG(String(), "Unimplemented _get_visible_name in add-on.");
}
void EditorImportPlugin::get_recognized_extensions(List<String> *p_extensions) const {
- ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions")));
- Array extensions = get_script_instance()->call("_get_recognized_extensions");
- for (int i = 0; i < extensions.size(); i++) {
- p_extensions->push_back(extensions[i]);
+ Vector<String> extensions;
+
+ if (GDVIRTUAL_CALL(_get_recognized_extensions, extensions)) {
+ for (int i = 0; i < extensions.size(); i++) {
+ p_extensions->push_back(extensions[i]);
+ }
}
+ ERR_FAIL_MSG("Unimplemented _get_recognized_extensions in add-on.");
}
String EditorImportPlugin::get_preset_name(int p_idx) const {
- ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_preset_name")), "");
- return get_script_instance()->call("_get_preset_name", p_idx);
+ 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.");
}
int EditorImportPlugin::get_preset_count() const {
- ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_preset_count")), 0);
- return get_script_instance()->call("_get_preset_count");
+ int ret;
+ if (GDVIRTUAL_CALL(_get_preset_count, ret)) {
+ return ret;
+ }
+ ERR_FAIL_V_MSG(-1, "Unimplemented _get_preset_count in add-on.");
}
String EditorImportPlugin::get_save_extension() const {
- ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_save_extension")), "");
- return get_script_instance()->call("_get_save_extension");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_save_extension, ret)) {
+ return ret;
+ }
+ ERR_FAIL_V_MSG(String(), "Unimplemented _get_save_extension in add-on.");
}
String EditorImportPlugin::get_resource_type() const {
- ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_resource_type")), "");
- return get_script_instance()->call("_get_resource_type");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_resource_type, ret)) {
+ return ret;
+ }
+ ERR_FAIL_V_MSG(String(), "Unimplemented _get_resource_type in add-on.");
}
float EditorImportPlugin::get_priority() const {
- if (!(get_script_instance() && get_script_instance()->has_method("_get_priority"))) {
- return ResourceImporter::get_priority();
+ float ret;
+ if (GDVIRTUAL_CALL(_get_priority, ret)) {
+ return ret;
}
- return get_script_instance()->call("_get_priority");
+ ERR_FAIL_V_MSG(-1, "Unimplemented _get_priority in add-on.");
}
int EditorImportPlugin::get_import_order() const {
- if (!(get_script_instance() && get_script_instance()->has_method("_get_import_order"))) {
- return ResourceImporter::get_import_order();
+ int ret;
+ if (GDVIRTUAL_CALL(_get_import_order, ret)) {
+ return ret;
}
- return get_script_instance()->call("_get_import_order");
+ ERR_FAIL_V_MSG(-1, "Unimplemented _get_import_order in add-on.");
}
void EditorImportPlugin::get_import_options(List<ResourceImporter::ImportOption> *r_options, int p_preset) const {
- ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("_get_import_options")));
Array needed;
needed.push_back("name");
needed.push_back("default_value");
- Array options = get_script_instance()->call("_get_import_options", p_preset);
- 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"];
+ Array options;
+ if (GDVIRTUAL_CALL(_get_import_options, p_preset, options)) {
+ 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);
}
-
- 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);
}
+
+ ERR_FAIL_MSG("Unimplemented _get_import_options in add-on.");
}
bool EditorImportPlugin::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
- ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_option_visibility")), true);
Dictionary d;
Map<StringName, Variant>::Element *E = p_options.front();
while (E) {
d[E->key()] = E->get();
E = E->next();
}
- return get_script_instance()->call("_get_option_visibility", p_option, d);
+ bool visible;
+ if (GDVIRTUAL_CALL(_get_option_visibility, p_option, d, visible)) {
+ return visible;
+ }
+
+ ERR_FAIL_V_MSG(false, "Unimplemented _get_option_visibility in add-on.");
}
Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
- ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_import")), ERR_UNAVAILABLE);
Dictionary options;
Array platform_variants, gen_files;
@@ -139,28 +168,33 @@ Error EditorImportPlugin::import(const String &p_source_file, const String &p_sa
options[E->key()] = E->get();
E = E->next();
}
- Error err = (Error)get_script_instance()->call("_import", p_source_file, p_save_path, options, platform_variants, gen_files).operator int64_t();
- 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]);
+ int err;
+ 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;
}
- return err;
+ ERR_FAIL_V_MSG(ERR_METHOD_NOT_FOUND, "Unimplemented _import in add-on.");
}
void EditorImportPlugin::_bind_methods() {
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_importer_name"));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_visible_name"));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_preset_count"));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_preset_name", PropertyInfo(Variant::INT, "preset")));
- BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_recognized_extensions"));
- BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_import_options", PropertyInfo(Variant::INT, "preset")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_save_extension"));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_resource_type"));
- BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_get_priority"));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_import_order"));
- BIND_VMETHOD(MethodInfo(Variant::BOOL, "_get_option_visibility", PropertyInfo(Variant::STRING, "option"), PropertyInfo(Variant::DICTIONARY, "options")));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_import", PropertyInfo(Variant::STRING, "source_file"), PropertyInfo(Variant::STRING, "save_path"), PropertyInfo(Variant::DICTIONARY, "options"), PropertyInfo(Variant::ARRAY, "platform_variants"), PropertyInfo(Variant::ARRAY, "gen_files")));
+ 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)
+ GDVIRTUAL_BIND(_get_import_options, "preset_index")
+ GDVIRTUAL_BIND(_get_save_extension)
+ GDVIRTUAL_BIND(_get_resource_type)
+ GDVIRTUAL_BIND(_get_priority)
+ GDVIRTUAL_BIND(_get_import_order)
+ GDVIRTUAL_BIND(_get_option_visibility, "option_name", "options")
+ GDVIRTUAL_BIND(_import, "source_file", "save_path", "options", "platform_variants", "gen_files");
}
diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h
index 345a40e96d..49c959ab44 100644
--- a/editor/import/editor_import_plugin.h
+++ b/editor/import/editor_import_plugin.h
@@ -39,6 +39,19 @@ class EditorImportPlugin : public ResourceImporter {
protected:
static void _bind_methods();
+ GDVIRTUAL0RC(String, _get_importer_name)
+ GDVIRTUAL0RC(String, _get_visible_name)
+ GDVIRTUAL0RC(int, _get_preset_count)
+ GDVIRTUAL1RC(String, _get_preset_name, int)
+ GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions)
+ GDVIRTUAL1RC(Array, _get_import_options, int)
+ GDVIRTUAL0RC(String, _get_save_extension)
+ GDVIRTUAL0RC(String, _get_resource_type)
+ GDVIRTUAL0RC(float, _get_priority)
+ GDVIRTUAL0RC(int, _get_import_order)
+ GDVIRTUAL2RC(bool, _get_option_visibility, StringName, Dictionary)
+ GDVIRTUAL5RC(int, _import, String, String, Dictionary, Array, Array)
+
public:
EditorImportPlugin();
virtual String get_importer_name() const override;
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 492fa3f965..2b03ad928c 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -51,16 +51,17 @@
#include "scene/resources/world_margin_shape_3d.h"
uint32_t EditorSceneImporter::get_import_flags() const {
- if (get_script_instance()) {
- return get_script_instance()->call("_get_import_flags");
+ int ret;
+ if (GDVIRTUAL_CALL(_get_import_flags, ret)) {
+ return ret;
}
ERR_FAIL_V(0);
}
void EditorSceneImporter::get_extensions(List<String> *r_extensions) const {
- if (get_script_instance()) {
- Array arr = get_script_instance()->call("_get_extensions");
+ Vector<String> arr;
+ if (GDVIRTUAL_CALL(_get_extensions, arr)) {
for (int i = 0; i < arr.size(); i++) {
r_extensions->push_back(arr[i]);
}
@@ -71,16 +72,18 @@ void EditorSceneImporter::get_extensions(List<String> *r_extensions) const {
}
Node *EditorSceneImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
- if (get_script_instance()) {
- return get_script_instance()->call("_import_scene", p_path, p_flags, p_bake_fps);
+ Object *ret;
+ if (GDVIRTUAL_CALL(_import_scene, p_path, p_flags, p_bake_fps, ret)) {
+ return Object::cast_to<Node>(ret);
}
ERR_FAIL_V(nullptr);
}
Ref<Animation> EditorSceneImporter::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) {
- if (get_script_instance()) {
- return get_script_instance()->call("_import_animation", p_path, p_flags);
+ Ref<Animation> ret;
+ if (GDVIRTUAL_CALL(_import_animation, p_path, p_flags, p_bake_fps, ret)) {
+ return ret;
}
ERR_FAIL_V(nullptr);
@@ -101,15 +104,10 @@ void EditorSceneImporter::_bind_methods() {
ClassDB::bind_method(D_METHOD("import_scene_from_other_importer", "path", "flags", "bake_fps"), &EditorSceneImporter::import_scene_from_other_importer);
ClassDB::bind_method(D_METHOD("import_animation_from_other_importer", "path", "flags", "bake_fps"), &EditorSceneImporter::import_animation_from_other_importer);
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_import_flags"));
- BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_extensions"));
-
- MethodInfo mi = MethodInfo(Variant::OBJECT, "_import_scene", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"), PropertyInfo(Variant::INT, "bake_fps"));
- mi.return_val.class_name = "Node";
- BIND_VMETHOD(mi);
- mi = MethodInfo(Variant::OBJECT, "_import_animation", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"), PropertyInfo(Variant::INT, "bake_fps"));
- mi.return_val.class_name = "Animation";
- BIND_VMETHOD(mi);
+ GDVIRTUAL_BIND(_get_import_flags);
+ GDVIRTUAL_BIND(_get_extensions);
+ GDVIRTUAL_BIND(_import_scene, "path", "flags", "bake_fps");
+ GDVIRTUAL_BIND(_import_animation, "path", "flags", "bake_fps");
BIND_CONSTANT(IMPORT_SCENE);
BIND_CONSTANT(IMPORT_ANIMATION);
@@ -120,13 +118,14 @@ void EditorSceneImporter::_bind_methods() {
/////////////////////////////////
void EditorScenePostImport::_bind_methods() {
- BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_post_import", PropertyInfo(Variant::OBJECT, "scene")));
+ GDVIRTUAL_BIND(_post_import, "scene")
ClassDB::bind_method(D_METHOD("get_source_file"), &EditorScenePostImport::get_source_file);
}
Node *EditorScenePostImport::post_import(Node *p_scene) {
- if (get_script_instance()) {
- return get_script_instance()->call("_post_import", p_scene);
+ Object *ret;
+ if (GDVIRTUAL_CALL(_post_import, p_scene, ret)) {
+ return Object::cast_to<Node>(ret);
}
return p_scene;
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index 781beff689..542959be02 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -51,6 +51,11 @@ protected:
Node *import_scene_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
Ref<Animation> import_animation_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
+ GDVIRTUAL0RC(int, _get_import_flags)
+ GDVIRTUAL0RC(Vector<String>, _get_extensions)
+ GDVIRTUAL3R(Object *, _import_scene, String, uint32_t, uint32_t)
+ GDVIRTUAL3R(Ref<Animation>, _import_animation, String, uint32_t, uint32_t)
+
public:
enum ImportFlags {
IMPORT_SCENE = 1,
@@ -77,6 +82,8 @@ class EditorScenePostImport : public RefCounted {
protected:
static void _bind_methods();
+ GDVIRTUAL1R(Object *, _post_import, Node *)
+
public:
String get_source_file() const;
virtual Node *post_import(Node *p_scene);