1 /**
2 Node that represents collision shape data 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.collisionshape2d;
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.node2d;
25 import godot.shape2d;
26 /**
27 Node that represents collision shape data in 2D space.
28 
29 Editor facility for creating and editing collision shapes in 2D space. You can use this node to represent all sorts of collision shapes, for example, add this to an $(D Area2D) to give it a detection shape, or add it to a $(D PhysicsBody2D) to create a solid object. $(B IMPORTANT): this is an Editor-only helper to create shapes, use $(D CollisionObject2D.shapeOwnerGetShape) to get the actual shape.
30 */
31 @GodotBaseClass struct CollisionShape2D
32 {
33 	package(godot) enum string _GODOT_internal_name = "CollisionShape2D";
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("_shape_changed") GodotMethod!(void) _shapeChanged;
44 		@GodotName("get_one_way_collision_margin") GodotMethod!(double) getOneWayCollisionMargin;
45 		@GodotName("get_shape") GodotMethod!(Shape2D) getShape;
46 		@GodotName("is_disabled") GodotMethod!(bool) isDisabled;
47 		@GodotName("is_one_way_collision_enabled") GodotMethod!(bool) isOneWayCollisionEnabled;
48 		@GodotName("set_disabled") GodotMethod!(void, bool) setDisabled;
49 		@GodotName("set_one_way_collision") GodotMethod!(void, bool) setOneWayCollision;
50 		@GodotName("set_one_way_collision_margin") GodotMethod!(void, double) setOneWayCollisionMargin;
51 		@GodotName("set_shape") GodotMethod!(void, Shape2D) setShape;
52 	}
53 	/// 
54 	pragma(inline, true) bool opEquals(in CollisionShape2D other) const
55 	{ return _godot_object.ptr is other._godot_object.ptr; }
56 	/// 
57 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
58 	{ _godot_object.ptr = n; return null; }
59 	/// 
60 	pragma(inline, true) bool opEquals(typeof(null) n) const
61 	{ return _godot_object.ptr is n; }
62 	/// 
63 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
64 	mixin baseCasts;
65 	/// Construct a new instance of CollisionShape2D.
66 	/// Note: use `memnew!CollisionShape2D` instead.
67 	static CollisionShape2D _new()
68 	{
69 		static godot_class_constructor constructor;
70 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("CollisionShape2D");
71 		if(constructor is null) return typeof(this).init;
72 		return cast(CollisionShape2D)(constructor());
73 	}
74 	@disable new(size_t s);
75 	/**
76 	
77 	*/
78 	void _shapeChanged()
79 	{
80 		Array _GODOT_args = Array.make();
81 		String _GODOT_method_name = String("_shape_changed");
82 		this.callv(_GODOT_method_name, _GODOT_args);
83 	}
84 	/**
85 	
86 	*/
87 	double getOneWayCollisionMargin() const
88 	{
89 		checkClassBinding!(typeof(this))();
90 		return ptrcall!(double)(GDNativeClassBinding.getOneWayCollisionMargin, _godot_object);
91 	}
92 	/**
93 	
94 	*/
95 	Ref!Shape2D getShape() const
96 	{
97 		checkClassBinding!(typeof(this))();
98 		return ptrcall!(Shape2D)(GDNativeClassBinding.getShape, _godot_object);
99 	}
100 	/**
101 	
102 	*/
103 	bool isDisabled() const
104 	{
105 		checkClassBinding!(typeof(this))();
106 		return ptrcall!(bool)(GDNativeClassBinding.isDisabled, _godot_object);
107 	}
108 	/**
109 	
110 	*/
111 	bool isOneWayCollisionEnabled() const
112 	{
113 		checkClassBinding!(typeof(this))();
114 		return ptrcall!(bool)(GDNativeClassBinding.isOneWayCollisionEnabled, _godot_object);
115 	}
116 	/**
117 	
118 	*/
119 	void setDisabled(in bool disabled)
120 	{
121 		checkClassBinding!(typeof(this))();
122 		ptrcall!(void)(GDNativeClassBinding.setDisabled, _godot_object, disabled);
123 	}
124 	/**
125 	
126 	*/
127 	void setOneWayCollision(in bool enabled)
128 	{
129 		checkClassBinding!(typeof(this))();
130 		ptrcall!(void)(GDNativeClassBinding.setOneWayCollision, _godot_object, enabled);
131 	}
132 	/**
133 	
134 	*/
135 	void setOneWayCollisionMargin(in double margin)
136 	{
137 		checkClassBinding!(typeof(this))();
138 		ptrcall!(void)(GDNativeClassBinding.setOneWayCollisionMargin, _godot_object, margin);
139 	}
140 	/**
141 	
142 	*/
143 	void setShape(Shape2D shape)
144 	{
145 		checkClassBinding!(typeof(this))();
146 		ptrcall!(void)(GDNativeClassBinding.setShape, _godot_object, shape);
147 	}
148 	/**
149 	A disabled collision shape has no effect in the world. This property should be changed with $(D GodotObject.setDeferred).
150 	*/
151 	@property bool disabled()
152 	{
153 		return isDisabled();
154 	}
155 	/// ditto
156 	@property void disabled(bool v)
157 	{
158 		setDisabled(v);
159 	}
160 	/**
161 	Sets whether this collision shape should only detect collision on one side (top or bottom).
162 	*/
163 	@property bool oneWayCollision()
164 	{
165 		return isOneWayCollisionEnabled();
166 	}
167 	/// ditto
168 	@property void oneWayCollision(bool v)
169 	{
170 		setOneWayCollision(v);
171 	}
172 	/**
173 	The margin used for one-way collision (in pixels). Higher values will make the shape thicker, and work better for colliders that enter the shape at a high velocity.
174 	*/
175 	@property double oneWayCollisionMargin()
176 	{
177 		return getOneWayCollisionMargin();
178 	}
179 	/// ditto
180 	@property void oneWayCollisionMargin(double v)
181 	{
182 		setOneWayCollisionMargin(v);
183 	}
184 	/**
185 	The actual shape owned by this collision shape.
186 	*/
187 	@property Shape2D shape()
188 	{
189 		return getShape();
190 	}
191 	/// ditto
192 	@property void shape(Shape2D v)
193 	{
194 		setShape(v);
195 	}
196 }