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.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.classdb; 23 import godot.node2d; 24 import godot.navigationpolygon; 25 import godot.canvasitem; 26 import godot.node; 27 /** 28 2D navigation and pathfinding node. 29 30 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). 31 */ 32 @GodotBaseClass struct Navigation2D 33 { 34 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 _classBinding 42 { 43 __gshared: 44 @GodotName("navpoly_add") GodotMethod!(long, NavigationPolygon, Transform2D, GodotObject) navpolyAdd; 45 @GodotName("navpoly_set_transform") GodotMethod!(void, long, Transform2D) navpolySetTransform; 46 @GodotName("navpoly_remove") GodotMethod!(void, long) navpolyRemove; 47 @GodotName("get_simple_path") GodotMethod!(PoolVector2Array, Vector2, Vector2, bool) getSimplePath; 48 @GodotName("get_closest_point") GodotMethod!(Vector2, Vector2) getClosestPoint; 49 @GodotName("get_closest_point_owner") GodotMethod!(GodotObject, Vector2) getClosestPointOwner; 50 } 51 bool opEquals(in Navigation2D other) const { return _godot_object.ptr is other._godot_object.ptr; } 52 Navigation2D opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 53 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 54 mixin baseCasts; 55 static Navigation2D _new() 56 { 57 static godot_class_constructor constructor; 58 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Navigation2D"); 59 if(constructor is null) return typeof(this).init; 60 return cast(Navigation2D)(constructor()); 61 } 62 @disable new(size_t s); 63 /** 64 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). 65 */ 66 long navpolyAdd(NavigationPolygon mesh, in Transform2D xform, GodotObject owner = GodotObject.init) 67 { 68 checkClassBinding!(typeof(this))(); 69 return ptrcall!(long)(_classBinding.navpolyAdd, _godot_object, mesh, xform, owner); 70 } 71 /** 72 Sets the transform applied to the $(D NavigationPolygon) with the given ID. 73 */ 74 void navpolySetTransform(in long id, in Transform2D xform) 75 { 76 checkClassBinding!(typeof(this))(); 77 ptrcall!(void)(_classBinding.navpolySetTransform, _godot_object, id, xform); 78 } 79 /** 80 Removes the $(D NavigationPolygon) with the given ID. 81 */ 82 void navpolyRemove(in long id) 83 { 84 checkClassBinding!(typeof(this))(); 85 ptrcall!(void)(_classBinding.navpolyRemove, _godot_object, id); 86 } 87 /** 88 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. 89 */ 90 PoolVector2Array getSimplePath(in Vector2 start, in Vector2 end, in bool optimize = true) 91 { 92 checkClassBinding!(typeof(this))(); 93 return ptrcall!(PoolVector2Array)(_classBinding.getSimplePath, _godot_object, start, end, optimize); 94 } 95 /** 96 Returns the navigation point closest to the point given. Points are in local coordinate space. 97 */ 98 Vector2 getClosestPoint(in Vector2 to_point) 99 { 100 checkClassBinding!(typeof(this))(); 101 return ptrcall!(Vector2)(_classBinding.getClosestPoint, _godot_object, to_point); 102 } 103 /** 104 Returns the owner of the $(D NavigationPolygon) which contains the navigation point closest to the point given. This is usually a $(D NavigtionPolygonInstance). For polygons added via $(D navpolyAdd), returns the owner that was given (or `null` if the `owner` parameter was omitted). 105 */ 106 GodotObject getClosestPointOwner(in Vector2 to_point) 107 { 108 checkClassBinding!(typeof(this))(); 109 return ptrcall!(GodotObject)(_classBinding.getClosestPointOwner, _godot_object, to_point); 110 } 111 }