Skip to content

Commit

Permalink
regenerate color channels and minor logic fix for previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
erdelf committed Aug 27, 2020
1 parent ddf2e94 commit 5030bb1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
Binary file modified 1.2/Assemblies/AlienRace.dll
Binary file not shown.
68 changes: 43 additions & 25 deletions Source/AlienRace/AlienRace/AlienPartGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,31 @@ public class ColorChannelGenerator

public class AlienComp : ThingComp
{
public bool fixGenderPostSpawn;
public string crownType;
public Vector2 customDrawSize = Vector2.one;
public Vector2 customHeadDrawSize = Vector2.one;
public Vector2 customPortraitDrawSize = Vector2.one;
public Vector2 customPortraitHeadDrawSize = Vector2.one;
public bool fixGenderPostSpawn;
public string crownType;
public Vector2 customDrawSize = Vector2.one;
public Vector2 customHeadDrawSize = Vector2.one;
public Vector2 customPortraitDrawSize = Vector2.one;
public Vector2 customPortraitHeadDrawSize = Vector2.one;
public AlienGraphicMeshSet alienGraphics;
public AlienGraphicMeshSet alienHeadGraphics;
public AlienGraphicMeshSet alienPortraitGraphics;
public AlienGraphicMeshSet alienPortraitHeadGraphics;
public List<Graphic> addonGraphics;
public List<int> addonVariants;
public List<Graphic> addonGraphics;
public List<int> addonVariants;

private Dictionary<string, ExposableValueTuple<Color, Color>> colorChannels;

public Dictionary<string, ExposableValueTuple<Color, Color>> ColorChannels
{
get
{
if (this.colorChannels == null)
if (this.colorChannels == null || !this.colorChannels.Any())
{
this.colorChannels = new Dictionary<string, ExposableValueTuple<Color, Color>>();
Pawn pawn = (Pawn)this.parent;
ThingDef_AlienRace alienProps = ((ThingDef_AlienRace)this.parent.def);
AlienPartGenerator apg = alienProps.alienRace.generalSettings.alienPartGenerator;
Pawn pawn = (Pawn) this.parent;
ThingDef_AlienRace alienProps = ((ThingDef_AlienRace) this.parent.def);
AlienPartGenerator apg = alienProps.alienRace.generalSettings.alienPartGenerator;

this.colorChannels.Add("base", new ExposableValueTuple<Color, Color>(Color.white, Color.white));
this.colorChannels.Add("hair", new ExposableValueTuple<Color, Color>(Color.clear, Color.clear));
Expand All @@ -180,33 +180,40 @@ public Dictionary<string, ExposableValueTuple<Color, Color>> ColorChannels

foreach (ColorChannelGenerator channel in apg.colorChannels)
{
if(!this.colorChannels.ContainsKey(channel.name))
if (!this.colorChannels.ContainsKey(channel.name))
this.colorChannels.Add(channel.name, new ExposableValueTuple<Color, Color>(Color.white, Color.white));
ExposableValueTuple<Color, Color> colors = this.colorChannels[channel.name];
if(channel.first != null)
if (channel.first != null)
colors.first = this.GenerateColor(channel.first);
if (channel.second != null)
colors.second = this.GenerateColor(channel.second);
}

ExposableValueTuple<Color, Color> hairColors = this.colorChannels["hair"];
if (hairColors.first == Color.clear)
{
Color color = PawnHairColors.RandomHairColor(pawn.story.SkinColor, pawn.ageTracker.AgeBiologicalYears);
hairColors.first = color;
hairColors.first = color;
hairColors.second = color;
}

pawn.story.hairColor = hairColors.first;

if (alienProps.alienRace.hairSettings.getsGreyAt <= pawn.ageTracker.AgeBiologicalYears)
{
if (Rand.Value < GenMath.SmootherStep(alienProps.alienRace.hairSettings.getsGreyAt, pawn.RaceProps.ageGenerationCurve.Points.Count < 3 ? alienProps.alienRace.hairSettings.getsGreyAt + 35 : pawn.RaceProps.ageGenerationCurve.Points.Skip(pawn.RaceProps.ageGenerationCurve.Points.Count - 3).First().x, pawn.ageTracker.AgeBiologicalYears))
if (Rand.Value < GenMath.SmootherStep(alienProps.alienRace.hairSettings.getsGreyAt,
pawn.RaceProps.ageGenerationCurve.Points.Count < 3
? alienProps.alienRace.hairSettings.getsGreyAt + 35
: pawn.RaceProps.ageGenerationCurve.Points.Skip(pawn.RaceProps.ageGenerationCurve.Points.Count - 3).First().x,
pawn.ageTracker.AgeBiologicalYears))
{
float grey = Rand.Range(min: 0.65f, max: 0.85f);
pawn.story.hairColor = new Color(r: grey, g: grey, b: grey);
hairColors.first = pawn.story.hairColor;
hairColors.first = pawn.story.hairColor;
}
}
}

return this.colorChannels;
}
}
Expand All @@ -227,31 +234,42 @@ public override void PostSpawnSetup(bool respawningAfterLoad)
{
base.PostSpawnSetup(respawningAfterLoad: respawningAfterLoad);
AlienPartGenerator apg = ((ThingDef_AlienRace) this.parent.def).alienRace.generalSettings.alienPartGenerator;
this.customDrawSize = apg.customDrawSize;
this.customHeadDrawSize = apg.customHeadDrawSize;
this.customPortraitDrawSize = apg.customPortraitDrawSize;
this.customDrawSize = apg.customDrawSize;
this.customHeadDrawSize = apg.customHeadDrawSize;
this.customPortraitDrawSize = apg.customPortraitDrawSize;
this.customPortraitHeadDrawSize = apg.customPortraitHeadDrawSize;
}

public override void PostExposeData()
{
base.PostExposeData();
Scribe_Values.Look(value: ref this.fixGenderPostSpawn, label: "fixAlienGenderPostSpawn");
Scribe_Values.Look(value: ref this.crownType, label: "crownType");
Scribe_Values.Look(value: ref this.crownType, label: "crownType");
Scribe_Collections.Look(list: ref this.addonVariants, label: "addonVariants");
Scribe_Collections.Look(dict: ref this.colorChannels, label: "colorChannels");
}

public ExposableValueTuple<Color, Color> GetChannel(string channel) =>
public ExposableValueTuple<Color, Color> GetChannel(string channel) =>
this.ColorChannels[channel];

internal void AssignProperMeshs()
{
this.alienGraphics = meshPools[key: this.customDrawSize];
this.alienHeadGraphics = meshPools[key: this.customHeadDrawSize];
this.alienPortraitGraphics = meshPools[key: this.customPortraitDrawSize];
this.alienGraphics = meshPools[key: this.customDrawSize];
this.alienHeadGraphics = meshPools[key: this.customHeadDrawSize];
this.alienPortraitGraphics = meshPools[key: this.customPortraitDrawSize];
this.alienPortraitHeadGraphics = meshPools[key: this.customPortraitHeadDrawSize];
}

[DebugAction("AlienRace", "Regenerate all colorchannels", allowedGameStates = AllowedGameStates.PlayingOnMap)]
private static void RegenerateColorchannels()
{
foreach (Pawn pawn in Find.CurrentMap.mapPawns.AllPawns)
{
AlienComp comp = pawn.TryGetComp<AlienComp>();
if (comp != null)
comp.colorChannels = null;
}
}
}

public class ExposableValueTuple<K, V> : IExposable
Expand Down

0 comments on commit 5030bb1

Please sign in to comment.