1 /** 2 2D navigation and pathfinding node. 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.navigation2d; 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.navigationpolygon; 26 /** 27 2D navigation and pathfinding node. 28 29 Navigation2D provides navigation and pathfinding within a 2D area, specified as a collection of $(D NavigationPolygon) resources. By default, these are automatically collected from child $(D NavigationPolygonInstance) nodes, but they can also be added on the fly with $(D navpolyAdd). 30 $(B Note:) The current navigation system has many known issues and will not always return optimal paths as expected. These issues will be fixed in Godot 4.0. 31 */ 32 @GodotBaseClass struct Navigation2D 33 { 34 package(godot) enum string _GODOT_internal_name = "Navigation2D"; 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 GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("get_closest_point") GodotMethod!(Vector2, Vector2) getClosestPoint; 45 @GodotName("get_closest_point_owner") GodotMethod!(GodotObject, Vector2) getClosestPointOwner; 46 @GodotName("get_simple_path") GodotMethod!(PoolVector2Array, Vector2, Vector2, bool) getSimplePath; 47 @GodotName("navpoly_add") GodotMethod!(long, NavigationPolygon, Transform2D, GodotObject) navpolyAdd; 48 @GodotName("navpoly_remove") GodotMethod!(void, long) navpolyRemove; 49 @GodotName("navpoly_set_transform") GodotMethod!(void, long, Transform2D) navpolySetTransform; 50 } 51 /// 52 pragma(inline, true) bool opEquals(in Navigation2D other) const 53 { return _godot_object.ptr is other._godot_object.ptr; } 54 /// 55 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 56 { _godot_object.ptr = n; return null; } 57 /// 58 pragma(inline, true) bool opEquals(typeof(null) n) const 59 { return _godot_object.ptr is n; } 60 /// 61 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 62 mixin baseCasts; 63 /// Construct a new instance of Navigation2D. 64 /// Note: use `memnew!Navigation2D` instead. 65 static Navigation2D _new() 66 { 67 static godot_class_constructor constructor; 68 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Navigation2D"); 69 if(constructor is null) return typeof(this).init; 70 return cast(Navigation2D)(constructor()); 71 } 72 @disable new(size_t s); 73 /** 74 Returns the navigation point closest to the point given. Points are in local coordinate space. 75 */ 76 Vector2 getClosestPoint(in Vector2 to_point) 77 { 78 checkClassBinding!(typeof(this))(); 79 return ptrcall!(Vector2)(GDNativeClassBinding.getClosestPoint, _godot_object, to_point); 80 } 81 /** 82 Returns the owner of the $(D NavigationPolygon) which contains the navigation point closest to the point given. This is usually a $(D NavigationPolygonInstance). For polygons added via $(D navpolyAdd), returns the owner that was given (or `null` if the `owner` parameter was omitted). 83 */ 84 GodotObject getClosestPointOwner(in Vector2 to_point) 85 { 86 checkClassBinding!(typeof(this))(); 87 return ptrcall!(GodotObject)(GDNativeClassBinding.getClosestPointOwner, _godot_object, to_point); 88 } 89 /** 90 Returns the path between two given points. Points are in local coordinate space. If `optimize` is `true` (the default), the path is smoothed by merging path segments where possible. 91 $(B Note:) This method has known issues and will often return non-optimal paths. These issues will be fixed in Godot 4.0. 92 */ 93 PoolVector2Array getSimplePath(in Vector2 start, in Vector2 end, in bool optimize = true) 94 { 95 checkClassBinding!(typeof(this))(); 96 return ptrcall!(PoolVector2Array)(GDNativeClassBinding.getSimplePath, _godot_object, start, end, optimize); 97 } 98 /** 99 Adds a $(D NavigationPolygon). Returns an ID for use with $(D navpolyRemove) or $(D navpolySetTransform). If given, a $(D Transform2D) is applied to the polygon. The optional `owner` is used as return value for $(D getClosestPointOwner). 100 */ 101 long navpolyAdd(NavigationPolygon mesh, in Transform2D xform, GodotObject owner = GodotObject.init) 102 { 103 checkClassBinding!(typeof(this))(); 104 return ptrcall!(long)(GDNativeClassBinding.navpolyAdd, _godot_object, mesh, xform, owner); 105 } 106 /** 107 Removes the $(D NavigationPolygon) with the given ID. 108 */ 109 void navpolyRemove(in long id) 110 { 111 checkClassBinding!(typeof(this))(); 112 ptrcall!(void)(GDNativeClassBinding.navpolyRemove, _godot_object, id); 113 } 114 /** 115 Sets the transform applied to the $(D NavigationPolygon) with the given ID. 116 */ 117 void navpolySetTransform(in long id, in Transform2D xform) 118 { 119 checkClassBinding!(typeof(this))(); 120 ptrcall!(void)(GDNativeClassBinding.navpolySetTransform, _godot_object, id, xform); 121 } 122 }