1 /**
2 Base class for all objects affected by physics in 2D space.
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.physicsbody2d;
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.collisionobject2d;
23 import godot.node2d;
24 import godot.canvasitem;
25 import godot.node;
26 /**
27 Base class for all objects affected by physics in 2D space.
28 
29 PhysicsBody2D is an abstract base class for implementing a physics body. All *Body2D types inherit from it.
30 */
31 @GodotBaseClass struct PhysicsBody2D
32 {
33 	enum string _GODOT_internal_name = "PhysicsBody2D";
34 public:
35 @nogc nothrow:
36 	union { godot_object _godot_object; CollisionObject2D _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 _classBinding
41 	{
42 		__gshared:
43 		@GodotName("set_collision_layer") GodotMethod!(void, long) setCollisionLayer;
44 		@GodotName("get_collision_layer") GodotMethod!(long) getCollisionLayer;
45 		@GodotName("set_collision_mask") GodotMethod!(void, long) setCollisionMask;
46 		@GodotName("get_collision_mask") GodotMethod!(long) getCollisionMask;
47 		@GodotName("set_collision_mask_bit") GodotMethod!(void, long, bool) setCollisionMaskBit;
48 		@GodotName("get_collision_mask_bit") GodotMethod!(bool, long) getCollisionMaskBit;
49 		@GodotName("set_collision_layer_bit") GodotMethod!(void, long, bool) setCollisionLayerBit;
50 		@GodotName("get_collision_layer_bit") GodotMethod!(bool, long) getCollisionLayerBit;
51 		@GodotName("_set_layers") GodotMethod!(void, long) _setLayers;
52 		@GodotName("_get_layers") GodotMethod!(long) _getLayers;
53 		@GodotName("get_collision_exceptions") GodotMethod!(Array) getCollisionExceptions;
54 		@GodotName("add_collision_exception_with") GodotMethod!(void, GodotObject) addCollisionExceptionWith;
55 		@GodotName("remove_collision_exception_with") GodotMethod!(void, GodotObject) removeCollisionExceptionWith;
56 	}
57 	bool opEquals(in PhysicsBody2D other) const { return _godot_object.ptr is other._godot_object.ptr; }
58 	PhysicsBody2D opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
59 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
60 	mixin baseCasts;
61 	static PhysicsBody2D _new()
62 	{
63 		static godot_class_constructor constructor;
64 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PhysicsBody2D");
65 		if(constructor is null) return typeof(this).init;
66 		return cast(PhysicsBody2D)(constructor());
67 	}
68 	@disable new(size_t s);
69 	/**
70 	
71 	*/
72 	void setCollisionLayer(in long layer)
73 	{
74 		checkClassBinding!(typeof(this))();
75 		ptrcall!(void)(_classBinding.setCollisionLayer, _godot_object, layer);
76 	}
77 	/**
78 	
79 	*/
80 	long getCollisionLayer() const
81 	{
82 		checkClassBinding!(typeof(this))();
83 		return ptrcall!(long)(_classBinding.getCollisionLayer, _godot_object);
84 	}
85 	/**
86 	
87 	*/
88 	void setCollisionMask(in long mask)
89 	{
90 		checkClassBinding!(typeof(this))();
91 		ptrcall!(void)(_classBinding.setCollisionMask, _godot_object, mask);
92 	}
93 	/**
94 	
95 	*/
96 	long getCollisionMask() const
97 	{
98 		checkClassBinding!(typeof(this))();
99 		return ptrcall!(long)(_classBinding.getCollisionMask, _godot_object);
100 	}
101 	/**
102 	Sets individual bits on the collision mask. Use this if you only need to change one layer's value.
103 	*/
104 	void setCollisionMaskBit(in long bit, in bool value)
105 	{
106 		checkClassBinding!(typeof(this))();
107 		ptrcall!(void)(_classBinding.setCollisionMaskBit, _godot_object, bit, value);
108 	}
109 	/**
110 	Returns an individual bit on the collision mask.
111 	*/
112 	bool getCollisionMaskBit(in long bit) const
113 	{
114 		checkClassBinding!(typeof(this))();
115 		return ptrcall!(bool)(_classBinding.getCollisionMaskBit, _godot_object, bit);
116 	}
117 	/**
118 	Sets individual bits on the layer mask. Use this if you only need to change one layer's value.
119 	*/
120 	void setCollisionLayerBit(in long bit, in bool value)
121 	{
122 		checkClassBinding!(typeof(this))();
123 		ptrcall!(void)(_classBinding.setCollisionLayerBit, _godot_object, bit, value);
124 	}
125 	/**
126 	Returns an individual bit on the collision mask.
127 	*/
128 	bool getCollisionLayerBit(in long bit) const
129 	{
130 		checkClassBinding!(typeof(this))();
131 		return ptrcall!(bool)(_classBinding.getCollisionLayerBit, _godot_object, bit);
132 	}
133 	/**
134 	
135 	*/
136 	void _setLayers(in long mask)
137 	{
138 		Array _GODOT_args = Array.empty_array;
139 		_GODOT_args.append(mask);
140 		String _GODOT_method_name = String("_set_layers");
141 		this.callv(_GODOT_method_name, _GODOT_args);
142 	}
143 	/**
144 	
145 	*/
146 	long _getLayers() const
147 	{
148 		Array _GODOT_args = Array.empty_array;
149 		String _GODOT_method_name = String("_get_layers");
150 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long);
151 	}
152 	/**
153 	Returns an array of nodes that were added as collision exceptions for this body.
154 	*/
155 	Array getCollisionExceptions()
156 	{
157 		checkClassBinding!(typeof(this))();
158 		return ptrcall!(Array)(_classBinding.getCollisionExceptions, _godot_object);
159 	}
160 	/**
161 	Adds a body to the list of bodies that this body can't collide with.
162 	*/
163 	void addCollisionExceptionWith(GodotObject _body)
164 	{
165 		checkClassBinding!(typeof(this))();
166 		ptrcall!(void)(_classBinding.addCollisionExceptionWith, _godot_object, _body);
167 	}
168 	/**
169 	Removes a body from the list of bodies that this body can't collide with.
170 	*/
171 	void removeCollisionExceptionWith(GodotObject _body)
172 	{
173 		checkClassBinding!(typeof(this))();
174 		ptrcall!(void)(_classBinding.removeCollisionExceptionWith, _godot_object, _body);
175 	}
176 	/**
177 	Both $(D collisionLayer) and $(D collisionMask). Returns $(D collisionLayer) when accessed. Updates $(D collisionLayer) and $(D collisionMask) when modified.
178 	*/
179 	@property long layers()
180 	{
181 		return _getLayers();
182 	}
183 	/// ditto
184 	@property void layers(long v)
185 	{
186 		_setLayers(v);
187 	}
188 	/**
189 	The physics layers this area is in.
190 	Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the collision_mask property.
191 	A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A.
192 	*/
193 	@property long collisionLayer()
194 	{
195 		return getCollisionLayer();
196 	}
197 	/// ditto
198 	@property void collisionLayer(long v)
199 	{
200 		setCollisionLayer(v);
201 	}
202 	/**
203 	The physics layers this area scans for collisions.
204 	*/
205 	@property long collisionMask()
206 	{
207 		return getCollisionMask();
208 	}
209 	/// ditto
210 	@property void collisionMask(long v)
211 	{
212 		setCollisionMask(v);
213 	}
214 }