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.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 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 `_run()` method can be executed from the Script Editor's `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. Note that extending scripts need to have `tool mode` enabled.
30 Example script:
31 
32 
33 tool
34 extends EditorScript
35 
36 func _run():
37     print("Hello from the Godot Editor!")
38 
39 
40 Note that 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 $(I Output) dock.
41 */
42 @GodotBaseClass struct EditorScript
43 {
44 	enum string _GODOT_internal_name = "EditorScript";
45 public:
46 @nogc nothrow:
47 	union { godot_object _godot_object; Reference _GODOT_base; }
48 	alias _GODOT_base this;
49 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
50 	package(godot) __gshared bool _classBindingInitialized = false;
51 	package(godot) static struct _classBinding
52 	{
53 		__gshared:
54 		@GodotName("_run") GodotMethod!(void) _run;
55 		@GodotName("add_root_node") GodotMethod!(void, GodotObject) addRootNode;
56 		@GodotName("get_scene") GodotMethod!(Node) getScene;
57 		@GodotName("get_editor_interface") GodotMethod!(EditorInterface) getEditorInterface;
58 	}
59 	bool opEquals(in EditorScript other) const { return _godot_object.ptr is other._godot_object.ptr; }
60 	EditorScript opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
61 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
62 	mixin baseCasts;
63 	static EditorScript _new()
64 	{
65 		static godot_class_constructor constructor;
66 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorScript");
67 		if(constructor is null) return typeof(this).init;
68 		return cast(EditorScript)(constructor());
69 	}
70 	@disable new(size_t s);
71 	/**
72 	This method is executed by the Editor when `File -> Run` is used.
73 	*/
74 	void _run()
75 	{
76 		Array _GODOT_args = Array.empty_array;
77 		String _GODOT_method_name = String("_run");
78 		this.callv(_GODOT_method_name, _GODOT_args);
79 	}
80 	/**
81 	Adds `node` as a child of the root node in the editor context.
82 	WARNING: The implementation of this method is currently disabled.
83 	*/
84 	void addRootNode(GodotObject node)
85 	{
86 		checkClassBinding!(typeof(this))();
87 		ptrcall!(void)(_classBinding.addRootNode, _godot_object, node);
88 	}
89 	/**
90 	Returns the Editor's currently active scene.
91 	*/
92 	Node getScene()
93 	{
94 		checkClassBinding!(typeof(this))();
95 		return ptrcall!(Node)(_classBinding.getScene, _godot_object);
96 	}
97 	/**
98 	Returns the $(D EditorInterface) singleton instance.
99 	*/
100 	EditorInterface getEditorInterface()
101 	{
102 		checkClassBinding!(typeof(this))();
103 		return ptrcall!(EditorInterface)(_classBinding.getEditorInterface, _godot_object);
104 	}
105 }