A little code cleanup

This commit is contained in:
lutepickle 2023-03-05 19:24:23 -08:00
parent 8752aa1437
commit 842f6ceec1
6 changed files with 20 additions and 41 deletions

View file

@ -28,10 +28,7 @@ namespace RJW_Menstruation
}
}
}
if (filth != null)
{
filth.AddSources(sources);
}
filth?.AddSources(sources);
return false;
}
if (filth != null)

View file

@ -207,8 +207,7 @@ namespace RJW_Menstruation
do
{
Pawn baby = comp.babies[0];
Pawn thisFather = baby.GetFather();
if (thisFather == null) thisFather = father;
Pawn thisFather = baby.GetFather() ?? father;
baby.relations.ClearAllRelations(); // To keep ApplyBirthOutcome from erroring when it tries to set up relations
PregnancyUtility.ApplyBirthOutcome(thisOutcome, quality, ritual, genes, geneticMother, birtherThing, thisFather, doctor, lordJobRitual, assignments);
@ -258,8 +257,7 @@ namespace RJW_Menstruation
do
{
Pawn baby = comp.babies[0];
Pawn thisFather = baby.GetFather();
if (thisFather == null) thisFather = father;
Pawn thisFather = baby.GetFather() ?? father;
baby.relations.ClearAllRelations();
PregnancyUtility.ApplyBirthOutcome(outcome, quality, ritual, genes, geneticMother, birtherThing, thisFather, doctor, lordJobRitual, assignments);

View file

@ -151,10 +151,7 @@ namespace RJW_Menstruation
else if (gestationProgress < 0.8f) icon = fetustex + "04";
else icon = fetustex + "05";
Texture2D result = TryGetTwinsIcon(icon, babycount);
if (result == null) result = ContentFinder<Texture2D>.Get((icon), true);
return result;
return TryGetTwinsIcon(icon, babycount) ?? ContentFinder<Texture2D>.Get((icon), true);
}
public static Texture2D TryGetTwinsIcon(string path, int babycount)
@ -205,10 +202,7 @@ namespace RJW_Menstruation
if (hediffs.Count == 1) return ContentFinder<Texture2D>.Get(path + "Womb_Egged_Large", true);
else return ContentFinder<Texture2D>.Get(path + "Womb_Egged_ManyMixed", true);
}
Texture2D result = ContentFinder<Texture2D>.Get(path + "Womb_Egged_" + hediffs.Count(), false);
if (result == null) result = ContentFinder<Texture2D>.Get(path + "Womb_Egged_Many", true);
return result;
return ContentFinder<Texture2D>.Get(path + "Womb_Egged_" + hediffs.Count(), false) ?? ContentFinder<Texture2D>.Get(path + "Womb_Egged_Many", true);
}
public static Texture2D GetWombIcon(this HediffComp_Menstruation comp)
{
@ -307,8 +301,8 @@ namespace RJW_Menstruation
public static Texture2D GetAnalIcon(this Pawn pawn, bool drawOrigin = false)
{
Hediff hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_anusBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllAnuses.Contains(h.def));
if (hediff == null) hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_anusBPR(pawn)).FirstOrDefault(h => h.def.defName.ToLower().Contains("anus"));
Hediff hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_anusBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllAnuses.Contains(h.def)) ??
Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_anusBPR(pawn)).FirstOrDefault(h => h.def.defName.ToLower().Contains("anus"));
if (hediff == null) return ContentFinder<Texture2D>.Get(("Genitals/Anal00"), true);
string icon;

View file

@ -150,8 +150,7 @@ namespace RJW_Menstruation
if (Configurations.EnableBirthVaginaMorph)
{
// The comp still has the pregnancy attached at this point in the process
Hediff vagina = __instance.GetMenstruationCompFromPregnancy()?.parent;
if (vagina == null) vagina = mother.health.hediffSet.hediffs.FirstOrFallback(x => VariousDefOf.AllVaginas.Contains(x.def));
Hediff vagina = (__instance.GetMenstruationCompFromPregnancy()?.parent) ?? mother.health.hediffSet.hediffs.FirstOrFallback(x => VariousDefOf.AllVaginas.Contains(x.def));
if (vagina == null) return;
float morph = Mathf.Max(baby.BodySize - Mathf.Pow(vagina.Severity * mother.BodySize, 2), 0f);
vagina.Severity += morph * Configurations.VaginaMorphPower;

View file

@ -37,20 +37,14 @@ namespace RJW_Menstruation
{
BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
FieldInfo fieldInfo = type?.GetField(name, flags);
if (fieldInfo != null)
{
fieldInfo.SetValue(null, value);
}
fieldInfo?.SetValue(null, value);
}
public static void SetMemberValue(this object obj, string name, object value)
{
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
FieldInfo fieldInfo = obj?.GetType().GetField(name, flags);
if (fieldInfo != null)
{
fieldInfo.SetValue(obj, value);
}
fieldInfo?.SetValue(obj, value);
}

View file

@ -66,12 +66,10 @@ namespace RJW_Menstruation
public static float GetCumVolume(this Pawn pawn, List<Hediff> hediffs)
{
CompHediffBodyPart part = hediffs?.FindAll((Hediff hed) => hed.def.defName.ToLower().Contains("penis")).InRandomOrder().FirstOrDefault()?.TryGetComp<CompHediffBodyPart>();
if (part == null) part = hediffs?.FindAll((Hediff hed) => hed.def.defName.ToLower().Contains("ovipositorf")).InRandomOrder().FirstOrDefault()?.TryGetComp<CompHediffBodyPart>();
if (part == null) part = hediffs?.FindAll((Hediff hed) => hed.def.defName.ToLower().Contains("ovipositorm")).InRandomOrder().FirstOrDefault()?.TryGetComp<CompHediffBodyPart>();
if (part == null) part = hediffs?.FindAll((Hediff hed) => hed.def.defName.ToLower().Contains("tentacle")).InRandomOrder().FirstOrDefault()?.TryGetComp<CompHediffBodyPart>();
CompHediffBodyPart part = (((hediffs?.FindAll((Hediff hed) => hed.def.defName.ToLower().Contains("penis")).InRandomOrder().FirstOrDefault()?.TryGetComp<CompHediffBodyPart>()) ??
(hediffs?.FindAll((Hediff hed) => hed.def.defName.ToLower().Contains("ovipositorf")).InRandomOrder().FirstOrDefault()?.TryGetComp<CompHediffBodyPart>())) ??
(hediffs?.FindAll((Hediff hed) => hed.def.defName.ToLower().Contains("ovipositorm")).InRandomOrder().FirstOrDefault()?.TryGetComp<CompHediffBodyPart>())) ??
(hediffs?.FindAll((Hediff hed) => hed.def.defName.ToLower().Contains("tentacle")).InRandomOrder().FirstOrDefault()?.TryGetComp<CompHediffBodyPart>());
return pawn.GetCumVolume(part);
}
@ -194,9 +192,8 @@ namespace RJW_Menstruation
public static void DrawBreastIcon(this Pawn pawn, Rect rect)
{
Hediff hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_breastsBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllBreasts.Contains(h.def));
if (hediff == null)
hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_uddersBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllBreasts.Contains(h.def));
Hediff hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_breastsBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllBreasts.Contains(h.def)) ??
Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_uddersBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllBreasts.Contains(h.def));
Texture2D breast, nipple, areola;
if (hediff != null)
{
@ -359,15 +356,15 @@ namespace RJW_Menstruation
}
public static string GetAnusLabel(this Pawn pawn)
{
Hediff hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_anusBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllAnuses.Contains(h.def));
if (hediff == null) hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_anusBPR(pawn)).FirstOrDefault(h => h.def.defName.ToLower().Contains("anus"));
Hediff hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_anusBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllAnuses.Contains(h.def)) ??
Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_anusBPR(pawn)).FirstOrDefault(h => h.def.defName.ToLower().Contains("anus"));
if (hediff != null) return hediff.LabelBase.CapitalizeFirst() + "\n(" + hediff.LabelInBrackets + ")";
else return "";
}
public static string GetBreastLabel(this Pawn pawn)
{
Hediff hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_breastsBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllBreasts.Contains(h.def));
if (hediff == null) hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_uddersBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllBreasts.Contains(h.def));
Hediff hediff = Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_breastsBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllBreasts.Contains(h.def)) ??
Genital_Helper.get_PartsHediffList(pawn, Genital_Helper.get_uddersBPR(pawn)).FirstOrDefault(h => VariousDefOf.AllBreasts.Contains(h.def));
if (hediff != null) return hediff.LabelBase.CapitalizeFirst() + "\n(" + hediff.LabelInBrackets + ")";
else return "";
}