Add PeekBaby and BabyCount to PregeneratedBabies

This commit is contained in:
lutepickle 2024-05-17 08:36:12 -07:00
parent afcb7bf7c5
commit 64923264b9
4 changed files with 21 additions and 6 deletions

Binary file not shown.

View File

@ -21,7 +21,22 @@ namespace RJW_Menstruation
public bool HasBaby
{
get => !babies.NullOrEmpty();
get => !babies.NullOrEmpty();
}
public int BabyCount
{
get
{
if (babies == null) return 0;
else return babies.Count;
}
}
public Pawn PeekBaby()
{
if (babies.NullOrEmpty()) return null;
else return babies.First();
}
public Pawn PopBaby()
@ -210,7 +225,7 @@ namespace RJW_Menstruation
float birthQuality = PregnancyUtility.GetBirthQualityFor(mother);
do
{
Pawn baby = comp.babies[0];
Pawn baby = comp.PeekBaby();
Pawn thisFather = baby.GetFather() ?? father;
baby.relations.ClearAllRelations(); // To keep ApplyBirthOutcome from erroring when it tries to set up relations
@ -269,7 +284,7 @@ namespace RJW_Menstruation
// Though even if it does, that's probably okay. More babies more memories after all
do
{
Pawn baby = comp.babies[0];
Pawn baby = comp.PeekBaby();
Pawn thisFather = baby.GetFather() ?? father;
baby.relations.ClearAllRelations();

View File

@ -118,8 +118,8 @@ namespace RJW_Menstruation
}
else if (babiescomp?.HasBaby ?? false)
{
babydef = babiescomp.babies.First().def;
babycount = babiescomp.babies.Count;
babydef = babiescomp.PeekBaby().def;
babycount = babiescomp.BabyCount;
}
else
{

View File

@ -178,7 +178,7 @@ namespace RJW_Menstruation
}
}
HediffComp_PregeneratedBabies babiescomp = comp.Pregnancy.TryGetComp<HediffComp_PregeneratedBabies>();
return babiescomp?.babies?.FirstOrDefault();
return babiescomp?.PeekBaby();
}
public static void DrawBreastIcon(this Pawn pawn, Rect rect)