1 /** 2 Post process scenes after import 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.editorscenepostimport; 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 Post process scenes after import 26 27 Imported scenes can be automatically modified right after import by setting their $(I Custom Script) Import property to a `tool` script that inherits from this class. 28 The $(D postImport) callback receives the imported scene's root node and returns the modified version of the scene. Usage example: 29 30 31 tool # needed so it runs in editor 32 extends EditorScenePostImport 33 34 # This sample changes all node names 35 36 # Called right after the scene is imported and gets the root node 37 func post_import(scene): 38 # change all node names to "modified_$(D oldnodename)" 39 iterate(scene) 40 return scene # remember to return the imported scene 41 42 func iterate(node): 43 if node != null: 44 node.name = "modified_"+node.name 45 for child in node.get_children(): 46 iterate(child) 47 48 49 */ 50 @GodotBaseClass struct EditorScenePostImport 51 { 52 enum string _GODOT_internal_name = "EditorScenePostImport"; 53 public: 54 @nogc nothrow: 55 union { godot_object _godot_object; Reference _GODOT_base; } 56 alias _GODOT_base this; 57 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 58 package(godot) __gshared bool _classBindingInitialized = false; 59 package(godot) static struct _classBinding 60 { 61 __gshared: 62 @GodotName("post_import") GodotMethod!(GodotObject, GodotObject) postImport; 63 @GodotName("get_source_folder") GodotMethod!(String) getSourceFolder; 64 @GodotName("get_source_file") GodotMethod!(String) getSourceFile; 65 } 66 bool opEquals(in EditorScenePostImport other) const { return _godot_object.ptr is other._godot_object.ptr; } 67 EditorScenePostImport opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 68 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 69 mixin baseCasts; 70 static EditorScenePostImport _new() 71 { 72 static godot_class_constructor constructor; 73 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorScenePostImport"); 74 if(constructor is null) return typeof(this).init; 75 return cast(EditorScenePostImport)(constructor()); 76 } 77 @disable new(size_t s); 78 /** 79 Gets called after the scene got imported and has to return the modified version of the scene. 80 */ 81 GodotObject postImport(GodotObject scene) 82 { 83 Array _GODOT_args = Array.empty_array; 84 _GODOT_args.append(scene); 85 String _GODOT_method_name = String("post_import"); 86 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!GodotObject); 87 } 88 /** 89 Returns the resource folder the imported scene file is located in. 90 */ 91 String getSourceFolder() const 92 { 93 checkClassBinding!(typeof(this))(); 94 return ptrcall!(String)(_classBinding.getSourceFolder, _godot_object); 95 } 96 /** 97 Returns the source file path which got imported (e.g. `res://scene.dae`). 98 */ 99 String getSourceFile() const 100 { 101 checkClassBinding!(typeof(this))(); 102 return ptrcall!(String)(_classBinding.getSourceFile, _godot_object); 103 } 104 }