1 /**
2 A node that has methods to draw outlines or use indices of vertices to create navigation polygons.
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.navigationpolygon;
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.classdb;
24 import godot.resource;
25 /**
26 A node that has methods to draw outlines or use indices of vertices to create navigation polygons.
27 
28 There are two ways to create polygons. Either by using the $(D addOutline) method, or using the $(D addPolygon) method.
29 Using $(D addOutline):
30 
31 
32 var polygon = NavigationPolygon.new()
33 var outline = PoolVector2Array($(D Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)))
34 polygon.add_outline(outline)
35 polygon.make_polygons_from_outlines()
36 $NavigationPolygonInstance.navpoly = polygon
37 
38 
39 Using $(D addPolygon) and indices of the vertices array.
40 
41 
42 var polygon = NavigationPolygon.new()
43 var vertices = PoolVector2Array($(D Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)))
44 polygon.set_vertices(vertices)
45 var indices = PoolIntArray(0, 3, 1)
46 polygon.add_polygon(indices)
47 $NavigationPolygonInstance.navpoly = polygon
48 
49 
50 */
51 @GodotBaseClass struct NavigationPolygon
52 {
53 	package(godot) enum string _GODOT_internal_name = "NavigationPolygon";
54 public:
55 @nogc nothrow:
56 	union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; }
57 	alias _GODOT_base this;
58 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
59 	package(godot) __gshared bool _classBindingInitialized = false;
60 	package(godot) static struct GDNativeClassBinding
61 	{
62 		__gshared:
63 		@GodotName("_get_outlines") GodotMethod!(Array) _getOutlines;
64 		@GodotName("_get_polygons") GodotMethod!(Array) _getPolygons;
65 		@GodotName("_set_outlines") GodotMethod!(void, Array) _setOutlines;
66 		@GodotName("_set_polygons") GodotMethod!(void, Array) _setPolygons;
67 		@GodotName("add_outline") GodotMethod!(void, PoolVector2Array) addOutline;
68 		@GodotName("add_outline_at_index") GodotMethod!(void, PoolVector2Array, long) addOutlineAtIndex;
69 		@GodotName("add_polygon") GodotMethod!(void, PoolIntArray) addPolygon;
70 		@GodotName("clear_outlines") GodotMethod!(void) clearOutlines;
71 		@GodotName("clear_polygons") GodotMethod!(void) clearPolygons;
72 		@GodotName("get_outline") GodotMethod!(PoolVector2Array, long) getOutline;
73 		@GodotName("get_outline_count") GodotMethod!(long) getOutlineCount;
74 		@GodotName("get_polygon") GodotMethod!(PoolIntArray, long) getPolygon;
75 		@GodotName("get_polygon_count") GodotMethod!(long) getPolygonCount;
76 		@GodotName("get_vertices") GodotMethod!(PoolVector2Array) getVertices;
77 		@GodotName("make_polygons_from_outlines") GodotMethod!(void) makePolygonsFromOutlines;
78 		@GodotName("remove_outline") GodotMethod!(void, long) removeOutline;
79 		@GodotName("set_outline") GodotMethod!(void, long, PoolVector2Array) setOutline;
80 		@GodotName("set_vertices") GodotMethod!(void, PoolVector2Array) setVertices;
81 	}
82 	/// 
83 	pragma(inline, true) bool opEquals(in NavigationPolygon other) const
84 	{ return _godot_object.ptr is other._godot_object.ptr; }
85 	/// 
86 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
87 	{ _godot_object.ptr = n; return null; }
88 	/// 
89 	pragma(inline, true) bool opEquals(typeof(null) n) const
90 	{ return _godot_object.ptr is n; }
91 	/// 
92 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
93 	mixin baseCasts;
94 	/// Construct a new instance of NavigationPolygon.
95 	/// Note: use `memnew!NavigationPolygon` instead.
96 	static NavigationPolygon _new()
97 	{
98 		static godot_class_constructor constructor;
99 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("NavigationPolygon");
100 		if(constructor is null) return typeof(this).init;
101 		return cast(NavigationPolygon)(constructor());
102 	}
103 	@disable new(size_t s);
104 	/**
105 	
106 	*/
107 	Array _getOutlines() const
108 	{
109 		Array _GODOT_args = Array.make();
110 		String _GODOT_method_name = String("_get_outlines");
111 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array);
112 	}
113 	/**
114 	
115 	*/
116 	Array _getPolygons() const
117 	{
118 		Array _GODOT_args = Array.make();
119 		String _GODOT_method_name = String("_get_polygons");
120 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array);
121 	}
122 	/**
123 	
124 	*/
125 	void _setOutlines(in Array outlines)
126 	{
127 		Array _GODOT_args = Array.make();
128 		_GODOT_args.append(outlines);
129 		String _GODOT_method_name = String("_set_outlines");
130 		this.callv(_GODOT_method_name, _GODOT_args);
131 	}
132 	/**
133 	
134 	*/
135 	void _setPolygons(in Array polygons)
136 	{
137 		Array _GODOT_args = Array.make();
138 		_GODOT_args.append(polygons);
139 		String _GODOT_method_name = String("_set_polygons");
140 		this.callv(_GODOT_method_name, _GODOT_args);
141 	}
142 	/**
143 	Appends a $(D PoolVector2Array) that contains the vertices of an outline to the internal array that contains all the outlines. You have to call $(D makePolygonsFromOutlines) in order for this array to be converted to polygons that the engine will use.
144 	*/
145 	void addOutline(in PoolVector2Array outline)
146 	{
147 		checkClassBinding!(typeof(this))();
148 		ptrcall!(void)(GDNativeClassBinding.addOutline, _godot_object, outline);
149 	}
150 	/**
151 	Adds a $(D PoolVector2Array) that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position. You have to call $(D makePolygonsFromOutlines) in order for this array to be converted to polygons that the engine will use.
152 	*/
153 	void addOutlineAtIndex(in PoolVector2Array outline, in long index)
154 	{
155 		checkClassBinding!(typeof(this))();
156 		ptrcall!(void)(GDNativeClassBinding.addOutlineAtIndex, _godot_object, outline, index);
157 	}
158 	/**
159 	Adds a polygon using the indices of the vertices you get when calling $(D getVertices).
160 	*/
161 	void addPolygon(in PoolIntArray polygon)
162 	{
163 		checkClassBinding!(typeof(this))();
164 		ptrcall!(void)(GDNativeClassBinding.addPolygon, _godot_object, polygon);
165 	}
166 	/**
167 	Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.
168 	*/
169 	void clearOutlines()
170 	{
171 		checkClassBinding!(typeof(this))();
172 		ptrcall!(void)(GDNativeClassBinding.clearOutlines, _godot_object);
173 	}
174 	/**
175 	Clears the array of polygons, but it doesn't clear the array of outlines and vertices.
176 	*/
177 	void clearPolygons()
178 	{
179 		checkClassBinding!(typeof(this))();
180 		ptrcall!(void)(GDNativeClassBinding.clearPolygons, _godot_object);
181 	}
182 	/**
183 	Returns a $(D PoolVector2Array) containing the vertices of an outline that was created in the editor or by script.
184 	*/
185 	PoolVector2Array getOutline(in long idx) const
186 	{
187 		checkClassBinding!(typeof(this))();
188 		return ptrcall!(PoolVector2Array)(GDNativeClassBinding.getOutline, _godot_object, idx);
189 	}
190 	/**
191 	Returns the number of outlines that were created in the editor or by script.
192 	*/
193 	long getOutlineCount() const
194 	{
195 		checkClassBinding!(typeof(this))();
196 		return ptrcall!(long)(GDNativeClassBinding.getOutlineCount, _godot_object);
197 	}
198 	/**
199 	Returns a $(D PoolIntArray) containing the indices of the vertices of a created polygon.
200 	*/
201 	PoolIntArray getPolygon(in long idx)
202 	{
203 		checkClassBinding!(typeof(this))();
204 		return ptrcall!(PoolIntArray)(GDNativeClassBinding.getPolygon, _godot_object, idx);
205 	}
206 	/**
207 	Returns the count of all polygons.
208 	*/
209 	long getPolygonCount() const
210 	{
211 		checkClassBinding!(typeof(this))();
212 		return ptrcall!(long)(GDNativeClassBinding.getPolygonCount, _godot_object);
213 	}
214 	/**
215 	Returns a $(D PoolVector2Array) containing all the vertices being used to create the polygons.
216 	*/
217 	PoolVector2Array getVertices() const
218 	{
219 		checkClassBinding!(typeof(this))();
220 		return ptrcall!(PoolVector2Array)(GDNativeClassBinding.getVertices, _godot_object);
221 	}
222 	/**
223 	Creates polygons from the outlines added in the editor or by script.
224 	*/
225 	void makePolygonsFromOutlines()
226 	{
227 		checkClassBinding!(typeof(this))();
228 		ptrcall!(void)(GDNativeClassBinding.makePolygonsFromOutlines, _godot_object);
229 	}
230 	/**
231 	Removes an outline created in the editor or by script. You have to call $(D makePolygonsFromOutlines) for the polygons to update.
232 	*/
233 	void removeOutline(in long idx)
234 	{
235 		checkClassBinding!(typeof(this))();
236 		ptrcall!(void)(GDNativeClassBinding.removeOutline, _godot_object, idx);
237 	}
238 	/**
239 	Changes an outline created in the editor or by script. You have to call $(D makePolygonsFromOutlines) for the polygons to update.
240 	*/
241 	void setOutline(in long idx, in PoolVector2Array outline)
242 	{
243 		checkClassBinding!(typeof(this))();
244 		ptrcall!(void)(GDNativeClassBinding.setOutline, _godot_object, idx, outline);
245 	}
246 	/**
247 	Sets the vertices that can be then indexed to create polygons with the $(D addPolygon) method.
248 	*/
249 	void setVertices(in PoolVector2Array vertices)
250 	{
251 		checkClassBinding!(typeof(this))();
252 		ptrcall!(void)(GDNativeClassBinding.setVertices, _godot_object, vertices);
253 	}
254 	/**
255 	
256 	*/
257 	@property Array outlines()
258 	{
259 		return _getOutlines();
260 	}
261 	/// ditto
262 	@property void outlines(Array v)
263 	{
264 		_setOutlines(v);
265 	}
266 	/**
267 	
268 	*/
269 	@property Array polygons()
270 	{
271 		return _getPolygons();
272 	}
273 	/// ditto
274 	@property void polygons(Array v)
275 	{
276 		_setPolygons(v);
277 	}
278 	/**
279 	
280 	*/
281 	@property PoolVector2Array vertices()
282 	{
283 		return getVertices();
284 	}
285 	/// ditto
286 	@property void vertices(PoolVector2Array v)
287 	{
288 		setVertices(v);
289 	}
290 }