phaser2-navmesh
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -1,2 +0,2 @@ | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.Phaser2NavMeshPlugin=n():t.Phaser2NavMeshPlugin=n()}(window,function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var i in t)e.d(r,i,function(n){return t[n]}.bind(null,i));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=1)}([function(t,n,e){var r,i,o;!function(n){"object"==typeof t&&"object"==typeof t.exports?t.exports=n():(i=[],void 0===(o="function"==typeof(r=n)?r.apply(void 0,i):r)||(t.exports=o))}(function(){function t(t){for(var n=t,e=[];n.parent;)e.unshift(n),n=n.parent;return e}var n={search:function(e,r,o,a){e.cleanDirty();var s=(a=a||{}).heuristic||n.heuristics.manhattan,u=a.closest||!1,h=new i(function(t){return t.f}),l=r;for(r.h=s(r,o),e.markDirty(r),h.push(r);h.size()>0;){var c=h.pop();if(c===o)return t(c);c.closed=!0;for(var f=e.neighbors(c),y=0,p=f.length;y<p;++y){var d=f[y];if(!d.closed&&!d.isWall()){var v=c.g+d.getCost(c),g=d.visited;(!g||v<d.g)&&(d.visited=!0,d.parent=c,d.h=d.h||s(d,o),d.g=v,d.f=d.g+d.h,e.markDirty(d),u&&(d.h<l.h||d.h===l.h&&d.g<l.g)&&(l=d),g?h.rescoreElement(d):h.push(d))}}}return u?t(l):[]},heuristics:{manhattan:function(t,n){return Math.abs(n.x-t.x)+Math.abs(n.y-t.y)},diagonal:function(t,n){var e=Math.sqrt(2),r=Math.abs(n.x-t.x),i=Math.abs(n.y-t.y);return 1*(r+i)+(e-2)*Math.min(r,i)}},cleanNode:function(t){t.f=0,t.g=0,t.h=0,t.visited=!1,t.closed=!1,t.parent=null}};function e(t,n){n=n||{},this.nodes=[],this.diagonal=!!n.diagonal,this.grid=[];for(var e=0;e<t.length;e++){this.grid[e]=[];for(var i=0,o=t[e];i<o.length;i++){var a=new r(e,i,o[i]);this.grid[e][i]=a,this.nodes.push(a)}}this.init()}function r(t,n,e){this.x=t,this.y=n,this.weight=e}function i(t){this.content=[],this.scoreFunction=t}return e.prototype.init=function(){this.dirtyNodes=[];for(var t=0;t<this.nodes.length;t++)n.cleanNode(this.nodes[t])},e.prototype.cleanDirty=function(){for(var t=0;t<this.dirtyNodes.length;t++)n.cleanNode(this.dirtyNodes[t]);this.dirtyNodes=[]},e.prototype.markDirty=function(t){this.dirtyNodes.push(t)},e.prototype.neighbors=function(t){var n=[],e=t.x,r=t.y,i=this.grid;return i[e-1]&&i[e-1][r]&&n.push(i[e-1][r]),i[e+1]&&i[e+1][r]&&n.push(i[e+1][r]),i[e]&&i[e][r-1]&&n.push(i[e][r-1]),i[e]&&i[e][r+1]&&n.push(i[e][r+1]),this.diagonal&&(i[e-1]&&i[e-1][r-1]&&n.push(i[e-1][r-1]),i[e+1]&&i[e+1][r-1]&&n.push(i[e+1][r-1]),i[e-1]&&i[e-1][r+1]&&n.push(i[e-1][r+1]),i[e+1]&&i[e+1][r+1]&&n.push(i[e+1][r+1])),n},e.prototype.toString=function(){for(var t=[],n=this.grid,e=0;e<n.length;e++){for(var r=[],i=n[e],o=0;o<i.length;o++)r.push(i[o].weight);t.push(r.join(" "))}return t.join("\n")},r.prototype.toString=function(){return"["+this.x+" "+this.y+"]"},r.prototype.getCost=function(t){return t&&t.x!=this.x&&t.y!=this.y?1.41421*this.weight:this.weight},r.prototype.isWall=function(){return 0===this.weight},i.prototype={push:function(t){this.content.push(t),this.sinkDown(this.content.length-1)},pop:function(){var t=this.content[0],n=this.content.pop();return this.content.length>0&&(this.content[0]=n,this.bubbleUp(0)),t},remove:function(t){var n=this.content.indexOf(t),e=this.content.pop();n!==this.content.length-1&&(this.content[n]=e,this.scoreFunction(e)<this.scoreFunction(t)?this.sinkDown(n):this.bubbleUp(n))},size:function(){return this.content.length},rescoreElement:function(t){this.sinkDown(this.content.indexOf(t))},sinkDown:function(t){for(var n=this.content[t];t>0;){var e=(t+1>>1)-1,r=this.content[e];if(!(this.scoreFunction(n)<this.scoreFunction(r)))break;this.content[e]=n,this.content[t]=r,t=e}},bubbleUp:function(t){for(var n=this.content.length,e=this.content[t],r=this.scoreFunction(e);;){var i,o=t+1<<1,a=o-1,s=null;if(a<n){var u=this.content[a];(i=this.scoreFunction(u))<r&&(s=a)}if(o<n){var h=this.content[o];this.scoreFunction(h)<(null===s?r:i)&&(s=o)}if(null===s)break;this.content[t]=this.content[s],this.content[s]=e,t=s}}},{astar:n,Graph:e}})},function(t,n,e){"use strict";e.r(n);var r=e(0),i=e.n(r),o=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var a=function(){function t(n,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.x=n||0,this.y=e||0}return o(t,[{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"angle",value:function(t){return Math.atan2(t.y-this.y,t.x-this.x)}},{key:"distance",value:function(t){var n=t.x-this.x,e=t.y-this.y;return Math.sqrt(n*n+e*e)}},{key:"add",value:function(t){this.x+=t.x,this.y+=t.y}},{key:"subtract",value:function(t){this.x-=t.x,this.y-=t.y}},{key:"clone",value:function(){return new t(this.x,this.y)}}]),t}(),s=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var u=function(){function t(n,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.id=n,this.polygon=e,this.edges=e.edges,this.neighbors=[],this.portals=[],this.centroid=this.calculateCentroid(),this.boundingRadius=this.calculateRadius(),this.weight=1}return s(t,[{key:"getPoints",value:function(){return this.polygon.points}},{key:"contains",value:function(t){return this.polygon.contains(t.x,t.y)||this.isPointOnEdge(t)}},{key:"calculateCentroid",value:function(){var t=new a(0,0),n=this.polygon.points.length;return this.polygon.points.forEach(function(n){return t.add(n)}),t.x/=n,t.y/=n,t}},{key:"calculateRadius",value:function(){var t=0,n=!0,e=!1,r=void 0;try{for(var i,o=this.polygon.points[Symbol.iterator]();!(n=(i=o.next()).done);n=!0){var a=i.value,s=this.centroid.distance(a);s>t&&(t=s)}}catch(t){e=!0,r=t}finally{try{!n&&o.return&&o.return()}finally{if(e)throw r}}return t}},{key:"isPointOnEdge",value:function(t){var n=t.x,e=t.y,r=!0,i=!1,o=void 0;try{for(var a,s=this.edges[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){if(a.value.pointOnSegment(n,e))return!0}}catch(t){i=!0,o=t}finally{try{!r&&s.return&&s.return()}finally{if(i)throw o}}return!1}},{key:"destroy",value:function(){this.neighbors=[],this.portals=[]}},{key:"toString",value:function(){return"NavPoly(id: "+this.id+" at: "+this.centroid+")"}},{key:"isWall",value:function(){return 0===this.weight}},{key:"centroidDistance",value:function(t){return this.centroid.distance(t.centroid)}},{key:"getCost",value:function(t){return this.centroidDistance(t)}}]),t}(),h=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var l=function(){function t(n){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.nodes=n,this.init()}return h(t,[{key:"neighbors",value:function(t){return t.neighbors}},{key:"navHeuristic",value:function(t,n){return t.centroidDistance(n)}},{key:"destroy",value:function(){this.cleanDirty(),this.nodes=[]}}]),t}();l.prototype.init=i.a.Graph.prototype.init,l.prototype.cleanDirty=i.a.Graph.prototype.cleanDirty,l.prototype.markDirty=i.a.Graph.prototype.markDirty;var c=l;function f(t,n,e){var r=n.x-t.x,i=n.y-t.y;return(e.x-t.x)*i-r*(e.y-t.y)}function y(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-4;return Math.abs(t-n)<=e}function p(t,n){var e=t-n,r=e+Math.PI,i=2*Math.PI;return e=r-Math.floor(r/i)*i,e-=Math.PI}function d(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-4,r=f(t.start,t.end,n.start),i=f(t.start,t.end,n.end);return!(!y(r,0,e)||!y(i,0,e))}var v=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var g=function(){function t(){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.portals=[]}return v(t,[{key:"push",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;null===n&&(n=t),this.portals.push({left:t,right:n})}},{key:"stringPull",value:function(){var t,n,e,r=this.portals,i=[],o=0,a=0,s=0;t=r[0].left,n=r[0].left,e=r[0].right,i.push(t);for(var u=1;u<r.length;u++){var h=r[u].left,l=r[u].right;if(f(t,e,l)<=0){if(!(t.equals(e)||f(t,n,l)>0)){i.push(n),n=t=n,e=t,a=o=a,s=o,u=o;continue}e=l,s=u}if(f(t,n,h)>=0){if(!(t.equals(n)||f(t,e,h)<0)){i.push(e),n=t=e,e=t,a=o=s,s=o,u=o;continue}n=h,a=u}}return 0!==i.length&&i[i.length-1].equals(r[r.length-1].left)||i.push(r[r.length-1].left),this.path=i,i}}]),t}(),b=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var x=function(){function t(n,e,r,i){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.start=new a(n,e),this.end=new a(r,i),this.left=Math.min(n,r),this.right=Math.max(n,r),this.top=Math.min(e,i),this.bottom=Math.max(e,i)}return b(t,[{key:"pointOnSegment",value:function(t,n){return t>=this.left&&t<=this.right&&n>=this.top&&n<=this.bottom&&this.pointOnLine(t,n)}},{key:"pointOnLine",value:function(t,n){return(t-this.left)*(this.bottom-this.top)==(this.right-this.left)*(n-this.top)}}]),t}(),w=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var m=function(){function t(n){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.points=n,this.edges=[];for(var r=1;r<n.length;r++){var i=n[r-1],o=n[r];this.edges.push(new x(i.x,i.y,o.x,o.y))}if(e){var a=n[0],s=n[n.length-1];this.edges.push(new x(a.x,a.y,s.x,s.y))}}return w(t,[{key:"contains",value:function(t,n){for(var e=!1,r=-1,i=this.points.length-1;++r<this.points.length;i=r){var o=this.points[r].x,a=this.points[r].y,s=this.points[i].x,u=this.points[i].y;(a<=n&&n<u||u<=n&&n<a)&&t<(s-o)*(n-a)/(u-a)+o&&(e=!e)}return e}}]),t}(),k=function(){return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,n){var e=[],r=!0,i=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(r=(a=s.next()).done)&&(e.push(a.value),!n||e.length!==n);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&s.return&&s.return()}finally{if(i)throw o}}return e}(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),P=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var _=function(){function t(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this._meshShrinkAmount=e;var r=n.map(function(t){var n=t.map(function(t){return new a(t.x,t.y)});return new m(n)});this._navPolygons=r.map(function(t,n){return new u(n,t)}),this._calculateNeighbors(),this._graph=new c(this._navPolygons)}return P(t,[{key:"getPolygons",value:function(){return this._navPolygons}},{key:"destroy",value:function(){this._graph.destroy();var t=!0,n=!1,e=void 0;try{for(var r,i=this._navPolygons[Symbol.iterator]();!(t=(r=i.next()).done);t=!0){r.value.destroy()}}catch(t){n=!0,e=t}finally{try{!t&&i.return&&i.return()}finally{if(n)throw e}}this._navPolygons=[]}},{key:"findPath",value:function(t,n){var e=null,r=null,o=Number.MAX_VALUE,s=Number.MAX_VALUE,u=void 0,h=void 0,l=new a(t.x,t.y),c=new a(n.x,n.y),f=!0,y=!1,p=void 0;try{for(var d,v=this._navPolygons[Symbol.iterator]();!(f=(d=v.next()).done);f=!0){var b=d.value;h=b.boundingRadius,(u=b.centroid.distance(l))<=o&&u<=h&&b.contains(l)&&(e=b,o=u),(u=b.centroid.distance(c))<=s&&u<=h&&b.contains(c)&&(r=b,s=u)}}catch(t){y=!0,p=t}finally{try{!f&&v.return&&v.return()}finally{if(y)throw p}}if(!e&&this._meshShrinkAmount>0){var x=!0,w=!1,m=void 0;try{for(var k,P=this._navPolygons[Symbol.iterator]();!(x=(k=P.next()).done);x=!0){var _=k.value;if(h=_.boundingRadius+this._meshShrinkAmount,(u=_.centroid.distance(l))<=h){var M=this._projectPointToPolygon(l,_).distance;M<=this._meshShrinkAmount&&M<o&&(e=_,o=M)}}}catch(t){w=!0,m=t}finally{try{!x&&P.return&&P.return()}finally{if(w)throw m}}}if(!r&&this._meshShrinkAmount>0){var G=!0,S=!1,j=void 0;try{for(var O,E=this._navPolygons[Symbol.iterator]();!(G=(O=E.next()).done);G=!0){var N=O.value;if(h=N.boundingRadius+this._meshShrinkAmount,(u=N.centroid.distance(c))<=h){var T=this._projectPointToPolygon(c,N).distance;T<=this._meshShrinkAmount&&T<s&&(r=N,s=T)}}}catch(t){S=!0,j=t}finally{try{!G&&E.return&&E.return()}finally{if(S)throw j}}}if(!e||!r)return null;if(e===r)return[l,c];var D=i.a.astar.search(this._graph,e,r,{heuristic:this._graph.navHeuristic});if(0===D.length)return null;D.unshift(e);var A=new g;A.push(l);for(var F=0;F<D.length-1;F++){for(var C=D[F],q=D[F+1],R=null,U=0;U<C.neighbors.length;U++)C.neighbors[U].id===q.id&&(R=C.portals[U]);A.push(R.start,R.end)}A.push(c),A.stringPull();var L=null,I=[],W=!0,V=!1,X=void 0;try{for(var z,H=A.path[Symbol.iterator]();!(W=(z=H.next()).done);W=!0){var B=z.value.clone();L&&B.equals(L)||I.push(B),L=B}}catch(t){V=!0,X=t}finally{try{!W&&H.return&&H.return()}finally{if(V)throw X}}return I}},{key:"_calculateNeighbors",value:function(){for(var t=0;t<this._navPolygons.length;t++)for(var n=this._navPolygons[t],e=t+1;e<this._navPolygons.length;e++){var r=this._navPolygons[e];if(!(n.centroid.distance(r.centroid)>n.boundingRadius+r.boundingRadius)){var i=!0,o=!1,a=void 0;try{for(var s,u=n.edges[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){var h=s.value,l=!0,c=!1,f=void 0;try{for(var y,v=r.edges[Symbol.iterator]();!(l=(y=v.next()).done);l=!0){var g=y.value;if(d(h,g)){var b=this._getSegmentOverlap(h,g);if(b){n.neighbors.push(r),r.neighbors.push(n);var w=k(b,2),m=w[0],P=w[1],_=n.centroid.angle(h.start),M=n.centroid.angle(b[0]),G=n.centroid.angle(b[1]),S=p(_,M),j=p(_,G);S<j?n.portals.push(new x(m.x,m.y,P.x,P.y)):n.portals.push(new x(P.x,P.y,m.x,m.y)),_=r.centroid.angle(g.start),M=r.centroid.angle(b[0]),G=r.centroid.angle(b[1]),(S=p(_,M))<(j=p(_,G))?r.portals.push(new x(m.x,m.y,P.x,P.y)):r.portals.push(new x(P.x,P.y,m.x,m.y))}}}}catch(t){c=!0,f=t}finally{try{!l&&v.return&&v.return()}finally{if(c)throw f}}}}catch(t){o=!0,a=t}finally{try{!i&&u.return&&u.return()}finally{if(o)throw a}}}}}},{key:"_getSegmentOverlap",value:function(t,n){var e=[{line:t,point:t.start},{line:t,point:t.end},{line:n,point:n.start},{line:n,point:n.end}];e.sort(function(t,n){return t.point.x<n.point.x?-1:t.point.x>n.point.x?1:t.point.y<n.point.y?-1:t.point.y>n.point.y?1:0});var r=e[0].line===e[1].line,i=e[1].point.equals(e[2].point);return r||i?null:[e[1].point,e[2].point]}},{key:"_projectPointToPolygon",value:function(t,n){var e=null,r=Number.MAX_VALUE,i=!0,o=!1,a=void 0;try{for(var s,u=n.edges[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){var h=s.value,l=this._projectPointToEdge(t,h),c=t.distance(l);(null===e||c<r)&&(r=c,e=l)}}catch(t){o=!0,a=t}finally{try{!i&&u.return&&u.return()}finally{if(o)throw a}}return{point:e,distance:r}}},{key:"_distanceSquared",value:function(t,n){var e=n.x-t.x,r=n.y-t.y;return e*e+r*r}},{key:"_projectPointToEdge",value:function(t,n){var e=n.start,r=n.end,i=this._distanceSquared(e,r),o=((t.x-e.x)*(r.x-e.x)+(t.y-e.y)*(r.y-e.y))/i;return o=function(t,n,e){return t<n&&(t=n),t>e&&(t=e),t}(o,0,1),new a(e.x+o*(r.x-e.x),e.y+o*(r.y-e.y))}}]),t}(),M=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();function G(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);n<t.length;n++)e[n]=t[n];return e}return Array.from(t)}var S=function(){function t(n,e,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.key=e,this.plugin=n,this.game=n.game,this.debugGraphics=null,this.navMesh=new _(r,i)}return M(t,[{key:"findPath",value:function(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Phaser.Point,r=this.navMesh.findPath(t,n);return r?r.map(function(t){var n=t.x,r=t.y;return new e(n,r)}):r}},{key:"enableDebug",value:function(t){return t||this.debugGraphics?t&&(this.debugGraphics&&this.debugGraphics.destroy(),this.debugGraphics=t):this.debugGraphics=this.game.add.graphics(),this.debugGraphics.visible=!0,this.debugGraphics}},{key:"disableDebug",value:function(){this.debugGraphics&&(this.debugGraphics.visible=!1)}},{key:"isDebugEnabled",value:function(){return this.debugGraphics&&this.debugGraphics.visible}},{key:"debugDrawClear",value:function(){this.debugGraphics&&this.debugGraphics.clear()}},{key:"debugDrawMesh",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=n.drawCentroid,r=void 0===e||e,i=n.drawBounds,o=void 0!==i&&i,a=n.drawNeighbors,s=void 0===a||a,u=n.drawPortals,h=void 0===u||u,l=n.palette,c=void 0===l?[41136,6965820,13382463,15427649,15583569]:l;this.debugGraphics&&this.navMesh.getPolygons().forEach(function(n){var e=c[n.id%c.length];if(t.debugGraphics.lineWidth=0,t.debugGraphics.beginFill(e),t.debugGraphics.drawPolygon(new(Function.prototype.bind.apply(Phaser.Polygon,[null].concat(G(n.getPoints()))))),t.debugGraphics.endFill(),r&&(t.debugGraphics.beginFill(0),t.debugGraphics.drawEllipse(n.centroid.x,n.centroid.y,4,4),t.debugGraphics.endFill()),o){t.debugGraphics.lineStyle(1,16777215);var i=n.boundingRadius;t.debugGraphics.drawEllipse(n.centroid.x,n.centroid.y,i,i)}s&&(t.debugGraphics.lineStyle(2,0),n.neighbors.forEach(function(e){t.debugGraphics.moveTo(n.centroid.x,n.centroid.y),t.debugGraphics.lineTo(e.centroid.x,e.centroid.y)})),h&&(t.debugGraphics.lineStyle(10,0),n.portals.forEach(function(n){t.debugGraphics.moveTo(n.start.x,n.start.y),t.debugGraphics.lineTo(n.end.x,n.end.y)}))})}},{key:"debugDrawPath",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:65280,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;if(this.debugGraphics&&t&&t.length){this.debugGraphics.lineStyle(e,n,r),this.debugGraphics.drawShape(new(Function.prototype.bind.apply(Phaser.Polygon,[null].concat(G(t))))),this.debugGraphics.beginFill(n,r);var i=.5*e;if(this.debugGraphics.drawEllipse(t[0].x,t[0].y,i,i),t.length>1){var o=t[t.length-1];this.debugGraphics.drawEllipse(o.x,o.y,i,i)}this.debugGraphics.endFill()}}},{key:"destroy",value:function(){this.navMesh&&this.navMesh.destroy(),this.debugGraphics&&this.debugGraphics.destroy(),this.plugin.removeMesh(this.key),this.navMesh=void 0,this.debugGraphics=void 0,this.plugin=void 0,this.scene=void 0}}]),t}(),j=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var O=function(t){function n(t,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,n);var r=function(t,n){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?t:n}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e));return r.phaserNavMeshes={},r}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(t,n):t.__proto__=n)}(n,Phaser.Plugin),j(n,[{key:"destroy",value:function(){this.systems.events.Object.values(this.phaserNavMeshes).forEach(function(t){return t.destroy()}),this.phaserNavMeshes=[],this.game=void 0}},{key:"removeMesh",value:function(t){this.phaserNavMeshes[t]&&(this.phaserNavMeshes[t].destroy(),this.phaserNavMeshes[t]=void 0)}},{key:"buildMeshFromTiled",value:function(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(this.phaserNavMeshes[t])return console.warn("NavMeshPlugin: a navmesh already exists with the given key: "+t),this.phaserNavMeshes[t];n&&0!==n.length||console.warn("NavMeshPlugin: The given tilemap object layer is empty or undefined: "+n);var r=(n||[]).map(function(t){var n=t.y,e=t.y+t.height,r=t.x,i=t.x+t.width;return[{x:r,y:n},{x:r,y:e},{x:i,y:e},{x:i,y:n}]}),i=new S(this,t,r,e);return this.phaserNavMeshes[t]=i,i}}]),n}();e.d(n,"Phaser2NavMesh",function(){return S});n.default=O}]).default}); | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.Phaser2NavMeshPlugin=n():t.Phaser2NavMeshPlugin=n()}(window,function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var i in t)e.d(r,i,function(n){return t[n]}.bind(null,i));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=1)}([function(t,n,e){var r,i,o;!function(n){"object"==typeof t&&"object"==typeof t.exports?t.exports=n():(i=[],void 0===(o="function"==typeof(r=n)?r.apply(void 0,i):r)||(t.exports=o))}(function(){function t(t){for(var n=t,e=[];n.parent;)e.unshift(n),n=n.parent;return e}var n={search:function(e,r,o,a){e.cleanDirty();var s=(a=a||{}).heuristic||n.heuristics.manhattan,u=a.closest||!1,h=new i(function(t){return t.f}),l=r;for(r.h=s(r,o),e.markDirty(r),h.push(r);h.size()>0;){var c=h.pop();if(c===o)return t(c);c.closed=!0;for(var f=e.neighbors(c),y=0,p=f.length;y<p;++y){var d=f[y];if(!d.closed&&!d.isWall()){var v=c.g+d.getCost(c),g=d.visited;(!g||v<d.g)&&(d.visited=!0,d.parent=c,d.h=d.h||s(d,o),d.g=v,d.f=d.g+d.h,e.markDirty(d),u&&(d.h<l.h||d.h===l.h&&d.g<l.g)&&(l=d),g?h.rescoreElement(d):h.push(d))}}}return u?t(l):[]},heuristics:{manhattan:function(t,n){return Math.abs(n.x-t.x)+Math.abs(n.y-t.y)},diagonal:function(t,n){var e=Math.sqrt(2),r=Math.abs(n.x-t.x),i=Math.abs(n.y-t.y);return 1*(r+i)+(e-2)*Math.min(r,i)}},cleanNode:function(t){t.f=0,t.g=0,t.h=0,t.visited=!1,t.closed=!1,t.parent=null}};function e(t,n){n=n||{},this.nodes=[],this.diagonal=!!n.diagonal,this.grid=[];for(var e=0;e<t.length;e++){this.grid[e]=[];for(var i=0,o=t[e];i<o.length;i++){var a=new r(e,i,o[i]);this.grid[e][i]=a,this.nodes.push(a)}}this.init()}function r(t,n,e){this.x=t,this.y=n,this.weight=e}function i(t){this.content=[],this.scoreFunction=t}return e.prototype.init=function(){this.dirtyNodes=[];for(var t=0;t<this.nodes.length;t++)n.cleanNode(this.nodes[t])},e.prototype.cleanDirty=function(){for(var t=0;t<this.dirtyNodes.length;t++)n.cleanNode(this.dirtyNodes[t]);this.dirtyNodes=[]},e.prototype.markDirty=function(t){this.dirtyNodes.push(t)},e.prototype.neighbors=function(t){var n=[],e=t.x,r=t.y,i=this.grid;return i[e-1]&&i[e-1][r]&&n.push(i[e-1][r]),i[e+1]&&i[e+1][r]&&n.push(i[e+1][r]),i[e]&&i[e][r-1]&&n.push(i[e][r-1]),i[e]&&i[e][r+1]&&n.push(i[e][r+1]),this.diagonal&&(i[e-1]&&i[e-1][r-1]&&n.push(i[e-1][r-1]),i[e+1]&&i[e+1][r-1]&&n.push(i[e+1][r-1]),i[e-1]&&i[e-1][r+1]&&n.push(i[e-1][r+1]),i[e+1]&&i[e+1][r+1]&&n.push(i[e+1][r+1])),n},e.prototype.toString=function(){for(var t=[],n=this.grid,e=0;e<n.length;e++){for(var r=[],i=n[e],o=0;o<i.length;o++)r.push(i[o].weight);t.push(r.join(" "))}return t.join("\n")},r.prototype.toString=function(){return"["+this.x+" "+this.y+"]"},r.prototype.getCost=function(t){return t&&t.x!=this.x&&t.y!=this.y?1.41421*this.weight:this.weight},r.prototype.isWall=function(){return 0===this.weight},i.prototype={push:function(t){this.content.push(t),this.sinkDown(this.content.length-1)},pop:function(){var t=this.content[0],n=this.content.pop();return this.content.length>0&&(this.content[0]=n,this.bubbleUp(0)),t},remove:function(t){var n=this.content.indexOf(t),e=this.content.pop();n!==this.content.length-1&&(this.content[n]=e,this.scoreFunction(e)<this.scoreFunction(t)?this.sinkDown(n):this.bubbleUp(n))},size:function(){return this.content.length},rescoreElement:function(t){this.sinkDown(this.content.indexOf(t))},sinkDown:function(t){for(var n=this.content[t];t>0;){var e=(t+1>>1)-1,r=this.content[e];if(!(this.scoreFunction(n)<this.scoreFunction(r)))break;this.content[e]=n,this.content[t]=r,t=e}},bubbleUp:function(t){for(var n=this.content.length,e=this.content[t],r=this.scoreFunction(e);;){var i,o=t+1<<1,a=o-1,s=null;if(a<n){var u=this.content[a];(i=this.scoreFunction(u))<r&&(s=a)}if(o<n){var h=this.content[o];this.scoreFunction(h)<(null===s?r:i)&&(s=o)}if(null===s)break;this.content[t]=this.content[s],this.content[s]=e,t=s}}},{astar:n,Graph:e}})},function(t,n,e){"use strict";e.r(n);var r=e(0),i=e.n(r),o=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var a=function(){function t(n,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.x=n||0,this.y=e||0}return o(t,[{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"angle",value:function(t){return Math.atan2(t.y-this.y,t.x-this.x)}},{key:"distance",value:function(t){var n=t.x-this.x,e=t.y-this.y;return Math.sqrt(n*n+e*e)}},{key:"add",value:function(t){this.x+=t.x,this.y+=t.y}},{key:"subtract",value:function(t){this.x-=t.x,this.y-=t.y}},{key:"clone",value:function(){return new t(this.x,this.y)}}]),t}(),s=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var u=function(){function t(n,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.id=n,this.polygon=e,this.edges=e.edges,this.neighbors=[],this.portals=[],this.centroid=this.calculateCentroid(),this.boundingRadius=this.calculateRadius(),this.weight=1}return s(t,[{key:"getPoints",value:function(){return this.polygon.points}},{key:"contains",value:function(t){return this.polygon.contains(t.x,t.y)||this.isPointOnEdge(t)}},{key:"calculateCentroid",value:function(){var t=new a(0,0),n=this.polygon.points.length;return this.polygon.points.forEach(function(n){return t.add(n)}),t.x/=n,t.y/=n,t}},{key:"calculateRadius",value:function(){var t=0,n=!0,e=!1,r=void 0;try{for(var i,o=this.polygon.points[Symbol.iterator]();!(n=(i=o.next()).done);n=!0){var a=i.value,s=this.centroid.distance(a);s>t&&(t=s)}}catch(t){e=!0,r=t}finally{try{!n&&o.return&&o.return()}finally{if(e)throw r}}return t}},{key:"isPointOnEdge",value:function(t){var n=t.x,e=t.y,r=!0,i=!1,o=void 0;try{for(var a,s=this.edges[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){if(a.value.pointOnSegment(n,e))return!0}}catch(t){i=!0,o=t}finally{try{!r&&s.return&&s.return()}finally{if(i)throw o}}return!1}},{key:"destroy",value:function(){this.neighbors=[],this.portals=[]}},{key:"toString",value:function(){return"NavPoly(id: "+this.id+" at: "+this.centroid+")"}},{key:"isWall",value:function(){return 0===this.weight}},{key:"centroidDistance",value:function(t){return this.centroid.distance(t.centroid)}},{key:"getCost",value:function(t){return this.centroidDistance(t)}}]),t}(),h=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var l=function(){function t(n){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.nodes=n,this.init()}return h(t,[{key:"neighbors",value:function(t){return t.neighbors}},{key:"navHeuristic",value:function(t,n){return t.centroidDistance(n)}},{key:"destroy",value:function(){this.cleanDirty(),this.nodes=[]}}]),t}();l.prototype.init=i.a.Graph.prototype.init,l.prototype.cleanDirty=i.a.Graph.prototype.cleanDirty,l.prototype.markDirty=i.a.Graph.prototype.markDirty;var c=l;function f(t,n,e){var r=n.x-t.x,i=n.y-t.y;return(e.x-t.x)*i-r*(e.y-t.y)}function y(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-4;return Math.abs(t-n)<=e}function p(t,n){var e=t-n,r=e+Math.PI,i=2*Math.PI;return e=r-Math.floor(r/i)*i,e-=Math.PI}function d(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-4,r=f(t.start,t.end,n.start),i=f(t.start,t.end,n.end);return!(!y(r,0,e)||!y(i,0,e))}var v=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var g=function(){function t(){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.portals=[]}return v(t,[{key:"push",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;null===n&&(n=t),this.portals.push({left:t,right:n})}},{key:"stringPull",value:function(){var t,n,e,r=this.portals,i=[],o=0,a=0,s=0;t=r[0].left,n=r[0].left,e=r[0].right,i.push(t);for(var u=1;u<r.length;u++){var h=r[u].left,l=r[u].right;if(f(t,e,l)<=0){if(!(t.equals(e)||f(t,n,l)>0)){i.push(n),n=t=n,e=t,a=o=a,s=o,u=o;continue}e=l,s=u}if(f(t,n,h)>=0){if(!(t.equals(n)||f(t,e,h)<0)){i.push(e),n=t=e,e=t,a=o=s,s=o,u=o;continue}n=h,a=u}}return 0!==i.length&&i[i.length-1].equals(r[r.length-1].left)||i.push(r[r.length-1].left),this.path=i,i}}]),t}(),b=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var x=function(){function t(n,e,r,i){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.start=new a(n,e),this.end=new a(r,i),this.left=Math.min(n,r),this.right=Math.max(n,r),this.top=Math.min(e,i),this.bottom=Math.max(e,i)}return b(t,[{key:"pointOnSegment",value:function(t,n){return t>=this.left&&t<=this.right&&n>=this.top&&n<=this.bottom&&this.pointOnLine(t,n)}},{key:"pointOnLine",value:function(t,n){return(t-this.left)*(this.bottom-this.top)==(this.right-this.left)*(n-this.top)}}]),t}(),w=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var m=function(){function t(n){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.points=n,this.edges=[];for(var r=1;r<n.length;r++){var i=n[r-1],o=n[r];this.edges.push(new x(i.x,i.y,o.x,o.y))}if(e){var a=n[0],s=n[n.length-1];this.edges.push(new x(a.x,a.y,s.x,s.y))}}return w(t,[{key:"contains",value:function(t,n){for(var e=!1,r=-1,i=this.points.length-1;++r<this.points.length;i=r){var o=this.points[r].x,a=this.points[r].y,s=this.points[i].x,u=this.points[i].y;(a<=n&&n<u||u<=n&&n<a)&&t<(s-o)*(n-a)/(u-a)+o&&(e=!e)}return e}}]),t}(),k=function(){return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,n){var e=[],r=!0,i=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(r=(a=s.next()).done)&&(e.push(a.value),!n||e.length!==n);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&s.return&&s.return()}finally{if(i)throw o}}return e}(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),P=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var _=function(){function t(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this._meshShrinkAmount=e;var r=n.map(function(t){var n=t.map(function(t){return new a(t.x,t.y)});return new m(n)});this._navPolygons=r.map(function(t,n){return new u(n,t)}),this._calculateNeighbors(),this._graph=new c(this._navPolygons)}return P(t,[{key:"getPolygons",value:function(){return this._navPolygons}},{key:"destroy",value:function(){this._graph.destroy();var t=!0,n=!1,e=void 0;try{for(var r,i=this._navPolygons[Symbol.iterator]();!(t=(r=i.next()).done);t=!0){r.value.destroy()}}catch(t){n=!0,e=t}finally{try{!t&&i.return&&i.return()}finally{if(n)throw e}}this._navPolygons=[]}},{key:"findPath",value:function(t,n){var e=null,r=null,o=Number.MAX_VALUE,s=Number.MAX_VALUE,u=void 0,h=void 0,l=new a(t.x,t.y),c=new a(n.x,n.y),f=!0,y=!1,p=void 0;try{for(var d,v=this._navPolygons[Symbol.iterator]();!(f=(d=v.next()).done);f=!0){var b=d.value;h=b.boundingRadius,(u=b.centroid.distance(l))<=o&&u<=h&&b.contains(l)&&(e=b,o=u),(u=b.centroid.distance(c))<=s&&u<=h&&b.contains(c)&&(r=b,s=u)}}catch(t){y=!0,p=t}finally{try{!f&&v.return&&v.return()}finally{if(y)throw p}}if(!e&&this._meshShrinkAmount>0){var x=!0,w=!1,m=void 0;try{for(var k,P=this._navPolygons[Symbol.iterator]();!(x=(k=P.next()).done);x=!0){var _=k.value;if(h=_.boundingRadius+this._meshShrinkAmount,(u=_.centroid.distance(l))<=h){var M=this._projectPointToPolygon(l,_).distance;M<=this._meshShrinkAmount&&M<o&&(e=_,o=M)}}}catch(t){w=!0,m=t}finally{try{!x&&P.return&&P.return()}finally{if(w)throw m}}}if(!r&&this._meshShrinkAmount>0){var G=!0,S=!1,j=void 0;try{for(var O,E=this._navPolygons[Symbol.iterator]();!(G=(O=E.next()).done);G=!0){var N=O.value;if(h=N.boundingRadius+this._meshShrinkAmount,(u=N.centroid.distance(c))<=h){var T=this._projectPointToPolygon(c,N).distance;T<=this._meshShrinkAmount&&T<s&&(r=N,s=T)}}}catch(t){S=!0,j=t}finally{try{!G&&E.return&&E.return()}finally{if(S)throw j}}}if(!e||!r)return null;if(e===r)return[l,c];var D=i.a.astar.search(this._graph,e,r,{heuristic:this._graph.navHeuristic});if(0===D.length)return null;D.unshift(e);var A=new g;A.push(l);for(var F=0;F<D.length-1;F++){for(var C=D[F],q=D[F+1],R=null,U=0;U<C.neighbors.length;U++)C.neighbors[U].id===q.id&&(R=C.portals[U]);A.push(R.start,R.end)}A.push(c),A.stringPull();var L=null,I=[],W=!0,V=!1,X=void 0;try{for(var z,H=A.path[Symbol.iterator]();!(W=(z=H.next()).done);W=!0){var B=z.value.clone();L&&B.equals(L)||I.push(B),L=B}}catch(t){V=!0,X=t}finally{try{!W&&H.return&&H.return()}finally{if(V)throw X}}return I}},{key:"_calculateNeighbors",value:function(){for(var t=0;t<this._navPolygons.length;t++)for(var n=this._navPolygons[t],e=t+1;e<this._navPolygons.length;e++){var r=this._navPolygons[e];if(!(n.centroid.distance(r.centroid)>n.boundingRadius+r.boundingRadius)){var i=!0,o=!1,a=void 0;try{for(var s,u=n.edges[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){var h=s.value,l=!0,c=!1,f=void 0;try{for(var y,v=r.edges[Symbol.iterator]();!(l=(y=v.next()).done);l=!0){var g=y.value;if(d(h,g)){var b=this._getSegmentOverlap(h,g);if(b){n.neighbors.push(r),r.neighbors.push(n);var w=k(b,2),m=w[0],P=w[1],_=n.centroid.angle(h.start),M=n.centroid.angle(b[0]),G=n.centroid.angle(b[1]),S=p(_,M),j=p(_,G);S<j?n.portals.push(new x(m.x,m.y,P.x,P.y)):n.portals.push(new x(P.x,P.y,m.x,m.y)),_=r.centroid.angle(g.start),M=r.centroid.angle(b[0]),G=r.centroid.angle(b[1]),(S=p(_,M))<(j=p(_,G))?r.portals.push(new x(m.x,m.y,P.x,P.y)):r.portals.push(new x(P.x,P.y,m.x,m.y))}}}}catch(t){c=!0,f=t}finally{try{!l&&v.return&&v.return()}finally{if(c)throw f}}}}catch(t){o=!0,a=t}finally{try{!i&&u.return&&u.return()}finally{if(o)throw a}}}}}},{key:"_getSegmentOverlap",value:function(t,n){var e=[{line:t,point:t.start},{line:t,point:t.end},{line:n,point:n.start},{line:n,point:n.end}];e.sort(function(t,n){return t.point.x<n.point.x?-1:t.point.x>n.point.x?1:t.point.y<n.point.y?-1:t.point.y>n.point.y?1:0});var r=e[0].line===e[1].line,i=e[1].point.equals(e[2].point);return r||i?null:[e[1].point,e[2].point]}},{key:"_projectPointToPolygon",value:function(t,n){var e=null,r=Number.MAX_VALUE,i=!0,o=!1,a=void 0;try{for(var s,u=n.edges[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){var h=s.value,l=this._projectPointToEdge(t,h),c=t.distance(l);(null===e||c<r)&&(r=c,e=l)}}catch(t){o=!0,a=t}finally{try{!i&&u.return&&u.return()}finally{if(o)throw a}}return{point:e,distance:r}}},{key:"_distanceSquared",value:function(t,n){var e=n.x-t.x,r=n.y-t.y;return e*e+r*r}},{key:"_projectPointToEdge",value:function(t,n){var e=n.start,r=n.end,i=this._distanceSquared(e,r),o=((t.x-e.x)*(r.x-e.x)+(t.y-e.y)*(r.y-e.y))/i;return o=function(t,n,e){return t<n&&(t=n),t>e&&(t=e),t}(o,0,1),new a(e.x+o*(r.x-e.x),e.y+o*(r.y-e.y))}}]),t}(),M=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();function G(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);n<t.length;n++)e[n]=t[n];return e}return Array.from(t)}var S=function(){function t(n,e,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.key=e,this.plugin=n,this.game=n.game,this.debugGraphics=null,this.navMesh=new _(r,i)}return M(t,[{key:"findPath",value:function(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Phaser.Point,r=this.navMesh.findPath(t,n);return r?r.map(function(t){var n=t.x,r=t.y;return new e(n,r)}):r}},{key:"enableDebug",value:function(t){return t||this.debugGraphics?t&&(this.debugGraphics&&this.debugGraphics.destroy(),this.debugGraphics=t):this.debugGraphics=this.game.add.graphics(),this.debugGraphics.visible=!0,this.debugGraphics}},{key:"disableDebug",value:function(){this.debugGraphics&&(this.debugGraphics.visible=!1)}},{key:"isDebugEnabled",value:function(){return this.debugGraphics&&this.debugGraphics.visible}},{key:"debugDrawClear",value:function(){this.debugGraphics&&this.debugGraphics.clear()}},{key:"debugDrawMesh",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=n.drawCentroid,r=void 0===e||e,i=n.drawBounds,o=void 0!==i&&i,a=n.drawNeighbors,s=void 0===a||a,u=n.drawPortals,h=void 0===u||u,l=n.palette,c=void 0===l?[41136,6965820,13382463,15427649,15583569]:l;this.debugGraphics&&this.navMesh.getPolygons().forEach(function(n){var e=c[n.id%c.length];if(t.debugGraphics.lineWidth=0,t.debugGraphics.beginFill(e),t.debugGraphics.drawPolygon(new(Function.prototype.bind.apply(Phaser.Polygon,[null].concat(G(n.getPoints()))))),t.debugGraphics.endFill(),r&&(t.debugGraphics.beginFill(0),t.debugGraphics.drawEllipse(n.centroid.x,n.centroid.y,4,4),t.debugGraphics.endFill()),o){t.debugGraphics.lineStyle(1,16777215);var i=n.boundingRadius;t.debugGraphics.drawEllipse(n.centroid.x,n.centroid.y,i,i)}s&&(t.debugGraphics.lineStyle(2,0),n.neighbors.forEach(function(e){t.debugGraphics.moveTo(n.centroid.x,n.centroid.y),t.debugGraphics.lineTo(e.centroid.x,e.centroid.y)})),h&&(t.debugGraphics.lineStyle(10,0),n.portals.forEach(function(n){t.debugGraphics.moveTo(n.start.x,n.start.y),t.debugGraphics.lineTo(n.end.x,n.end.y)}))})}},{key:"debugDrawPath",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:65280,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;if(this.debugGraphics&&t&&t.length){this.debugGraphics.lineStyle(e,n,r),this.debugGraphics.drawShape(new(Function.prototype.bind.apply(Phaser.Polygon,[null].concat(G(t))))),this.debugGraphics.beginFill(n,r);var i=.5*e;if(this.debugGraphics.drawEllipse(t[0].x,t[0].y,i,i),t.length>1){var o=t[t.length-1];this.debugGraphics.drawEllipse(o.x,o.y,i,i)}this.debugGraphics.endFill()}}},{key:"destroy",value:function(){this.navMesh&&this.navMesh.destroy(),this.debugGraphics&&this.debugGraphics.destroy(),this.plugin.removeMesh(this.key),this.navMesh=void 0,this.debugGraphics=void 0,this.plugin=void 0,this.scene=void 0}}]),t}(),j=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var O=function(t){function n(t,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,n);var r=function(t,n){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?t:n}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e));return r.phaserNavMeshes={},r}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(t,n):t.__proto__=n)}(n,Phaser.Plugin),j(n,[{key:"destroy",value:function(){Object.values(this.phaserNavMeshes).forEach(function(t){return t.destroy()}),this.phaserNavMeshes=[],this.game=void 0}},{key:"removeMesh",value:function(t){this.phaserNavMeshes[t]&&(this.phaserNavMeshes[t].destroy(),this.phaserNavMeshes[t]=void 0)}},{key:"buildMeshFromTiled",value:function(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(this.phaserNavMeshes[t])return console.warn("NavMeshPlugin: a navmesh already exists with the given key: "+t),this.phaserNavMeshes[t];n&&0!==n.length||console.warn("NavMeshPlugin: The given tilemap object layer is empty or undefined: "+n);var r=(n||[]).map(function(t){var n=t.y,e=t.y+t.height,r=t.x,i=t.x+t.width;return[{x:r,y:n},{x:r,y:e},{x:i,y:e},{x:i,y:n}]}),i=new S(this,t,r,e);return this.phaserNavMeshes[t]=i,i}}]),n}();e.d(n,"Phaser2NavMesh",function(){return S});n.default=O}]).default}); | ||
//# sourceMappingURL=phaser2-navmesh.min.js.map |
{ | ||
"name": "phaser2-navmesh", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A plugin for Phaser (v2) for fast pathfinding using navigation meshes", | ||
@@ -5,0 +5,0 @@ "main": "dist/phaser2-navmesh.min.js", |
@@ -24,3 +24,3 @@ import Phaser2NavMesh from "./phaser2-navmesh"; | ||
destroy() { | ||
this.systems.events.Object.values(this.phaserNavMeshes).forEach(m => m.destroy()); | ||
Object.values(this.phaserNavMeshes).forEach(m => m.destroy()); | ||
this.phaserNavMeshes = []; | ||
@@ -43,3 +43,2 @@ this.game = undefined; | ||
/** | ||
@@ -46,0 +45,0 @@ * Load a navmesh from Tiled. Currently assumes that the polygons are squares! Does not support |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
267339