Added type definitions for EasyStar.js 0.1.6

This commit is contained in:
Magnus Gustafsson
2014-02-02 00:16:19 +00:00
parent 7480b03ef1
commit 65f47d2f20
3 changed files with 142 additions and 0 deletions

61
easystarjs/README.md Executable file
View File

@@ -0,0 +1,61 @@
easystarjs.d.ts
===========
This is a typescript definitions file for EasyStar.js located here: https://github.com/prettymuchbryce/easystarjs
Main site: http://easystarjs.com/
Basic Usage
==========
Import Statements
-----------------
Reference the easystarjs.d.ts file in your project and include the following import statement
```typescript
/// <reference path="easystarjs.d.ts" />
// Include the following import
import EasyStar = require("easystarjs");
```
See tests for further details on how to use this library.
Change Log
==========
1.0 2014/02/02
---------------
* First version for EasyStar.js 0.1.6
License
=======
easystarjs.d.ts Copyright (c) 2014 Magnus Gustafsson http://github.com/borundin/easystarjs.d.ts
This definitions file is for EasyStar.js ->
https://github.com/prettymuchbryce/easystarjs
EasyStar.js Copyright (c) 2012-2013 Bryce Neal
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

47
easystarjs/easystarjs-tests.ts Executable file
View File

@@ -0,0 +1,47 @@
/// <reference path="easystarjs.d.ts"/>
// 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
*/

34
easystarjs/easystarjs.d.ts vendored Executable file
View File

@@ -0,0 +1,34 @@
// Type definitions for EasyStar.js 0.1.6
// Project: http://easystarjs.com/
// Definitions by: Magnus Gustafsson <https://github.com/borundin>
// 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;
}
}