UNPKG

@koreez/phaser3-isometric-plugin

Version:
128 lines 4.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Cube_1 = require("./Cube"); var Point3_1 = require("./Point3"); var IsoObject = (function () { function IsoObject(projector, phaserIsoGameObject, x, y, z) { this.projector = projector; this.__phaserIsoGameObject = phaserIsoGameObject; this.__isoPosition = new Point3_1.Point3(x, y, z); this.snap = 0; this.__project(); this.__isoBounds = this.__resetIsoBounds(); } Object.defineProperty(IsoObject.prototype, "isoX", { get: function () { return this.__isoPosition.x; }, set: function (value) { this.__isoPosition.x = value; this.__project(); this.__resetIsoBounds(); this.__updateDepth(); }, enumerable: true, configurable: true }); Object.defineProperty(IsoObject.prototype, "isoY", { get: function () { return this.__isoPosition.y; }, set: function (value) { this.__isoPosition.y = value; this.__project(); this.__resetIsoBounds(); this.__updateDepth(); }, enumerable: true, configurable: true }); Object.defineProperty(IsoObject.prototype, "isoZ", { get: function () { return this.__isoPosition.z; }, set: function (value) { this.__isoPosition.z = value; this.__project(); this.__resetIsoBounds(); }, enumerable: true, configurable: true }); Object.defineProperty(IsoObject.prototype, "isoPosition", { get: function () { return this.__isoPosition; }, set: function (value) { this.__isoPosition = value; }, enumerable: true, configurable: true }); Object.defineProperty(IsoObject.prototype, "isoBounds", { get: function () { if (!this.__isoBounds) { this.__resetIsoBounds(); } return this.__isoBounds; }, enumerable: true, configurable: true }); IsoObject.prototype.set2DPosition = function (x, y) { var out = new Point3_1.Point3(); this.projector.unproject(new Phaser.Geom.Point(x, y || this.__phaserIsoGameObject.y), out, this.isoZ); this.isoX = out.x; this.isoY = out.y; }; IsoObject.prototype.setIsoPosition = function (point) { this.isoX = point.x; this.isoY = point.y; this.isoZ = point.z; }; IsoObject.prototype.__resetIsoBounds = function () { if (typeof this.__isoBounds === 'undefined') { this.__isoBounds = new Cube_1.Cube(); } var asx = Math.abs(this.__phaserIsoGameObject.scaleX); var asy = Math.abs(this.__phaserIsoGameObject.scaleY); this.__isoBounds.widthX = Math.round(Math.abs(this.__phaserIsoGameObject.width) * 0.5) * asx; this.__isoBounds.widthY = Math.round(Math.abs(this.__phaserIsoGameObject.width) * 0.5) * asx; this.__isoBounds.height = Math.round(Math.abs(this.__phaserIsoGameObject.height) - Math.abs(this.__phaserIsoGameObject.width) * 0.5) * asy; this.__isoBounds.x = this.isoX + this.__isoBounds.widthX * -this.__phaserIsoGameObject.originX + this.__isoBounds.widthX * 0.5; this.__isoBounds.y = this.isoY + this.__isoBounds.widthY * this.__phaserIsoGameObject.originX - this.__isoBounds.widthY * 0.5; this.__isoBounds.z = this.isoZ - Math.abs(this.__phaserIsoGameObject.height) * (1 - this.__phaserIsoGameObject.originY) + Math.abs(this.__phaserIsoGameObject.width * 0.5); return this.__isoBounds; }; IsoObject.prototype.__updateDepth = function () { this.__phaserIsoGameObject.depth = this.isoX + this.isoY; }; IsoObject.prototype.__project = function () { var _a = this.projector.project(this.__isoPosition), x = _a.x, y = _a.y; this.__phaserIsoGameObject.x = x; this.__phaserIsoGameObject.y = y; this.__phaserIsoGameObject.depth = this.__isoPosition.x + this.__isoPosition.y + this.__isoPosition.z * 1.25; if (this.snap > 0) { this.__phaserIsoGameObject.x = Phaser.Math.Snap.To(this.__phaserIsoGameObject.x, this.snap); this.__phaserIsoGameObject.y = Phaser.Math.Snap.To(this.__phaserIsoGameObject.y, this.snap); } }; return IsoObject; }()); exports.IsoObject = IsoObject; //# sourceMappingURL=IsoObject.js.map