diff --git a/README.md b/README.md index 6c88b1287..251263010 100755 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ List of Definitions * [domo](http://domo-js.com/) (by [Steve Fenton](https://github.com/Steve-Fenton)) * [dust](http://linkedin.github.com/dustjs) (by [Marcelo Dezem](https://github.com/mdezem)) * [EaselJS](http://www.createjs.com/#!/EaselJS) (by [Pedro Ferreira](https://bitbucket.org/drk4)) +* [EasyStar](http://easystarjs.com/) (by [Magnus Gustafsson](https://github.com/Borundin)) * [ember.js](http://emberjs.com/) (by [Boris Yankov](https://github.com/borisyankov)) * [EpicEditor](http://epiceditor.com/) (by [Boris Yankov](https://github.com/borisyankov)) * [ES6-Promises](https://github.com/jakearchibald/ES6-Promises) (by [François de Campredon](https://github.com/fdecampredon/)) diff --git a/easystarjs/easystarjs-tests.ts b/easystarjs/easystarjs-tests.ts new file mode 100755 index 000000000..a63d4ea0f --- /dev/null +++ b/easystarjs/easystarjs-tests.ts @@ -0,0 +1,47 @@ +/// + +// For node.js compile using: tsc --module commonjs easystarjs-tests.ts +// then run using: node easystarjs-tests.js +import EasyStar = require('easystarjs'); + +var test = new EasyStar.js(); + +test.setGrid([ + [0, 0, 0, 1, 0], + [0, 0, 0, 1, 0], + [0, 0, 1, 1, 0], + [0, 0, 0, 0, 0], + [0, 0, 0, 1, 0] +]); +test.setAcceptableTiles([0]); +test.setIterationsPerCalculation(1000); +test.findPath(2, 0, 4, 4, function (path: EasyStar.Position[]) +{ + if (path == null) + { + console.log("No path found!"); + return; + } + for (var i = 0; i < path.length; i++) + { + var pos = path[i]; + console.log("%d, %d", pos.x, pos.y); + } +}); + +test.calculate(); + +/* +Should log: + +2, 0 +2, 1 +1, 1 +1, 2 +1, 3 +2, 3 +3, 3 +4, 3 +4, 4 + +*/ \ No newline at end of file diff --git a/easystarjs/easystarjs.d.ts b/easystarjs/easystarjs.d.ts new file mode 100755 index 000000000..7640b1a8b --- /dev/null +++ b/easystarjs/easystarjs.d.ts @@ -0,0 +1,34 @@ +// Type definitions for EasyStar.js 0.1.6 +// Project: http://easystarjs.com/ +// Definitions by: Magnus Gustafsson +// Definitions: https://github.com/borisyankov/DefinitelyTyped +/* +easystarjs.d.ts may be freely distributed under the MIT license. +*/ + +declare module "easystarjs" +{ + class js + { + new (): js; + setGrid(grid: number[][]): void; + setAcceptableTiles(tiles: number[]): void; + findPath(startX: number, startY: number, endX: number, endY: number, callback: (path: Position[]) => void): void; + calculate(): void; + setIterationsPerCalculation(iterations: number): void; + avoidAdditionalPoint(x: number, y: number): void; + stopAvoidingAdditionalPoint(x: number, y: number): void; + stopAvoidingAllAdditionalPoints(): void; + enableDiagonals(): void; + disableDiagonals(): void; + setTileCost(tileType: number, multiplicativeCost: number): void; + } + + interface Position + { + x: number; + y: number; + } +} + + \ No newline at end of file