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.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.reference; 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 getRecognizedExtension) 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 Importer" 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, r_platform_variants, r_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 exercise to the reader 66 67 var filename = save_path + "." + get_save_extension() 68 ResourceSaver.save(filename, mesh) 69 return OK 70 71 72 */ 73 @GodotBaseClass struct EditorImportPlugin 74 { 75 enum string _GODOT_internal_name = "EditorImportPlugin"; 76 public: 77 @nogc nothrow: 78 union { godot_object _godot_object; Reference _GODOT_base; } 79 alias _GODOT_base this; 80 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 81 package(godot) __gshared bool _classBindingInitialized = false; 82 package(godot) static struct _classBinding 83 { 84 __gshared: 85 @GodotName("get_importer_name") GodotMethod!(String) getImporterName; 86 @GodotName("get_visible_name") GodotMethod!(String) getVisibleName; 87 @GodotName("get_preset_count") GodotMethod!(long) getPresetCount; 88 @GodotName("get_preset_name") GodotMethod!(String, long) getPresetName; 89 @GodotName("get_recognized_extensions") GodotMethod!(Array) getRecognizedExtensions; 90 @GodotName("get_import_options") GodotMethod!(Array, long) getImportOptions; 91 @GodotName("get_save_extension") GodotMethod!(String) getSaveExtension; 92 @GodotName("get_resource_type") GodotMethod!(String) getResourceType; 93 @GodotName("get_priority") GodotMethod!(double) getPriority; 94 @GodotName("get_import_order") GodotMethod!(long) getImportOrder; 95 @GodotName("get_option_visibility") GodotMethod!(bool, String, Dictionary) getOptionVisibility; 96 @GodotName("import") GodotMethod!(long, String, String, Dictionary, Array, Array) _import; 97 } 98 bool opEquals(in EditorImportPlugin other) const { return _godot_object.ptr is other._godot_object.ptr; } 99 EditorImportPlugin opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 100 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 101 mixin baseCasts; 102 static EditorImportPlugin _new() 103 { 104 static godot_class_constructor constructor; 105 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorImportPlugin"); 106 if(constructor is null) return typeof(this).init; 107 return cast(EditorImportPlugin)(constructor()); 108 } 109 @disable new(size_t s); 110 /** 111 Get the unique name of the importer. 112 */ 113 String getImporterName() 114 { 115 Array _GODOT_args = Array.empty_array; 116 String _GODOT_method_name = String("get_importer_name"); 117 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 118 } 119 /** 120 Get the name to display in the import window. 121 */ 122 String getVisibleName() 123 { 124 Array _GODOT_args = Array.empty_array; 125 String _GODOT_method_name = String("get_visible_name"); 126 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 127 } 128 /** 129 Get 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. 130 */ 131 long getPresetCount() 132 { 133 Array _GODOT_args = Array.empty_array; 134 String _GODOT_method_name = String("get_preset_count"); 135 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long); 136 } 137 /** 138 Get the name of the options preset at this index. 139 */ 140 String getPresetName(in long preset) 141 { 142 Array _GODOT_args = Array.empty_array; 143 _GODOT_args.append(preset); 144 String _GODOT_method_name = String("get_preset_name"); 145 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 146 } 147 /** 148 Get the list of file extensions to associate with this loader (case insensitive). e.g. $(D "obj"). 149 */ 150 Array getRecognizedExtensions() 151 { 152 Array _GODOT_args = Array.empty_array; 153 String _GODOT_method_name = String("get_recognized_extensions"); 154 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array); 155 } 156 /** 157 Get 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). 158 */ 159 Array getImportOptions(in long preset) 160 { 161 Array _GODOT_args = Array.empty_array; 162 _GODOT_args.append(preset); 163 String _GODOT_method_name = String("get_import_options"); 164 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array); 165 } 166 /** 167 Get the extension used to save this resource in the `.import` directory. 168 */ 169 String getSaveExtension() 170 { 171 Array _GODOT_args = Array.empty_array; 172 String _GODOT_method_name = String("get_save_extension"); 173 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 174 } 175 /** 176 Get the Godot resource type associated with this loader. e.g. "Mesh" or "Animation". 177 */ 178 String getResourceType() 179 { 180 Array _GODOT_args = Array.empty_array; 181 String _GODOT_method_name = String("get_resource_type"); 182 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 183 } 184 /** 185 Get the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. Default value is 1.0. 186 */ 187 double getPriority() 188 { 189 Array _GODOT_args = Array.empty_array; 190 String _GODOT_method_name = String("get_priority"); 191 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!double); 192 } 193 /** 194 Get 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. 195 */ 196 long getImportOrder() 197 { 198 Array _GODOT_args = Array.empty_array; 199 String _GODOT_method_name = String("get_import_order"); 200 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long); 201 } 202 /** 203 204 */ 205 bool getOptionVisibility(StringArg0)(in StringArg0 option, in Dictionary options) 206 { 207 Array _GODOT_args = Array.empty_array; 208 _GODOT_args.append(option); 209 _GODOT_args.append(options); 210 String _GODOT_method_name = String("get_option_visibility"); 211 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 212 } 213 /** 214 215 */ 216 long _import(StringArg0, StringArg1)(in StringArg0 source_file, in StringArg1 save_path, in Dictionary options, in Array r_platform_variants, in Array r_gen_files) 217 { 218 Array _GODOT_args = Array.empty_array; 219 _GODOT_args.append(source_file); 220 _GODOT_args.append(save_path); 221 _GODOT_args.append(options); 222 _GODOT_args.append(r_platform_variants); 223 _GODOT_args.append(r_gen_files); 224 String _GODOT_method_name = String("import"); 225 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long); 226 } 227 }