LCOV - code coverage report
Current view: top level - maps/random/rmgen/painter - LayeredPainter.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 13 14 92.9 %
Date: 2023-04-02 12:52:40 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /**
       2             :  * The LayeredPainter sets different Terrains within the Area.
       3             :  * It choses the Terrain depending on the distance to the border of the Area.
       4             :  *
       5             :  * The Terrains given in the first array are painted from the border of the area towards the center (outermost first).
       6             :  * The widths array has one item less than the Terrains array.
       7             :  * Each width specifies how many tiles the corresponding Terrain should be wide (distance to the prior Terrain border).
       8             :  * The remaining area is filled with the last terrain.
       9             :  */
      10             : function LayeredPainter(terrainArray, widths)
      11             : {
      12           1 :         if (!(terrainArray instanceof Array))
      13           0 :                 throw new Error("LayeredPainter: terrains must be an array!");
      14             : 
      15           2 :         this.terrains = terrainArray.map(terrain => createTerrain(terrain));
      16           1 :         this.widths = widths;
      17             : }
      18             : 
      19           6 : LayeredPainter.prototype.paint = function(area)
      20             : {
      21           1 :         breadthFirstSearchPaint({
      22             :                 "area": area,
      23             :                 "brushSize": 1,
      24             :                 "gridSize": g_Map.getSize(),
      25        1251 :                 "withinArea": (area, position) => area.contains(position),
      26             :                 "paintTile": (point, distance) => {
      27          49 :                         let width = 0;
      28          49 :                         let i = 0;
      29             : 
      30          49 :                         for (; i < this.widths.length; ++i)
      31             :                         {
      32          49 :                                 width += this.widths[i];
      33          49 :                                 if (width >= distance)
      34          40 :                                         break;
      35             :                         }
      36             : 
      37          49 :                         this.terrains[i].place(point);
      38             :                 }
      39             :         });
      40             : };

Generated by: LCOV version 1.14