Spaces:
Running
Running
File size: 3,435 Bytes
4ee4376 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
import Phaser from 'phaser';
import location from './location';
import corners from './corners';
import * as CONST from '../constants';
export default class position {
#depth = 0;
#depthAdjustment = 0;
#rotate = false;
#location;
#cell;
#offset;
#seaLevel;
#corners;
constructor (options) {
this.#cell = options.cell;
this.#location = new location(options.data.x, options.data.y, options.data.z);
this.#rotate = options.data.rotate;
this.#corners = new corners({ cell: this.#cell, corners: options.data.corners });
this.updateOffset();
}
get depth () {
return (this.#location.x + this.#location.y) * 64;
}
set depth (depth) {
this.#depthAdjustment = depth;
}
get rotate () {
return this.#rotate;
}
set rotate (rotate) {
this.#rotate = rotate;
}
get corners () {
return this.#corners;
}
set corners (corners) {
this.#corners = new corners(corners);
}
get underwater () {
if (this.z < this.#cell.scene.city.waterLevel && [CONST.TERRAIN_SUBMERGED, CONST.TERRAIN_SHORE].includes(this.#cell.water.type))
return true;
else
return false;
}
get seaLevel () {
let offset = (this.#cell.scene.city.waterLevel - this.z) * CONST.LAYER_OFFSET;
if (offset < 0)
offset = 0;
return offset;
}
get offset () {
return this.#offset;
}
updateOffset () {
this.#offset = new location(
(this.x - this.y) * (CONST.TILE_WIDTH / 2),
(this.y + this.x) * (CONST.TILE_HEIGHT / 2),
(CONST.LAYER_OFFSET * this.z) + CONST.LAYER_OFFSET
);
}
get location () {
return this.#location;
}
set x (x) {
this.#location.x = x;
this.updateOffset();
}
set y (y) {
this.#location.y = y;
this.updateOffset();
}
set z (z) {
this.#location.z = z;
this.updateOffset();
}
get x () {
return this.#location.x;
}
get y () {
return this.#location.y;
}
get z () {
return this.#location.z;
}
get top () {
return new Phaser.Math.Vector2(
this.#offset.x + (CONST.TILE_WIDTH / 2),
this.#offset.y - this.#offset.z - CONST.TILE_HEIGHT
);
}
get topLeft () {
return new Phaser.Math.Vector2(
this.#offset.x,
this.#offset.y - this.#offset.z - CONST.TILE_HEIGHT
);
}
get topRight () {
return new Phaser.Math.Vector2(
this.#offset.x + CONST.TILE_WIDTH,
this.#offset.y - this.#offset.z - CONST.TILE_HEIGHT
);
}
get center () {
return new Phaser.Math.Vector2(
this.#offset.x + (CONST.TILE_WIDTH / 2),
(this.#offset.y - this.#offset.z) - (CONST.TILE_WIDTH / 2)
);
}
get centerLeft () {
return new Phaser.Math.Vector2(
this.#offset.x,
(this.#offset.y - this.#offset.z) - (CONST.TILE_WIDTH / 2)
);
}
get centerRight () {
return new Phaser.Math.Vector2(
this.#offset.x + CONST.TILE_WIDTH,
(this.#offset.y - this.#offset.z) - (CONST.TILE_WIDTH / 2)
);
}
get bottom () {
return new Phaser.Math.Vector2(
this.#offset.x + (CONST.TILE_WIDTH / 2),
this.#offset.y - this.#offset.z
);
}
get bottomLeft () {
return new Phaser.Math.Vector2(
this.#offset.x,
this.#offset.y - this.#offset.z
);
}
get bottomRight () {
return new Phaser.Math.Vector2(
this.#offset.x + CONST.TILE_WIDTH,
this.#offset.y - this.#offset.z
);
}
} |