@koreez/phaser3-isometric-plugin
Version:
Phaser3 isometirc plugin
302 lines • 9.98 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Point3_1 = require("./Point3");
var Cube = (function () {
function Cube(x, y, z, widthX, widthY, height) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
if (z === void 0) { z = 0; }
if (widthX === void 0) { widthX = 0; }
if (widthY === void 0) { widthY = 0; }
if (height === void 0) { height = 0; }
this.x = x;
this.y = y;
this.z = z;
this.widthX = widthX;
this.widthY = widthY;
this.height = height;
this.__corners = [
new Point3_1.Point3(this.x, this.y, this.z),
new Point3_1.Point3(this.x, this.y, this.z + this.height),
new Point3_1.Point3(this.x, this.y + this.widthY, this.z),
new Point3_1.Point3(this.x, this.y + this.widthY, this.z + this.height),
new Point3_1.Point3(this.x + this.widthX, this.y, this.z),
new Point3_1.Point3(this.x + this.widthX, this.y, this.z + this.height),
new Point3_1.Point3(this.x + this.widthX, this.y + this.widthY, this.z),
new Point3_1.Point3(this.x + this.widthX, this.y + this.widthY, this.z + this.height),
];
}
Object.defineProperty(Cube.prototype, "halfWidthX", {
get: function () {
return Math.round(this.widthX * 0.5);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "halfWidthY", {
get: function () {
return Math.round(this.widthY * 0.5);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "halfHeight", {
get: function () {
return Math.round(this.height * 0.5);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "bottom", {
get: function () {
return this.z;
},
set: function (value) {
this.height = value >= this.top ? 0 : this.top - value;
this.z = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "top", {
get: function () {
return this.z + this.height;
},
set: function (value) {
this.height = value <= this.z ? 0 : value - this.z;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "backX", {
get: function () {
return this.x;
},
set: function (value) {
this.widthX = value >= this.frontX ? 0 : this.frontX - value;
this.x = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "backY", {
get: function () {
return this.y;
},
set: function (value) {
this.widthY = value >= this.frontY ? 0 : this.frontY - value;
this.y = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "frontX", {
get: function () {
return this.x + this.widthX;
},
set: function (value) {
this.widthX = value <= this.x ? 0 : value - this.x;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "frontY", {
get: function () {
return this.y + this.widthY;
},
set: function (value) {
this.widthY = value <= this.y ? 0 : value - this.y;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "volume", {
get: function () {
return this.widthX * this.widthY * this.height;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "centerX", {
get: function () {
return this.x + this.halfWidthX;
},
set: function (value) {
this.x = value - this.halfWidthX;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "centerY", {
get: function () {
return this.y + this.halfWidthY;
},
set: function (value) {
this.y = value - this.halfWidthY;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "centerZ", {
get: function () {
return this.z + this.halfHeight;
},
set: function (value) {
this.z = value - this.halfHeight;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "randomX", {
get: function () {
return this.x + Math.random() * this.widthX;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "randomY", {
get: function () {
return this.y + Math.random() * this.widthY;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "randomZ", {
get: function () {
return this.z + Math.random() * this.height;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Cube.prototype, "empty", {
get: function () {
return !this.widthX || !this.widthY || !this.height;
},
set: function (value) {
if (value === true) {
this.setTo(0, 0, 0, 0, 0, 0);
}
},
enumerable: true,
configurable: true
});
Cube.size = function (a, output) {
if (typeof output === 'undefined' || output === null) {
output = new Point3_1.Point3(a.widthX, a.widthY, a.height);
}
else {
output.setTo(a.widthX, a.widthY, a.height);
}
return output;
};
Cube.clone = function (a, output) {
if (typeof output === 'undefined' || output === null) {
output = new Cube(a.x, a.y, a.z, a.widthX, a.widthY, a.height);
}
else {
output.setTo(a.x, a.y, a.z, a.widthX, a.widthY, a.height);
}
return output;
};
Cube.contains = function (a, x, y, z) {
if (a.widthX <= 0 || a.widthY <= 0 || a.height <= 0) {
return false;
}
return (x >= a.x &&
x <= a.frontX &&
y >= a.y &&
y <= a.frontY &&
z >= a.z &&
z <= a.top);
};
Cube.containsXY = function (a, x, y) {
if (a.widthX <= 0 || a.widthY <= 0) {
return false;
}
return x >= a.x && x <= a.frontX && y >= a.y && y <= a.frontY;
};
Cube.containsPoint3 = function (a, point3) {
return Cube.contains(a, point3.x, point3.y, point3.z);
};
Cube.containsCube = function (a, b) {
if (a.volume > b.volume) {
return false;
}
return (a.x >= b.x &&
a.y >= b.y &&
a.z >= b.z &&
a.frontX <= b.frontX &&
a.frontY <= b.frontY &&
a.top <= b.top);
};
Cube.intersects = function (a, b) {
if (a.widthX <= 0 ||
a.widthY <= 0 ||
a.height <= 0 ||
b.widthX <= 0 ||
b.widthY <= 0 ||
b.height <= 0) {
return false;
}
return !(a.frontX < b.x ||
a.frontY < b.y ||
a.x > b.frontX ||
a.y > b.frontY ||
a.z > b.top ||
a.top < b.z);
};
Cube.prototype.setTo = function (x, y, z, widthX, widthY, height) {
this.x = x;
this.y = y;
this.z = z;
this.widthX = widthX;
this.widthY = widthY;
this.height = height;
return this;
};
Cube.prototype.copyFrom = function (source) {
this.setTo(source.x, source.y, source.z, source.widthX, source.widthY, source.height);
return this;
};
Cube.prototype.copyTo = function (dest) {
dest.x = this.x;
dest.y = this.y;
dest.z = this.z;
dest.widthX = this.widthX;
dest.widthY = this.widthY;
dest.height = this.height;
return this;
};
Cube.prototype.size = function (output) {
return Cube.size(this, output);
};
Cube.prototype.contains = function (x, y, z) {
return Cube.contains(this, x, y, z);
};
Cube.prototype.containsXY = function (x, y) {
return Cube.containsXY(this, x, y);
};
Cube.prototype.clone = function (output) {
return Cube.clone(this, output);
};
Cube.prototype.intersects = function (b) {
return Cube.intersects(this, b);
};
Cube.prototype.getCorners = function () {
this.__corners[0].setTo(this.x, this.y, this.z);
this.__corners[1].setTo(this.x, this.y, this.z + this.height);
this.__corners[2].setTo(this.x, this.y + this.widthY, this.z);
this.__corners[3].setTo(this.x, this.y + this.widthY, this.z + this.height);
this.__corners[4].setTo(this.x + this.widthX, this.y, this.z);
this.__corners[5].setTo(this.x + this.widthX, this.y, this.z + this.height);
this.__corners[6].setTo(this.x + this.widthX, this.y + this.widthY, this.z);
this.__corners[7].setTo(this.x + this.widthX, this.y + this.widthY, this.z + this.height);
return this.__corners;
};
Cube.prototype.toString = function () {
return "[{Cube (x=" + this.x + " y=" + this.y + " z=" + this.z + " widthX=" + this.widthX + " widthY=" + this.widthY + " height=" + this.height + " empty=" + this.empty + ")}]";
};
return Cube;
}());
exports.Cube = Cube;
//# sourceMappingURL=Cube.js.map