Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions SwitchMaster/Assets/KMColorblindMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using UnityEngine;

public class KMColorblindMode : MonoBehaviour
{
[SerializeField]
private bool _colorblindMode = false;

public bool ColorblindModeActive
{
get
{
if (Application.isEditor)
return _colorblindMode;

string key = null;

KMBombModule bombModule = GetComponent<KMBombModule>();
KMNeedyModule needyModule = GetComponent<KMNeedyModule>();

if (bombModule != null)
key = bombModule.ModuleType;
else if (needyModule != null)
key = needyModule.ModuleType;
else
key = Regex.Replace(gameObject.name, @"\(Clone\)$", "");

try
{
var settingsPath = Path.Combine(Path.Combine(Application.persistentDataPath, "Modsettings"), "ColorblindMode.json");

ColorblindModeSettings settings = new ColorblindModeSettings();
if (File.Exists(settingsPath))
settings = JsonConvert.DeserializeObject<ColorblindModeSettings>(File.ReadAllText(settingsPath));

bool? isEnabled = null;
if (!string.IsNullOrEmpty(key) && !settings.EnabledModules.TryGetValue(key, out isEnabled))
settings.EnabledModules[key] = null;

File.WriteAllText(settingsPath, JsonConvert.SerializeObject(settings, Formatting.Indented));
return isEnabled ?? settings.Enabled;
}
catch (Exception e)
{
Debug.LogFormat(@"[Colorblind Mode] Error in ""{0}"": {1} ({2})\n{3}", key ?? "<null>", e.Message, e.GetType().FullName, e.StackTrace);
return false;
}
}
}
}

internal class ColorblindModeSettings
{
public bool Enabled = false;
public Dictionary<string, bool?> EnabledModules = new Dictionary<string, bool?>();
}
11 changes: 11 additions & 0 deletions SwitchMaster/Assets/KMColorblindMode.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions SwitchMaster/Assets/The Switch/CBTextMat.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: CBTextMat
m_Shader: {fileID: 4800000, guid: 306ffc165961a2c40806bad3bb861c43, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: b56500c841d890348ad8a3a72d2e7588, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
8 changes: 8 additions & 0 deletions SwitchMaster/Assets/The Switch/CBTextMat.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
22 changes: 22 additions & 0 deletions SwitchMaster/Assets/The Switch/OstrichSans-Heavy_90.otf.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 34 additions & 4 deletions SwitchMaster/Assets/The Switch/Switch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,29 @@ public class Switch : MonoBehaviour
public KMBombInfo BombInfo;
public KMBombModule BombModule;
public KMAudio KMAudio;
public KMColorblindMode CBMode;
public KMSelectable FlipperSelectable;
public Transform FlipperPosition;
public MeshRenderer TopLED;
public MeshRenderer BottomLED;
public TextMesh TopCBText;
public TextMesh BottomCBText;

protected string TopName = "none";
protected string BottomName = "none";
protected bool SOLVED = false;
protected bool FlipperDown = false;
protected bool FirstSuccess = false;
protected bool InitMove = true;
protected bool FlipperMoving = false;
protected bool CBEnabled = false;
protected int BottomColor;
protected int TopColor;
protected int TimerSeconds1;
protected int TimerSeconds2;
protected int NeededNumber;

private string TwitchHelpMessage = "Use !{0} flip 5 to flip when the seconds digits of the timer contains 5";
private string TwitchHelpMessage = "Use !{0} flip 5 to flip when the seconds digits of the timer contains 5. Use !{0} colorblind to toggle colorblind mode.";

System.Collections.IEnumerator ProcessTwitchCommand(string command)
{
Expand All @@ -41,14 +47,29 @@ System.Collections.IEnumerator ProcessTwitchCommand(string command)
{
while (TimerSeconds1 != PressOn && TimerSeconds2 != PressOn)
{
yield return null;
yield return "trycancel";
}
yield return FlipperSelectable;
yield return null;
yield return FlipperSelectable;
yield break;
}
}
else if (Regex.IsMatch(LowerCommand, @"\s*colorblind|colourblind|cb\s*$"))
{
yield return null;
CBEnabled = !CBEnabled;
if (CBEnabled)
{
TopCBText.text = TopName[0].ToString();
BottomCBText.text = BottomName[0].ToString();
}
else
{
TopCBText.text = "";
BottomCBText.text = "";
}
}
yield break;
}

Expand Down Expand Up @@ -95,8 +116,6 @@ protected void ModuleInit()
TopColor = UnityEngine.Random.Range(1, 7);
BottomColor = UnityEngine.Random.Range(1, 7);

string TopName = "none";
string BottomName = "none";
Color Orange = new Color(1f, 0.5f, 0f);
Color Purple = new Color(0.75f, 0f, 0.75f);
int RuleNumber;
Expand Down Expand Up @@ -222,11 +241,21 @@ protected void ModuleInit()

if (SOLVED)
{
if (CBEnabled)
{
TopCBText.text = "";
BottomCBText.text = "";
}
BottomLED.material.color = Color.black;
TopLED.material.color = Color.black;
}
else
{
if (CBEnabled)
{
TopCBText.text = TopName[0].ToString();
BottomCBText.text = BottomName[0].ToString();
}
DebugLog("Switch is {0}. Top LED is {1}, bottom LED is {2}", FlipperDown ? "down" : "up", TopName, BottomName);
DebugLog("Rule is {0}, number needed is {1}", RuleNumber.ToString(), NeededNumber.ToString());
}
Expand All @@ -235,6 +264,7 @@ protected void ModuleInit()

protected void Start()
{
CBEnabled = CBMode.ColorblindModeActive;
int FlipInt = UnityEngine.Random.Range(0, 2);
if (FlipInt == 1)
{
Expand Down
Loading