1 /** 2 Post-processes 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.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.reference; 24 /** 25 Post-processes scenes after import. 26 27 Imported scenes can be automatically modified right after import by setting their $(B 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 package(godot) 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 GDNativeClassBinding 60 { 61 __gshared: 62 @GodotName("get_source_file") GodotMethod!(String) getSourceFile; 63 @GodotName("get_source_folder") GodotMethod!(String) getSourceFolder; 64 @GodotName("post_import") GodotMethod!(GodotObject, GodotObject) postImport; 65 } 66 /// 67 pragma(inline, true) bool opEquals(in EditorScenePostImport other) const 68 { return _godot_object.ptr is other._godot_object.ptr; } 69 /// 70 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 71 { _godot_object.ptr = n; return null; } 72 /// 73 pragma(inline, true) bool opEquals(typeof(null) n) const 74 { return _godot_object.ptr is n; } 75 /// 76 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 77 mixin baseCasts; 78 /// Construct a new instance of EditorScenePostImport. 79 /// Note: use `memnew!EditorScenePostImport` instead. 80 static EditorScenePostImport _new() 81 { 82 static godot_class_constructor constructor; 83 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorScenePostImport"); 84 if(constructor is null) return typeof(this).init; 85 return cast(EditorScenePostImport)(constructor()); 86 } 87 @disable new(size_t s); 88 /** 89 Returns the source file path which got imported (e.g. `res://scene.dae`). 90 */ 91 String getSourceFile() const 92 { 93 checkClassBinding!(typeof(this))(); 94 return ptrcall!(String)(GDNativeClassBinding.getSourceFile, _godot_object); 95 } 96 /** 97 Returns the resource folder the imported scene file is located in. 98 */ 99 String getSourceFolder() const 100 { 101 checkClassBinding!(typeof(this))(); 102 return ptrcall!(String)(GDNativeClassBinding.getSourceFolder, _godot_object); 103 } 104 /** 105 Called after the scene was imported. This method must return the modified version of the scene. 106 */ 107 GodotObject postImport(GodotObject scene) 108 { 109 Array _GODOT_args = Array.make(); 110 _GODOT_args.append(scene); 111 String _GODOT_method_name = String("post_import"); 112 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!GodotObject); 113 } 114 }