Skip to content

Commit

Permalink
Refactor hands visibility logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicguru committed Feb 14, 2024
1 parent a80cad6 commit 6e38fa2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Source/ThingGenerator/AMSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,6 @@ public class Settings : SimpleSettingsBase
"You can opt out of this functionality by disabling this option.\nNote: logging does not occur the first time you run the game with this mod.")]
public bool SendStatistics = true;

public bool TrailsAreDisabled => TrailColor.a <= 0 || TrailLengthScale <= 0;

[NonSerialized]
public bool IsFirstTimeRunning = true;
#endregion
Expand Down
32 changes: 24 additions & 8 deletions Source/ThingGenerator/AnimRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,24 +1321,40 @@ private void ConfigureHandsForPawn(Pawn pawn, int index)
var handsMode = tweak?.HandsMode ?? HandsMode.Default;

// Hands and skin color...
string mainHandName = $"HandA{(index > 0 ? (index + 1) : "")}";
string altHandName = $"HandB{(index > 0 ? (index + 1) : "")}";
string mainHandName = $"HandA{(index > 0 ? index + 1 : "")}";
string altHandName = $"HandB{(index > 0 ? index + 1 : "")}";

Color skinColor = pawn.story?.SkinColor ?? Color.white;

// Hand visibility uses the animation data first and foremost, and if the animation does
// not care about hand visibility, then it is dictated by the weapon.
var vis = Def.GetHandsVisibility(index);

/*
* Order of descending priority for deciding what hand(s) to show:
* - Mod settings.
* - Has hands (humanoids only).
* - Animation requirement.
* - Weapon requirement.
*/

// Settings:
bool settingsShowHands = Core.Settings.ShowHands;

// Humanoid?
bool isHumanoid = pawn.RaceProps.Humanlike;

// Animation requirement.
bool? animMainHand = vis.showMainHand;
if (animMainHand != null && !pawn.RaceProps.Humanlike)
animMainHand = null;
bool? animAltHand = vis.showAltHand;
if (animAltHand != null && !pawn.RaceProps.Humanlike)
animAltHand = null;

bool showMain = Core.Settings.ShowHands && (animMainHand ?? (weapon != null && handsMode != HandsMode.No_Hands));
bool showAlt = Core.Settings.ShowHands && (animAltHand ?? (weapon != null && handsMode == HandsMode.Default));
// Weapon requirement:
bool? weaponMainHand = weapon == null ? null : handsMode != HandsMode.No_Hands;
bool? weaponAltHand = weapon == null ? null : handsMode == HandsMode.Default;

// Final calculation:
bool showMain = settingsShowHands && isHumanoid && (animMainHand ?? weaponMainHand ?? false);
bool showAlt = settingsShowHands && isHumanoid && (animAltHand ?? weaponAltHand ?? false);

// Apply main hand.
var mainHandPart = GetPart(mainHandName);
Expand Down

0 comments on commit 6e38fa2

Please sign in to comment.