prettymuchbryce / easystarjs

An asynchronous A* pathfinding API written in Javascript.
MIT License
1.9k stars 165 forks source link

Add findPathSync to find & calculate a path then return the result directly #62

Open mikedevelops opened 6 years ago

mikedevelops commented 6 years ago

The proposal is an implementation similar to (https://github.com/prettymuchbryce/easystarjs/pull/54).

This change would not remove or modify from the existing public API or existing enableSync() method. It adds an additional method to the public API that allows users to find a path and calculate it's route truly synchronously with no callback.

Example usage...

var easyStar = new EasyStar.js();
var grid = [
    [0, 1, 0],
    [0, 0, 0],
    [0, 0, 0],
];
easyStar.setGrid(grid);
easyStar.setAcceptableTiles([0]);

const path = easyStar.findPathSync(0, 0, 1, 1); // your path array or null

I've done some semicolon and JSDoc housekeeping along the way, as well as added tests for the existing enableSync() behaviour.

prettymuchbryce commented 6 years ago

Thanks very much for the change. This is looking great! Just a couple of small comments around the Zalgo stuff. Thanks for the additional cleanup as well!

Could you bump the minor version in package.json and change it throughout the code? It's kind of annoying right now, as you need to change it in a number of places, so alternatively you could simply remove the files changed in bin and I can create the built files when I go to bump the version and release.