Line data Source code
1 : /** 2 : * Paints the given texture-mapping to the given tiles. 3 : * 4 : * @param {string[]} textureIDs - Names of the terrain textures 5 : * @param {number[]} textureNames - One-dimensional array of indices of texturenames, one for each tile of the entire map. 6 : * @returns 7 : */ 8 : function TerrainTextureArrayPainter(textureIDs, textureNames) 9 : { 10 0 : this.textureIDs = textureIDs; 11 0 : this.textureNames = textureNames; 12 : } 13 : 14 6 : TerrainTextureArrayPainter.prototype.paint = function(area) 15 : { 16 0 : let sourceSize = Math.sqrt(this.textureIDs.length); 17 0 : let scale = sourceSize / g_Map.getSize(); 18 : 19 0 : for (let point of area.getPoints()) 20 : { 21 0 : let sourcePos = Vector2D.mult(point, scale).floor(); 22 0 : g_Map.setTexture(point, this.textureNames[this.textureIDs[sourcePos.x * sourceSize + sourcePos.y]]); 23 : } 24 : };