Skip to content

Commit

Permalink
last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigma88 committed Nov 18, 2017
1 parent 17e5923 commit fd9c9ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
27 changes: 12 additions & 15 deletions [Source]/SigmaReplacements/Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,59 +272,56 @@ internal static Sprite SetTexture(this Sprite sprite, Texture newTex, bool fit =
return Sprite.Create((Texture2D)newTex, rect, pivot);
}

internal static Color? At(this List<Color?> list, Color? element, List<Color?> reference, ProtoCrewMember kerbal, bool useGameSeed)
internal static Color? At(this List<Color?> list, Color? element, List<Color?> reference, ProtoCrewMember kerbal, bool useGameSeed, string name = "")
{
if (reference.Contains(element) && list?.Count > reference.IndexOf(element))
return list[reference.IndexOf(element)];
else
return list.Pick(kerbal, useGameSeed);
return list.Pick(kerbal, useGameSeed, name);
}

internal static Texture At(this List<Texture> list, Texture element, List<Texture> reference, ProtoCrewMember kerbal, bool useGameSeed)
internal static Texture At(this List<Texture> list, Texture element, List<Texture> reference, ProtoCrewMember kerbal, bool useGameSeed, string name = "")
{
if (reference.Contains(element) && list?.Count > reference.IndexOf(element))
return list[reference.IndexOf(element)];
else
return list.Pick(kerbal, useGameSeed);
return list.Pick(kerbal, useGameSeed, name);
}

internal static Vector2? At(this List<Vector2?> list, Texture element, List<Texture> reference, ProtoCrewMember kerbal, bool useGameSeed, string name = "")
{
if (reference.Contains(element) && list?.Count > reference.IndexOf(element))
return list[reference.IndexOf(element)];
else
return list.Pick(kerbal, useGameSeed);
return list.Pick(kerbal, useGameSeed, name);
}

internal static Texture Pick(this List<Texture> list, ProtoCrewMember kerbal, bool useGameSeed, string name = "")
{
if (list?.Count > 1 && kerbal != null)
return list[kerbal.Hash(useGameSeed) % list.Count];
else if (list?.Count > 0)
{
UnityEngine.Debug.Log("SigmaLog: GET HASH FROM NAME = " + name + " > " + (name.Hash(useGameSeed) % list.Count) + " > AVAILABLE ITEMS = " + list?.Count);
return list[name.Hash(useGameSeed) % list.Count];
}
else
return null;
}

internal static Color? Pick(this List<Color?> list, ProtoCrewMember kerbal, bool useGameSeed, string name = "")
{
if (list.Count > 1 && kerbal != null)
if (list?.Count > 1 && kerbal != null)
return list[kerbal.Hash(useGameSeed) % list.Count];
else if (list.Count > 0)
return list[Math.Abs(name.GetHashCode()) % list.Count];
else if (list?.Count > 0)
return list[name.Hash(useGameSeed) % list.Count];
else
return null;
}

internal static Vector2? Pick(this List<Vector2?> list, ProtoCrewMember kerbal, bool useGameSeed)
internal static Vector2? Pick(this List<Vector2?> list, ProtoCrewMember kerbal, bool useGameSeed, string name = "")
{
if (list.Count > 1 && kerbal != null)
if (list?.Count > 1 && kerbal != null)
return list[kerbal.Hash(useGameSeed) % list.Count];
else if (list.Count > 0)
return list[0];
else if (list?.Count > 0)
return list[name.Hash(useGameSeed) % list.Count];
else
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion [Source]/SigmaReplacements/Navigation/CustomNavBall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal void Pick(NavBallInfo info, ProtoCrewMember kerbal = null, string name
FrameTex = FrameTex ?? info.FrameTex.Pick(kerbal, info.useGameSeed, name);
FrameTexRes = FrameTexRes ?? info.FrameTexRes.At(FrameTex, info.FrameTex, kerbal, info.useGameSeed, name);
IVAbaseTex = IVAbaseTex ?? info.IVAbaseTex.Pick(kerbal, info.useGameSeed, name);
IVAemissiveTex = IVAemissiveTex ?? info.IVAemissiveTex.Pick(kerbal, info.useGameSeed, name);
IVAemissiveTex = IVAemissiveTex ?? info.IVAemissiveTex.At(NavBallTex, info.NavBallTex, kerbal, info.useGameSeed, name);
IVAprogradeTex = IVAprogradeTex ?? info.IVAprogradeTex.Pick(kerbal, info.useGameSeed, name);
}

Expand Down

0 comments on commit fd9c9ce

Please sign in to comment.