Changeset 25090

Timestamp:
Mar 20, 2021, 5:14:35 PM (3 years ago)
Author:
Freagarach
Message:

Store components to be miraged in cmpFogging.

Allows modders (and us) to just add an IID to the array and ensure the Mirage()-function to exist in the respective component.

Differential revision: D3713
Comment by: @wraitii

Location:
ps/trunk/binaries/data/mods/public/simulation/components
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/components/Fogging.js

    r24447 r25090  
    88    "<a:help>Allows this entity to be replaced by mirage entities in the fog-of-war.</a:help>" +
    99    "<empty/>";
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
    1024
    1125Fogging.prototype.Init = function()
     
    107121
    108122    // Store valuable information into the mirage component (especially for the GUI).
    109     let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
    110     if (cmpIdentity)
    111         cmpMirage.CopyIdentity(cmpIdentity);
    112 
    113     let cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation);
    114     if (cmpFoundation)
    115         cmpMirage.CopyFoundation(cmpFoundation);
    116 
    117     let cmpRepairable = Engine.QueryInterface(this.entity, IID_Repairable);
    118     if (cmpRepairable && !cmpFoundation)
    119         cmpMirage.CopyRepairable(cmpRepairable);
    120 
    121     let cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
    122     if (cmpHealth)
    123         cmpMirage.CopyHealth(cmpHealth);
    124 
    125     let cmpCapturable = Engine.QueryInterface(this.entity, IID_Capturable);
    126     if (cmpCapturable)
    127         cmpMirage.CopyCapturable(cmpCapturable);
    128 
    129     let cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply);
    130     if (cmpResourceSupply)
    131         cmpMirage.CopyResourceSupply(cmpResourceSupply);
    132 
    133     let cmpMarket = Engine.QueryInterface(this.entity, IID_Market);
    134     if (cmpMarket)
    135         cmpMirage.CopyMarket(cmpMarket);
     123    for (let component of this.componentsToMirage)
     124        cmpMirage.CopyComponent(component);
    136125
    137126    // Notify the GUI the entity has been replaced by a mirage, in case it is selected at this moment.
  • ps/trunk/binaries/data/mods/public/simulation/components/Mirage.js

    r25089 r25090  
    5050// Parent entity data
    5151
    52 Mirage.prototype.CopyCapturable = function(cmpCapturable)
     52/**
     53 * @param {number} iid - The component to mirage.
     54 */
     55Mirage.prototype.CopyComponent = function(iid)
    5356{
    54     this.miragedIids.set(IID_Capturable, cmpCapturable.Mirage());
    55 };
    56 
    57 Mirage.prototype.CopyFoundation = function(cmpFoundation)
    58 {
    59     this.miragedIids.set(IID_Foundation, cmpFoundation.Mirage());
    60 };
    61 
    62 Mirage.prototype.CopyHealth = function(cmpHealth)
    63 {
    64     this.miragedIids.set(IID_Health, cmpHealth.Mirage());
    65 };
    66 
    67 Mirage.prototype.CopyIdentity = function(cmpIdentity)
    68 {
    69     this.miragedIids.set(IID_Identity, cmpIdentity.Mirage());
    70 };
    71 
    72 Mirage.prototype.CopyMarket = function(cmpMarket)
    73 {
    74     this.miragedIids.set(IID_Market, cmpMarket.Mirage(this.entity, this.player));
    75 };
    76 
    77 Mirage.prototype.CopyRepairable = function(cmpRepairable)
    78 {
    79     this.miragedIids.set(IID_Repairable, cmpRepairable.Mirage());
    80 };
    81 
    82 Mirage.prototype.CopyResourceSupply = function(cmpResourceSupply)
    83 {
    84     this.miragedIids.set(IID_ResourceSupply, cmpResourceSupply.Mirage());
     57    let cmp = Engine.QueryInterface(this.parent, iid);
     58    if (cmp)
     59        this.miragedIids.set(iid, cmp.Mirage(this.entity, this.player));
    8560};
    8661
Note: See TracChangeset for help on using the changeset viewer.