Location
A helper module for dealing with locations. You can assign these to units, tiles, whatever.
Example
var Location = ; var myLocation = '2:3';var hugeArrayOfLocations = location ... hugeArrayOfLocations;
Methods
var Location = require;
var location = new Location(x, y)
Returns a Location
object at (x, y)
.
Also accepts String
input:
var loc = '8:8'`
is equivalent to:
var loc = 88
location.toString()
Returns (x,y) coordinates as a string, separated by a colon.
var location = 5 4;location -> '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 = 5 4;var location2 = 5 4; location1 -> true var location3 = 2 8;var location4 = 2 2; location3 -> false
location.isNextTo(location)
Compare two location objects. If adjacent, returns true
.
var location1 = 5 4;var location2 = 5 3; location1 -> true
location.copy()
Returns a new instance of Location
with the same values.
Installation
npm install habitants-location
Tests
npm test