LCOV - code coverage report
Current view: top level - maps/random/rmgen - Terrain.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 7 13 53.8 %
Date: 2023-04-02 12:52:40 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /**
       2             :  * @file A Terrain is a class that modifies an arbitrary property of a given tile.
       3             :  */
       4             : 
       5             : /**
       6             :  * SimpleTerrain paints the given texture on the terrain.
       7             :  *
       8             :  * Optionally it places an entity on the affected tiles and
       9             :  * replaces prior entities added by SimpleTerrain on the same tile.
      10             :  */
      11             : function SimpleTerrain(texture, templateName = undefined)
      12             : {
      13           2 :         if (texture === undefined)
      14           0 :                 throw new Error("SimpleTerrain: texture not defined");
      15             : 
      16           2 :         this.texture = texture;
      17           2 :         this.templateName = templateName;
      18             : }
      19             : 
      20           6 : SimpleTerrain.prototype.place = function(position)
      21             : {
      22          49 :         if (this.templateName && g_Map.validTilePassable(position))
      23           0 :                 g_Map.setTerrainEntity(this.templateName, 0, Vector2D.add(position, new Vector2D(0.5, 0.5)), randomAngle());
      24             : 
      25          49 :         g_Map.setTexture(position, this.texture);
      26             : };
      27             : 
      28             : /**
      29             :  * RandomTerrain places one of the given Terrains on the tile.
      30             :  * It choses a random Terrain each tile.
      31             :  * This is commonly used to create heterogeneous forests.
      32             :  */
      33             : function RandomTerrain(terrains)
      34             : {
      35           0 :         if (!(terrains instanceof Array) || !terrains.length)
      36           0 :                 throw new Error("RandomTerrain: Invalid terrains array");
      37             : 
      38           0 :         this.terrains = terrains;
      39             : }
      40             : 
      41           6 : RandomTerrain.prototype.place = function(position)
      42             : {
      43           0 :         pickRandom(this.terrains).place(position);
      44             : };

Generated by: LCOV version 1.14