Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Killface1980 committed Nov 8, 2017
1 parent 0254eb1 commit 9f49e7a
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 68 deletions.
Binary file modified Assemblies/FacialStuff.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions Defs/JobDefs/Clutter_Jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<driverClass>FacialStuff.FaceStyling_Bench.Job_FaceStyling</driverClass>
<reportString>Going to the styling station.</reportString>
</JobDef>

<!--
<JobDef>
<defName>ChangeAppearance</defName>
<driverClass>FacialStuff.FaceStyling_Bench.Job_FaceStylingJoy</driverClass>
Expand All @@ -17,5 +17,5 @@
<joyGainRate>1.2</joyGainRate>
<joyKind>Passive</joyKind>
</JobDef>

-->
</Defs>
14 changes: 7 additions & 7 deletions Source/RW_FacialStuff/CompFace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public string BrowTexPath([NotNull] BrowDef browDef)
}

// Can be called externally
public void CheckForAddedOrMissingParts(Pawn p)
public void CheckForAddedOrMissingParts([NotNull] Pawn p)
{
if (!Controller.settings.ShowExtraParts)
{
Expand Down Expand Up @@ -671,9 +671,9 @@ public Material MouthMatAt(Rot4 facing, bool portrait)
return material;
}

public bool PawnFaceIsNull()
public bool HasPawnFace()
{
return this.pawnFace == null;
return this.pawnFace != null;
}

public override void PostDraw()
Expand Down Expand Up @@ -909,10 +909,10 @@ private void InitializeGraphicsBeard()

private void InitializeGraphicsBrows()
{
Color color = this.pawn.story.hairColor * this.pawn.story.SkinColor * Color.gray;
Color color = this.pawn.story.hairColor * Color.gray;
this.faceGraphicPart.BrowGraphic = GraphicDatabase.Get<Graphic_Multi_NaturalHeadParts>(
this.texPathBrow,
ShaderDatabase.Cutout,
ShaderDatabase.CutoutSkin,
Vector2.one,
color);
}
Expand Down Expand Up @@ -1048,13 +1048,13 @@ private void InitializeGraphicsWrinkles()

this.faceGraphicPart.WrinkleGraphic = GraphicDatabase.Get<Graphic_Multi_NaturalHeadParts>(
pawnFaceWrinkleDef.texPath + "_" + this.PawnCrownType + "_" + this.PawnHeadType,
ShaderDatabase.TransparentPostLight,
ShaderDatabase.CutoutSkin,
Vector2.one,
wrinkleColor);

this.faceGraphicPart.RottingWrinkleGraphic = GraphicDatabase.Get<Graphic_Multi_NaturalHeadParts>(
pawnFaceWrinkleDef.texPath + "_" + this.PawnCrownType + "_" + this.PawnHeadType,
ShaderDatabase.TransparentPostLight,
ShaderDatabase.CutoutSkin,
Vector2.one,
wrinkleColor * FaceTextures.SkinRottingMultiplyColor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override IEnumerable<FloatMenuOption> GetFloatMenuOptions(Pawn pawn)
return new List<FloatMenuOption> { item2 };
}

if (pawn.TryGetComp<CompFace>() == null)
if (!pawn.HasFace())
{
FloatMenuOption item3 =
new FloatMenuOption("FacialStuffEditor.CannotUseNoFacePawn".Translate(pawn), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using FacialStuff.FaceStyling_Bench.UI.DTO.SelectionWidgetDTOs;
using FacialStuff.Genetics;
using FacialStuff.Graphics;
using FacialStuff.newStuff;
using FacialStuff.Utilities;

using JetBrains.Annotations;
Expand Down Expand Up @@ -193,7 +194,7 @@ static DialogFaceStyling()
public DialogFaceStyling(Pawn p)
{
pawn = p;
this.faceComp = pawn.TryGetComp<CompFace>();
pawn.GetFace(out this.faceComp);

this.hats = Prefs.HatsOnlyOnMap;
this.gear = Controller.settings.FilterHats;
Expand Down
28 changes: 15 additions & 13 deletions Source/RW_FacialStuff/Genetics/HairMelanin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using RimWorld;
using System.Collections.Generic;
using System.Linq;

using FacialStuff.newStuff;

using UnityEngine;
using Verse;

Expand Down Expand Up @@ -125,14 +128,17 @@ public static HairDNA GenerateHairMelaninAndCuticula(
// Special hair colors
float factionColor = Rand.Value;
float limit = 0.98f;
Faction faction = pawn.GetComp<CompFace>().originFaction;
if (faction.def.techLevel > TechLevel.Industrial)
if (pawn.GetFace(out CompFace face))
{
limit *= pawn.gender == Gender.Female ? 0.7f : 0.9f;
Faction faction = face.originFaction;
if (faction.def.techLevel > TechLevel.Industrial)
{
limit *= pawn.gender == Gender.Female ? 0.7f : 0.9f;

float techMod = (faction.def.techLevel - TechLevel.Industrial) / 5f;
SimpleCurve ageCure = new SimpleCurve { { 0.1f, 1f }, { 0.25f, 1f - techMod }, { 0.6f, 0.9f } };
limit *= ageCure.Evaluate(pawn.ageTracker.AgeBiologicalYears / 100f);
float techMod = (faction.def.techLevel - TechLevel.Industrial) / 5f;
SimpleCurve ageCure = new SimpleCurve { { 0.1f, 1f }, { 0.25f, 1f - techMod }, { 0.6f, 0.9f } };
limit *= ageCure.Evaluate(pawn.ageTracker.AgeBiologicalYears / 100f);
}
}

// if (pawn.story.hairDef.hairTags.Contains("Punk"))
Expand Down Expand Up @@ -199,13 +205,9 @@ private static bool GetHairDNAByBlood([NotNull] Pawn pawn, ref HairColorRequest
return false;
}

Pawn relPawn = pawn.relations.FamilyByBlood.Where(
x =>
{
// cuticula check to prevent old pawns with incomplete stats
CompFace compFace = x.TryGetComp<CompFace>();
return compFace != null && !compFace.PawnFaceIsNull();
}).FirstOrDefault();
Pawn relPawn =
pawn.relations.FamilyByBlood.FirstOrDefault(
x => pawn.GetFace(out CompFace face) && face.HasPawnFace());

PawnFace pawnFace = relPawn?.TryGetComp<CompFace>()?.PawnFace;
if (pawnFace == null)
Expand Down
71 changes: 37 additions & 34 deletions Source/RW_FacialStuff/Harmony/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace FacialStuff.Detouring
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;

using FacialStuff.newStuff;

using UnityEngine;
using Verse;
using Verse.Sound;
Expand Down Expand Up @@ -139,8 +142,7 @@ public static void AddFaceEditButton(Page_ConfigureStartingPawns __instance, Rec

Pawn pawn = (Pawn)PawnFieldInfo?.GetValue(__instance);

CompFace face = pawn.TryGetComp<CompFace>();
if (face == null)
if (!pawn.GetFace(out CompFace face))
{
return;
}
Expand Down Expand Up @@ -184,9 +186,7 @@ public static void DirtyCache_Postfix(HediffSet __instance)
{
return;
}

CompFace face = pawn.GetComp<CompFace>();
if (face == null)
if (!pawn.GetFace(out CompFace face))
{
return;
}
Expand Down Expand Up @@ -309,16 +309,19 @@ public static void TryInteractWith_Postfix(Pawn_InteractionsTracker __instance,

if (__result)
{
CompFace pawnFace = pawn.GetComp<CompFace>();
if (pawnFace != null && pawnFace.HeadRotator != null && !pawnFace.IsChild)
if (pawn.GetFace(out CompFace face))
{
pawnFace.HeadRotator.LookAtPawn(recipient);
if (face.HeadRotator != null && !face.IsChild)
{
face.HeadRotator.LookAtPawn(recipient);
}
}

CompFace recipientFace = recipient.GetComp<CompFace>();
if (recipientFace != null && recipientFace.HeadRotator != null && !recipientFace.IsChild)
if (recipient.GetFace(out CompFace recipientFace))
{
recipientFace.HeadRotator.LookAtPawn(pawn);
if ( recipientFace.HeadRotator != null && !recipientFace.IsChild)
{
recipientFace.HeadRotator.LookAtPawn(pawn);
}
}
}
}
Expand All @@ -328,15 +331,15 @@ private static void CheckAllInjected()
// Now to enjoy the benefits of having made a popular mod!
// This will be our little secret.
Backstory childMe = new Backstory
{
bodyTypeMale = BodyType.Male,
bodyTypeFemale = BodyType.Female,
slot = BackstorySlot.Childhood,
baseDesc =
{
bodyTypeMale = BodyType.Male,
bodyTypeFemale = BodyType.Female,
slot = BackstorySlot.Childhood,
baseDesc =
"NAME never believed what was common sense and always doubted other people. HECAP later went on inflating toads with HIS sushi stick. It was there HE earned HIS nickname.",
requiredWorkTags = WorkTags.Violent,
shuffleable = false
};
requiredWorkTags = WorkTags.Violent,
shuffleable = false
};
childMe.SetTitle("Lost child");
childMe.SetTitleShort("Seeker");
childMe.skillGains.Add("Shooting", 4);
Expand All @@ -346,15 +349,15 @@ private static void CheckAllInjected()
childMe.ResolveReferences();

Backstory adultMale = new Backstory
{
bodyTypeMale = BodyType.Male,
bodyTypeFemale = BodyType.Female,
slot = BackstorySlot.Adulthood,
baseDesc =
{
bodyTypeMale = BodyType.Male,
bodyTypeFemale = BodyType.Female,
slot = BackstorySlot.Adulthood,
baseDesc =
"HECAP left the military early on and acquired his skills on his own. HECAP doesn't like doctors, thus HECAP prefers to tend his wounds himself.",
shuffleable = false,
spawnCategories = new List<string>()
};
shuffleable = false,
spawnCategories = new List<string>()
};
adultMale.spawnCategories.AddRange(new[] { "Civil", "Raider", "Slave", "Trader", "Traveler" });
adultMale.SetTitle("Lone gunman");
adultMale.SetTitleShort("Gunman");
Expand All @@ -366,12 +369,12 @@ private static void CheckAllInjected()
adultMale.ResolveReferences();

PawnBio me = new PawnBio
{
childhood = childMe,
adulthood = adultMale,
gender = GenderPossibility.Male,
name = NameTriple.FromString("Gator 'Killface' Stinkwater")
};
{
childhood = childMe,
adulthood = adultMale,
gender = GenderPossibility.Male,
name = NameTriple.FromString("Gator 'Killface' Stinkwater")
};
me.PostLoad();
SolidBioDatabase.allBios.Add(me);
BackstoryDatabase.AddBackstory(childMe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EdB.PrepareCarefully;

using FacialStuff.FaceStyling_Bench;
using FacialStuff.newStuff;

using global::Harmony;

Expand All @@ -20,8 +21,8 @@ public static void AddFaceEditButton(PanelBackstory __instance, State state)
{
Rect panelRect = __instance.PanelRect;
Pawn pawn = state.CurrentPawn.Pawn;
CompFace face = pawn.TryGetComp<CompFace>();
if (face == null)

if (!pawn.HasFace())
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using EdB.PrepareCarefully;
using global::Harmony;
using System.Linq;

using FacialStuff.newStuff;

using Verse;

public static class PresetLoader_Postfix
Expand All @@ -16,7 +19,7 @@ public static void LoadFace(ref CustomPawn __result, SaveRecordPawnV3 record)
}

Pawn pawn = __result.Pawn;
if (pawn?.TryGetComp<CompFace>() == null)
if (!pawn.HasFace())
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using global::Harmony;
using System.Collections.Generic;
using System.Linq;

using FacialStuff.newStuff;

using Verse;

public static class SaveRecordPawnV3_Postfix
Expand All @@ -21,7 +24,7 @@ public static void ExposeFaceData(SaveRecordPawnV3 __instance)
if (SavedPawns.Keys.Contains(__instance.id) && Scribe.mode == LoadSaveMode.Saving)
{
CustomPawn customPawn = SavedPawns[__instance.id] as CustomPawn;
if (customPawn?.Pawn.TryGetComp<CompFace>() == null)
if (!customPawn?.Pawn.HasFace() == true)
{
return;
}
Expand Down
8 changes: 4 additions & 4 deletions Source/RW_FacialStuff/Harmony/optional/Werewolf_Patches.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace FacialStuff.Harmony.optional
{
using FacialStuff.newStuff;

using Verse;

using Werewolf;
Expand All @@ -8,8 +10,7 @@ public class Werewolf_Patches
{
public static void TransformBack_Postfix(CompWerewolf __instance)
{
CompFace face = __instance.Pawn.TryGetComp<CompFace>();
if (face == null)
if (!__instance.Pawn.GetFace(out CompFace face))
{
return;
}
Expand All @@ -20,8 +21,7 @@ public static void TransformBack_Postfix(CompWerewolf __instance)

public static void TransformInto_Prefix(CompWerewolf __instance)
{
CompFace face = __instance.Pawn.TryGetComp<CompFace>();
if (face != null)
if (__instance.Pawn.GetFace(out CompFace face))
{
face.DontRender = true;
}
Expand Down
5 changes: 4 additions & 1 deletion Source/RW_FacialStuff/ITab_Pawn_Face.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using RimWorld;
using System.Collections.Generic;
using System.Linq;

using FacialStuff.newStuff;

using UnityEngine;
using Verse;

Expand Down Expand Up @@ -407,7 +410,7 @@ protected override void FillTab()
delegate
{
foreach (Pawn pawn in Find.VisibleMap.mapPawns.AllPawnsSpawned.Where(
x => x.GetComp<CompFace>() != null))
x => x.HasFace()))
{
Color color = Color.white;
CompFace face = pawn.GetComp<CompFace>();
Expand Down
8 changes: 7 additions & 1 deletion Source/RW_FacialStuff/newStuff/Class2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ namespace FacialStuff.newStuff

public static class Class2
{
public static bool GetFace([NotNull] this Pawn pawn, [CanBeNull] out CompFace face)
public static bool GetFace([NotNull] this Pawn pawn, [NotNull] out CompFace face)
{
face = pawn.GetComp<CompFace>();
return face != null;
}

public static bool HasFace([CanBeNull] this Pawn pawn)
{
CompFace face = pawn?.GetComp<CompFace>();
return face != null;
}
}
}

0 comments on commit 9f49e7a

Please sign in to comment.