LCOV - code coverage report
Current view: top level - simulation/components - BiomeReplacer.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 18 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /**
       2             :   * A manager class for biomes.
       3             :   * @class
       4             :   * @constructor
       5             :   */
       6             : function BiomeReplacer() {}
       7             : 
       8             : /**
       9             :  * Defines the XML schema and help strings of the component.
      10             :  * @memberof BiomeReplacer
      11             :  */
      12           0 : BiomeReplacer.prototype.Schema = `
      13             :         <a:help>Defines the variants an entity can assume depending on a map biome.</a:help>
      14             :         <a:example>
      15             :                 <Variants>
      16             :                         <Winter>
      17             :                                 <AffectedBiomes datatype="tokens">generic/alpine</AffectedBiomes>
      18             :                                 <ActorVariant>winter</ActorVariant>
      19             :                         </Winter>
      20             :                 </Variants>
      21             :         </a:example>
      22             :         <element name='Variants' a:help='Effect for having multiple builders.'>
      23             :                 <oneOrMore>
      24             :                         <element a:help='Element containing the variant data.'>
      25             :                                 <anyName/>
      26             :                                 <interleave>
      27             :                                         <element name='AffectedBiomes' a:help='Names of the biomes affected byt this variant'>
      28             :                                                 <attribute name='datatype'>
      29             :                                                         <value>tokens</value>
      30             :                                                 </attribute>
      31             :                                                 <text/>
      32             :                                         </element>
      33             :                                         <element name='ActorVariant' a:help='Actor variant to switch to.'>
      34             :                                                 <text/>
      35             :                                         </element>
      36             :                                 </interleave>
      37             :                         </element>
      38             :                 </oneOrMore>
      39             :         </element>`;
      40             : 
      41             : /**
      42             :  * Initializes the biome replacer.
      43             :  * @memberof BiomeReplacer
      44             :  */
      45           0 : BiomeReplacer.prototype.Init = function()
      46             : {
      47             : 
      48             : }
      49             : 
      50             : 
      51             : /**
      52             :  * @param {{ "from": number, "to": number }} msg - Message containing the old new owner.
      53             :  * @memberof BiomeReplacer
      54             :  */
      55           0 : BiomeReplacer.prototype.OnCreate = function(msg)
      56             : {
      57             : 
      58           0 :                 const currentBiome = Engine.QueryInterface(SYSTEM_ENTITY, IID_BiomeManager)?.GetBiome();
      59             : 
      60           0 :                 if (!currentBiome)
      61           0 :                         return;
      62             : 
      63           0 :                 let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
      64             : 
      65           0 :                 if (!cmpVisual)
      66           0 :                         return;
      67             : 
      68           0 :                 for (const variantName of Object.keys(this.template.Variants))
      69             :                 {
      70           0 :                         const variant = this.template.Variants[variantName];
      71           0 :                         if (!variant.AffectedBiomes || !variant.AffectedBiomes._string)
      72           0 :                                 continue;
      73             : 
      74           0 :                         const affectedBiomes = variant.AffectedBiomes._string.split(" ");
      75           0 :                         if (affectedBiomes.indexOf(currentBiome) !== -1)
      76             :                         {
      77           0 :                                 cmpVisual.SelectAnimation(variant.ActorVariant, false, 1.0);
      78           0 :                                 return;
      79             :                         }
      80             :                 }
      81             : };
      82             : 
      83           0 : Engine.RegisterComponentType(IID_BiomeReplacer, "BiomeReplacer", BiomeReplacer);

Generated by: LCOV version 1.14