Skip to content

Commit

Permalink
Added colorblind mode for LED Math & Conditional Buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
eXish authored and samfundev committed Aug 11, 2024
1 parent 56d6df8 commit 3adce0f
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Tweaks/TweaksAssembly/BombWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ Dictionary<string, object> makeEventInfo(string type)
{ "parliament", bombComponent => new ParliamentTweak(bombComponent) },
{ "ForeignExchangeRates", bombComponent => new ForeignExchangeRatesTweak(bombComponent) },
{ "Symbstructions", bombComponent => new SymbstructionsTweak(bombComponent) },
{ "lgndLEDMath", bombComponent => new LEDMathTweak(bombComponent) },
{ "conditionalButtons", bombComponent => new ConditionalButtonsTweak(bombComponent) },

{ "Wires", bombComponent => new WiresLogging(bombComponent) },
{ "Keypad", bombComponent => new KeypadLogging(bombComponent) }
Expand Down
65 changes: 65 additions & 0 deletions Tweaks/TweaksAssembly/Modules/Tweaks/ConditionalButtonsTweak.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Collections.Generic;
using UnityEngine;

class ConditionalButtonsTweak : ModuleTweak
{
private readonly Dictionary<string, string> colorblindChars = new Dictionary<string, string>()
{
{ "pink", "I" },
{ "orange", "O" },
{ "purple", "P" },
{ "white", "W" },
{ "blue", "B" },
{ "yellow", "Y" },
{ "light green", "LG" },
{ "red", "R" },
{ "black", "K" },
{ "dark green", "DG" }
};

private readonly List<GameObject> colorblindText = new List<GameObject>();

public ConditionalButtonsTweak(BombComponent bombComponent) : base(bombComponent, "conditionalButtons")
{
if (!ColorblindMode.IsActive("conditionalButtons"))
return;

UpdateColorblind();

foreach (var selectable in bombComponent.GetComponent<KMSelectable>().Children)
{
var previous = selectable.OnInteract;
selectable.OnInteract = () => {
previous();
foreach (var text in colorblindText)
text.SetActive(false);
return false;
};
}
}

private void UpdateColorblind()
{
void makeText(GameObject btn, string letter)
{
var text = new GameObject("ColorblindText");
text.transform.SetParent(btn.transform, false);
colorblindText.Add(text);

var mesh = text.AddComponent<TextMesh>();
mesh.transform.localPosition = new Vector3(0, 0, 0.0051f);
mesh.transform.localEulerAngles = new Vector3(0, 180, 180);
mesh.characterSize = letter.Length == 1 ? 0.0015f : 0.0013f;
mesh.fontSize = 80;
mesh.anchor = TextAnchor.MiddleCenter;
mesh.GetComponent<MeshRenderer>().sharedMaterial.shader = Shader.Find("GUI/KT 3D Text");

mesh.text = letter;
mesh.color = (letter == "K" || letter == "DG") ? Color.white : Color.black;
}

var buttons = bombComponent.GetComponent<KMSelectable>().Children;
for (int i = 0; i < buttons.Length; i++)
makeText(buttons[i].gameObject, colorblindChars[buttons[i].GetComponent<MeshRenderer>().material.name.Replace(" (Instance)", "")]);
}
}
54 changes: 54 additions & 0 deletions Tweaks/TweaksAssembly/Modules/Tweaks/LEDMathTweak.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using UnityEngine;

class LEDMathTweak : ModuleTweak
{
private readonly string[] colorblindChars = { "R", "B", "G", "Y" };

private readonly List<GameObject> colorblindText = new List<GameObject>();

public LEDMathTweak(BombComponent bombComponent) : base(bombComponent, "LEDMathScript")
{
if (!ColorblindMode.IsActive("lgndLEDMath"))
return;

UpdateColorblind();

bombComponent.OnPass += (_) => {
foreach (var text in colorblindText)
{
text.SetActive(false);
}
return false;
};
}

private void UpdateColorblind()
{
void makeText(GameObject led, string letter)
{
var text = new GameObject("ColorblindText");
text.transform.SetParent(led.transform, false);
colorblindText.Add(text);

var mesh = text.AddComponent<TextMesh>();
mesh.transform.localPosition = new Vector3(0, 0.501f, 0);
mesh.transform.localEulerAngles = new Vector3(90, 0, 0);
mesh.characterSize = 0.08f;
mesh.fontSize = 80;
mesh.anchor = TextAnchor.MiddleCenter;
mesh.GetComponent<MeshRenderer>().sharedMaterial.shader = Shader.Find("GUI/KT 3D Text");

mesh.text = letter;
mesh.color = Color.black;
}

var ledA = component.GetValue<MeshRenderer>("ledA").gameObject;
var ledB = component.GetValue<MeshRenderer>("ledB").gameObject;
var ledOp = component.GetValue<MeshRenderer>("ledOp").gameObject;
makeText(ledA, colorblindChars[component.GetValue<int>("ledAIndex")]);
makeText(ledB, colorblindChars[component.GetValue<int>("ledBIndex")]);
makeText(ledOp, colorblindChars[component.GetValue<int>("ledOpIndex")]);
}
}

0 comments on commit 3adce0f

Please sign in to comment.