1 /**
2 Base script that can be used to add extension functions to the editor.
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.editorscript;
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 import godot.node;
25 import godot.editorinterface;
26 /**
27 Base script that can be used to add extension functions to the editor.
28 
29 Scripts extending this class and implementing its $(D _run) method can be executed from the Script Editor's $(B File > Run) menu option (or by pressing `Ctrl+Shift+X`) while the editor is running. This is useful for adding custom in-editor functionality to Godot. For more complex additions, consider using $(D EditorPlugin)s instead.
30 $(B Note:) Extending scripts need to have `tool` mode enabled.
31 $(B Example script:)
32 
33 
34 tool
35 extends EditorScript
36 
37 func _run():
38     print("Hello from the Godot Editor!")
39 
40 
41 $(B Note:) The script is run in the Editor context, which means the output is visible in the console window started with the Editor (stdout) instead of the usual Godot $(B Output) dock.
42 */
43 @GodotBaseClass struct EditorScript
44 {
45 	package(godot) enum string _GODOT_internal_name = "EditorScript";
46 public:
47 @nogc nothrow:
48 	union { /** */ godot_object _godot_object; /** */ Reference _GODOT_base; }
49 	alias _GODOT_base this;
50 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
51 	package(godot) __gshared bool _classBindingInitialized = false;
52 	package(godot) static struct GDNativeClassBinding
53 	{
54 		__gshared:
55 		@GodotName("_run") GodotMethod!(void) _run;
56 		@GodotName("add_root_node") GodotMethod!(void, Node) addRootNode;
57 		@GodotName("get_editor_interface") GodotMethod!(EditorInterface) getEditorInterface;
58 		@GodotName("get_scene") GodotMethod!(Node) getScene;
59 	}
60 	/// 
61 	pragma(inline, true) bool opEquals(in EditorScript other) const
62 	{ return _godot_object.ptr is other._godot_object.ptr; }
63 	/// 
64 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
65 	{ _godot_object.ptr = n; return null; }
66 	/// 
67 	pragma(inline, true) bool opEquals(typeof(null) n) const
68 	{ return _godot_object.ptr is n; }
69 	/// 
70 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
71 	mixin baseCasts;
72 	/// Construct a new instance of EditorScript.
73 	/// Note: use `memnew!EditorScript` instead.
74 	static EditorScript _new()
75 	{
76 		static godot_class_constructor constructor;
77 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorScript");
78 		if(constructor is null) return typeof(this).init;
79 		return cast(EditorScript)(constructor());
80 	}
81 	@disable new(size_t s);
82 	/**
83 	This method is executed by the Editor when $(B File > Run) is used.
84 	*/
85 	void _run()
86 	{
87 		Array _GODOT_args = Array.make();
88 		String _GODOT_method_name = String("_run");
89 		this.callv(_GODOT_method_name, _GODOT_args);
90 	}
91 	/**
92 	Adds `node` as a child of the root node in the editor context.
93 	$(B Warning:) The implementation of this method is currently disabled.
94 	*/
95 	void addRootNode(Node node)
96 	{
97 		checkClassBinding!(typeof(this))();
98 		ptrcall!(void)(GDNativeClassBinding.addRootNode, _godot_object, node);
99 	}
100 	/**
101 	Returns the $(D EditorInterface) singleton instance.
102 	*/
103 	EditorInterface getEditorInterface()
104 	{
105 		checkClassBinding!(typeof(this))();
106 		return ptrcall!(EditorInterface)(GDNativeClassBinding.getEditorInterface, _godot_object);
107 	}
108 	/**
109 	Returns the Editor's currently active scene.
110 	*/
111 	Node getScene()
112 	{
113 		checkClassBinding!(typeof(this))();
114 		return ptrcall!(Node)(GDNativeClassBinding.getScene, _godot_object);
115 	}
116 }