Change GetHARComp to return a ThingComp, since using a type that might not be loaded will cause an error upon trying to open the dev actions

This commit is contained in:
lutepickle 2022-08-18 06:46:34 -07:00
parent 08e3a2fd51
commit 973e83c8f1
2 changed files with 6 additions and 5 deletions

Binary file not shown.

View file

@ -14,15 +14,16 @@ namespace RJW_Menstruation
return pawn?.def is ThingDef_AlienRace;
}
public static AlienPartGenerator.AlienComp GetHARComp(this Pawn pawn)
// Can't have it be a AlienPartGenerator.AlienComp due to the way the dev actions look for functions
public static ThingComp GetHARComp(this Pawn pawn)
{
return pawn?.TryGetComp<AlienPartGenerator.AlienComp>();
}
public static void CopyHARProperties(Pawn baby, Pawn original)
{
AlienPartGenerator.AlienComp babyHARComp = baby.GetHARComp();
AlienPartGenerator.AlienComp originalHARComp = original.GetHARComp();
AlienPartGenerator.AlienComp babyHARComp = (AlienPartGenerator.AlienComp)baby.GetHARComp();
AlienPartGenerator.AlienComp originalHARComp = (AlienPartGenerator.AlienComp)original.GetHARComp();
if (babyHARComp == null || originalHARComp == null) return;
babyHARComp.crownType = originalHARComp.crownType;
@ -37,8 +38,8 @@ namespace RJW_Menstruation
// HAR doesn't populate variants until the graphics are called for, so this has to happen late
public static void CopyHARPropertiesPostBirth(Pawn baby, Pawn original)
{
AlienPartGenerator.AlienComp babyHARComp = baby.GetHARComp();
AlienPartGenerator.AlienComp originalHARComp = original.GetHARComp();
AlienPartGenerator.AlienComp babyHARComp = (AlienPartGenerator.AlienComp)baby.GetHARComp();
AlienPartGenerator.AlienComp originalHARComp = (AlienPartGenerator.AlienComp)original.GetHARComp();
if (babyHARComp == null || originalHARComp == null) return;
if (originalHARComp.addonVariants != null) // Testing has shown that the addons are valid by this point, but it's better to be safe
babyHARComp.addonVariants = new List<int>(originalHARComp.addonVariants);