1 /**
2 Base node for 2D collision objects.
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.collisionobject2d;
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.node2d;
24 import godot.inputevent;
25 import godot.shape2d;
26 /**
27 Base node for 2D collision objects.
28 
29 CollisionObject2D is the base class for 2D physics objects. It can hold any number of 2D collision $(D Shape2D)s. Each shape must be assigned to a $(I shape owner). The CollisionObject2D can have any number of shape owners. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the `shape_owner_*` methods.
30 */
31 @GodotBaseClass struct CollisionObject2D
32 {
33 	package(godot) enum string _GODOT_internal_name = "CollisionObject2D";
34 public:
35 @nogc nothrow:
36 	union { /** */ godot_object _godot_object; /** */ Node2D _GODOT_base; }
37 	alias _GODOT_base this;
38 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
39 	package(godot) __gshared bool _classBindingInitialized = false;
40 	package(godot) static struct GDNativeClassBinding
41 	{
42 		__gshared:
43 		@GodotName("_input_event") GodotMethod!(void, GodotObject, InputEvent, long) _inputEvent;
44 		@GodotName("create_shape_owner") GodotMethod!(long, GodotObject) createShapeOwner;
45 		@GodotName("get_rid") GodotMethod!(RID) getRid;
46 		@GodotName("get_shape_owner_one_way_collision_margin") GodotMethod!(double, long) getShapeOwnerOneWayCollisionMargin;
47 		@GodotName("get_shape_owners") GodotMethod!(Array) getShapeOwners;
48 		@GodotName("is_pickable") GodotMethod!(bool) isPickable;
49 		@GodotName("is_shape_owner_disabled") GodotMethod!(bool, long) isShapeOwnerDisabled;
50 		@GodotName("is_shape_owner_one_way_collision_enabled") GodotMethod!(bool, long) isShapeOwnerOneWayCollisionEnabled;
51 		@GodotName("remove_shape_owner") GodotMethod!(void, long) removeShapeOwner;
52 		@GodotName("set_pickable") GodotMethod!(void, bool) setPickable;
53 		@GodotName("shape_find_owner") GodotMethod!(long, long) shapeFindOwner;
54 		@GodotName("shape_owner_add_shape") GodotMethod!(void, long, Shape2D) shapeOwnerAddShape;
55 		@GodotName("shape_owner_clear_shapes") GodotMethod!(void, long) shapeOwnerClearShapes;
56 		@GodotName("shape_owner_get_owner") GodotMethod!(GodotObject, long) shapeOwnerGetOwner;
57 		@GodotName("shape_owner_get_shape") GodotMethod!(Shape2D, long, long) shapeOwnerGetShape;
58 		@GodotName("shape_owner_get_shape_count") GodotMethod!(long, long) shapeOwnerGetShapeCount;
59 		@GodotName("shape_owner_get_shape_index") GodotMethod!(long, long, long) shapeOwnerGetShapeIndex;
60 		@GodotName("shape_owner_get_transform") GodotMethod!(Transform2D, long) shapeOwnerGetTransform;
61 		@GodotName("shape_owner_remove_shape") GodotMethod!(void, long, long) shapeOwnerRemoveShape;
62 		@GodotName("shape_owner_set_disabled") GodotMethod!(void, long, bool) shapeOwnerSetDisabled;
63 		@GodotName("shape_owner_set_one_way_collision") GodotMethod!(void, long, bool) shapeOwnerSetOneWayCollision;
64 		@GodotName("shape_owner_set_one_way_collision_margin") GodotMethod!(void, long, double) shapeOwnerSetOneWayCollisionMargin;
65 		@GodotName("shape_owner_set_transform") GodotMethod!(void, long, Transform2D) shapeOwnerSetTransform;
66 	}
67 	/// 
68 	pragma(inline, true) bool opEquals(in CollisionObject2D other) const
69 	{ return _godot_object.ptr is other._godot_object.ptr; }
70 	/// 
71 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
72 	{ _godot_object.ptr = n; return null; }
73 	/// 
74 	pragma(inline, true) bool opEquals(typeof(null) n) const
75 	{ return _godot_object.ptr is n; }
76 	/// 
77 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
78 	mixin baseCasts;
79 	/// Construct a new instance of CollisionObject2D.
80 	/// Note: use `memnew!CollisionObject2D` instead.
81 	static CollisionObject2D _new()
82 	{
83 		static godot_class_constructor constructor;
84 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("CollisionObject2D");
85 		if(constructor is null) return typeof(this).init;
86 		return cast(CollisionObject2D)(constructor());
87 	}
88 	@disable new(size_t s);
89 	/**
90 	Accepts unhandled $(D InputEvent)s. Requires $(D inputPickable) to be `true`. `shape_idx` is the child index of the clicked $(D Shape2D). Connect to the `input_event` signal to easily pick up these events.
91 	*/
92 	void _inputEvent(GodotObject viewport, InputEvent event, in long shape_idx)
93 	{
94 		Array _GODOT_args = Array.make();
95 		_GODOT_args.append(viewport);
96 		_GODOT_args.append(event);
97 		_GODOT_args.append(shape_idx);
98 		String _GODOT_method_name = String("_input_event");
99 		this.callv(_GODOT_method_name, _GODOT_args);
100 	}
101 	/**
102 	Creates a new shape owner for the given object. Returns `owner_id` of the new owner for future reference.
103 	*/
104 	long createShapeOwner(GodotObject owner)
105 	{
106 		checkClassBinding!(typeof(this))();
107 		return ptrcall!(long)(GDNativeClassBinding.createShapeOwner, _godot_object, owner);
108 	}
109 	/**
110 	Returns the object's $(D RID).
111 	*/
112 	RID getRid() const
113 	{
114 		checkClassBinding!(typeof(this))();
115 		return ptrcall!(RID)(GDNativeClassBinding.getRid, _godot_object);
116 	}
117 	/**
118 	Returns the `one_way_collision_margin` of the shape owner identified by given `owner_id`.
119 	*/
120 	double getShapeOwnerOneWayCollisionMargin(in long owner_id) const
121 	{
122 		checkClassBinding!(typeof(this))();
123 		return ptrcall!(double)(GDNativeClassBinding.getShapeOwnerOneWayCollisionMargin, _godot_object, owner_id);
124 	}
125 	/**
126 	Returns an $(D Array) of `owner_id` identifiers. You can use these ids in other methods that take `owner_id` as an argument.
127 	*/
128 	Array getShapeOwners()
129 	{
130 		checkClassBinding!(typeof(this))();
131 		return ptrcall!(Array)(GDNativeClassBinding.getShapeOwners, _godot_object);
132 	}
133 	/**
134 	
135 	*/
136 	bool isPickable() const
137 	{
138 		checkClassBinding!(typeof(this))();
139 		return ptrcall!(bool)(GDNativeClassBinding.isPickable, _godot_object);
140 	}
141 	/**
142 	If `true`, the shape owner and its shapes are disabled.
143 	*/
144 	bool isShapeOwnerDisabled(in long owner_id) const
145 	{
146 		checkClassBinding!(typeof(this))();
147 		return ptrcall!(bool)(GDNativeClassBinding.isShapeOwnerDisabled, _godot_object, owner_id);
148 	}
149 	/**
150 	Returns `true` if collisions for the shape owner originating from this $(D CollisionObject2D) will not be reported to collided with $(D CollisionObject2D)s.
151 	*/
152 	bool isShapeOwnerOneWayCollisionEnabled(in long owner_id) const
153 	{
154 		checkClassBinding!(typeof(this))();
155 		return ptrcall!(bool)(GDNativeClassBinding.isShapeOwnerOneWayCollisionEnabled, _godot_object, owner_id);
156 	}
157 	/**
158 	Removes the given shape owner.
159 	*/
160 	void removeShapeOwner(in long owner_id)
161 	{
162 		checkClassBinding!(typeof(this))();
163 		ptrcall!(void)(GDNativeClassBinding.removeShapeOwner, _godot_object, owner_id);
164 	}
165 	/**
166 	
167 	*/
168 	void setPickable(in bool enabled)
169 	{
170 		checkClassBinding!(typeof(this))();
171 		ptrcall!(void)(GDNativeClassBinding.setPickable, _godot_object, enabled);
172 	}
173 	/**
174 	Returns the `owner_id` of the given shape.
175 	*/
176 	long shapeFindOwner(in long shape_index) const
177 	{
178 		checkClassBinding!(typeof(this))();
179 		return ptrcall!(long)(GDNativeClassBinding.shapeFindOwner, _godot_object, shape_index);
180 	}
181 	/**
182 	Adds a $(D Shape2D) to the shape owner.
183 	*/
184 	void shapeOwnerAddShape(in long owner_id, Shape2D shape)
185 	{
186 		checkClassBinding!(typeof(this))();
187 		ptrcall!(void)(GDNativeClassBinding.shapeOwnerAddShape, _godot_object, owner_id, shape);
188 	}
189 	/**
190 	Removes all shapes from the shape owner.
191 	*/
192 	void shapeOwnerClearShapes(in long owner_id)
193 	{
194 		checkClassBinding!(typeof(this))();
195 		ptrcall!(void)(GDNativeClassBinding.shapeOwnerClearShapes, _godot_object, owner_id);
196 	}
197 	/**
198 	Returns the parent object of the given shape owner.
199 	*/
200 	GodotObject shapeOwnerGetOwner(in long owner_id) const
201 	{
202 		checkClassBinding!(typeof(this))();
203 		return ptrcall!(GodotObject)(GDNativeClassBinding.shapeOwnerGetOwner, _godot_object, owner_id);
204 	}
205 	/**
206 	Returns the $(D Shape2D) with the given id from the given shape owner.
207 	*/
208 	Ref!Shape2D shapeOwnerGetShape(in long owner_id, in long shape_id) const
209 	{
210 		checkClassBinding!(typeof(this))();
211 		return ptrcall!(Shape2D)(GDNativeClassBinding.shapeOwnerGetShape, _godot_object, owner_id, shape_id);
212 	}
213 	/**
214 	Returns the number of shapes the given shape owner contains.
215 	*/
216 	long shapeOwnerGetShapeCount(in long owner_id) const
217 	{
218 		checkClassBinding!(typeof(this))();
219 		return ptrcall!(long)(GDNativeClassBinding.shapeOwnerGetShapeCount, _godot_object, owner_id);
220 	}
221 	/**
222 	Returns the child index of the $(D Shape2D) with the given id from the given shape owner.
223 	*/
224 	long shapeOwnerGetShapeIndex(in long owner_id, in long shape_id) const
225 	{
226 		checkClassBinding!(typeof(this))();
227 		return ptrcall!(long)(GDNativeClassBinding.shapeOwnerGetShapeIndex, _godot_object, owner_id, shape_id);
228 	}
229 	/**
230 	Returns the shape owner's $(D Transform2D).
231 	*/
232 	Transform2D shapeOwnerGetTransform(in long owner_id) const
233 	{
234 		checkClassBinding!(typeof(this))();
235 		return ptrcall!(Transform2D)(GDNativeClassBinding.shapeOwnerGetTransform, _godot_object, owner_id);
236 	}
237 	/**
238 	Removes a shape from the given shape owner.
239 	*/
240 	void shapeOwnerRemoveShape(in long owner_id, in long shape_id)
241 	{
242 		checkClassBinding!(typeof(this))();
243 		ptrcall!(void)(GDNativeClassBinding.shapeOwnerRemoveShape, _godot_object, owner_id, shape_id);
244 	}
245 	/**
246 	If `true`, disables the given shape owner.
247 	*/
248 	void shapeOwnerSetDisabled(in long owner_id, in bool disabled)
249 	{
250 		checkClassBinding!(typeof(this))();
251 		ptrcall!(void)(GDNativeClassBinding.shapeOwnerSetDisabled, _godot_object, owner_id, disabled);
252 	}
253 	/**
254 	If `enable` is `true`, collisions for the shape owner originating from this $(D CollisionObject2D) will not be reported to collided with $(D CollisionObject2D)s.
255 	*/
256 	void shapeOwnerSetOneWayCollision(in long owner_id, in bool enable)
257 	{
258 		checkClassBinding!(typeof(this))();
259 		ptrcall!(void)(GDNativeClassBinding.shapeOwnerSetOneWayCollision, _godot_object, owner_id, enable);
260 	}
261 	/**
262 	Sets the `one_way_collision_margin` of the shape owner identified by given `owner_id` to `margin` pixels.
263 	*/
264 	void shapeOwnerSetOneWayCollisionMargin(in long owner_id, in double margin)
265 	{
266 		checkClassBinding!(typeof(this))();
267 		ptrcall!(void)(GDNativeClassBinding.shapeOwnerSetOneWayCollisionMargin, _godot_object, owner_id, margin);
268 	}
269 	/**
270 	Sets the $(D Transform2D) of the given shape owner.
271 	*/
272 	void shapeOwnerSetTransform(in long owner_id, in Transform2D transform)
273 	{
274 		checkClassBinding!(typeof(this))();
275 		ptrcall!(void)(GDNativeClassBinding.shapeOwnerSetTransform, _godot_object, owner_id, transform);
276 	}
277 	/**
278 	If `true`, this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least one `collision_layer` bit to be set.
279 	*/
280 	@property bool inputPickable()
281 	{
282 		return isPickable();
283 	}
284 	/// ditto
285 	@property void inputPickable(bool v)
286 	{
287 		setPickable(v);
288 	}
289 }