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

          Line data    Source code
       1           0 : const VIS_HIDDEN = 0;
       2           0 : const VIS_FOGGED = 1;
       3           0 : const VIS_VISIBLE = 2;
       4             : 
       5             : function Mirage() {}
       6             : 
       7           0 : Mirage.prototype.Schema =
       8             :         "<a:help>Mirage entities replace real entities in the fog-of-war.</a:help>" +
       9             :         "<empty/>";
      10             : 
      11           0 : Mirage.prototype.Init = function()
      12             : {
      13           0 :         this.parent = INVALID_ENTITY;
      14           0 :         this.player = null;
      15             : 
      16           0 :         this.miragedIids = new Map();
      17             : };
      18             : 
      19           0 : Mirage.prototype.SetParent = function(ent)
      20             : {
      21           0 :         this.parent = ent;
      22             : };
      23             : 
      24           0 : Mirage.prototype.GetParent = function()
      25             : {
      26           0 :         return this.parent;
      27             : };
      28             : 
      29           0 : Mirage.prototype.SetPlayer = function(player)
      30             : {
      31           0 :         this.player = player;
      32             : };
      33             : 
      34           0 : Mirage.prototype.GetPlayer = function()
      35             : {
      36           0 :         return this.player;
      37             : };
      38             : 
      39           0 : Mirage.prototype.Mirages = function(iid)
      40             : {
      41           0 :         return this.miragedIids.has(iid);
      42             : };
      43             : 
      44           0 : Mirage.prototype.Get = function(iid)
      45             : {
      46           0 :         return this.miragedIids.get(iid);
      47             : };
      48             : 
      49             : // ============================
      50             : // Parent entity data
      51             : 
      52             : /**
      53             :  * @param {number} iid - The component to mirage.
      54             :  */
      55           0 : Mirage.prototype.CopyComponent = function(iid)
      56             : {
      57           0 :         let cmp = Engine.QueryInterface(this.parent, iid);
      58           0 :         if (cmp)
      59           0 :                 this.miragedIids.set(iid, cmp.Mirage(this.entity, this.player));
      60             : };
      61             : 
      62             : // ============================
      63             : 
      64           0 : Mirage.prototype.OnVisibilityChanged = function(msg)
      65             : {
      66             :         // Mirages get VIS_HIDDEN when the original entity becomes VIS_VISIBLE.
      67           0 :         if (msg.player != this.player || msg.newVisibility != VIS_HIDDEN)
      68           0 :                 return;
      69             : 
      70           0 :         if (this.miragedIids.has(IID_Market))
      71           0 :                 this.miragedIids.get(IID_Market).UpdateTraders(msg);
      72             : 
      73           0 :         if (this.parent == INVALID_ENTITY)
      74           0 :                 Engine.DestroyEntity(this.entity);
      75             :         else
      76           0 :                 Engine.PostMessage(this.entity, MT_EntityRenamed, { "entity": this.entity, "newentity": this.parent });
      77             : };
      78             : 
      79           0 : Engine.RegisterComponentType(IID_Mirage, "Mirage", Mirage);

Generated by: LCOV version 1.14