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