1 /**
2 Class information repository.
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.classdb;
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 /**
24 Class information repository.
25 
26 Provides access to metadata stored for every available class.
27 */
28 @GodotBaseClass struct ClassDBSingleton
29 {
30 	package(godot) enum string _GODOT_internal_name = "_ClassDB";
31 public:
32 @nogc nothrow:
33 	union { /** */ godot_object _godot_object; /** */ GodotObject _GODOT_base; }
34 	alias _GODOT_base this;
35 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
36 	package(godot) __gshared bool _classBindingInitialized = false;
37 	package(godot) static struct GDNativeClassBinding
38 	{
39 		__gshared:
40 		godot_object _singleton;
41 		immutable char* _singletonName = "ClassDB";
42 		@GodotName("can_instance") GodotMethod!(bool, String) canInstance;
43 		@GodotName("class_exists") GodotMethod!(bool, String) classExists;
44 		@GodotName("class_get_category") GodotMethod!(String, String) classGetCategory;
45 		@GodotName("class_get_integer_constant") GodotMethod!(long, String, String) classGetIntegerConstant;
46 		@GodotName("class_get_integer_constant_list") GodotMethod!(PoolStringArray, String, bool) classGetIntegerConstantList;
47 		@GodotName("class_get_method_list") GodotMethod!(Array, String, bool) classGetMethodList;
48 		@GodotName("class_get_property") GodotMethod!(Variant, GodotObject, String) classGetProperty;
49 		@GodotName("class_get_property_list") GodotMethod!(Array, String, bool) classGetPropertyList;
50 		@GodotName("class_get_signal") GodotMethod!(Dictionary, String, String) classGetSignal;
51 		@GodotName("class_get_signal_list") GodotMethod!(Array, String, bool) classGetSignalList;
52 		@GodotName("class_has_integer_constant") GodotMethod!(bool, String, String) classHasIntegerConstant;
53 		@GodotName("class_has_method") GodotMethod!(bool, String, String, bool) classHasMethod;
54 		@GodotName("class_has_signal") GodotMethod!(bool, String, String) classHasSignal;
55 		@GodotName("class_set_property") GodotMethod!(GodotError, GodotObject, String, Variant) classSetProperty;
56 		@GodotName("get_class_list") GodotMethod!(PoolStringArray) getClassList;
57 		@GodotName("get_inheriters_from_class") GodotMethod!(PoolStringArray, String) getInheritersFromClass;
58 		@GodotName("get_parent_class") GodotMethod!(String, String) getParentClass;
59 		@GodotName("instance") GodotMethod!(Variant, String) instance;
60 		@GodotName("is_class_enabled") GodotMethod!(bool, String) isClassEnabled;
61 		@GodotName("is_parent_class") GodotMethod!(bool, String, String) isParentClass;
62 	}
63 	/// 
64 	pragma(inline, true) bool opEquals(in ClassDBSingleton other) const
65 	{ return _godot_object.ptr is other._godot_object.ptr; }
66 	/// 
67 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
68 	{ _godot_object.ptr = n; return null; }
69 	/// 
70 	pragma(inline, true) bool opEquals(typeof(null) n) const
71 	{ return _godot_object.ptr is n; }
72 	/// 
73 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
74 	mixin baseCasts;
75 	/// Construct a new instance of ClassDBSingleton.
76 	/// Note: use `memnew!ClassDBSingleton` instead.
77 	static ClassDBSingleton _new()
78 	{
79 		static godot_class_constructor constructor;
80 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("_ClassDB");
81 		if(constructor is null) return typeof(this).init;
82 		return cast(ClassDBSingleton)(constructor());
83 	}
84 	@disable new(size_t s);
85 	/**
86 	Returns `true` if you can instance objects from the specified `class`, `false` in other case.
87 	*/
88 	bool canInstance(in String _class) const
89 	{
90 		checkClassBinding!(typeof(this))();
91 		return ptrcall!(bool)(GDNativeClassBinding.canInstance, _godot_object, _class);
92 	}
93 	/**
94 	Returns whether the specified `class` is available or not.
95 	*/
96 	bool classExists(in String _class) const
97 	{
98 		checkClassBinding!(typeof(this))();
99 		return ptrcall!(bool)(GDNativeClassBinding.classExists, _godot_object, _class);
100 	}
101 	/**
102 	Returns a category associated with the class for use in documentation and the Asset Library. Debug mode required.
103 	*/
104 	String classGetCategory(in String _class) const
105 	{
106 		checkClassBinding!(typeof(this))();
107 		return ptrcall!(String)(GDNativeClassBinding.classGetCategory, _godot_object, _class);
108 	}
109 	/**
110 	Returns the value of the integer constant `name` of `class` or its ancestry. Always returns 0 when the constant could not be found.
111 	*/
112 	long classGetIntegerConstant(in String _class, in String name) const
113 	{
114 		checkClassBinding!(typeof(this))();
115 		return ptrcall!(long)(GDNativeClassBinding.classGetIntegerConstant, _godot_object, _class, name);
116 	}
117 	/**
118 	Returns an array with the names all the integer constants of `class` or its ancestry.
119 	*/
120 	PoolStringArray classGetIntegerConstantList(in String _class, in bool no_inheritance = false) const
121 	{
122 		checkClassBinding!(typeof(this))();
123 		return ptrcall!(PoolStringArray)(GDNativeClassBinding.classGetIntegerConstantList, _godot_object, _class, no_inheritance);
124 	}
125 	/**
126 	Returns an array with all the methods of `class` or its ancestry if `no_inheritance` is `false`. Every element of the array is a $(D Dictionary) with the following keys: `args`, `default_args`, `flags`, `id`, `name`, `return: (class_name, hint, hint_string, name, type, usage)`.
127 	$(B Note:) In exported release builds the debug info is not available, so the returned dictionaries will contain only method names.
128 	*/
129 	Array classGetMethodList(in String _class, in bool no_inheritance = false) const
130 	{
131 		checkClassBinding!(typeof(this))();
132 		return ptrcall!(Array)(GDNativeClassBinding.classGetMethodList, _godot_object, _class, no_inheritance);
133 	}
134 	/**
135 	Returns the value of `property` of `class` or its ancestry.
136 	*/
137 	Variant classGetProperty(GodotObject object, in String property) const
138 	{
139 		checkClassBinding!(typeof(this))();
140 		return ptrcall!(Variant)(GDNativeClassBinding.classGetProperty, _godot_object, object, property);
141 	}
142 	/**
143 	Returns an array with all the properties of `class` or its ancestry if `no_inheritance` is `false`.
144 	*/
145 	Array classGetPropertyList(in String _class, in bool no_inheritance = false) const
146 	{
147 		checkClassBinding!(typeof(this))();
148 		return ptrcall!(Array)(GDNativeClassBinding.classGetPropertyList, _godot_object, _class, no_inheritance);
149 	}
150 	/**
151 	Returns the `signal` data of `class` or its ancestry. The returned value is a $(D Dictionary) with the following keys: `args`, `default_args`, `flags`, `id`, `name`, `return: (class_name, hint, hint_string, name, type, usage)`.
152 	*/
153 	Dictionary classGetSignal(in String _class, in String signal) const
154 	{
155 		checkClassBinding!(typeof(this))();
156 		return ptrcall!(Dictionary)(GDNativeClassBinding.classGetSignal, _godot_object, _class, signal);
157 	}
158 	/**
159 	Returns an array with all the signals of `class` or its ancestry if `no_inheritance` is `false`. Every element of the array is a $(D Dictionary) as described in $(D classGetSignal).
160 	*/
161 	Array classGetSignalList(in String _class, in bool no_inheritance = false) const
162 	{
163 		checkClassBinding!(typeof(this))();
164 		return ptrcall!(Array)(GDNativeClassBinding.classGetSignalList, _godot_object, _class, no_inheritance);
165 	}
166 	/**
167 	Returns whether `class` or its ancestry has an integer constant called `name` or not.
168 	*/
169 	bool classHasIntegerConstant(in String _class, in String name) const
170 	{
171 		checkClassBinding!(typeof(this))();
172 		return ptrcall!(bool)(GDNativeClassBinding.classHasIntegerConstant, _godot_object, _class, name);
173 	}
174 	/**
175 	Returns whether `class` (or its ancestry if `no_inheritance` is `false`) has a method called `method` or not.
176 	*/
177 	bool classHasMethod(in String _class, in String method, in bool no_inheritance = false) const
178 	{
179 		checkClassBinding!(typeof(this))();
180 		return ptrcall!(bool)(GDNativeClassBinding.classHasMethod, _godot_object, _class, method, no_inheritance);
181 	}
182 	/**
183 	Returns whether `class` or its ancestry has a signal called `signal` or not.
184 	*/
185 	bool classHasSignal(in String _class, in String signal) const
186 	{
187 		checkClassBinding!(typeof(this))();
188 		return ptrcall!(bool)(GDNativeClassBinding.classHasSignal, _godot_object, _class, signal);
189 	}
190 	/**
191 	Sets `property` value of `class` to `value`.
192 	*/
193 	GodotError classSetProperty(VariantArg2)(GodotObject object, in String property, in VariantArg2 value) const
194 	{
195 		checkClassBinding!(typeof(this))();
196 		return ptrcall!(GodotError)(GDNativeClassBinding.classSetProperty, _godot_object, object, property, value);
197 	}
198 	/**
199 	Returns the names of all the classes available.
200 	*/
201 	PoolStringArray getClassList() const
202 	{
203 		checkClassBinding!(typeof(this))();
204 		return ptrcall!(PoolStringArray)(GDNativeClassBinding.getClassList, _godot_object);
205 	}
206 	/**
207 	Returns the names of all the classes that directly or indirectly inherit from `class`.
208 	*/
209 	PoolStringArray getInheritersFromClass(in String _class) const
210 	{
211 		checkClassBinding!(typeof(this))();
212 		return ptrcall!(PoolStringArray)(GDNativeClassBinding.getInheritersFromClass, _godot_object, _class);
213 	}
214 	/**
215 	Returns the parent class of `class`.
216 	*/
217 	String getParentClass(in String _class) const
218 	{
219 		checkClassBinding!(typeof(this))();
220 		return ptrcall!(String)(GDNativeClassBinding.getParentClass, _godot_object, _class);
221 	}
222 	/**
223 	Creates an instance of `class`.
224 	*/
225 	Variant instance(in String _class) const
226 	{
227 		checkClassBinding!(typeof(this))();
228 		return ptrcall!(Variant)(GDNativeClassBinding.instance, _godot_object, _class);
229 	}
230 	/**
231 	Returns whether this `class` is enabled or not.
232 	*/
233 	bool isClassEnabled(in String _class) const
234 	{
235 		checkClassBinding!(typeof(this))();
236 		return ptrcall!(bool)(GDNativeClassBinding.isClassEnabled, _godot_object, _class);
237 	}
238 	/**
239 	Returns whether `inherits` is an ancestor of `class` or not.
240 	*/
241 	bool isParentClass(in String _class, in String inherits) const
242 	{
243 		checkClassBinding!(typeof(this))();
244 		return ptrcall!(bool)(GDNativeClassBinding.isParentClass, _godot_object, _class, inherits);
245 	}
246 }
247 /// Returns: the ClassDBSingleton
248 @property @nogc nothrow pragma(inline, true)
249 ClassDBSingleton ClassDB()
250 {
251 	checkClassBinding!ClassDBSingleton();
252 	return ClassDBSingleton(ClassDBSingleton.GDNativeClassBinding._singleton);
253 }