Fix HAR compatibility, copy all HAR properties for enzygotic siblings.

This commit is contained in:
lutepickle 2022-08-11 18:43:12 -07:00
parent 624ae1ce75
commit d1ceebb4e7
7 changed files with 39 additions and 20 deletions

Binary file not shown.

View file

@ -249,8 +249,8 @@ namespace RJW_Menstruation
public RJW_Menstruation(ModContentPack content) : base(content)
{
GetSettings<Configurations>();
Configurations.HARActivated = ModLister.HasActiveModWithName("Humanoid Alien Races 2.0");
Configurations.LLActivated = ModLister.HasActiveModWithName("RimJobWorld - Licentia Labs");
Configurations.HARActivated = ModLister.GetActiveModWithIdentifier("erdelf.HumanoidAlienRaces") != null;
Configurations.LLActivated = ModLister.GetActiveModWithIdentifier("LustLicentia.RJWLabs") != null;
}

View file

@ -1,4 +1,6 @@
using System.Linq;
using AlienRace;
using System.Collections.Generic;
using UnityEngine;
using Verse;
namespace RJW_Menstruation
@ -8,24 +10,38 @@ namespace RJW_Menstruation
public static bool IsHAR(this Pawn pawn)
{
return pawn.def.GetType().ToString().StartsWith("AlienRace");
if (!Configurations.HARActivated) return false;
return pawn?.def is ThingDef_AlienRace;
}
public static ThingComp GetHARComp(this Pawn pawn)
public static AlienPartGenerator.AlienComp GetHARComp(this Pawn pawn)
{
return pawn?.GetComps<ThingComp>()?.First(x => x.GetType().Namespace.EqualsIgnoreCase("AlienRace") && x.GetType().Name.EndsWith("AlienComp"));
return pawn?.TryGetComp<AlienPartGenerator.AlienComp>();
}
public static string GetHARCrown(this Pawn pawn)
public static void CopyHARProperties(Pawn baby, Pawn original)
{
return (string)pawn.GetHARComp().GetMemberValue("crownType");
AlienPartGenerator.AlienComp babyHARComp = baby.GetHARComp();
AlienPartGenerator.AlienComp originalHARComp = original.GetHARComp();
if (babyHARComp == null || originalHARComp == null) return;
babyHARComp.crownType = originalHARComp.crownType;
foreach(KeyValuePair<string, AlienPartGenerator.ExposableValueTuple<Color, Color>> channel in originalHARComp.ColorChannels)
{
babyHARComp.OverwriteColorChannel(channel.Key, channel.Value.first, channel.Value.second);
}
babyHARComp.headMaskVariant = originalHARComp.headMaskVariant;
babyHARComp.bodyMaskVariant = originalHARComp.bodyMaskVariant;
}
public static void SetHARCrown(this Pawn pawn, string crown)
// 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)
{
pawn.GetHARComp().SetMemberValue("crownType", crown);
AlienPartGenerator.AlienComp babyHARComp = baby.GetHARComp();
AlienPartGenerator.AlienComp originalHARComp = 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);
}
}
}

View file

@ -238,6 +238,8 @@ namespace RJW_Menstruation
CopyBodyPartRecord(baby, original, Genital_Helper.get_genitalsBPR(baby), Genital_Helper.get_genitalsBPR(original));
CopyBodyPartRecord(baby, original, Genital_Helper.get_breastsBPR(baby), Genital_Helper.get_breastsBPR(original));
CopyBodyPartRecord(baby, original, Genital_Helper.get_anusBPR(baby), Genital_Helper.get_anusBPR(original));
if (baby.IsHAR())
HARCompatibility.CopyHARPropertiesPostBirth(baby, original);
}
public override void PostBirth(Pawn mother, Pawn father, Pawn baby)
@ -417,7 +419,6 @@ namespace RJW_Menstruation
int division = 1;
Pawn firstbaby = null;
string firstheadpath = null;
string firstHARcrown = null;
int traitSeed = Rand.Int;
List<Trait> parentTraits = GetInheritableTraits(mother, father);
while (Rand.Chance(Configurations.EnzygoticTwinsChance) && division < Configurations.MaxEnzygoticTwins) division++;
@ -442,10 +443,6 @@ namespace RJW_Menstruation
if (head != null) baby.story.SetMemberValue("headGraphicPath", head.GraphicPath);
firstheadpath = (string)baby.story.GetMemberValue("headGraphicPath");
}
if (Configurations.HARActivated && baby.IsHAR())
{
firstHARcrown = baby.GetHARCrown();
}
}
else
@ -456,9 +453,9 @@ namespace RJW_Menstruation
baby.story.crownType = firstbaby.story.crownType;
baby.story.SetMemberValue("headGraphicPath", firstheadpath);
if (Configurations.HARActivated && baby.IsHAR())
if (baby.IsHAR())
{
baby.SetHARCrown(firstHARcrown);
HARCompatibility.CopyHARProperties(baby, firstbaby);
}
}
}

View file

@ -89,6 +89,10 @@
<Compile Include="VariousDefOf.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="AlienRace">
<HintPath>..\..\..\..\..\..\..\..\workshop\content\294100\839005762\1.3\Assemblies\AlienRace.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>