From 969310c932ae847732b1e90da005924fdadcf5a8 Mon Sep 17 00:00:00 2001 From: Mal Date: Wed, 29 Jan 2020 00:33:53 +0100 Subject: [PATCH] Tilorswift: Background color and fix table size. --- levels/level.json | 1 + tilorswift/js/Terrain.js | 11 ++++++++--- tilorswift/style.css | 1 - 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/levels/level.json b/levels/level.json index 2fc095e..82564c9 100644 --- a/levels/level.json +++ b/levels/level.json @@ -4,6 +4,7 @@ "scale": 3, "rows": 10, "columns": 17, + "backgroundColor": "#6096ff", "matrix": [ [6 ,6 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,4 ,4 ], [6 ,6 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,4 ,4 ], diff --git a/tilorswift/js/Terrain.js b/tilorswift/js/Terrain.js index c4fc135..f32ea8d 100644 --- a/tilorswift/js/Terrain.js +++ b/tilorswift/js/Terrain.js @@ -3,20 +3,25 @@ import Tileset from "./Tileset.js"; export default class Terrain { - constructor(tileset, tilesX, tilesY) + constructor(tileset, tilesX, tilesY, backgroundColor = 'black') { this.tileset = tileset; this.fields = []; this.tilesX = tilesX; this.tilesY = tilesY; + this.backgroundColor = backgroundColor; this.htmlElement = document.createElement('table'); - this.htmlElement.id = 'level'; this.init(); } init() { + this.htmlElement.id = 'level'; + this.htmlElement.style.backgroundColor = this.backgroundColor; + this.htmlElement.style.width = this.tileset.getTileWidth() * this.tilesX + 'px'; + this.htmlElement.style.height = this.tileset.getTileHeight() * this.tilesY + 'px'; + for (let r = 0; r < this.tilesY; r++) { let row = []; let tr = document.createElement('tr'); @@ -51,7 +56,7 @@ export default class Terrain imageTileset.src = terrainData.tileset; let tileset = new Tileset(imageTileset, terrainData.tiles, terrainData.scale); - let terrain = new Terrain(tileset, terrainData.columns, terrainData.rows); + let terrain = new Terrain(tileset, terrainData.columns, terrainData.rows, terrainData.backgroundColor); for (let y = 0; y < terrainData.matrix.length; y++) { for (let x = 0; x < terrainData.matrix[y].length; x++) { diff --git a/tilorswift/style.css b/tilorswift/style.css index 8d299b3..a3f8565 100644 --- a/tilorswift/style.css +++ b/tilorswift/style.css @@ -1,7 +1,6 @@ body { padding: 0; margin: 0; - background-color: #6096ff; } #level {