habitants-location
v0.0.2
Published
location object helper for 2d cartesian coordinates
Readme
Location
A helper module for dealing with locations. You can assign these to units, tiles, whatever.
Example
var Location = require('location');
var myLocation = new Location('2:3');
var hugeArrayOfLocations = [location, ...]
hugeArrayOfLocations.forEach(function (location) {
if (myLocation.isEqualTo(location)) return 'Same Location!' + location;
else return 'Not the same Location!' + location;
});Methods
var Location = require('location');var location = new Location(x, y)
Returns a Location object at (x, y).
Also accepts String input:
var loc = new Location('8:8')`is equivalent to:
var loc = new Location(8,8)location.toString()
Returns (x,y) coordinates as a string, separated by a colon.
var location = new Location(5, 4);
location.toString() -> '5:4'location.isEqualTo(location)
Compare two location objects, and it will return a boolean.
Both x and y values must match to be true.
var location1 = new Location(5, 4);
var location2 = new Location(5, 4);
location1.isEqualTo(location2) -> true
var location3 = new Location(2, 8);
var location4 = new Location(2, 2);
location3.isEqualTo(location4) -> falselocation.isNextTo(location)
Compare two location objects. If adjacent, returns true.
var location1 = new Location(5, 4);
var location2 = new Location(5, 3);
location1.isNextTo(location2) -> truelocation.copy()
Returns a new instance of Location with the same values.
Installation
npm install habitants-locationTests
npm test