Comparing version 0.0.11 to 0.0.12
module.exports = { | ||
JSCoord: require("./JSCoord") | ||
} | ||
JSCoord: require("./JSCoord"), | ||
} |
239
JSCoord.js
module.exports = class JSCoord { | ||
/** | ||
/** | ||
* @param {Number[]} coordinates | ||
*/ | ||
constructor(...coordinates) { | ||
let x = coordinates[0][0] || coordinates[0], y = coordinates[0][1] || coordinates[1] || coordinates[0][0] || coordinates[0], z = coordinates[0][2] || coordinates[2] | ||
/** | ||
constructor (...coordinates) { | ||
let x = coordinates[0][0] || coordinates[0], y = coordinates[0][1] || coordinates[1] || coordinates[0][0] || coordinates[0], z = coordinates[0][2] || coordinates[2] | ||
/** | ||
* @type {Number} | ||
*/ | ||
this.x = x | ||
/** | ||
this.x = x | ||
/** | ||
* @type {Number} | ||
*/ | ||
this.y = y | ||
/** | ||
this.y = y | ||
/** | ||
* @type {Number} | ||
*/ | ||
this.z = z | ||
} | ||
/** | ||
this.z = z | ||
} | ||
/** | ||
* Increase X by amount. | ||
* @param {Number} amount | ||
* @param {Number} amount | ||
*/ | ||
incrX(amount = 1) { | ||
if (this.map && this.map.x && (this.x + amount > this.map.x || this.x + amount < 0 - this.map.x)) throw new Error("New amount exceeds maximum map size."); else { | ||
this.x += amount | ||
return this | ||
} | ||
} | ||
/** | ||
incrX (amount = 1) { | ||
if (this.map && this.map.x && (this.x + amount > this.map.x || this.x + amount < 0 - this.map.x)) { throw new Error("New amount exceeds maximum map size.") } else { | ||
this.x += amount | ||
return this | ||
} | ||
} | ||
/** | ||
* Decrease X by amount. | ||
* @param {Number} amount | ||
* @param {Number} amount | ||
*/ | ||
decrX(amount = 1) { | ||
if (this.map && this.map.x && (this.x + amount > this.map.x || this.x + amount < 0 - this.map.x)) throw new Error("New amount does not exceed minimum map size."); else { | ||
this.x -= amount | ||
return this | ||
} | ||
} | ||
/** | ||
decrX (amount = 1) { | ||
if (this.map && this.map.x && (this.x + amount > this.map.x || this.x + amount < 0 - this.map.x)) { throw new Error("New amount does not exceed minimum map size.") } else { | ||
this.x -= amount | ||
return this | ||
} | ||
} | ||
/** | ||
* Increase Y by amount. | ||
* @param {Number} amount | ||
* @param {Number} amount | ||
*/ | ||
incrY(amount = 1) { | ||
if (this.map && this.map.y && (this.y + amount > this.map.y || this.y + amount < 0 - this.map.y)) throw new Error("New amount exceeds maximum map size."); else { | ||
this.y += amount | ||
return this | ||
} | ||
} | ||
/** | ||
incrY (amount = 1) { | ||
if (this.map && this.map.y && (this.y + amount > this.map.y || this.y + amount < 0 - this.map.y)) { throw new Error("New amount exceeds maximum map size.") } else { | ||
this.y += amount | ||
return this | ||
} | ||
} | ||
/** | ||
* Decrease Y by amount. | ||
* @param {Number} amount | ||
* @param {Number} amount | ||
*/ | ||
decrY(amount = 1) { | ||
if (this.map && this.map.y && (this.y + amount > this.map.y || this.y + amount < 0 - this.map.y)) throw new Error("New amount does not exceed minimum map size."); else { | ||
this.y -= amount | ||
return this | ||
} | ||
} | ||
/** | ||
decrY (amount = 1) { | ||
if (this.map && this.map.y && (this.y + amount > this.map.y || this.y + amount < 0 - this.map.y)) { throw new Error("New amount does not exceed minimum map size.") } else { | ||
this.y -= amount | ||
return this | ||
} | ||
} | ||
/** | ||
* Increase Z by amount. | ||
* @param {Number} amount | ||
* @param {Number} amount | ||
*/ | ||
incrZ(amount = 1) { | ||
if (this.map && this.map.z && (this.z + amount > this.map.z || this.z + amount < 0 - this.map.z)) throw new Error("New amount exceeds maximum map size."); else { | ||
this.z += amount | ||
return this | ||
} | ||
} | ||
/** | ||
incrZ (amount = 1) { | ||
if (this.map && this.map.z && (this.z + amount > this.map.z || this.z + amount < 0 - this.map.z)) { throw new Error("New amount exceeds maximum map size.") } else { | ||
this.z += amount | ||
return this | ||
} | ||
} | ||
/** | ||
* Decrease Z by amount. | ||
* @param {Number} amount | ||
* @param {Number} amount | ||
*/ | ||
decrZ(amount = 1) { | ||
if (this.map && this.map.z && (this.z + amount > this.map.z || this.z + amount < 0 - this.map.z)) throw new Error("New amount does not exceed minimum map size."); else { | ||
this.z -= amount | ||
return this | ||
} | ||
} | ||
/** | ||
decrZ (amount = 1) { | ||
if (this.map && this.map.z && (this.z + amount > this.map.z || this.z + amount < 0 - this.map.z)) { throw new Error("New amount does not exceed minimum map size.") } else { | ||
this.z -= amount | ||
return this | ||
} | ||
} | ||
/** | ||
* Invert X axis value. | ||
*/ | ||
invX() { | ||
this.x = 0 - this.x | ||
return this | ||
} | ||
/** | ||
invX () { | ||
this.x = 0 - this.x | ||
return this | ||
} | ||
/** | ||
* Invert Y axis value. | ||
*/ | ||
invY() { | ||
this.y = 0 - this.y | ||
return this | ||
} | ||
/** | ||
invY () { | ||
this.y = 0 - this.y | ||
return this | ||
} | ||
/** | ||
* Invert Z axis value. | ||
*/ | ||
invZ() { | ||
this.z = 0 - this.z | ||
return this | ||
} | ||
getArray() { | ||
return [this.x, this.y, this.z] | ||
} | ||
getObject() { | ||
return { | ||
x: this.x, | ||
y: this.y, | ||
z: this.z | ||
} | ||
} | ||
/** | ||
* | ||
* @param {Number[]} size | ||
invZ () { | ||
this.z = 0 - this.z | ||
return this | ||
} | ||
getArray () { | ||
return [this.x, this.y, this.z] | ||
} | ||
getObject () { | ||
return { | ||
x: this.x, | ||
y: this.y, | ||
z: this.z, | ||
} | ||
} | ||
/** | ||
* | ||
* @param {Number[]} size | ||
*/ | ||
setMap(...size) { | ||
let x = size[0][0] || size[0], y = size[0][1] || size[1] || size[0][0] || size[0], z = size[0][2] || size[2] | ||
/** | ||
setMap (...size) { | ||
let x = size[0][0] || size[0], y = size[0][1] || size[1] || size[0][0] || size[0], z = size[0][2] || size[2] | ||
/** | ||
* @type {Number[]} | ||
*/ | ||
if (this.x > x || this.x < 0 - x || this.y > y || this.y < 0 - y || this.z > z || this.z < 0 - z) throw new Error("Can not set map size as one or more coordinates exceed new map size."); else { | ||
this.map = {x, y, z} | ||
return this | ||
} | ||
} | ||
/** | ||
if (this.x > x || this.x < 0 - x || this.y > y || this.y < 0 - y || this.z > z || this.z < 0 - z) { throw new Error("Can not set map size as one or more coordinates exceed new map size.") } else { | ||
this.map = { x, y, z } | ||
return this | ||
} | ||
} | ||
/** | ||
* Set X to provided value. | ||
* @param {Number} val | ||
*/ | ||
setX(val) { | ||
if (this.map && this.map.x && (val > this.map.x || val < 0 - this.map.x)) throw new Error("New value does not fit in Map range."); else { | ||
this.x = val | ||
return this | ||
} | ||
} | ||
/** | ||
setX (val) { | ||
if (this.map && this.map.x && (val > this.map.x || val < 0 - this.map.x)) { throw new Error("New value does not fit in Map range.") } else { | ||
this.x = val | ||
return this | ||
} | ||
} | ||
/** | ||
* Set Y to provided value. | ||
* @param {Number} val | ||
*/ | ||
setY(val) { | ||
if (this.map && this.map.y && (val > this.map.y || val < 0 - this.map.y)) throw new Error("New value does not fit in Map range."); else { | ||
this.y = val | ||
return this | ||
} | ||
} | ||
/** | ||
setY (val) { | ||
if (this.map && this.map.y && (val > this.map.y || val < 0 - this.map.y)) { throw new Error("New value does not fit in Map range.") } else { | ||
this.y = val | ||
return this | ||
} | ||
} | ||
/** | ||
* Set Z to provided value. | ||
* @param {Number} val | ||
*/ | ||
setZ(val) { | ||
if (this.map && this.map.z && (val > this.map.z || val < 0 - this.map.z)) throw new Error("New value does not fit in Map range."); else { | ||
this.z = val | ||
return this | ||
} | ||
setZ (val) { | ||
if (this.map && this.map.z && (val > this.map.z || val < 0 - this.map.z)) { throw new Error("New value does not fit in Map range.") } else { | ||
this.z = val | ||
return this | ||
} | ||
} | ||
} | ||
/** | ||
* Resets X, Y, Z to 0. | ||
*/ | ||
reset() { | ||
this.x = 0 | ||
this.y = 0 | ||
this.z = 0 | ||
return this | ||
} | ||
} |
{ | ||
"name": "jscoord", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "A simple Map coordinate system for NodeJS and potentially the browser.", | ||
@@ -18,3 +18,7 @@ "main": "index.js", | ||
"type": "git" | ||
} | ||
}, | ||
"scripts": { | ||
"lint": "eslint . --fix" | ||
}, | ||
"pre-commit": [ "lint" ] | ||
} |
12186
6
285