summaryrefslogtreecommitdiff
path: root/src/scripts/views/layers/wall.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripts/views/layers/wall.ts')
-rw-r--r--src/scripts/views/layers/wall.ts62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/scripts/views/layers/wall.ts b/src/scripts/views/layers/wall.ts
new file mode 100644
index 00000000..06ba4675
--- /dev/null
+++ b/src/scripts/views/layers/wall.ts
@@ -0,0 +1,62 @@
+import {Colors} from "../../colors";
+import {MapView} from "../mapview";
+import {Util} from "../../util";
+import {Layer} from "./layer";
+import {CELL_SIZE} from "../../controllers/mapcontroller";
+
+
+/**
+ * Class responsible for rendering the walls.
+ */
+export class WallLayer implements Layer {
+ public container: createjs.Container;
+
+ private mapView: MapView;
+ private walls: IRoomWall[];
+ private wallLineWidth: number;
+
+
+ constructor(mapView: MapView) {
+ this.mapView = mapView;
+ this.container = new createjs.Container();
+ this.wallLineWidth = CELL_SIZE / 20.0;
+
+ this.generateWalls();
+ this.draw();
+ }
+
+ /**
+ * Calls the Util.deriveWallLocations function to generate the wall locations.
+ */
+ public generateWalls(): void {
+ this.walls = Util.deriveWallLocations(this.mapView.currentDatacenter.rooms);
+ }
+
+ /**
+ * Draws all walls to the canvas.
+ */
+ public draw(): void {
+ this.container.removeAllChildren();
+
+ // Draw walls
+ this.walls.forEach((element: IRoomWall) => {
+ if (element.horizontal) {
+ MapView.drawLine(
+ CELL_SIZE * element.startPos[0] - this.wallLineWidth / 2.0,
+ CELL_SIZE * element.startPos[1],
+ CELL_SIZE * (element.startPos[0] + element.length) + this.wallLineWidth / 2.0,
+ CELL_SIZE * element.startPos[1],
+ this.wallLineWidth, Colors.WALL_COLOR, this.container
+ );
+ } else {
+ MapView.drawLine(
+ CELL_SIZE * element.startPos[0],
+ CELL_SIZE * element.startPos[1] - this.wallLineWidth / 2.0,
+ CELL_SIZE * element.startPos[0],
+ CELL_SIZE * (element.startPos[1] + element.length) + this.wallLineWidth / 2.0,
+ this.wallLineWidth, Colors.WALL_COLOR, this.container
+ );
+ }
+ });
+ }
+} \ No newline at end of file