Skip to content

Commit 0a5f712

Browse files
committed
Merge pull request godotengine#104740 from Jojo-1000/update-import-plugin-docs
Update EditorImportPlugin docs and clarify which methods are required
2 parents 4226355 + 71723f7 commit 0a5f712

File tree

3 files changed

+62
-80
lines changed

3 files changed

+62
-80
lines changed

doc/classes/EditorImportPlugin.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,18 @@
124124
<return type="bool" />
125125
<description>
126126
Tells whether this importer can be run in parallel on threads, or, on the contrary, it's only safe for the editor to call it from the main thread, for one file at a time.
127-
If this method is not overridden, it will return [code]false[/code] by default.
128127
If this importer's implementation is thread-safe and can be run in parallel, override this with [code]true[/code] to optimize for concurrency.
128+
If not overridden, returns [code]false[/code].
129129
</description>
130130
</method>
131131
<method name="_get_format_version" qualifiers="virtual const">
132132
<return type="int" />
133133
<description>
134134
Gets the format version of this importer. Increment this version when making incompatible changes to the format of the imported resources.
135+
If not overridden, the format version is [code]0[/code].
135136
</description>
136137
</method>
137-
<method name="_get_import_options" qualifiers="virtual const">
138+
<method name="_get_import_options" qualifiers="virtual required const">
138139
<return type="Dictionary[]" />
139140
<param index="0" name="path" type="String" />
140141
<param index="1" name="preset_index" type="int" />
@@ -148,7 +149,7 @@
148149
Gets the order of this importer to be run when importing resources. Importers with [i]lower[/i] import orders will be called first, and higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. The default import order is [code]0[/code] unless overridden by a specific importer. See [enum ResourceImporter.ImportOrder] for some predefined values.
149150
</description>
150151
</method>
151-
<method name="_get_importer_name" qualifiers="virtual const">
152+
<method name="_get_importer_name" qualifiers="virtual required const">
152153
<return type="String" />
153154
<description>
154155
Gets the unique name of the importer.
@@ -189,9 +190,10 @@
189190
<return type="int" />
190191
<description>
191192
Gets the number of initial presets defined by the plugin. Use [method _get_import_options] to get the default options for the preset and [method _get_preset_name] to get the name of the preset.
193+
By default, there are no presets.
192194
</description>
193195
</method>
194-
<method name="_get_preset_name" qualifiers="virtual const">
196+
<method name="_get_preset_name" qualifiers="virtual required const">
195197
<return type="String" />
196198
<param index="0" name="preset_index" type="int" />
197199
<description>
@@ -204,31 +206,31 @@
204206
Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is [code]1.0[/code].
205207
</description>
206208
</method>
207-
<method name="_get_recognized_extensions" qualifiers="virtual const">
209+
<method name="_get_recognized_extensions" qualifiers="virtual required const">
208210
<return type="PackedStringArray" />
209211
<description>
210212
Gets the list of file extensions to associate with this loader (case-insensitive). e.g. [code]["obj"][/code].
211213
</description>
212214
</method>
213-
<method name="_get_resource_type" qualifiers="virtual const">
215+
<method name="_get_resource_type" qualifiers="virtual required const">
214216
<return type="String" />
215217
<description>
216218
Gets the Godot resource type associated with this loader. e.g. [code]"Mesh"[/code] or [code]"Animation"[/code].
217219
</description>
218220
</method>
219-
<method name="_get_save_extension" qualifiers="virtual const">
221+
<method name="_get_save_extension" qualifiers="virtual required const">
220222
<return type="String" />
221223
<description>
222224
Gets the extension used to save this resource in the [code].godot/imported[/code] directory (see [member ProjectSettings.application/config/use_hidden_project_data_directory]).
223225
</description>
224226
</method>
225-
<method name="_get_visible_name" qualifiers="virtual const">
227+
<method name="_get_visible_name" qualifiers="virtual required const">
226228
<return type="String" />
227229
<description>
228230
Gets the name to display in the import window. You should choose this name as a continuation to "Import as", e.g. "Import as Special Mesh".
229231
</description>
230232
</method>
231-
<method name="_import" qualifiers="virtual const">
233+
<method name="_import" qualifiers="virtual required const">
232234
<return type="int" enum="Error" />
233235
<param index="0" name="source_file" type="String" />
234236
<param index="1" name="save_path" type="String" />

editor/import/editor_import_plugin.cpp

Lines changed: 43 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,28 @@
3535

3636
String EditorImportPlugin::get_importer_name() const {
3737
String ret;
38-
if (GDVIRTUAL_CALL(_get_importer_name, ret)) {
39-
return ret;
40-
}
41-
ERR_FAIL_V_MSG(String(), "Unimplemented _get_importer_name in add-on.");
38+
GDVIRTUAL_CALL(_get_importer_name, ret);
39+
return ret;
4240
}
4341

4442
String EditorImportPlugin::get_visible_name() const {
4543
String ret;
46-
if (GDVIRTUAL_CALL(_get_visible_name, ret)) {
47-
return ret;
48-
}
49-
ERR_FAIL_V_MSG(String(), "Unimplemented _get_visible_name in add-on.");
44+
GDVIRTUAL_CALL(_get_visible_name, ret);
45+
return ret;
5046
}
5147

5248
void EditorImportPlugin::get_recognized_extensions(List<String> *p_extensions) const {
5349
Vector<String> extensions;
54-
55-
if (GDVIRTUAL_CALL(_get_recognized_extensions, extensions)) {
56-
for (int i = 0; i < extensions.size(); i++) {
57-
p_extensions->push_back(extensions[i]);
58-
}
59-
return;
50+
GDVIRTUAL_CALL(_get_recognized_extensions, extensions);
51+
for (int i = 0; i < extensions.size(); i++) {
52+
p_extensions->push_back(extensions[i]);
6053
}
61-
ERR_FAIL_MSG("Unimplemented _get_recognized_extensions in add-on.");
6254
}
6355

6456
String EditorImportPlugin::get_preset_name(int p_idx) const {
6557
String ret;
66-
if (GDVIRTUAL_CALL(_get_preset_name, p_idx, ret)) {
67-
return ret;
68-
}
69-
ERR_FAIL_V_MSG(itos(p_idx), "Unimplemented _get_preset_name in add-on.");
58+
GDVIRTUAL_CALL(_get_preset_name, p_idx, ret);
59+
return ret;
7060
}
7161

7262
int EditorImportPlugin::get_preset_count() const {
@@ -79,18 +69,14 @@ int EditorImportPlugin::get_preset_count() const {
7969

8070
String EditorImportPlugin::get_save_extension() const {
8171
String ret;
82-
if (GDVIRTUAL_CALL(_get_save_extension, ret)) {
83-
return ret;
84-
}
85-
ERR_FAIL_V_MSG(String(), "Unimplemented _get_save_extension in add-on.");
72+
GDVIRTUAL_CALL(_get_save_extension, ret);
73+
return ret;
8674
}
8775

8876
String EditorImportPlugin::get_resource_type() const {
8977
String ret;
90-
if (GDVIRTUAL_CALL(_get_resource_type, ret)) {
91-
return ret;
92-
}
93-
ERR_FAIL_V_MSG(String(), "Unimplemented _get_resource_type in add-on.");
78+
GDVIRTUAL_CALL(_get_resource_type, ret);
79+
return ret;
9480
}
9581

9682
float EditorImportPlugin::get_priority() const {
@@ -120,35 +106,31 @@ int EditorImportPlugin::get_format_version() const {
120106
void EditorImportPlugin::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options, int p_preset) const {
121107
Array needed = { "name", "default_value" };
122108
TypedArray<Dictionary> options;
123-
if (GDVIRTUAL_CALL(_get_import_options, p_path, p_preset, options)) {
124-
for (int i = 0; i < options.size(); i++) {
125-
Dictionary d = options[i];
126-
ERR_FAIL_COND(!d.has_all(needed));
127-
String name = d["name"];
128-
Variant default_value = d["default_value"];
129-
130-
PropertyHint hint = PROPERTY_HINT_NONE;
131-
if (d.has("property_hint")) {
132-
hint = (PropertyHint)d["property_hint"].operator int64_t();
133-
}
134-
135-
String hint_string;
136-
if (d.has("hint_string")) {
137-
hint_string = d["hint_string"];
138-
}
139-
140-
uint32_t usage = PROPERTY_USAGE_DEFAULT;
141-
if (d.has("usage")) {
142-
usage = d["usage"];
143-
}
144-
145-
ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value);
146-
r_options->push_back(option);
109+
GDVIRTUAL_CALL(_get_import_options, p_path, p_preset, options);
110+
for (int i = 0; i < options.size(); i++) {
111+
Dictionary d = options[i];
112+
ERR_FAIL_COND(!d.has_all(needed));
113+
String name = d["name"];
114+
Variant default_value = d["default_value"];
115+
116+
PropertyHint hint = PROPERTY_HINT_NONE;
117+
if (d.has("property_hint")) {
118+
hint = (PropertyHint)d["property_hint"].operator int64_t();
119+
}
120+
121+
String hint_string;
122+
if (d.has("hint_string")) {
123+
hint_string = d["hint_string"];
124+
}
125+
126+
uint32_t usage = PROPERTY_USAGE_DEFAULT;
127+
if (d.has("usage")) {
128+
usage = d["usage"];
147129
}
148-
return;
149-
}
150130

151-
ERR_FAIL_MSG("Unimplemented _get_import_options in add-on.");
131+
ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value);
132+
r_options->push_back(option);
133+
}
152134
}
153135

154136
bool EditorImportPlugin::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
@@ -176,16 +158,14 @@ Error EditorImportPlugin::import(ResourceUID::ID p_source_id, const String &p_so
176158
}
177159

178160
Error err = OK;
179-
if (GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err)) {
180-
for (int i = 0; i < platform_variants.size(); i++) {
181-
r_platform_variants->push_back(platform_variants[i]);
182-
}
183-
for (int i = 0; i < gen_files.size(); i++) {
184-
r_gen_files->push_back(gen_files[i]);
185-
}
186-
return err;
161+
GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err);
162+
for (int i = 0; i < platform_variants.size(); i++) {
163+
r_platform_variants->push_back(platform_variants[i]);
164+
}
165+
for (int i = 0; i < gen_files.size(); i++) {
166+
r_gen_files->push_back(gen_files[i]);
187167
}
188-
ERR_FAIL_V_MSG(ERR_METHOD_NOT_FOUND, "Unimplemented _import in add-on.");
168+
return err;
189169
}
190170

191171
bool EditorImportPlugin::can_import_threaded() const {

editor/import/editor_import_plugin.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ class EditorImportPlugin : public ResourceImporter {
3939
protected:
4040
static void _bind_methods();
4141

42-
GDVIRTUAL0RC(String, _get_importer_name)
43-
GDVIRTUAL0RC(String, _get_visible_name)
42+
GDVIRTUAL0RC_REQUIRED(String, _get_importer_name)
43+
GDVIRTUAL0RC_REQUIRED(String, _get_visible_name)
4444
GDVIRTUAL0RC(int, _get_preset_count)
45-
GDVIRTUAL1RC(String, _get_preset_name, int)
46-
GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions)
47-
GDVIRTUAL2RC(TypedArray<Dictionary>, _get_import_options, String, int)
48-
GDVIRTUAL0RC(String, _get_save_extension)
49-
GDVIRTUAL0RC(String, _get_resource_type)
45+
GDVIRTUAL1RC_REQUIRED(String, _get_preset_name, int)
46+
GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_recognized_extensions)
47+
GDVIRTUAL2RC_REQUIRED(TypedArray<Dictionary>, _get_import_options, String, int)
48+
GDVIRTUAL0RC_REQUIRED(String, _get_save_extension)
49+
GDVIRTUAL0RC_REQUIRED(String, _get_resource_type)
5050
GDVIRTUAL0RC(float, _get_priority)
5151
GDVIRTUAL0RC(int, _get_import_order)
5252
GDVIRTUAL0RC(int, _get_format_version)
5353
GDVIRTUAL3RC(bool, _get_option_visibility, String, StringName, Dictionary)
54-
GDVIRTUAL5RC(Error, _import, String, String, Dictionary, TypedArray<String>, TypedArray<String>)
54+
GDVIRTUAL5RC_REQUIRED(Error, _import, String, String, Dictionary, TypedArray<String>, TypedArray<String>)
5555
GDVIRTUAL0RC(bool, _can_import_threaded)
5656

5757
Error _append_import_external_resource(const String &p_file, const Dictionary &p_custom_options = Dictionary(), const String &p_custom_importer = String(), Variant p_generator_parameters = Variant());

0 commit comments

Comments
 (0)