summaryrefslogtreecommitdiff
path: root/src/scripts/views/layers/wall.ts
blob: 06ba46756414ffa232eb3acee064773175684e00 (plain)
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
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
                );
            }
        });
    }
}