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