Component Mod Classes - PULSAR-Modders/pulsar-mod-loader GitHub Wiki
Modded components are handled through inheritable classes found in PulsarModLoader.Content.Components
. They are handled in one of two ways: A inherited class which is fed values and methods which are used to override a component, or a class which contains an instantiation call for a PLShipComponent which would be a component created for the mod. The former can only override provided options, while the latter can be customized greatly. Examples for the differences would include Reactors vs Turrets which have been included below, however most principles will apply to every other modded component type.
Note the Name
value for all components must be unique. Components with duplicate names will not be loaded.
Value-Fed Component
The ReactorMod class has many overridable values such as Name, Description, EnergyOutputMax, etc.
class Goodie : PulsarModLoader.Content.Components.Reactor.ReactorMod
{
public override string Name => "Goodie";
public override string Description => "Idk, I just make things";
public override float EnergyOutputMax => 1000000f;
public override bool Experimental => true;
}
Instantiated Component
The TurretMod class only has two overridable values. The PLShipComponent and the unique Name for the manager (will not be applied to the shipcomponent itself).
class DragonTurretMod : PulsarModLoader.Content.Components.Turret.TurretMod
{
public override PLShipComponent PLTurret => new DragonTurret();
public override string Name => "MegaDragonCannon";
}
Getting the Component Subtype
Component subtypes are thrown into the log file on load, and can be acquired in game through each manager's ID request method, which simply requires the component name. For reactors, the method used is ReactorModManager.Instance.GetReactorIDFromName(string ReactorName)
. All components have a similarly named method.
Instantiating Components
Each component manager has a class for instantiating the component. For Reactors, the following method is used: ReactorModManager.Instance.CreateReactor(int Subtype, int level)
. All components have a similar method for instantiating components, each of which will instantiate a PLShipComponent of the specified type (PLReactor for this example).
Additionally, all vanilla methods which instantiate components through their typeIDs will return modded components if the IDs match.