1 /**
2 Registers a custom resource importer in the editor. Use the class to parse any file and import it as a new resource type.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.editorimportplugin;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.resourceimporter;
24 /**
25 Registers a custom resource importer in the editor. Use the class to parse any file and import it as a new resource type.
26 
27 EditorImportPlugins provide a way to extend the editor's resource import functionality. Use them to import resources from custom files or to provide alternatives to the editor's existing importers. Register your $(D EditorPlugin) with $(D EditorPlugin.addImportPlugin).
28 EditorImportPlugins work by associating with specific file extensions and a resource type. See $(D getRecognizedExtensions) and $(D getResourceType). They may optionally specify some import presets that affect the import process. EditorImportPlugins are responsible for creating the resources and saving them in the `.import` directory.
29 Below is an example EditorImportPlugin that imports a $(D Mesh) from a file with the extension ".special" or ".spec":
30 
31 
32 tool
33 extends EditorImportPlugin
34 
35 func get_importer_name():
36     return "my.special.plugin"
37 
38 func get_visible_name():
39     return "Special Mesh"
40 
41 func get_recognized_extensions():
42     return $(D "special", "spec")
43 
44 func get_save_extension():
45     return "mesh"
46 
47 func get_resource_type():
48     return "Mesh"
49 
50 func get_preset_count():
51     return 1
52 
53 func get_preset_name(i):
54     return "Default"
55 
56 func get_import_options(i):
57     return $(D {"name": "my_option", "default_value": false})
58 
59 func import(source_file, save_path, options, platform_variants, gen_files):
60     var file = File.new()
61     if file.open(source_file, File.READ) != OK:
62         return FAILED
63 
64     var mesh = Mesh.new()
65     # Fill the Mesh with data read in "file", left as an exercise to the reader
66 
67     var filename = save_path + "." + get_save_extension()
68     return ResourceSaver.save(filename, mesh)
69 
70 
71 */
72 @GodotBaseClass struct EditorImportPlugin
73 {
74 	package(godot) enum string _GODOT_internal_name = "EditorImportPlugin";
75 public:
76 @nogc nothrow:
77 	union { /** */ godot_object _godot_object; /** */ ResourceImporter _GODOT_base; }
78 	alias _GODOT_base this;
79 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
80 	package(godot) __gshared bool _classBindingInitialized = false;
81 	package(godot) static struct GDNativeClassBinding
82 	{
83 		__gshared:
84 		@GodotName("get_import_options") GodotMethod!(Array, long) getImportOptions;
85 		@GodotName("get_import_order") GodotMethod!(long) getImportOrder;
86 		@GodotName("get_importer_name") GodotMethod!(String) getImporterName;
87 		@GodotName("get_option_visibility") GodotMethod!(bool, String, Dictionary) getOptionVisibility;
88 		@GodotName("get_preset_count") GodotMethod!(long) getPresetCount;
89 		@GodotName("get_preset_name") GodotMethod!(String, long) getPresetName;
90 		@GodotName("get_priority") GodotMethod!(double) getPriority;
91 		@GodotName("get_recognized_extensions") GodotMethod!(Array) getRecognizedExtensions;
92 		@GodotName("get_resource_type") GodotMethod!(String) getResourceType;
93 		@GodotName("get_save_extension") GodotMethod!(String) getSaveExtension;
94 		@GodotName("get_visible_name") GodotMethod!(String) getVisibleName;
95 		@GodotName("import") GodotMethod!(long, String, String, Dictionary, Array, Array) _import;
96 	}
97 	/// 
98 	pragma(inline, true) bool opEquals(in EditorImportPlugin other) const
99 	{ return _godot_object.ptr is other._godot_object.ptr; }
100 	/// 
101 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
102 	{ _godot_object.ptr = n; return null; }
103 	/// 
104 	pragma(inline, true) bool opEquals(typeof(null) n) const
105 	{ return _godot_object.ptr is n; }
106 	/// 
107 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
108 	mixin baseCasts;
109 	/// Construct a new instance of EditorImportPlugin.
110 	/// Note: use `memnew!EditorImportPlugin` instead.
111 	static EditorImportPlugin _new()
112 	{
113 		static godot_class_constructor constructor;
114 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorImportPlugin");
115 		if(constructor is null) return typeof(this).init;
116 		return cast(EditorImportPlugin)(constructor());
117 	}
118 	@disable new(size_t s);
119 	/**
120 	Gets the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys: `name`, `default_value`, `property_hint` (optional), `hint_string` (optional), `usage` (optional).
121 	*/
122 	Array getImportOptions(in long preset)
123 	{
124 		Array _GODOT_args = Array.make();
125 		_GODOT_args.append(preset);
126 		String _GODOT_method_name = String("get_import_options");
127 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array);
128 	}
129 	/**
130 	Gets the order of this importer to be run when importing resources. Higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported.
131 	*/
132 	long getImportOrder()
133 	{
134 		Array _GODOT_args = Array.make();
135 		String _GODOT_method_name = String("get_import_order");
136 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long);
137 	}
138 	/**
139 	Gets the unique name of the importer.
140 	*/
141 	String getImporterName()
142 	{
143 		Array _GODOT_args = Array.make();
144 		String _GODOT_method_name = String("get_importer_name");
145 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String);
146 	}
147 	/**
148 	This method can be overridden to hide specific import options if conditions are met. This is mainly useful for hiding options that depend on others if one of them is disabled. For example:
149 	
150 	
151 	func get_option_visibility(option, options):
152 	    # Only show the lossy quality setting if the compression mode is set to "Lossy".
153 	    if option == "compress/lossy_quality" and options.has("compress/mode"):
154 	        return int(options$(D "compress/mode")) == COMPRESS_LOSSY
155 	
156 	    return true
157 	
158 	
159 	Return `true` to make all options always visible.
160 	*/
161 	bool getOptionVisibility(in String option, in Dictionary options)
162 	{
163 		Array _GODOT_args = Array.make();
164 		_GODOT_args.append(option);
165 		_GODOT_args.append(options);
166 		String _GODOT_method_name = String("get_option_visibility");
167 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool);
168 	}
169 	/**
170 	Gets the number of initial presets defined by the plugin. Use $(D getImportOptions) to get the default options for the preset and $(D getPresetName) to get the name of the preset.
171 	*/
172 	long getPresetCount()
173 	{
174 		Array _GODOT_args = Array.make();
175 		String _GODOT_method_name = String("get_preset_count");
176 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long);
177 	}
178 	/**
179 	Gets the name of the options preset at this index.
180 	*/
181 	String getPresetName(in long preset)
182 	{
183 		Array _GODOT_args = Array.make();
184 		_GODOT_args.append(preset);
185 		String _GODOT_method_name = String("get_preset_name");
186 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String);
187 	}
188 	/**
189 	Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is `1.0`.
190 	*/
191 	double getPriority()
192 	{
193 		Array _GODOT_args = Array.make();
194 		String _GODOT_method_name = String("get_priority");
195 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!double);
196 	}
197 	/**
198 	Gets the list of file extensions to associate with this loader (case-insensitive). e.g. `$(D "obj")`.
199 	*/
200 	Array getRecognizedExtensions()
201 	{
202 		Array _GODOT_args = Array.make();
203 		String _GODOT_method_name = String("get_recognized_extensions");
204 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array);
205 	}
206 	/**
207 	Gets the Godot resource type associated with this loader. e.g. `"Mesh"` or `"Animation"`.
208 	*/
209 	String getResourceType()
210 	{
211 		Array _GODOT_args = Array.make();
212 		String _GODOT_method_name = String("get_resource_type");
213 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String);
214 	}
215 	/**
216 	Gets the extension used to save this resource in the `.import` directory.
217 	*/
218 	String getSaveExtension()
219 	{
220 		Array _GODOT_args = Array.make();
221 		String _GODOT_method_name = String("get_save_extension");
222 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String);
223 	}
224 	/**
225 	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".
226 	*/
227 	String getVisibleName()
228 	{
229 		Array _GODOT_args = Array.make();
230 		String _GODOT_method_name = String("get_visible_name");
231 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String);
232 	}
233 	/**
234 	Imports `source_file` into `save_path` with the import `options` specified. The `platform_variants` and `gen_files` arrays will be modified by this function.
235 	This method must be overridden to do the actual importing work. See this class' description for an example of overriding this method.
236 	*/
237 	long _import(in String source_file, in String save_path, in Dictionary options, in Array platform_variants, in Array gen_files)
238 	{
239 		Array _GODOT_args = Array.make();
240 		_GODOT_args.append(source_file);
241 		_GODOT_args.append(save_path);
242 		_GODOT_args.append(options);
243 		_GODOT_args.append(platform_variants);
244 		_GODOT_args.append(gen_files);
245 		String _GODOT_method_name = String("import");
246 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long);
247 	}
248 }