Skip to content
Gareth Parker edited this page May 17, 2023 · 7 revisions

While they share the same name as comps in the base game, comps for your replace lists work differently. A comp for your replacement list must implement the Replace_Stuff_Compatibility.Comps.IReplacementComp interface, defining a PreAction and PostAction method. PreAction will occur when the New Thing has been built, but before the Old Thing has been destroyed. This is useful for transferring items or settings between the two Things. PostAction will occur after the Old Thing has been destroyed. Here's an example:

namespace Replace_Stuff_Compatibility.Comps;

public class CopyStorageSettingsComp: IReplacementComp
{
  public void PreAction(Thing newThing, Thing oldThing)
  {
    if (newThing is not Building_Storage newStorage || oldThing is not Building_Storage oldStorage) return;
    
    newStorage.settings.CopyFrom(oldStorage.settings);
  }

  public void PostAction(Thing newThing, Thing oldThing)
  {
  }
}

This comp will take the New Thing and Old Thing, check that they are both storage buildings and copy over the Storage Settings. Note that attempting to put the logic in PostAction will not work, since the oldThing will have already been destroyed.

In order to define that a list uses this comp, we declare the Class Name in a list of comps, as such:

<Defs>
  <Replace_Stuff_Compatibility.InterchangeableItems MayRequire="lwm.deepstorage">
    <defName>ReplacementMod_DeepStorage</defName>
    <replaceLists>
      <li>
        <items>
          <li>Shelf</li>
          <li>LWM_BigShelf</li>
          <li>LWM_VeryBigShelf</li>
        </items>
        <comps>
          <li>Replace_Stuff_Compatibility.Comps.CopyStorageSettingsComp</li>
        </comps>
      </li>
    </replaceLists>
  </Replace_Stuff_Compatibility.InterchangeableItems>
</Defs>

Note that we are declaring the Class Name as a string value as opposed to using the traditional <li Class="YourCompHere"> syntax from the main game. Comps can be useful for reducing the fuss of replacing items that require some configuration, such as Armour Racks that are assigned to Colonists or Heaters/Coolers that have assigned temperatures.

The main restriction behind comps is that Category lists cannot have comps attached to them.

Clone this wiki locally